Skip to content

Commit 5c8b253

Browse files
committed
Compute status line reproducer length on demand
1 parent 7b14fdf commit 5c8b253

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

lib/Echidna/Campaign.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ runSymWorker callback vm dict workerId _ name = do
145145
, ncalls = 0
146146
, totalGas = 0
147147
, runningThreads = []
148-
, lastShrinkP = Nothing
149148
}
150149

151150
-- We could pattern match on workerType here to ignore WorkerEvents from SymbolicWorkers,
@@ -343,7 +342,6 @@ runFuzzWorker callback vm dict workerId initialCorpus testLimit = do
343342
, ncalls = 0
344343
, totalGas = 0
345344
, runningThreads = []
346-
, lastShrinkP = Nothing
347345
}
348346

349347
flip runStateT initialState $ do

lib/Echidna/Shrink.hs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Control.Monad ((<=<))
44
import Control.Monad.Catch (MonadThrow)
55
import Control.Monad.Random.Strict (MonadRandom, getRandomR, uniform)
66
import Control.Monad.Reader.Class (MonadReader (ask), asks)
7-
import Control.Monad.State.Strict (MonadIO, MonadState, modify')
7+
import Control.Monad.State.Strict (MonadIO)
88
import Control.Monad.ST (RealWorld)
99
import Data.Set qualified as Set
1010
import Data.List qualified as List
@@ -18,12 +18,12 @@ import Echidna.Types.Solidity (SolConf(..))
1818
import Echidna.Types.Test (TestValue(..), EchidnaTest(..), TestState(..), isOptimizationTest)
1919
import Echidna.Types.Tx (Tx(..), hasReverted, isUselessNoCall, catNoCalls, TxCall(..))
2020
import Echidna.Types.Config
21-
import Echidna.Types.Campaign (CampaignConf(..), WorkerState(..))
21+
import Echidna.Types.Campaign (CampaignConf(..))
2222
import Echidna.Test (getResultFromVM, checkETest)
2323

2424
-- | Top level function to shrink the complexity of the sequence of transactions once
2525
shrinkTest
26-
:: (MonadIO m, MonadThrow m, MonadRandom m, MonadReader Env m, MonadState WorkerState m)
26+
:: (MonadIO m, MonadThrow m, MonadRandom m, MonadReader Env m)
2727
=> VM Concrete RealWorld
2828
-> EchidnaTest
2929
-> m (Maybe EchidnaTest)
@@ -42,19 +42,17 @@ shrinkTest vm test = do
4242
if length rr > 1 || any canShrinkTx rr then do
4343
maybeShrunk <- shrinkSeq vm (checkETest test) test.value rr
4444
-- check if the shrunk sequence passes the test or not
45-
case maybeShrunk of
45+
pure $ case maybeShrunk of
4646
-- the test still fails, let's create another test with the reduced sequence
4747
Just (txs, val, vm') -> do
48-
let afterLen = length txs
49-
modify' $ \ws -> ws { lastShrinkP = Just afterLen }
50-
pure $ Just test { state = Large (i + 1)
48+
Just test { state = Large (i + 1)
5149
, reproducer = txs
5250
, vm = Just vm'
5351
, result = getResultFromVM vm'
5452
, value = val }
5553
Nothing ->
5654
-- The test passed, so no success with shrinking this time, just bump number of tries to shrink
57-
pure $ Just test { state = Large (i + 1), reproducer = rr}
55+
Just test { state = Large (i + 1), reproducer = rr}
5856
else
5957
pure $ Just test { state = if isOptimizationTest test
6058
then Large (i + 1)
@@ -91,7 +89,7 @@ removeReverts' vm (t:txs) ftxs = do
9189
-- | Given a call sequence that solves some Echidna test, try to randomly
9290
-- generate a smaller one that still solves that test.
9391
shrinkSeq
94-
:: (MonadIO m, MonadRandom m, MonadReader Env m, MonadThrow m, MonadState WorkerState m)
92+
:: (MonadIO m, MonadRandom m, MonadReader Env m, MonadThrow m)
9593
=> VM Concrete RealWorld
9694
-> (VM Concrete RealWorld -> m (TestValue, VM Concrete RealWorld))
9795
-> TestValue

lib/Echidna/Types/Campaign.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ data WorkerState = WorkerState
8484
, runningThreads :: [ThreadId]
8585
-- ^ Extra threads currently being run,
8686
-- aside from the main worker thread
87-
, lastShrinkP :: Maybe Int
88-
-- ^ Last known reproducer length that still falsifies
8987
}
9088

9189
initialWorkerState :: WorkerState
@@ -97,7 +95,6 @@ initialWorkerState =
9795
, ncalls = 0
9896
, totalGas = 0
9997
, runningThreads = []
100-
, lastShrinkP = Nothing
10198
}
10299

103100
defaultTestLimit :: Int

lib/Echidna/UI.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,13 @@ statusLine env states lastUpdateRef = do
417417
| null shrinkCounters = ", shrinking: N/A"
418418
| otherwise = ", shrinking: " <> show (maximum shrinkCounters)
419419
<> "/" <> show shrinkLimit
420-
<> maybe "" (\p -> "(" <> show p <> ")") (listToMaybe $ mapMaybe (.lastShrinkP) states)
420+
<> formatCurrentLength
421+
where
422+
formatCurrentLength =
423+
let lengths = [length test.reproducer | test <- tests,
424+
case test.state of Large _ -> True; _ -> False,
425+
not (null test.reproducer)]
426+
in maybe "" (\p -> " (" <> show p <> ")") (listToMaybe lengths)
421427

422428
pure $ "tests: " <> show (length $ filter didFail tests) <> "/" <> show (length tests)
423429
<> ", fuzzing: " <> show totalCalls <> "/" <> show env.cfg.campaignConf.testLimit

0 commit comments

Comments
 (0)