Skip to content

Commit 943e89b

Browse files
authored
Merge pull request #1411 from crytic/faster-saving
Speed up coverage filename calculation
2 parents 8408892 + 14dc75b commit 943e89b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

lib/Echidna/Output/Corpus.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ saveTxs :: Env -> FilePath -> [[Tx]] -> IO ()
2323
saveTxs env dir = mapM_ saveTxSeq where
2424
saveTxSeq txSeq = do
2525
createDirectoryIfMissing True dir
26-
let file = dir </> (show . abs . hash . show) txSeq <.> "txt"
27-
unlessM (doesFileExist file) $ encodeFile file (toJSON txSeq)
28-
pushCampaignEvent env (ReproducerSaved file)
26+
let file = dir </> (show . abs . hash) txSeq <.> "txt"
27+
unlessM (doesFileExist file) $ do
28+
encodeFile file (toJSON txSeq)
29+
pushCampaignEvent env (ReproducerSaved file)
2930

3031
loadTxs :: FilePath -> IO [(FilePath, [Tx])]
3132
loadTxs dir = do

lib/Echidna/Types/Tx.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import Data.Aeson (FromJSON, ToJSON, parseJSON, toJSON, object, withObject, (.=)
1414
import Data.Aeson.TH (deriveJSON, defaultOptions)
1515
import Data.Aeson.Types (Parser)
1616
import Data.ByteString (ByteString)
17+
import Data.Hashable (Hashable(..))
1718
import Data.Text (Text)
19+
import Data.Vector (Vector, toList)
1820
import Data.Word (Word64)
1921

2022
import EVM.ABI (encodeAbiValue, AbiValue(..), AbiType)
@@ -67,6 +69,16 @@ data Tx = Tx
6769
, delay :: !(W256, W256) -- ^ (Time, # of blocks since last call)
6870
} deriving (Eq, Ord, Show, Generic)
6971

72+
instance Hashable a => Hashable (Vector a) where
73+
hashWithSalt s v = s `hashWithSalt` toList v
74+
75+
deriving instance Hashable Tx
76+
deriving instance Hashable TxCall
77+
deriving instance Hashable AbiValue
78+
deriving instance Hashable AbiType
79+
deriving anyclass instance Hashable Addr
80+
deriving anyclass instance Hashable W256
81+
7082
deriving instance NFData Tx
7183
deriving instance NFData TxCall
7284
deriving instance NFData AbiValue

src/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ main = withUtf8 $ withCP65001 $ do
9393
(results, finalVM) <- reproduceTest vm test
9494
let subdir = dir </> "reproducers-traces"
9595
liftIO $ createDirectoryIfMissing True subdir
96-
let file = subdir </> (show . abs . hash . show) test.reproducer <.> "txt"
96+
let file = subdir </> (show . abs . hash) test.reproducer <.> "txt"
9797
txsPrinted <- ppFailWithTraces Nothing finalVM results
9898
liftIO $ writeFile file (ppTestName test <> ": " <> txsPrinted)
9999

0 commit comments

Comments
 (0)