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

Constructor calls in HEVM equivalence #162

wants to merge 47 commits into from

Conversation

zoep
Copy link
Collaborator

@zoep zoep commented Sep 28, 2023

This PR adds support for multiple contracts in Act spec (WIP). More precisely:

  • Allow constructor calls in constructors
  • Remove --contract option, since all contracts in the spec are now checked by default

TODO:

  • Allow accessing external state variables in behaviours
  • Add failing tests

@zoep zoep changed the title Constructor call in HEVM equivalence Constructor callsin HEVM equivalence Sep 28, 2023
@zoep zoep changed the title Constructor callsin HEVM equivalence Constructor calls in HEVM equivalence Sep 28, 2023
@@ -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.

@@ -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.

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.

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.


updatesToExpr :: Layout -> Id -> [StorageUpdate] -> ContractMap -> ContractMap
updatesToExpr layout cid upds initmap = foldl (flip $ updateToExpr layout cid) initmap upds
updatesToExpr :: CodeMap -> Layout -> Id -> EVM.Expr EVM.EAddr -> [StorageUpdate] -> (ContractMap, [EVM.Prop]) -> (ContractMap, [EVM.Prop])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The return type propagates the preconditions of constructor calls upwards after substitution. As we discussed this is probably not needed. I will think about this a bit more and probably will be removing this from the return type.

@zoep zoep marked this pull request as draft September 29, 2023 10:28
@zoep zoep requested a review from d-xo September 29, 2023 10:29
@zoep zoep closed this Oct 25, 2023
@zoep
Copy link
Collaborator Author

zoep commented Oct 25, 2023

Subsumed by #167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant