Skip to content

Commit

Permalink
Deal with Gas opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
msooseth committed Jan 13, 2025
1 parent 7a80814 commit 9e5bc4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/EVM/SMT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ assertPropsNoSimp psPreConc = do
<> smt2Line ""
<> (declareAddrs addresses)
<> smt2Line ""
<> declareGasVars psPreConc
<> (declareBufs toDeclarePsElim bufs stores)
<> smt2Line ""
<> (declareVars . nubOrd $ foldl (<>) [] allVars)
Expand Down Expand Up @@ -438,6 +439,16 @@ declareAddrs names = SMT2 (["; symbolic addresseses"] <> fmap declare names) cex
declare n = "(declare-fun " <> n <> " () Addr)"
cexvars = (mempty :: CexVars){ addrs = fmap toLazyText names }

declareGasVars :: [Prop] -> SMT2
declareGasVars ps = SMT2 (["; gas variables"] <> fmap declare names) mempty mempty
where
declare n = "(declare-fun gas_" <> n <> " () (_ BitVec 256))"
names :: [Builder] = nubOrd $ concatMap (foldProp go mempty) ps
go :: Expr a -> [Builder]
go e = case e of
Gas g -> [fromLazyText $ T.pack $ show g]
_ -> []

declareFrameContext :: [(Builder, [Prop])] -> Err SMT2
declareFrameContext names = do
decls <- concatMapM declare names
Expand Down Expand Up @@ -845,6 +856,7 @@ exprToSMT = \case
encPrev <- exprToSMT prev
pure $ "(store" `sp` encPrev `sp` encIdx `sp` encVal <> ")"
SLoad idx store -> op2 "select" store idx
Gas freshVar -> pure $ fromLazyText $ "gas_" <> (T.pack $ show freshVar)

a -> internalError $ "TODO: implement: " <> show a
where
Expand Down
2 changes: 1 addition & 1 deletion src/EVM/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ data Expr (a :: EType) where

Balance :: Expr EAddr -> Expr EWord

Gas :: Int -- frame idx
Gas :: Int -- fresh gas variable
-> Expr EWord

-- code
Expand Down

0 comments on commit 9e5bc4b

Please sign in to comment.