Skip to content

Commit

Permalink
Merge pull request #411 from ethereum/fixing-mem-explode
Browse files Browse the repository at this point in the history
Fixing mem explosion issue
  • Loading branch information
msooseth authored Oct 18, 2023
2 parents 6f4ed8b + 10a1e79 commit c4174c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CopySlice+WriteWord+ConcreteBuf now truncates ConcreteBuf in special cases
- Better simplification of Eq IR elements
- Run a toplevel constant folding reasoning system on branch conditions
- Mem explosion in `writeWord` function was possible in case `offset` was close to 2^256. Fixed.

## API Changes

Expand Down
6 changes: 3 additions & 3 deletions src/EVM/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ writeByte offset byte src = WriteByte offset byte src

writeWord :: Expr EWord -> Expr EWord -> Expr Buf -> Expr Buf
writeWord o@(Lit offset) (WAddr (LitAddr val)) b@(ConcreteBuf _)
| offset + 32 < maxBytes
| offset < maxBytes && offset + 32 < maxBytes
= writeWord o (Lit $ into val) b
writeWord (Lit offset) (Lit val) (ConcreteBuf "")
| offset + 32 < maxBytes
| offset < maxBytes && offset + 32 < maxBytes
= ConcreteBuf $ BS.replicate (unsafeInto offset) 0 <> word256Bytes val
writeWord o@(Lit offset) v@(Lit val) buf@(ConcreteBuf src)
| offset + 32 < maxBytes
| offset < maxBytes && offset + 32 < maxBytes
= ConcreteBuf $ (padRight (unsafeInto offset) $ BS.take (unsafeInto offset) src)
<> word256Bytes val
<> BS.drop ((unsafeInto offset) + 32) src
Expand Down

0 comments on commit c4174c5

Please sign in to comment.