File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -420,12 +420,20 @@ discoverMaxReads props benv senv = bufMap
420
420
421
421
-- | Returns an SMT2 object with all buffers referenced from the input props declared, and with the appropriate cex extraction metadata attached
422
422
declareBufs :: [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
424
425
where
426
+ smtBufNames = " ; buffers" : fmap declareBuf allBufs
427
+ smtBufLengths = " ; buffer lengths" : fmap declareLength allBufs
428
+ smtEmptyRelations = " ; empty buffer relations" : concatMap emptyRelation allBufs
425
429
cexvars = (mempty :: CexVars ){ buffers = discoverMaxReads props bufEnv storeEnv }
426
430
allBufs = fmap fromLazyText $ Map. keys cexvars. buffers
427
431
declareBuf n = " (declare-fun " <> n <> " () (Array (_ BitVec 256) (_ BitVec 8)))"
428
432
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)) ))" ]
429
437
430
438
-- Given a list of variable names, create an SMT2 object with the variables declared
431
439
declareVars :: [Builder ] -> SMT2
Original file line number Diff line number Diff line change @@ -515,6 +515,13 @@ tests = testGroup "hevm"
515
515
let e = BufLength (CopySlice (Lit 0x2 ) (Lit 0x2 ) (Lit 0x1 ) (ConcreteBuf " " ) (ConcreteBuf " " ))
516
516
b <- checkEquiv e (Expr. simplify e)
517
517
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
518
525
, test " simp-max-buflength" $ do
519
526
let simp = Expr. simplify $ Max (Lit 0 ) (BufLength (AbstractBuf " txdata" ))
520
527
assertEqualM " max-buflength rules" simp $ BufLength (AbstractBuf " txdata" )
You can’t perform that action at this time.
0 commit comments