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

Support for multiple contracts in equivalence check #167

Merged
merged 80 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
80 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
e1dbd56
HEVM: small cleanup
zoep Oct 4, 2023
475d10f
HEVM: split utils files
zoep Oct 4, 2023
6bcda2a
HEVM: split utils files
zoep Oct 4, 2023
29d498d
flake: update hevm
zoep Oct 4, 2023
b5263fa
HEVM: WIP pass contract map to behaviours
zoep Oct 4, 2023
14df701
HEVM: pass contract map to behaviours
zoep Oct 9, 2023
dc7e0f0
HEVM: behavior equivalence
zoep Oct 9, 2023
0304c25
HEVM: remove some traces
zoep Oct 9, 2023
3f4572b
tests: updates multi tests
zoep Oct 9, 2023
8d342ff
Merge branch 'main' of github.com:ethereum/act into multiple-contract…
zoep Oct 9, 2023
3f2dc13
flake: use hevm commit
zoep Oct 10, 2023
cf4621e
hevm: fix storage access of other contracts
zoep Oct 12, 2023
705cc5a
hevm: port everything to state monad
zoep Oct 13, 2023
7b3d0c3
hevm: wip in compiling
zoep Oct 17, 2023
6eb73b3
hevm: refector compiles
zoep Oct 18, 2023
df13c33
hevm: fix bugs
zoep Oct 18, 2023
1ef09b8
hevm: fix fresh counter bug
zoep Oct 19, 2023
914e7f3
test: multi test
zoep Oct 19, 2023
353c2fc
merge
zoep Oct 24, 2023
b39e58e
hevm: remove warnings
zoep Oct 25, 2023
079c164
tests: add failing tests
zoep Oct 25, 2023
9a34507
hevm: cleanup
zoep Oct 25, 2023
af0e21b
makefile: add back test
zoep Oct 25, 2023
9a58aa4
bump hevm
zoep Oct 25, 2023
dcea80b
Update Makefile
zoep Nov 13, 2023
f78a5fa
Update src/HEVM.hs
zoep Nov 13, 2023
852f1d2
Merge branch 'multiple-contracts-behv' of github.com:ethereum/act int…
zoep Nov 20, 2023
63237e8
hevm: nits from PR
zoep Nov 20, 2023
cfd868a
merge
zoep Nov 20, 2023
236a15b
wip updating hevm
zoep Nov 20, 2023
eb89f82
HEVM updates
zoep Nov 21, 2023
f4a4b6e
add file
zoep Nov 22, 2023
c7d9010
hevm: fix warnings
zoep Nov 22, 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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
zoep marked this conversation as resolved.
Show resolved Hide resolved

.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)
./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
13 changes: 7 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs";
hevmUpstream = {
url = "github:ethereum/hevm";
url = "github:ethereum/hevm/f96f0993b73c2937db48bb38e29634d922c40af1";
Copy link
Collaborator

Choose a reason for hiding this comment

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

whats on this branch that still hasn't gone into main?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nothing, I believe. There was an unpushed commit from Oct 25 that updates the version.

inputs.nixpkgs.follows = "nixpkgs";
};
};
Expand Down
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 ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a note that it would be nice to support parallel solvers here at some point, but doesn't need to change for this PR

checkContracts solvers opts store cmap
where
getBytecode :: IO (BS.ByteString, BS.ByteString)
getBytecode =

createContractMap :: [Contract] -> IO (Map Id (Contract, BS.ByteString, BS.ByteString))
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

Choose a reason for hiding this comment

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

why?

(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