11module Echidna.Mutator.Corpus where
22
33import Control.Monad.Random.Strict (MonadRandom , getRandomR , weighted )
4- import Data.Set (Set )
54import Data.Set qualified as Set
65
76import Echidna.Mutator.Array
@@ -11,10 +10,10 @@ import Echidna.Types.Tx (Tx)
1110import Echidna.Types.Corpus
1211
1312defaultMutationConsts :: Num a => MutationConsts a
14- defaultMutationConsts = (1 , 1 , 1 , 1 )
13+ defaultMutationConsts = (1 , 1 , 1 , 1 , 1 )
1514
1615fromConsts :: Num a => MutationConsts Integer -> MutationConsts a
17- fromConsts (a, b, c, d) = let fi = fromInteger in (fi a, fi b, fi c, fi d)
16+ fromConsts (a, b, c, d, e ) = let fi = fromInteger in (fi a, fi b, fi c, fi d, fi e )
1817
1918data TxsMutation = Identity
2019 | Shrinking
@@ -28,6 +27,7 @@ data CorpusMutation = RandomAppend TxsMutation
2827 | RandomPrepend TxsMutation
2928 | RandomSplice
3029 | RandomInterleave
30+ | RemoveReverts
3131 deriving (Eq , Ord , Show )
3232
3333mutator :: MonadRandom m => TxsMutation -> [Tx ] -> m [Tx ]
@@ -63,10 +63,10 @@ selectAndCombine f ql corpus gtxs = do
6363
6464selectFromCorpus
6565 :: MonadRandom m
66- => Set ( Int , [ Tx ])
66+ => Corpus
6767 -> m [Tx ]
6868selectFromCorpus =
69- weighted . map (\ (i, txs) -> (txs, fromIntegral i)) . Set. toDescList
69+ weighted . map (\ (i, txs) -> (txs, fromIntegral i)) . Set. toDescList . fst
7070
7171getCorpusMutation
7272 :: MonadRandom m
@@ -85,12 +85,13 @@ getCorpusMutation (RandomPrepend m) = mut (mutator m)
8585 pure . take ql $ take k gtxs ++ rtxs'
8686getCorpusMutation RandomSplice = selectAndCombine spliceAtRandom
8787getCorpusMutation RandomInterleave = selectAndCombine interleaveAtRandom
88+ getCorpusMutation RemoveReverts = \ _ (_, revertingTxs) txs -> pure $ filter (not . flip Set. member revertingTxs) txs
8889
8990seqMutatorsStateful
9091 :: MonadRandom m
9192 => MutationConsts Rational
9293 -> m CorpusMutation
93- seqMutatorsStateful (c1, c2, c3, c4) = weighted
94+ seqMutatorsStateful (c1, c2, c3, c4, c5 ) = weighted
9495 [(RandomAppend Identity , 800 ),
9596 (RandomPrepend Identity , 200 ),
9697
@@ -107,14 +108,16 @@ seqMutatorsStateful (c1, c2, c3, c4) = weighted
107108 (RandomPrepend Deletion , c3),
108109
109110 (RandomSplice , c4),
110- (RandomInterleave , c4)
111+ (RandomInterleave , c4),
112+
113+ (RemoveReverts , c5)
111114 ]
112115
113116seqMutatorsStateless
114117 :: MonadRandom m
115118 => MutationConsts Rational
116119 -> m CorpusMutation
117- seqMutatorsStateless (c1, c2, _, _) = weighted
120+ seqMutatorsStateless (c1, c2, _, _, _ ) = weighted
118121 [(RandomAppend Identity , 800 ),
119122 (RandomPrepend Identity , 200 ),
120123
0 commit comments