Skip to content

Commit

Permalink
Fixing up BufLength, the use of nubOrd, and adding one more PLT rule
Browse files Browse the repository at this point in the history
  • Loading branch information
msooseth committed Nov 8, 2023
1 parent 778dd4d commit 182c2f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Added
- New solc-specific simplification rules that should make the final Props a lot more readable
- Better BufLength and Max simplifications of Expr, and further solc-specific simplifications of Expr

## [0.52.0] - 2023-10-26

Expand Down
11 changes: 6 additions & 5 deletions src/EVM/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ bufLengthEnv env useEnv buf = go (Lit 0) buf
where
go :: Expr EWord -> Expr Buf -> Expr EWord
go l (ConcreteBuf b) = EVM.Expr.max l (Lit (unsafeInto . BS.length $ b))
go l (AbstractBuf b) = Max l (BufLength (AbstractBuf b))
go l (AbstractBuf b) = EVM.Expr.max l (BufLength (AbstractBuf b))
go l (WriteWord idx _ b) = go (EVM.Expr.max l (add idx (Lit 32))) b
go l (WriteByte idx _ b) = go (EVM.Expr.max l (add idx (Lit 1))) b
go l (CopySlice _ dstOffset size _ dst) = go (EVM.Expr.max l (add dstOffset size)) dst
Expand Down Expand Up @@ -946,9 +946,7 @@ simplify e = if (mapExpr go e == e)
go (EVM.Types.Not (EVM.Types.Not a)) = a

-- Some trivial min / max eliminations
go (Max a b) = case (a, b) of
(Lit 0, _) -> b
_ -> EVM.Expr.max a b
go (Max a b) = EVM.Expr.max a b
go (Min a b) = case (a, b) of
(Lit 0, _) -> Lit 0
_ -> EVM.Expr.min a b
Expand Down Expand Up @@ -1012,6 +1010,7 @@ simplifyProp prop =
go (PLEq (Lit l) (Lit r)) = PBool (l <= r)
go (PLEq a (Max b _)) | a == b = PBool True
go (PLEq a (Max _ b)) | a == b = PBool True
go (PLT (Max (Lit a) b) (Lit c)) | a < c = PLT b (Lit c)

-- negations
go (PNeg (PBool b)) = PBool (Prelude.not b)
Expand Down Expand Up @@ -1086,7 +1085,7 @@ flattenProps (a:ax) = case a of

-- removes redundant (constant True/False) props
remRedundantProps :: [Prop] -> [Prop]
remRedundantProps p = collapseFalse . filter (\x -> x /= PBool True) . nubOrd $ p
remRedundantProps p = nubOrd $ collapseFalse . filter (\x -> x /= PBool True) . nubOrd $ p
where
collapseFalse ps = if isJust $ find (== PBool False) ps then [PBool False] else ps

Expand Down Expand Up @@ -1285,6 +1284,8 @@ min :: Expr EWord -> Expr EWord -> Expr EWord
min x y = normArgs Min Prelude.min x y

max :: Expr EWord -> Expr EWord -> Expr EWord
max (Lit 0) y = y
max x (Lit 0) = x
max x y = normArgs Max Prelude.max x y

numBranches :: Expr End -> Int
Expand Down

0 comments on commit 182c2f5

Please sign in to comment.