building-secure-contracts
building-secure-contracts copied to clipboard
Add Echidna tips & tricks
trafficstars
- If you fuzz a parameter that is expected to have only some values, use
%:
function f(uint index) public{
index = `index%2`
if (index == 0) {...}
elif (index == 1) {...}
}
- To fuzz an arbitrary array length, you can use a push/pop approach (explain why?):
uint my_array[]
function push(uint a) public{
my_array.push(a)
}
function pop() public{
my_array.pop()
}
Note that in some cases the push/pop approach will tend to produce smaller arrays than you want. Omitting pop can be a good idea (indeed, I would wager a decent chunk of the reason swarm testing works is omitting pop).
@ggrieco-tob : can you add an example for the push/pop example in https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/echidna/fuzzing_tips.md ?
This was added