Skip to content

Commit 0ba7790

Browse files
committed
Fixing up merge issues of symbolic queue
Fixing Fixing
1 parent b2d8923 commit 0ba7790

File tree

3 files changed

+57
-84
lines changed

3 files changed

+57
-84
lines changed

cli/cli.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ equivalence eqOpts cOpts = do
405405
when (isNothing bytecodeB) $ liftIO $ do
406406
putStrLn "Error: invalid or no bytecode for program B. Provide a valid one with --code-b or --code-b-file"
407407
exitFailure
408-
let veriOpts = defaultVeriOpts { iterConf = IterConfig {
408+
let veriOpts = (defaultVeriOpts :: VeriOpts) { iterConf = IterConfig {
409409
maxIter = parseMaxIters cOpts.maxIterations
410410
, askSmtIters = cOpts.askSmtIterations
411411
, loopHeuristic = cOpts.loopDetectionHeuristic

src/EVM/Expr.hs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,47 @@ simplifyNoLitToKeccak e = untilFixpoint (mapExpr go) e
10631063
| a == b = Lit 1
10641064
| otherwise = eq a b
10651065

1066+
-- COMPARISONS
1067+
-- First special cases
1068+
1069+
-- we write at least 32, so if x <= 32, it's FALSE
1070+
go o@(EVM.Types.LT (BufLength (WriteWord {})) (Lit x))
1071+
| x <= 32 = Lit 0
1072+
| otherwise = o
1073+
-- we write at least 32, so if x < 32, it's TRUE
1074+
go o@(EVM.Types.LT (Lit x) (BufLength (WriteWord {})))
1075+
| x < 32 = Lit 1
1076+
| otherwise = o
1077+
1078+
-- If a >= b then the value of the `Max` expression can never be < b
1079+
go o@(LT (Max (Lit a) _) (Lit b))
1080+
| a >= b = Lit 0
1081+
| otherwise = o
1082+
go o@(SLT (Sub (Max (Lit a) _) (Lit b)) (Lit c))
1083+
= let sa, sb, sc :: Int256
1084+
sa = fromIntegral a
1085+
sb = fromIntegral b
1086+
sc = fromIntegral c
1087+
in if sa >= sb && sa - sb >= sc
1088+
then Lit 0
1089+
else o
1090+
1091+
-- normalize all comparisons in terms of (S)LT
1092+
go (EVM.Types.GT a b) = lt b a
1093+
go (EVM.Types.GEq a b) = iszero (lt a b)
1094+
go (EVM.Types.LEq a b) = iszero (lt b a)
1095+
go (SGT a b) = slt b a
1096+
1097+
-- LT
1098+
go (EVM.Types.LT _ (Lit 0)) = Lit 0
1099+
go (EVM.Types.LT a (Lit 1)) = iszero a
1100+
go (EVM.Types.LT a b) = lt a b
1101+
1102+
-- SLT
1103+
go (SLT _ (Lit a)) | a == minLitSigned = Lit 0
1104+
go (SLT (Lit a) _) | a == maxLitSigned = Lit 0
1105+
go (SLT a b) = slt a b
1106+
10661107
-- Masking as as per Solidity bit-packing of e.g. function parameters
10671108
go (And (Lit mask1) (Or (And (Lit mask2) _) x)) | (mask1 .&. mask2 == 0)
10681109
= And (Lit mask1) x
@@ -1210,15 +1251,6 @@ simplifyNoLitToKeccak e = untilFixpoint (mapExpr go) e
12101251
| b == (Lit 0) = a
12111252
| otherwise = EVM.Expr.or a b
12121253

1213-
-- we write at least 32, so if x <= 32, it's FALSE
1214-
go o@(EVM.Types.LT (BufLength (WriteWord {})) (Lit x))
1215-
| x <= 32 = Lit 0
1216-
| otherwise = o
1217-
-- we write at least 32, so if x < 32, it's TRUE
1218-
go o@(EVM.Types.LT (Lit x) (BufLength (WriteWord {})))
1219-
| x < 32 = Lit 1
1220-
| otherwise = o
1221-
12221254
-- Double NOT is a no-op, since it's a bitwise inversion
12231255
go (EVM.Types.Not (EVM.Types.Not a)) = a
12241256

src/EVM/SymExec.hs

Lines changed: 15 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,20 @@ freezeVM vm = do
322322
m@(SymbolicMemory _) -> pure m
323323

324324
data InterpTask m = InterpTask
325-
{fetcher :: Fetch.Fetcher Symbolic m RealWorld
325+
{fetcher :: Fetch.Fetcher Symbolic m
326326
, iterConf :: IterConfig
327-
, vm :: VM Symbolic RealWorld
327+
, vm :: VM Symbolic
328328
, taskq :: Chan (InterpTask m)
329329
, numTasks :: TVar Natural
330-
, stepper :: Stepper Symbolic RealWorld (Expr End)
330+
, stepper :: Stepper Symbolic (Expr End)
331331
}
332332
newtype InterpreterInstance = InterpreterInstance { instanceId :: Int }
333333

334334
interpret :: forall m . App m
335-
=> Fetch.Fetcher Symbolic m RealWorld
335+
=> Fetch.Fetcher Symbolic m
336336
-> IterConfig
337-
-> VM Symbolic RealWorld
338-
-> Stepper Symbolic RealWorld (Expr End)
337+
-> VM Symbolic
338+
-> Stepper Symbolic (Expr End)
339339
-> m [Expr End]
340340
interpret fetcher iterConf vm stepper = do
341341
conf <- readConfig
@@ -442,18 +442,9 @@ interpretInternal t@InterpTask{..} res = eval (Operational.view stepper)
442442
let newDepth = vm.exploreDepth+1
443443
runOne frozen newDepth vals
444444
where
445-
<<<<<<< HEAD
446-
runOne :: App m => VM 'Symbolic RealWorld -> Int -> [Expr EWord] -> m (Expr End)
445+
runOne :: App m => VM 'Symbolic -> Int -> [Expr EWord] -> m (Expr End)
447446
runOne frozen newDepth [v] = do
448447
conf <- readConfig
449-
=======
450-
goITE :: [(Expr EWord, Expr End)] -> Expr End
451-
goITE [] = internalError "goITE: empty list"
452-
goITE [(_, end)] = end
453-
goITE ((val,end):ps) = ITE (Eq expr val) end (goITE ps)
454-
runOne :: App m => VM 'Symbolic -> Int -> Expr EWord -> m (Expr 'End)
455-
runOne frozen newDepth v = do
456-
>>>>>>> main
457448
(ra, vma) <- liftIO $ stToIO $ runStateT (continue v) frozen { result = Nothing, exploreDepth = newDepth }
458449
when (conf.debug) $ liftIO $ putStrLn $ "Running last task for ForkMany at depth " <> show newDepth
459450
flip interpretInternal res t { vm = vma, stepper = (k ra) }
@@ -668,15 +659,9 @@ verifyContract :: forall m . App m
668659
-> Maybe Sig
669660
-> [String]
670661
-> VeriOpts
671-
<<<<<<< HEAD
672-
-> Maybe (Precondition RealWorld)
673-
-> Postcondition RealWorld
674-
-> m ([Expr End], [VerifyResult])
675-
=======
676662
-> Maybe Precondition
677663
-> Postcondition
678-
-> m (Expr End, [VerifyResult])
679-
>>>>>>> main
664+
-> m ([Expr End], [VerifyResult])
680665
verifyContract solvers theCode signature' concreteArgs opts maybepre post = do
681666
calldata <- mkCalldata signature' concreteArgs
682667
preState <- liftIO $ stToIO $ abstractVM calldata theCode maybepre False
@@ -690,13 +675,8 @@ exploreContract :: forall m . App m
690675
-> Maybe Sig
691676
-> [String]
692677
-> VeriOpts
693-
<<<<<<< HEAD
694-
-> Maybe (Precondition RealWorld)
695-
-> m [Expr End]
696-
=======
697678
-> Maybe Precondition
698-
-> m (Expr End)
699-
>>>>>>> main
679+
-> m [Expr End]
700680
exploreContract solvers theCode signature' concreteArgs opts maybepre = do
701681
calldata <- mkCalldata signature' concreteArgs
702682
preState <- liftIO $ stToIO $ abstractVM calldata theCode maybepre False
@@ -766,11 +746,7 @@ getPartials = mapMaybe go
766746

767747

768748
-- | Symbolically execute the VM and return the representention of the execution
769-
<<<<<<< HEAD
770-
executeVM :: forall m . App m => Fetch.Fetcher Symbolic m RealWorld -> IterConfig -> VM Symbolic RealWorld -> m [Expr End]
771-
=======
772-
executeVM :: forall m . App m => Fetch.Fetcher Symbolic m -> IterConfig -> VM Symbolic -> m (Expr End)
773-
>>>>>>> main
749+
executeVM :: forall m . App m => Fetch.Fetcher Symbolic m -> IterConfig -> VM Symbolic -> m [Expr End]
774750
executeVM fetcher iterConfig preState = interpret fetcher iterConfig preState runExpr
775751

776752
-- | Symbolically execute the VM and check all endstates against the
@@ -779,27 +755,16 @@ verify :: App m
779755
=> SolverGroup
780756
-> Fetch.Fetcher Symbolic m
781757
-> VeriOpts
782-
<<<<<<< HEAD
783-
-> VM Symbolic RealWorld
784-
-> Postcondition RealWorld
785-
-> m ([Expr End], [VerifyResult])
786-
=======
787758
-> VM Symbolic
788759
-> Postcondition
789-
-> m (Expr End, [VerifyResult])
790-
>>>>>>> main
760+
-> m ([Expr End], [VerifyResult])
791761
verify solvers fetcher opts preState post = do
792762
(ends1, partials) <- verifyInputs solvers opts fetcher preState post
793763
let (ends2, results) = verifyResults preState ends1
794764
pure (ends2 <> fmap snd partials, filter (not . isQed) results)
795765

796-
<<<<<<< HEAD
797-
verifyResults :: VM Symbolic RealWorld -> [(SMTResult, Expr End)] -> ([Expr End], [VerifyResult])
766+
verifyResults :: VM Symbolic-> [(SMTResult, Expr End)] -> ([Expr End], [VerifyResult])
798767
verifyResults preState res = (map snd res, fmap toVRes res)
799-
=======
800-
verifyResults :: VM Symbolic -> Expr End -> [(SMTResult, Expr End)] -> (Expr End, [VerifyResult])
801-
verifyResults preState expr cexs = if null cexs then (expr, [Qed]) else (expr, fmap toVRes cexs)
802-
>>>>>>> main
803768
where
804769
toVRes :: (SMTResult, Expr End) -> VerifyResult
805770
toVRes (res2, leaf) = case res2 of
@@ -814,17 +779,10 @@ verifyInputs
814779
:: App m
815780
=> SolverGroup
816781
-> VeriOpts
817-
<<<<<<< HEAD
818-
-> Fetch.Fetcher Symbolic m RealWorld
819-
-> VM Symbolic RealWorld
820-
-> Postcondition RealWorld
821-
-> m ([(SMTResult, Expr End)], [(PartialExec, Expr End)])
822-
=======
823782
-> Fetch.Fetcher Symbolic m
824783
-> VM Symbolic
825784
-> Postcondition
826-
-> m (Expr End, [(SMTResult, Expr End)], [(PartialExec, Expr End)])
827-
>>>>>>> main
785+
-> m ([(SMTResult, Expr End)], [(PartialExec, Expr End)])
828786
verifyInputs solvers opts fetcher preState post = do
829787
conf <- readConfig
830788
let call = mconcat ["prefix 0x", getCallPrefix preState.state.calldata]
@@ -932,33 +890,16 @@ equivalenceCheck solvers sess bytecodeA bytecodeB opts calldata create = do
932890
let branchesA = rewriteFresh "A-" branchesAorig
933891
branchesB = rewriteFresh "B-" branchesBorig
934892
let partialIssues = EqIssues mempty (filter isPartial branchesA <> filter isPartial branchesB)
935-
<<<<<<< HEAD
936-
issues <- equivalenceCheck' solvers branchesA branchesB create
937-
pure $ filterQeds (issues <> partialIssues)
938-
=======
939893
issues <- equivalenceCheck' solvers sess branchesA branchesB create
940-
pure $ oneQedOrNoQed issues <> partialIssues
941-
>>>>>>> main
894+
pure $ filterQeds (issues <> partialIssues)
942895
where
943896
-- decompiles the given bytecode into a list of branches
944897
getBranches :: App m => ByteString -> m [Expr End]
945898
getBranches bs = do
946899
let bytecode = if BS.null bs then BS.pack [0] else bs
947900
prestate <- liftIO $ stToIO $ abstractVM calldata bytecode Nothing create
948-
<<<<<<< HEAD
949-
interpret (Fetch.oracle solvers Nothing mempty) opts.iterConf prestate runExpr
901+
interpret (Fetch.oracle solvers sess Fetch.noRpc) opts.iterConf prestate runExpr
950902
filterQeds (EqIssues res partials) = EqIssues (filter (\(r, _) -> not . isQed $ r) res) partials
951-
=======
952-
expr <- interpret (Fetch.oracle solvers sess Fetch.noRpc) opts.iterConf prestate runExpr
953-
let simpl = if conf.simp then Expr.simplify expr else expr
954-
pure $ flattenExpr simpl
955-
oneQedOrNoQed :: EqIssues -> EqIssues
956-
oneQedOrNoQed (EqIssues res partials) =
957-
let allQed = all (\(r, _) -> isQed r) res
958-
in if allQed then EqIssues [(Qed, "")] partials
959-
else EqIssues (filter (\(r, _) -> not $ isQed r) res) partials
960-
>>>>>>> main
961-
962903

963904
rewriteFresh :: Text -> [Expr a] -> [Expr a]
964905
rewriteFresh prefix exprs = fmap (mapExpr mymap) exprs

0 commit comments

Comments
 (0)