Skip to content

Commit

Permalink
Merge pull request #409 from ethereum/evalprop-renamed
Browse files Browse the repository at this point in the history
Renaming evalProp to simplifyProp
  • Loading branch information
msooseth authored Oct 18, 2023
2 parents c4174c5 + c970fbd commit 3a52ccf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 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
- `evalProp` is renamed to `simplifyProp` for consistency
- Mem explosion in `writeWord` function was possible in case `offset` was close to 2^256. Fixed.

## API Changes
Expand Down
2 changes: 1 addition & 1 deletion src/EVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ branch cond continue = do
choosePath :: CodeLocation -> BranchCondition -> EVM s ()
choosePath loc (Case v) = do
assign #result Nothing
pushTo #constraints $ if v then Expr.evalProp (condSimp ./= Lit 0) else Expr.evalProp (condSimp .== Lit 0)
pushTo #constraints $ if v then Expr.simplifyProp (condSimp ./= Lit 0) else Expr.simplifyProp (condSimp .== Lit 0)
(iteration, _) <- use (#iterations % at loc % non (0,[]))
stack <- use (#state % #stack)
assign (#cache % #path % at (loc, iteration)) (Just v)
Expand Down
10 changes: 5 additions & 5 deletions src/EVM/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -978,14 +978,14 @@ simplify e = if (mapExpr go e == e)
simplifyProps :: [Prop] -> [Prop]
simplifyProps ps = if canBeSat then simplified else [PBool False]
where
simplified = remRedundantProps . map evalProp . flattenProps $ ps
simplified = remRedundantProps . map simplifyProp . flattenProps $ ps
canBeSat = constFoldProp simplified

-- | Evaluate the provided proposition down to its most concrete result
evalProp :: Prop -> Prop
evalProp prop =
simplifyProp :: Prop -> Prop
simplifyProp prop =
let new = mapProp' go (simpInnerExpr prop)
in if (new == prop) then prop else evalProp new
in if (new == prop) then prop else simplifyProp new
where
go :: Prop -> Prop

Expand Down Expand Up @@ -1305,7 +1305,7 @@ data ConstState = ConstState
constFoldProp :: [Prop] -> Bool
constFoldProp ps = oneRun ps (ConstState mempty True)
where
oneRun ps2 startState = (execState (mapM (go . evalProp) ps2) startState).canBeSat
oneRun ps2 startState = (execState (mapM (go . simplifyProp) ps2) startState).canBeSat
go :: Prop -> State ConstState ()
go x = case x of
PEq (Lit l) a -> do
Expand Down
2 changes: 1 addition & 1 deletion src/EVM/SymExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ verify solvers opts preState maybepost = do
let
-- Filter out any leaves that can be statically shown to be safe
canViolate = flip filter flattened $
\leaf -> case Expr.evalProp (post preState leaf) of
\leaf -> case Expr.simplifyProp (post preState leaf) of
PBool True -> False
_ -> True
assumes = preState.constraints
Expand Down
6 changes: 3 additions & 3 deletions test/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,14 @@ tests = testGroup "hevm"
Just asList -> do
let asBuf = Expr.fromList asList
checkEquiv asBuf input
, testProperty "evalProp-equivalence-lit" $ \(LitProp p) -> ioProperty $ do
, testProperty "simplifyProp-equivalence-lit" $ \(LitProp p) -> ioProperty $ do
let simplified = Expr.simplifyProps [p]
case simplified of
[] -> checkEquivProp (PBool True) p
[val@(PBool _)] -> checkEquivProp val p
_ -> assertFailure "must evaluate down to a literal bool"
, testProperty "evalProp-equivalence-sym" $ \(p) -> ioProperty $ do
let simplified = Expr.evalProp p
, testProperty "simplifyProp-equivalence-sym" $ \(p) -> ioProperty $ do
let simplified = Expr.simplifyProp p
checkEquivProp simplified p
, testProperty "simpProp-equivalence-sym" $ \(ps :: [Prop]) -> ioProperty $ do
let simplified = pand (Expr.simplifyProps ps)
Expand Down

0 comments on commit 3a52ccf

Please sign in to comment.