Skip to content

Commit

Permalink
Merge pull request #366 from ethereum/simplified-copyslice
Browse files Browse the repository at this point in the history
A fairly regular `CopySlice` simplification
  • Loading branch information
msooseth authored Sep 7, 2023
2 parents 5981ec3 + 7a6b43e commit 79d7a75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Contract balances can now be fully symbolic
- Contract code can now be fully abstract. Calls into contracts with unknown code will fail with `UnexpectedSymbolicArg`.
- Run expression simplification on branch conditions
- CopySlice+WriteWord+ConcreteBuf now truncates ConcreteBuf in special cases
- Better simplification of Eq IR elements

## API Changes
Expand Down
11 changes: 11 additions & 0 deletions src/EVM/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,17 @@ simplify e = if (mapExpr go e == e)
go (WriteWord a b c) = writeWord a b c

go (WriteByte a b c) = writeByte a b c

-- truncate some concrete source buffers to the portion relevant for the CopySlice if we're copying a fully concrete region
go orig@(CopySlice srcOff@(Lit n) dstOff size@(Lit sz)
-- It doesn't matter what wOffs we write to, because only the first
-- n+sz of ConcreteBuf will be used by CopySlice
(WriteWord wOff value (ConcreteBuf buf)) dst)
-- Let's not deal with overflow
| n+sz >= n && n+sz >= sz = (CopySlice srcOff dstOff size
(WriteWord wOff value (ConcreteBuf simplifiedBuf)) dst)
| otherwise = orig
where simplifiedBuf = BS.take (unsafeInto (n+sz)) buf
go (CopySlice a b c d f) = copySlice a b c d f

go (IndexWord a b) = indexWord a b
Expand Down

0 comments on commit 79d7a75

Please sign in to comment.