Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor calls in HEVM equivalence #162

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4b43752
HEVM: start from concrete store for constructors
zoep Aug 14, 2023
5c07cbd
wip
zoep Aug 14, 2023
c003c1c
wip
zoep Aug 15, 2023
9a32b6e
wip
zoep Aug 15, 2023
6176b61
Compiling
zoep Aug 17, 2023
3eb9b98
most examples are working
zoep Aug 19, 2023
da2cf1d
hevm: port to sym addresses
zoep Aug 21, 2023
99a1b98
fix initcode argumentsin hevm
zoep Aug 21, 2023
0c40cf2
ast: add ABI type tag to vars
zoep Aug 21, 2023
8c05638
hevm: remove warnings
zoep Aug 21, 2023
3e9e1b0
CLI: cleanup
zoep Aug 21, 2023
de0e0e3
HEVM: cleanup
zoep Aug 21, 2023
b80b2c4
test: fix compilation errors
zoep Aug 22, 2023
409aea1
hevm: wip multiple contracts
zoep Aug 25, 2023
631a2f8
hevm: wip multiple contracts
zoep Sep 4, 2023
a50afd9
hevm: pass contract map around
zoep Sep 4, 2023
b588f49
hevm: WIP create new contracts
zoep Sep 7, 2023
88b2581
hevm: WIP create new contracts
zoep Sep 7, 2023
b90866e
hevm: handle nonces for new contracts
zoep Sep 8, 2023
07dcb08
hevm: WIP multiple contracts
zoep Sep 8, 2023
ec4d6d7
WIP: substitutions
zoep Sep 13, 2023
4a27601
HEVM: argument substitutions
zoep Sep 14, 2023
72d4ec3
HEVM: propagate constraints
zoep Sep 14, 2023
650134a
HEVM: constructors with multiple contracts
zoep Sep 15, 2023
90d150e
HEVM: fix contract address
zoep Sep 21, 2023
ffa5c0f
HEVM: remove warnings
zoep Sep 21, 2023
63d7cde
tests: add multiple contracts tests
zoep Sep 21, 2023
c5b852f
hevm: fix bug in fresh address
zoep Sep 21, 2023
a71c65f
HEVM: wip
zoep Sep 22, 2023
bdf278d
hevm: merge with main
zoep Sep 25, 2023
807a55b
Makefile: remove multiple contracts
zoep Sep 25, 2023
f4b8285
Makefile: remove multiple contracts
zoep Sep 25, 2023
cf4d8b2
hevm: nits
zoep Sep 25, 2023
310ee3c
hevm: nits
zoep Sep 25, 2023
0f243a7
tests: fix test
zoep Sep 25, 2023
bd47005
hevm: add blockhash
zoep Sep 25, 2023
bc79bac
hevm: fix compilation error
zoep Sep 26, 2023
7fed969
CLI: remove contract option
zoep Sep 28, 2023
243528c
HEVM: remove condition propagation and add printing
zoep Sep 28, 2023
f15ce45
HEVM: add comment
zoep Sep 28, 2023
1beefaa
tests: nits
zoep Sep 28, 2023
b2d0daa
hevm: cleanup
zoep Sep 28, 2023
474822c
makefile: remove --contract
zoep Sep 28, 2023
37d49ac
makefile: add back tests
zoep Sep 28, 2023
6ab735d
makefile: remove test
zoep Sep 28, 2023
68a3608
tests: regenerate tests output
zoep Sep 29, 2023
525ae74
hevm: remove unused constructor id
zoep Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ postcondition_pass=$(wildcard tests/postconditions/pass/*.act) $(typing_pass)
postcondition_fail=$(wildcard tests/postconditions/fail/*.act)

# supposed to pass, but timeout
hevm_buggy=tests/hevm/pass/transfer/transfer.act
hevm_buggy=tests/hevm/pass/transfer/transfer.act tests/hevm/pass/multi3/multi3.act
# supposed to pass
hevm_pass=$(filter-out $(hevm_buggy), $(wildcard tests/hevm/pass/*/*.act))
# supposed to fail
Expand All @@ -53,7 +53,7 @@ hevm_fail=$(wildcard tests/hevm/fail/*/*.act)
failing_typing=tests/frontend/pass/array/array.act tests/frontend/pass/dss/vat.act tests/frontend/pass/creation/createMultiple.act tests/frontend/pass/staticstore/staticstore.act


coq-examples = tests/coq/transitions tests/coq/safemath tests/coq/exponent tests/coq/token tests/coq/ERC20 tests/coq/multi
coq-examples = tests/coq/transitions tests/coq/safemath tests/coq/exponent tests/coq/token tests/coq/ERC20 tests/coq/multi tests/coq/multi
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should pass once we merge #388 into hevm.


.PHONY: test-coq $(coq-examples)
test-coq: compiler $(coq-examples)
Expand Down Expand Up @@ -104,11 +104,11 @@ tests/%.postcondition.fail:

tests/hevm/pass/%.act.hevm.pass:
$(eval CONTRACT := $(shell awk '/contract/{ print $$2 }' tests/hevm/pass/$*.sol))
./bin/act hevm --spec tests/hevm/pass/$*.act --sol tests/hevm/pass/$*.sol --contract $(CONTRACT)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contact option is removed from CLI. Now all contracts in the spec are checked.

./bin/act hevm --spec tests/hevm/pass/$*.act --sol tests/hevm/pass/$*.sol

tests/hevm/fail/%.act.hevm.fail:
$(eval CONTRACT := $(shell awk '/contract/{ print $$2 }' tests/hevm/fail/$*.sol))
./bin/act hevm --spec tests/hevm/fail/$*.act --sol tests/hevm/fail/$*.sol --contract $(CONTRACT) && exit 1 || echo 0
./bin/act hevm --spec tests/hevm/fail/$*.act --sol tests/hevm/fail/$*.sol && exit 1 || echo 0

test-ci: test-parse test-type test-invariant test-postcondition test-coq test-hevm
test: test-ci test-cabal
43 changes: 23 additions & 20 deletions src/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import System.IO (hPutStrLn, stderr)
import Data.Text (unpack)
import Data.List
import qualified Data.Map as Map
import Data.Map (Map)
import Data.Maybe
import qualified Data.Text as Text
import qualified Data.Text.IO as TIO
Expand Down Expand Up @@ -77,7 +78,6 @@ data Command w
, sol :: w ::: Maybe String <?> "Path to .sol"
, code :: w ::: Maybe ByteString <?> "Runtime code"
, initcode :: w ::: Maybe ByteString <?> "Initial code"
, contract :: w ::: String <?> "Contract name"
, solver :: w ::: Maybe Text <?> "SMT solver: cvc5 (default) or z3"
, smttimeout :: w ::: Maybe Integer <?> "Timeout given to SMT solver in milliseconds (default: 20000)"
, debug :: w ::: Bool <?> "Print verbose SMT output (default: False)"
Expand Down Expand Up @@ -109,9 +109,9 @@ main = do
Coq f solver' smttimeout' debug' -> do
solver'' <- parseSolver solver'
coq' f solver'' smttimeout' debug'
HEVM spec' sol' code' initcode' contract' solver' smttimeout' debug' -> do
HEVM spec' sol' code' initcode' solver' smttimeout' debug' -> do
solver'' <- parseSolver solver'
hevm spec' (Text.pack contract') sol' code' initcode' solver'' smttimeout' debug'
hevm spec' sol' code' initcode' solver'' smttimeout' debug'


---------------------------------
Expand Down Expand Up @@ -207,29 +207,32 @@ coq' f solver' smttimeout' debug' = do
TIO.putStr $ coq claims


hevm :: FilePath -> Text -> Maybe FilePath -> Maybe ByteString -> Maybe ByteString -> Solvers.Solver -> Maybe Integer -> Bool -> IO ()
hevm actspec cid sol' code' initcode' solver' timeout debug' = do
let opts = if debug' then debugVeriOpts else defaultVeriOpts
(initcode'', bytecode) <- getBytecode
hevm :: FilePath -> Maybe FilePath -> Maybe ByteString -> Maybe ByteString -> Solvers.Solver -> Maybe Integer -> Bool -> IO ()
hevm actspec sol' code' initcode' solver' timeout debug' = do
specContents <- readFile actspec
proceed specContents (enrich <$> compile specContents) $ \act -> do
checkCases act solver' timeout debug'
Solvers.withSolvers solver' 1 (naturalFromInteger <$> timeout) $ \solvers -> do
-- Constructor check
checkConstructors solvers opts initcode'' bytecode act
-- Behavours check
checkBehaviours solvers opts bytecode act
-- ABI exhaustiveness sheck
checkAbi solvers opts act bytecode
proceed specContents (enrich <$> compile specContents) $ \ (Act store contracts) -> do
cmap <- createContractMap contracts
let opts = if debug' then debugVeriOpts else defaultVeriOpts

Solvers.withSolvers solver' 1 (naturalFromInteger <$> timeout) $ \solvers ->
checkContracts solvers opts store cmap
where
getBytecode :: IO (BS.ByteString, BS.ByteString)
getBytecode =

createContractMap :: [Contract] -> IO (Map Id (Contract, BS.ByteString, BS.ByteString))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We create a map from contact ids to their (Act spec, initcode, bytecode) triples. This makes it easy to look up the spec and the byte code of a contract when we encounter a call to its constructor. To check equivalence between the spec and the bytecodes, we traverse the map.

createContractMap contracts = do
foldM (\cmap spec'@(Contract cnstr _) -> do
let cid = _cname cnstr
(initcode'', runtimecode') <- getBytecode cid -- TODO do not reread the file each time
pure $ Map.insert cid (spec', initcode'', runtimecode') cmap
) mempty contracts

getBytecode :: Id -> IO (BS.ByteString, BS.ByteString)
getBytecode cid =
case (sol', code', initcode') of
(Just f, Nothing, Nothing) -> do
solContents <- TIO.readFile f
bytecodes cid solContents
(Nothing, Just c, Just i) -> pure (i, c)
bytecodes (Text.pack cid) solContents
(Nothing, Just _, Just _) -> render (text "Only Solidity file supported") >> exitFailure -- pure (i, c)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we can support bytecode input when we have multiple contracts.

(Nothing, Nothing, _) -> render (text "No runtime code is given" <> line) >> exitFailure
(Nothing, _, Nothing) -> render (text "No initial code is given" <> line) >> exitFailure
(Just _, Just _, _) -> render (text "Both Solidity file and runtime code are given. Please specify only one." <> line) >> exitFailure
Expand Down
Loading
Loading