Skip to content

Commit 5d49a9d

Browse files
committed
Speed up coverage filename calculation
Don't show and then hash; instead, compute hash directly.
1 parent b23878f commit 5d49a9d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/Echidna/Output/Corpus.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ 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"
26+
let file = dir </> (show . abs . hash) txSeq <.> "txt"
2727
unlessM (doesFileExist file) $ encodeFile file (toJSON txSeq)
2828
pushCampaignEvent env (ReproducerSaved file)
2929

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)