1
1
module Echidna.Mutator.Corpus where
2
2
3
3
import Control.Monad.Random.Strict (MonadRandom , getRandomR , weighted )
4
- import Data.Set (Set )
5
4
import Data.Set qualified as Set
6
5
7
6
import Echidna.Mutator.Array
@@ -11,10 +10,10 @@ import Echidna.Types.Tx (Tx)
11
10
import Echidna.Types.Corpus
12
11
13
12
defaultMutationConsts :: Num a => MutationConsts a
14
- defaultMutationConsts = (1 , 1 , 1 , 1 )
13
+ defaultMutationConsts = (1 , 1 , 1 , 1 , 1 )
15
14
16
15
fromConsts :: 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 )
18
17
19
18
data TxsMutation = Identity
20
19
| Shrinking
@@ -28,6 +27,7 @@ data CorpusMutation = RandomAppend TxsMutation
28
27
| RandomPrepend TxsMutation
29
28
| RandomSplice
30
29
| RandomInterleave
30
+ | RemoveReverts
31
31
deriving (Eq , Ord , Show )
32
32
33
33
mutator :: MonadRandom m => TxsMutation -> [Tx ] -> m [Tx ]
@@ -63,10 +63,10 @@ selectAndCombine f ql corpus gtxs = do
63
63
64
64
selectFromCorpus
65
65
:: MonadRandom m
66
- => Set ( Int , [ Tx ])
66
+ => Corpus
67
67
-> m [Tx ]
68
68
selectFromCorpus =
69
- weighted . map (\ (i, txs) -> (txs, fromIntegral i)) . Set. toDescList
69
+ weighted . map (\ (i, txs) -> (txs, fromIntegral i)) . Set. toDescList . fst
70
70
71
71
getCorpusMutation
72
72
:: MonadRandom m
@@ -85,12 +85,13 @@ getCorpusMutation (RandomPrepend m) = mut (mutator m)
85
85
pure . take ql $ take k gtxs ++ rtxs'
86
86
getCorpusMutation RandomSplice = selectAndCombine spliceAtRandom
87
87
getCorpusMutation RandomInterleave = selectAndCombine interleaveAtRandom
88
+ getCorpusMutation RemoveReverts = \ _ (_, revertingTxs) txs -> pure $ filter (not . flip Set. member revertingTxs) txs
88
89
89
90
seqMutatorsStateful
90
91
:: MonadRandom m
91
92
=> MutationConsts Rational
92
93
-> m CorpusMutation
93
- seqMutatorsStateful (c1, c2, c3, c4) = weighted
94
+ seqMutatorsStateful (c1, c2, c3, c4, c5 ) = weighted
94
95
[(RandomAppend Identity , 800 ),
95
96
(RandomPrepend Identity , 200 ),
96
97
@@ -107,14 +108,16 @@ seqMutatorsStateful (c1, c2, c3, c4) = weighted
107
108
(RandomPrepend Deletion , c3),
108
109
109
110
(RandomSplice , c4),
110
- (RandomInterleave , c4)
111
+ (RandomInterleave , c4),
112
+
113
+ (RemoveReverts , c5)
111
114
]
112
115
113
116
seqMutatorsStateless
114
117
:: MonadRandom m
115
118
=> MutationConsts Rational
116
119
-> m CorpusMutation
117
- seqMutatorsStateless (c1, c2, _, _) = weighted
120
+ seqMutatorsStateless (c1, c2, _, _, _ ) = weighted
118
121
[(RandomAppend Identity , 800 ),
119
122
(RandomPrepend Identity , 200 ),
120
123
0 commit comments