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

Allow to bypass EIP-170 and set up a custom max code size #544

Merged
merged 5 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions examples/solidity/basic/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ sender: ["0x10000", "0x20000", "0x00a329c0648769a73afac7f9381e08fb43dbea70"]
balanceAddr: 0xffffffff
#balanceContract overrides balanceAddr for the contract address
balanceContract: 0
#codeSize max code size for deployed contratcs (default 24576, per EIP-170)
codeSize: 0x6000
#solcArgs allows special args to solc
solcArgs: ""
#solcLibs is solc libraries
Expand Down
2,006 changes: 2,006 additions & 0 deletions examples/solidity/basic/eip-170.sol

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/solidity/basic/eip-170.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
codeSize: 28000
testLimit: 1
seqLen: 1
1 change: 1 addition & 0 deletions lib/Echidna/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ instance FromJSON EConfigWithUsage where
<*> v ..:? "sender" ..!= (0x10000 NE.:| [0x20000, defaultDeployer])
<*> v ..:? "balanceAddr" ..!= 0xffffffff
<*> v ..:? "balanceContract" ..!= 0
<*> v ..:? "codeSize" ..!= 0x6000 -- 24576 (EIP-170)
<*> v ..:? "prefix" ..!= "echidna_"
<*> v ..:? "cryticArgs" ..!= []
<*> v ..:? "solcArgs" ..!= ""
Expand Down
5 changes: 3 additions & 2 deletions lib/Echidna/Solidity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ data SolConf = SolConf { _contractAddr :: Addr -- ^ Contract addr
, _sender :: NE.NonEmpty Addr -- ^ Sender addresses to use
, _balanceAddr :: Integer -- ^ Initial balance of deployer and senders
, _balanceContract :: Integer -- ^ Initial balance of contract to test
, _codeSize :: Integer -- ^ Max code size for deployed contratcs (default 24576, per EIP-170)
, _prefix :: Text -- ^ Function name prefix used to denote tests
, _cryticArgs :: [String] -- ^ Args to pass to crytic
, _solcArgs :: String -- ^ Args to pass to @solc@
Expand Down Expand Up @@ -193,7 +194,7 @@ loadSpecified name cs = do
unless q . putStrLn $ "Analyzing contract: " <> c ^. contractName . unpacked

-- Local variables
SolConf ca d ads bala balc pref _ _ libs _ fp ma ch bm fs <- view hasLens
SolConf ca d ads bala balc mcs pref _ _ libs _ fp ma ch bm fs <- view hasLens

-- generate the complete abi mapping
let bc = c ^. creationCode
Expand All @@ -212,7 +213,7 @@ loadSpecified name cs = do

-- Set up initial VM, either with chosen contract or Etheno initialization file
-- need to use snd to add to ABI dict
blank' <- maybe (pure initialVM)
blank' <- maybe (pure (initialVM & block . maxCodeSize .~ w256 (fromInteger mcs)))
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should make _codeSize a Word instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What’s the reason? I mimicked the way balance works.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should merge it and then re-organize the types of the maxCodeSize, balance, etc in another PR

(loadEthenoBatch $ fst <$> tests)
fp
let blank = populateAddresses (NE.toList ads |> d) bala blank'
Expand Down
2 changes: 2 additions & 0 deletions src/test/Tests/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ compilationTests = testGroup "Compilation and loading tests"
pmatch _ConstructorArgs
, loadFails "bad/revert.sol" Nothing "failed to warn on a failed deployment" $
pmatch _DeploymentFailed
, loadFails "basic/eip-170.sol" Nothing "failed to warn on a failed deployment" $
pmatch _DeploymentFailed
]

loadFails :: FilePath -> Maybe Text -> String -> (SolException -> Bool) -> TestTree
Expand Down
2 changes: 2 additions & 0 deletions src/test/Tests/Integration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,6 @@ integrationTests = testGroup "Solidity Integration Testing"
[ ("echidna_still_alive failed", solved "echidna_still_alive") ]
, checkConstructorConditions "basic/codesize.sol"
"invalid codesize"
, testContract "basic/eip-170.sol" (Just "basic/eip-170.yaml")
[ ("echidna_test passed", passed "echidna_test") ]
]