Skip to content

Commit

Permalink
Set reasonable initial block time and number (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrieco-tob authored May 1, 2020
1 parent 7dc5024 commit ceb8fbc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/Echidna/Solidity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Echidna.ABI (encodeSig, hashSig, stripBytecodeMetadata, fa
import Echidna.Exec (execTx)
import Echidna.RPC (loadEthenoBatch)
import Echidna.Types.Signature (FunctionHash, SolSignature, SignatureMap)
import Echidna.Types.Tx (TxConf, TxCall(..), Tx(..))
import Echidna.Types.Tx (TxConf, TxCall(..), Tx(..), initialTimestamp, initialBlockNumber)
import Echidna.Types.World (World(..))
import Echidna.Processor

Expand Down Expand Up @@ -162,7 +162,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 $ Tx (SolCreate $ l ^. creationCode) d la 8000030 0 0 (0,0)) vm
where loadRest = execStateT (execTx $ Tx (SolCreate $ l ^. creationCode) d la 8000030 0 0 (initialTimestamp, initialBlockNumber)) vm

-- | Generate a string to use as argument in solc to link libraries starting from addrLibrary
linkLibraries :: [String] -> String
Expand Down Expand Up @@ -234,7 +234,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 $ Tx (SolCreate bc) d ca 8000030 0 (w256 $ fromInteger balc) (0, 0)
let transaction = unless (isJust fp) $ void . execTx $ Tx (SolCreate bc) d ca 8000030 0 (w256 $ fromInteger balc) (initialTimestamp,initialBlockNumber)
vm' <- execStateT transaction vm
case currentContract vm' of
Just _ -> return (vm', neFuns, fst <$> tests, abiMapping)
Expand Down
4 changes: 3 additions & 1 deletion lib/Echidna/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ genTxWith m s r c g gp mv t = do
v' = genValue ps mv
rs = NE.fromList . catMaybes $ mkR <$> toList m
mkR = _2 (flip M.lookup mm . view (bytecode . to stripBytecodeMetadata))
(tt,tn) <- t
let t' = return (initialTimestamp + tt, initialBlockNumber + tn)
v'' <- v' <$> s' <*> r' <*> c'
Tx <$> (SolCall <$> c') <*> s' <*> (fst <$> r') <*> g <*> gp <*> v'' <*> t
Tx <$> (SolCall <$> c') <*> s' <*> (fst <$> r') <*> g <*> gp <*> v'' <*> t'

getSignatures :: MonadRandom m => SignatureMap -> Maybe SignatureMap -> m SignatureMap
getSignatures hmm Nothing = return hmm
Expand Down
6 changes: 6 additions & 0 deletions lib/Echidna/Types/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ data TxCall = SolCreate ByteString
makePrisms ''TxCall
$(deriveJSON defaultOptions ''TxCall)

initialTimestamp :: Word
initialTimestamp = 1524785992 -- Thu Apr 26 23:39:52 UTC 2018

initialBlockNumber :: Word
initialBlockNumber = 4370000 -- Initial byzantium block

-- | A transaction is either a @CREATE@ or a regular call with an origin, destination, and value.
-- Note: I currently don't model nonces or signatures here.
data Tx = Tx { _call :: TxCall -- | Call
Expand Down

0 comments on commit ceb8fbc

Please sign in to comment.