ethereum / solidity-examples

Loose collection of Solidity example code
MIT License
532 stars 161 forks source link

Fix out of memory bound issue of Memory.copy() #58

Open qizhou opened 2 years ago

qizhou commented 2 years ago

The original implementation assumes the memory size >= max(src, dest) + ROUND_UP(len, 32), which is not always true (and result in unexpected revert).

The new implement will use reverse copy so that no out-of-copy memory will be touched (and also simplified the mask so that out-of-copy memory is unchanged).