Add @arcz 's suggestions

cov-wip-10-rebased-again
Sam Alws 10 months ago
parent 514220265d
commit 6a0e32f7de
  1. 3
      lib/Echidna/Campaign.hs
  2. 4
      lib/Echidna/Exec.hs
  3. 6
      lib/Echidna/Transaction.hs
  4. 6
      lib/Echidna/Types/CodehashMap.hs
  5. 2
      lib/Echidna/Types/Coverage.hs
  6. 2
      lib/Echidna/Types/Signature.hs

@ -156,14 +156,13 @@ randseq deployedContracts world = do
let
mutConsts = env.cfg.campaignConf.mutConsts
txConf = env.cfg.txConf
seqLen = env.cfg.campaignConf.seqLen
-- TODO: include reproducer when optimizing
--let rs = filter (not . null) $ map (.testReproducer) $ ca._tests
-- Generate new random transactions
randTxs <- replicateM seqLen (genTx world txConf deployedContracts)
randTxs <- replicateM seqLen (genTx world deployedContracts)
-- Generate a random mutator
cmut <- if seqLen == 1 then seqMutatorsStateless (fromConsts mutConsts)
else seqMutatorsStateful (fromConsts mutConsts)

@ -287,7 +287,7 @@ execTxWithCov tx = do
let (pc, opIx, depth) = currentCovLoc vm
contract = currentContract vm
maybeMetaVec <- lookupUsingCodehashOrInsert env.codehashMap contract env.dapp env.coverageRef $ do
maybeCovVec <- lookupUsingCodehashOrInsert env.codehashMap contract env.dapp env.coverageRef $ do
let size = BS.length . forceBuf . fromJust . view bytecode $ contract
if size == 0 then pure Nothing else do
-- IO for making a new vec
@ -296,7 +296,7 @@ execTxWithCov tx = do
forM_ [0..size-1] $ \i -> VMut.write vec i (-1, 0, 0)
pure $ Just vec
case maybeMetaVec of
case maybeCovVec of
Nothing -> pure ()
Just vec -> do
-- TODO: no-op when pc is out-of-bounds. This shouldn't happen but

@ -27,7 +27,7 @@ import Echidna.Orphans.JSON ()
import Echidna.Symbolic (forceWord, forceAddr)
import Echidna.Types (fromEVM)
import Echidna.Types.CodehashMap (lookupUsingCodehash)
import Echidna.Types.Config (Env(..))
import Echidna.Types.Config (Env(..), EConfig(..))
import Echidna.Types.Random
import Echidna.Types.Signature
(SignatureMap, SolCall, ContractA)
@ -58,11 +58,11 @@ getSignatures hmm (Just lmm) =
genTx
:: (MonadIO m, MonadRandom m, MonadState WorkerState m, MonadReader Env m)
=> World
-> TxConf
-> Map (Expr EAddr) Contract
-> m Tx
genTx world txConf deployedContracts = do
genTx world deployedContracts = do
env <- ask
let txConf = env.cfg.txConf
genDict <- gets (.genDict)
sigMap <- getSignatures world.highSignatureMap world.lowSignatureMap
sender <- rElem' world.senders

@ -8,14 +8,14 @@ import EVM.Dapp (DappInfo, findSrc)
import EVM.Solidity (SolcContract(..))
import EVM.Types (Contract(..), W256)
-- | Map from contracts' codehashes to their "real" (compile-time) codehash.
-- | Map from contracts' codehashes to their compile-time codehash.
-- This is relevant when the immutables solidity feature is used;
-- when this feature is not used, the map will just end up being an identity map.
-- `CodehashMap` is used in signature map and coverage map lookups.
type CodehashMap = IORef (Map W256 W256)
-- | Lookup a codehash in the `CodehashMap`.
-- In the case that it's not found, find the "real" (compile-time) codehash and add it to the map.
-- In the case that it's not found, find the compile-time codehash and add it to the map.
-- This is done using hevm's `findSrc` function.
lookupCodehash :: CodehashMap -> W256 -> Contract -> DappInfo -> IO W256
lookupCodehash chmap codehash contr dapp = do
@ -29,7 +29,7 @@ lookupCodehash chmap codehash contr dapp = do
-- | Given a map from codehash to some values of type `a`, lookup a contract in the map using its codehash.
-- In current use, the `Map W256 a` will be either a `SignatureMap` or a `CoverageMap`.
-- Returns the "real" codehash, and the map entry if it is found.
-- Returns the compile-time codehash, and the map entry if it is found.
lookupUsingCodehash :: CodehashMap -> Contract -> DappInfo -> Map W256 a -> IO (W256, Maybe a)
lookupUsingCodehash chmap contr dapp mapVal =
ifNotFound codehash $ do

@ -12,7 +12,7 @@ import EVM.Types (W256)
import Echidna.Types.Tx (TxResult)
-- | Map with the coverage information needed for fuzzing and source code printing.
-- Indexed by contracts' "real" codehash; see `CodehashMap`.
-- Indexed by contracts' compile-time codehash; see `CodehashMap`.
type CoverageMap = Map W256 (IOVector CoverageInfo)
-- | Basic coverage information

@ -28,7 +28,7 @@ type SolCall = (FunctionName, [AbiValue])
-- | A contract is just an address with an ABI (for our purposes).
type ContractA = (Addr, NonEmpty SolSignature)
-- | Indexed by contracts' "real" codehash; see `CodehashMap`.
-- | Indexed by contracts' compile-time codehash; see `CodehashMap`.
type SignatureMap = Map W256 (NonEmpty SolSignature)
knownBzzrPrefixes :: [ByteString]

Loading…
Cancel
Save