Use a sensible default value for block.gaslimit (#596)

* added a sensible value for block.gaslimit

* added test
pull/602/head
Gustavo Grieco 4 years ago committed by GitHub
parent dcc4eed7f5
commit f92159597c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      examples/solidity/basic/gaslimit.sol
  2. 4
      lib/Echidna/RPC.hs
  3. 6
      lib/Echidna/Solidity.hs
  4. 2
      lib/Echidna/Types/Tx.hs
  5. 2
      src/test/Tests/Integration.hs

@ -0,0 +1,7 @@
contract C {
function echidna_gaslimit() public returns (bool) {
return block.gaslimit > 0;
}
}

@ -138,5 +138,5 @@ execEthenoTxs ts addr et = do
-- | For an etheno txn, set up VM to execute txn
setupEthenoTx :: (MonadState x m, Has VM x) => Etheno -> m ()
setupEthenoTx (AccountCreated _) = pure ()
setupEthenoTx (ContractCreated f c _ _ d v) = setupTx $ createTxWithValue d f c unlimitedGasPerBlock (w256 v)
setupEthenoTx (FunctionCall f t _ _ d v) = setupTx $ Tx (SolCalldata d) f t unlimitedGasPerBlock 0 (w256 v) (0, 0)
setupEthenoTx (ContractCreated f c _ _ d v) = setupTx $ createTxWithValue d f c (fromInteger unlimitedGasPerBlock) (w256 v)
setupEthenoTx (FunctionCall f t _ _ d v) = setupTx $ Tx (SolCalldata d) f t (fromInteger unlimitedGasPerBlock) 0 (w256 v) (0, 0)

@ -157,7 +157,7 @@ loadLibraries :: (MonadIO m, MonadThrow m, MonadReader x m, Has SolConf x)
=> [SolcContract] -> Addr -> Addr -> VM -> m VM
loadLibraries [] _ _ vm = return vm
loadLibraries (l:ls) la d vm = loadLibraries ls (la + 1) d =<< loadRest
where loadRest = execStateT (execTx $ createTx (l ^. creationCode) d la unlimitedGasPerBlock) vm
where loadRest = execStateT (execTx $ createTx (l ^. creationCode) d la (fromInteger unlimitedGasPerBlock)) vm
-- | Generate a string to use as argument in solc to link libraries starting from addrLibrary
linkLibraries :: [String] -> String
@ -214,7 +214,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 & block . maxCodeSize .~ w256 (fromInteger mcs)))
blank' <- maybe (pure (initialVM & block . gaslimit .~ fromInteger unlimitedGasPerBlock & block . maxCodeSize .~ w256 (fromInteger mcs)))
(loadEthenoBatch $ fst <$> tests)
fp
let blank = populateAddresses (NE.toList ads |> d) bala blank'
@ -231,7 +231,7 @@ loadSpecified name cs = do
Just (t,_) -> throwM $ TestArgsFound t -- Test args check
Nothing -> do
vm <- loadLibraries ls addrLibrary d blank
let transaction = unless (isJust fp) $ void . execTx $ createTxWithValue bc d ca unlimitedGasPerBlock (w256 $ fromInteger balc)
let transaction = unless (isJust fp) $ void . execTx $ createTxWithValue bc d ca (fromInteger unlimitedGasPerBlock) (w256 $ fromInteger balc)
vm' <- execStateT transaction vm
case currentContract vm' of
Just _ -> return (vm', c ^. eventMap, neFuns, fst <$> tests, abiMapping)

@ -29,7 +29,7 @@ $(deriveJSON defaultOptions ''TxCall)
maxGasPerBlock :: Integer
maxGasPerBlock = 12500000 -- https://cointelegraph.com/news/ethereum-miners-vote-to-increase-gas-limit-causing-community-debate
unlimitedGasPerBlock :: Word
unlimitedGasPerBlock :: Integer
unlimitedGasPerBlock = 0xffffffff
defaultTimeDelay :: Integer

@ -142,6 +142,8 @@ integrationTests = testGroup "Solidity Integration Testing"
, ("f_open1 gas estimate wrong", gasInRange "f_open1" 18000 23000)
, ("push_b gas estimate wrong", gasInRange "push_b" 39000 45000)
]
, testContract "basic/gaslimit.sol" Nothing
[ ("echidna_gaslimit passed", passed "echidna_gaslimit") ]
, testContract "coverage/boolean.sol" (Just "coverage/boolean.yaml")
[ ("echidna_true failed", passed "echidna_true")
, ("unexpected corpus count ", countCorpus 5)]

Loading…
Cancel
Save