cov-wip-10-rebased-again
Sam Alws 10 months ago
parent 292168a8aa
commit 7c8fdbc793
  1. 4
      lib/Echidna/Transaction.hs
  2. 19
      lib/Echidna/Types/CodehashMap.hs

@ -13,7 +13,7 @@ import Control.Monad.Reader (MonadReader, ask)
import Control.Monad.State.Strict (MonadState, gets, modify', execState) import Control.Monad.State.Strict (MonadState, gets, modify', execState)
import Control.Monad.ST (RealWorld) import Control.Monad.ST (RealWorld)
import Data.Map (Map, toList) import Data.Map (Map, toList)
import Data.Maybe (mapMaybe) import Data.Maybe (catMaybes)
import Data.Set (Set) import Data.Set (Set)
import Data.Set qualified as Set import Data.Set qualified as Set
import Data.Vector qualified as V import Data.Vector qualified as V
@ -67,7 +67,7 @@ genTx world txConf deployedContracts = do
sigMap <- getSignatures world.highSignatureMap world.lowSignatureMap sigMap <- getSignatures world.highSignatureMap world.lowSignatureMap
sender <- rElem' world.senders sender <- rElem' world.senders
mappedList <- liftIO $ mapM (toContractA env sigMap) (toList deployedContracts) mappedList <- liftIO $ mapM (toContractA env sigMap) (toList deployedContracts)
(dstAddr, dstAbis) <- rElem' $ Set.fromList $ mapMaybe id mappedList (dstAddr, dstAbis) <- rElem' $ Set.fromList $ catMaybes mappedList
solCall <- genInteractionsM genDict dstAbis solCall <- genInteractionsM genDict dstAbis
value <- genValue txConf.maxValue genDict.dictValues world.payableSigs solCall value <- genValue txConf.maxValue genDict.dictValues world.payableSigs solCall
ts <- (,) <$> genDelay txConf.maxTimeDelay genDict.dictValues ts <- (,) <$> genDelay txConf.maxTimeDelay genDict.dictValues

@ -3,7 +3,6 @@ module Echidna.Types.CodehashMap where
import Data.IORef (IORef, readIORef, atomicModifyIORef') import Data.IORef (IORef, readIORef, atomicModifyIORef')
import Data.Map.Strict qualified as Map import Data.Map.Strict qualified as Map
import Data.Map.Strict (Map) import Data.Map.Strict (Map)
import Data.Maybe (fromMaybe)
import Echidna.Symbolic (forceWord) import Echidna.Symbolic (forceWord)
import EVM.Dapp (DappInfo, findSrc) import EVM.Dapp (DappInfo, findSrc)
import EVM.Solidity (SolcContract(..)) import EVM.Solidity (SolcContract(..))
@ -12,12 +11,14 @@ import EVM.Types (Contract(..), W256)
type CodehashMap = IORef (Map W256 W256) type CodehashMap = IORef (Map W256 W256)
lookupCodehash :: CodehashMap -> W256 -> Contract -> DappInfo -> IO W256 lookupCodehash :: CodehashMap -> W256 -> Contract -> DappInfo -> IO W256
lookupCodehash chmap codehash contr dapp = Map.lookup codehash <$> readIORef chmap >>= \case lookupCodehash chmap codehash contr dapp = do
Just val -> pure val chmapVal <- readIORef chmap
Nothing -> do case Map.lookup codehash chmapVal of
let originalCodehash = fromMaybe codehash $ (.runtimeCodehash) <$> findSrc contr dapp Just val -> pure val
atomicModifyIORef' chmap $ (, ()) . Map.insert codehash originalCodehash Nothing -> do
pure originalCodehash let originalCodehash = maybe codehash (.runtimeCodehash) (findSrc contr dapp)
atomicModifyIORef' chmap $ (, ()) . Map.insert codehash originalCodehash
pure originalCodehash
lookupUsingCodehash :: CodehashMap -> Contract -> DappInfo -> Map W256 a -> IO (W256, Maybe a) lookupUsingCodehash :: CodehashMap -> Contract -> DappInfo -> Map W256 a -> IO (W256, Maybe a)
lookupUsingCodehash chmap contr dapp mapVal = do lookupUsingCodehash chmap contr dapp mapVal = do
@ -26,7 +27,7 @@ lookupUsingCodehash chmap contr dapp mapVal = do
ifNotFound codehash' $ pure (codehash', Nothing) ifNotFound codehash' $ pure (codehash', Nothing)
where where
codehash = forceWord contr.codehash codehash = forceWord contr.codehash
ifNotFound key notFoundCase = case (Map.lookup key mapVal) of ifNotFound key notFoundCase = case Map.lookup key mapVal of
Nothing -> notFoundCase Nothing -> notFoundCase
Just val -> pure (key, Just val) Just val -> pure (key, Just val)
@ -41,6 +42,6 @@ lookupUsingCodehashOrInsert chmap contr dapp mapRef make = do
applyModification _ Nothing = pure Nothing applyModification _ Nothing = pure Nothing
applyModification key (Just val) = atomicModifyIORef' mapRef $ modifyFn key val applyModification key (Just val) = atomicModifyIORef' mapRef $ modifyFn key val
modifyFn key val oldMap = case (Map.lookup key oldMap) of modifyFn key val oldMap = case Map.lookup key oldMap of
Just val' -> (oldMap, Just val') Just val' -> (oldMap, Just val')
Nothing -> (Map.insert key val oldMap, Just val) Nothing -> (Map.insert key val oldMap, Just val)

Loading…
Cancel
Save