Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked mutators and tests to be more efficient #628

Merged
merged 5 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/solidity/basic/gasuse.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
testLimit: 1000
testLimit: 5000
testMaxGas: 4294967295
estimateGas: true
2 changes: 1 addition & 1 deletion examples/solidity/basic/now.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract C {
}

function guess(uint x) public {
if (x <= time + 1 weeks && x >= time - 1 weeks )
if (x <= time + 4 weeks && x >= time - 4 weeks )
state = true;
}

Expand Down
11 changes: 6 additions & 5 deletions lib/Echidna/Mutator/Corpus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ defaultMutationConsts = (1, 1, 1, 1)
fromConsts :: Num a => MutationConsts Integer -> MutationConsts a
fromConsts (a, b, c, d) = let fi = fromInteger in (fi a, fi b, fi c, fi d)

data TxsMutation = Shrinking
data TxsMutation = Identity
| Shrinking
| Mutation
| Expansion
| Swapping
| Deletion
deriving (Eq, Ord, Show)

data CorpusMutation = Skip
| RandomAppend TxsMutation
data CorpusMutation = RandomAppend TxsMutation
| RandomPrepend TxsMutation
| RandomSplice
| RandomInterleave
deriving (Eq, Ord, Show)

mutator :: MonadRandom m => TxsMutation -> [Tx] -> m [Tx]
mutator Identity = return
mutator Shrinking = mapM shrinkTx
mutator Mutation = mapM mutateTx
mutator Expansion = expandRandList
Expand All @@ -60,7 +61,6 @@ selectAndCombine f ql ctxs gtxs = do

getCorpusMutation :: (MonadRandom m, Has GenDict x, MonadState x m)
=> CorpusMutation -> (Int -> Corpus -> [Tx] -> m [Tx])
getCorpusMutation Skip = \_ _ -> return
getCorpusMutation (RandomAppend m) = mut (mutator m)
where mut f ql ctxs gtxs = do
rtxs' <- selectAndMutate f ctxs
Expand All @@ -75,7 +75,8 @@ getCorpusMutation RandomInterleave = selectAndCombine interleaveAtRandom

seqMutators :: MonadRandom m => MutationConsts Rational -> m CorpusMutation
seqMutators (c1, c2, c3, c4) = weighted
[(Skip, 1000),
[(RandomAppend Identity, 800),
(RandomPrepend Identity, 200),

(RandomAppend Shrinking, c1),
(RandomAppend Mutation, c2),
Expand Down