Figure 1. High overview of Fuzzing Architecture
Figure 2. Graph of the code (Path Graph)
pip install echidna
// SimpleMath.sol
pragma solidity ^0.8.0;
contract SimpleMath {
function add(uint256 a, uint256 b) public pure returns (uint256) {
return a + b;
}
}
Figure 3. `SimpleMath` contract
# fuzz_simple_math.py
from echidna import fuzz, test, result
# Import the contract to be fuzzed
import SimpleMath
# Define the test properties
@test
def test_add_overflow():
a = fuzz.uint256()
b = fuzz.uint256()
# Avoid potential overflow
assume(a < (2**256 - b))
assert SimpleMath.add(a, b) == a + b
Figure 4. Python code to test overflow
echidna-test fuzz_simple_math.py
HASHEX