Skip to content

Commit 31d4ef9

Browse files
committed
Oops, not concretization was missing
Testing
1 parent a577254 commit 31d4ef9

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/EVM/Expr.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,6 @@ simplifyNoLitToKeccak e = untilFixpoint (mapExpr go) e
12141214

12151215
-- Negation: ~x + 1 = 0 - x (two's complement)
12161216
go (Add (Lit 1) (Not b)) = Sub (Lit 0) b
1217-
go (Xor (Lit a) b) | a == maxLit = Not b
12181217

12191218
-- add / sub identities
12201219
go (Add a b)
@@ -1227,8 +1226,14 @@ simplifyNoLitToKeccak e = untilFixpoint (mapExpr go) e
12271226
| otherwise = sub a b
12281227

12291228
-- XOR normalization
1229+
go (Xor (Lit a) b) | a == maxLit = Not b
12301230
go (Xor a b) = EVM.Expr.xor a b
12311231

1232+
-- Not simplification
1233+
go (EVM.Types.Not (EVM.Types.Not a)) = a
1234+
go (Not a) = EVM.Expr.not a
1235+
1236+
-- EqByte
12321237
go (EqByte a b) = eqByte a b
12331238

12341239
-- SHL / SHR / SAR
@@ -1261,8 +1266,6 @@ simplifyNoLitToKeccak e = untilFixpoint (mapExpr go) e
12611266
| b == (Lit 0) = a
12621267
| otherwise = EVM.Expr.or a b
12631268

1264-
-- Double NOT is a no-op, since it's a bitwise inversion
1265-
go (EVM.Types.Not (EVM.Types.Not a)) = a
12661269

12671270
-- Some trivial min / max eliminations
12681271
go (Max a b) = EVM.Expr.max a b

test/EVM/Expr/ExprTests.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ basicSimplificationTests = testGroup "Basic simplification tests"
288288
, testCase "simp-xor-maxlit-plus1" $ do
289289
let simp = Expr.simplify $ Add (Lit 1) (Xor (Lit Expr.maxLit) (Var "x"))
290290
assertEqual "xor(maxLit, x) + 1 is negation" (Sub (Lit 0) (Var "x")) simp
291+
, testCase "simp-double-not" $ do
292+
let simp = Expr.simplify $ Not (Not (Var "a"))
293+
assertEqual "Not should be concretized" (Var "a") simp
294+
, testCase "simp-not-concrete" $ do
295+
let simp = Expr.simplify $ Not (Lit 0x55)
296+
assertEqual "Not should be concretized" (Lit 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa) simp
291297
]
292298

293299
propSimplificationTests :: TestTree
@@ -856,4 +862,4 @@ isSatOrUnknown :: SMTResult -> Bool
856862
isSatOrUnknown res = isSat res || isUnknown res
857863

858864
isUnsatOrUnknown :: SMTResult -> Bool
859-
isUnsatOrUnknown res = isQed res || isUnknown res
865+
isUnsatOrUnknown res = isQed res || isUnknown res

0 commit comments

Comments
 (0)