diff --git a/lib/Echidna/Solidity.hs b/lib/Echidna/Solidity.hs index 5e2f327cd..9ef256d91 100644 --- a/lib/Echidna/Solidity.hs +++ b/lib/Echidna/Solidity.hs @@ -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 @@ -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 @@ -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) diff --git a/lib/Echidna/Transaction.hs b/lib/Echidna/Transaction.hs index 49ea95333..34ec88e43 100644 --- a/lib/Echidna/Transaction.hs +++ b/lib/Echidna/Transaction.hs @@ -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 diff --git a/lib/Echidna/Types/Tx.hs b/lib/Echidna/Types/Tx.hs index ddf9b8967..2f5f8fafe 100644 --- a/lib/Echidna/Types/Tx.hs +++ b/lib/Echidna/Types/Tx.hs @@ -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