-
Notifications
You must be signed in to change notification settings - Fork 37
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
Changes from all commits
4b43752
5c07cbd
c003c1c
9a32b6e
6176b61
3eb9b98
da2cf1d
99a1b98
0c40cf2
8c05638
3e9e1b0
de0e0e3
b80b2c4
409aea1
631a2f8
a50afd9
b588f49
88b2581
b90866e
07dcb08
ec4d6d7
4a27601
72d4ec3
650134a
90d150e
ffa5c0f
63d7cde
c5b852f
a71c65f
bdf278d
807a55b
f4b8285
cf4d8b2
310ee3c
0f243a7
bd47005
bc79bac
7fed969
243528c
f15ce45
1beefaa
b2d0daa
474822c
37d49ac
6ab735d
68a3608
525ae74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
||
.PHONY: test-coq $(coq-examples) | ||
test-coq: compiler $(coq-examples) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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)" | ||
|
@@ -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' | ||
|
||
|
||
--------------------------------- | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.