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

Force corpus evaluation #1002

Merged
merged 2 commits into from
Mar 29, 2023
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
4 changes: 3 additions & 1 deletion lib/Echidna/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Echidna.Campaign where

import Control.DeepSeq (force)
import Control.Lens
import Control.Monad (replicateM, when)
import Control.Monad.Catch (MonadCatch(..), MonadThrow(..))
Expand Down Expand Up @@ -236,7 +237,8 @@ callseq initialCorpus vm world seqLen = do
else camp.gasInfo
-- If there is new coverage, add the transaction list to the corpus
, corpus = if camp'.newCoverage
then addToCorpus (camp.ncallseqs + 1) res camp.corpus
-- corpus is a bit too lazy, force the evaluation to reduce the memory usage
then force $ addToCorpus (camp.ncallseqs + 1) res camp.corpus
else camp.corpus
-- Reset the new coverage flag
, newCoverage = False
Expand Down
43 changes: 30 additions & 13 deletions lib/Echidna/Types/Tx.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}

module Echidna.Types.Tx where

Expand All @@ -15,20 +17,23 @@ import Data.Text (Text)
import Data.Word (Word64)

import EVM (VMResult(..), Error(..))
import EVM.ABI (encodeAbiValue, AbiValue(..))
import EVM.ABI (encodeAbiValue, AbiValue(..), AbiType)
import EVM.Types (Addr, W256)

import Echidna.Orphans.JSON ()
import Echidna.Types.Buffer (forceBuf)
import Echidna.Types.Signature (SolCall)
import Control.DeepSeq (NFData)
import GHC.Generics (Generic)
import Data.DoubleWord (Word256, Word128, Int256, Int128, Word160)

-- | A transaction call is either a @CREATE@, a fully instrumented 'SolCall', or
-- an abstract call consisting only of calldata.
data TxCall = SolCreate ByteString
| SolCall SolCall
| SolCalldata ByteString
data TxCall = SolCreate !ByteString
| SolCall !SolCall
| SolCalldata !ByteString
| NoCall
deriving (Show, Ord, Eq)
deriving (Show, Ord, Eq, Generic)
$(deriveJSON defaultOptions ''TxCall)

maxGasPerBlock :: Word64
Expand All @@ -51,14 +56,26 @@ 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
, src :: Addr -- | Origin
, dst :: Addr -- | Destination
, gas :: Word64 -- | Gas
, gasprice :: W256 -- | Gas price
, value :: W256 -- | Value
, delay :: (W256, W256) -- | (Time, # of blocks since last call)
} deriving (Eq, Ord, Show)
data Tx = Tx { call :: !TxCall -- | Call
, src :: !Addr -- | Origin
, dst :: !Addr -- | Destination
, gas :: !Word64 -- | Gas
, gasprice :: !W256 -- | Gas price
, value :: !W256 -- | Value
, delay :: !(W256, W256) -- | (Time, # of blocks since last call)
} deriving (Eq, Ord, Show, Generic)

deriving instance NFData Tx
deriving instance NFData TxCall
deriving instance NFData AbiValue
deriving instance NFData Word256
deriving instance NFData Word128
deriving instance NFData Int256
deriving instance NFData Int128
deriving instance NFData Word160
deriving instance NFData AbiType
deriving anyclass instance NFData Addr
deriving anyclass instance NFData W256

instance ToJSON Tx where
toJSON Tx{..} = object
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
- containers
- data-bword
- data-dword
- deepseq
- extra
- directory
- exceptions
Expand Down