File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed
Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232- Dumping of END states (.prop) files is now default for ` --debug `
3333- When cheatcode is missing, we produce a partial execution warning
3434- Size of calldata can be up to 2** 64, not 256. This is now reflected in the documentation
35+ - Zero-length buffers actually imply all-zero buffer, and vica-versa. This
36+ was assumed but not encoded. Fixed.
3537
3638## Changed
3739- Warnings now lead printing FAIL. This way, users don't accidentally think that
Original file line number Diff line number Diff line change @@ -420,12 +420,20 @@ discoverMaxReads props benv senv = bufMap
420420
421421-- | Returns an SMT2 object with all buffers referenced from the input props declared, and with the appropriate cex extraction metadata attached
422422declareBufs :: [Prop ] -> BufEnv -> StoreEnv -> SMT2
423- declareBufs props bufEnv storeEnv = SMT2 (" ; buffers" : fmap declareBuf allBufs <> (" ; buffer lengths" : fmap declareLength allBufs)) cexvars mempty
423+ declareBufs props bufEnv storeEnv =
424+ SMT2 (smtBufNames <> smtBufLengths <> smtEmptyRelations) cexvars mempty
424425 where
426+ smtBufNames = " ; buffers" : fmap declareBuf allBufs
427+ smtBufLengths = " ; buffer lengths" : fmap declareLength allBufs
428+ smtEmptyRelations = " ; empty buffer relations" : concatMap emptyRelation allBufs
425429 cexvars = (mempty :: CexVars ){ buffers = discoverMaxReads props bufEnv storeEnv }
426430 allBufs = fmap fromLazyText $ Map. keys cexvars. buffers
427431 declareBuf n = " (declare-fun " <> n <> " () (Array (_ BitVec 256) (_ BitVec 8)))"
428432 declareLength n = " (declare-fun " <> n <> " _length" <> " () (_ BitVec 256))"
433+ emptyRelation buf =
434+ let bufLen = buf <> " _length"
435+ in [" (assert (=> (= " <> bufLen <> " (_ bv0 256)) (= " <> buf <> " ((as const Buf) #b00000000)) ))"
436+ , " (assert (=> (= " <> buf <> " ((as const Buf) #b00000000)) (= " <> bufLen <> " (_ bv0 256)) ))" ]
429437
430438-- Given a list of variable names, create an SMT2 object with the variables declared
431439declareVars :: [Builder ] -> SMT2
Original file line number Diff line number Diff line change @@ -515,6 +515,13 @@ tests = testGroup "hevm"
515515 let e = BufLength (CopySlice (Lit 0x2 ) (Lit 0x2 ) (Lit 0x1 ) (ConcreteBuf " " ) (ConcreteBuf " " ))
516516 b <- checkEquiv e (Expr. simplify e)
517517 assertBoolM " Simplifier failed" b
518+ , test " simp-empty-buflength" $ do
519+ let e = PEq (BufLength (AbstractBuf " mybuf" )) (Lit 0 )
520+ let simp = Expr. simplifyProp e
521+ let simpExpected = PEq (AbstractBuf " mybuf" ) (ConcreteBuf " " )
522+ assertEqualM " buflen-to-empty" simp simpExpected
523+ ret <- checkEquivPropAndLHS e simpExpected
524+ assertBoolM " Must be equivalent" ret
518525 , test " simp-max-buflength" $ do
519526 let simp = Expr. simplify $ Max (Lit 0 ) (BufLength (AbstractBuf " txdata" ))
520527 assertEqualM " max-buflength rules" simp $ BufLength (AbstractBuf " txdata" )
You can’t perform that action at this time.
0 commit comments