Skip to content

Commit

Permalink
Merge pull request #570 from ethereum/fix-bug-in-equivalence-checking
Browse files Browse the repository at this point in the history
Fix bug in SMT encoding of reading multiple consecutive bytes
  • Loading branch information
msooseth authored Oct 1, 2024
2 parents e6fd219 + d585de4 commit 32595ae
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Multi-threaded running of Tracing.hs was not possible due to IO race. Fixed.
- Fixed multi-threading bug in symbolic interpretation
- Fixed simplification of concrete CopySlice with destination offset beyond destination size
- Fixed a bug in our SMT encoding of reading multiple consecutive bytes from concrete index

## [0.53.0] - 2024-02-23

Expand Down
7 changes: 2 additions & 5 deletions src/EVM/SMT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,9 @@ assertReads :: [Prop] -> BufEnv -> StoreEnv -> [Prop]
assertReads props benv senv = concatMap assertRead allReads
where
assertRead :: (Expr EWord, Expr EWord, Expr Buf) -> [Prop]
assertRead (_, Lit 0, _) = []
assertRead (idx, Lit 32, buf) = [PImpl (PGEq idx (bufLength buf)) (PEq (ReadWord idx buf) (Lit 0))]
assertRead (idx, Lit sz, buf) =
fmap
-- TODO: unsafeInto instead fromIntegral here makes symbolic tests fail
(PImpl (PGEq idx (bufLength buf)) . PEq (ReadByte idx buf) . LitByte . fromIntegral)
[(0::Int)..unsafeInto sz-1]
assertRead (idx, Lit sz, buf) = [PImpl (PGEq (Expr.add idx $ Lit offset) (bufLength buf)) (PEq (ReadByte (Expr.add idx $ Lit offset) buf) (LitByte 0)) | offset <- [(0::W256).. sz-1]]
assertRead (_, _, _) = internalError "Cannot generate assertions for accesses of symbolic size"

allReads = filter keepRead $ nubOrd $ findBufferAccess props <> findBufferAccess (Map.elems benv) <> findBufferAccess (Map.elems senv)
Expand Down
2 changes: 1 addition & 1 deletion test/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ tests = testGroup "hevm"
b = Expr.simplify a
ret <- checkEquiv a b
assertBoolM "must be equivalent" ret
, ignoreTest $ test "read-beyond-bound (negative-test)" $ do
, test "read-beyond-bound (negative-test)" $ do
let
e1 = CopySlice (Lit 1) (Lit 0) (Lit 2) (ConcreteBuf "a") (ConcreteBuf "")
e2 = ConcreteBuf "Definitely not the same!"
Expand Down

0 comments on commit 32595ae

Please sign in to comment.