Skip to content

Commit f921595

Browse files
Use a sensible default value for block.gaslimit (#596)
* added a sensible value for block.gaslimit * added test
1 parent dcc4eed commit f921595

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
contract C {
2+
3+
function echidna_gaslimit() public returns (bool) {
4+
return block.gaslimit > 0;
5+
}
6+
7+
}

lib/Echidna/RPC.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,5 @@ execEthenoTxs ts addr et = do
138138
-- | For an etheno txn, set up VM to execute txn
139139
setupEthenoTx :: (MonadState x m, Has VM x) => Etheno -> m ()
140140
setupEthenoTx (AccountCreated _) = pure ()
141-
setupEthenoTx (ContractCreated f c _ _ d v) = setupTx $ createTxWithValue d f c unlimitedGasPerBlock (w256 v)
142-
setupEthenoTx (FunctionCall f t _ _ d v) = setupTx $ Tx (SolCalldata d) f t unlimitedGasPerBlock 0 (w256 v) (0, 0)
141+
setupEthenoTx (ContractCreated f c _ _ d v) = setupTx $ createTxWithValue d f c (fromInteger unlimitedGasPerBlock) (w256 v)
142+
setupEthenoTx (FunctionCall f t _ _ d v) = setupTx $ Tx (SolCalldata d) f t (fromInteger unlimitedGasPerBlock) 0 (w256 v) (0, 0)

lib/Echidna/Solidity.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ loadLibraries :: (MonadIO m, MonadThrow m, MonadReader x m, Has SolConf x)
157157
=> [SolcContract] -> Addr -> Addr -> VM -> m VM
158158
loadLibraries [] _ _ vm = return vm
159159
loadLibraries (l:ls) la d vm = loadLibraries ls (la + 1) d =<< loadRest
160-
where loadRest = execStateT (execTx $ createTx (l ^. creationCode) d la unlimitedGasPerBlock) vm
160+
where loadRest = execStateT (execTx $ createTx (l ^. creationCode) d la (fromInteger unlimitedGasPerBlock)) vm
161161

162162
-- | Generate a string to use as argument in solc to link libraries starting from addrLibrary
163163
linkLibraries :: [String] -> String
@@ -214,7 +214,7 @@ loadSpecified name cs = do
214214

215215
-- Set up initial VM, either with chosen contract or Etheno initialization file
216216
-- need to use snd to add to ABI dict
217-
blank' <- maybe (pure (initialVM & block . maxCodeSize .~ w256 (fromInteger mcs)))
217+
blank' <- maybe (pure (initialVM & block . gaslimit .~ fromInteger unlimitedGasPerBlock & block . maxCodeSize .~ w256 (fromInteger mcs)))
218218
(loadEthenoBatch $ fst <$> tests)
219219
fp
220220
let blank = populateAddresses (NE.toList ads |> d) bala blank'
@@ -231,7 +231,7 @@ loadSpecified name cs = do
231231
Just (t,_) -> throwM $ TestArgsFound t -- Test args check
232232
Nothing -> do
233233
vm <- loadLibraries ls addrLibrary d blank
234-
let transaction = unless (isJust fp) $ void . execTx $ createTxWithValue bc d ca unlimitedGasPerBlock (w256 $ fromInteger balc)
234+
let transaction = unless (isJust fp) $ void . execTx $ createTxWithValue bc d ca (fromInteger unlimitedGasPerBlock) (w256 $ fromInteger balc)
235235
vm' <- execStateT transaction vm
236236
case currentContract vm' of
237237
Just _ -> return (vm', c ^. eventMap, neFuns, fst <$> tests, abiMapping)

lib/Echidna/Types/Tx.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $(deriveJSON defaultOptions ''TxCall)
2929
maxGasPerBlock :: Integer
3030
maxGasPerBlock = 12500000 -- https://cointelegraph.com/news/ethereum-miners-vote-to-increase-gas-limit-causing-community-debate
3131

32-
unlimitedGasPerBlock :: Word
32+
unlimitedGasPerBlock :: Integer
3333
unlimitedGasPerBlock = 0xffffffff
3434

3535
defaultTimeDelay :: Integer

src/test/Tests/Integration.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ integrationTests = testGroup "Solidity Integration Testing"
142142
, ("f_open1 gas estimate wrong", gasInRange "f_open1" 18000 23000)
143143
, ("push_b gas estimate wrong", gasInRange "push_b" 39000 45000)
144144
]
145+
, testContract "basic/gaslimit.sol" Nothing
146+
[ ("echidna_gaslimit passed", passed "echidna_gaslimit") ]
145147
, testContract "coverage/boolean.sol" (Just "coverage/boolean.yaml")
146148
[ ("echidna_true failed", passed "echidna_true")
147149
, ("unexpected corpus count ", countCorpus 5)]

0 commit comments

Comments
 (0)