Template repository intended to ease fuzzing components of Solidity projects, especially libraries.
Solidity
216
10 commits
updated Dec 25, 2023
DESCRIPTION_HERE
src
│
├── echidna.yaml # Configuration file for Echidna.
├── foundry.toml # Configuration file for Foundry.
├── build.sh # Buildscript for downloading, compiling, initializing, ...
├── implementation # Implementations to fuzz (downloaded by buildscript).
│ └── ...
├── expose # Expose functions of libraries for tests.
│ └── ...
├── interface # Interfaces for accessing exposers with incompatible Solidity versions.
│ └── ...
└── test # Actual fuzzing testcases.
├── ...
├── addresses.sol # Addresses of incompatible libs, generated by buildscript.
└── helpers.sol # Reusable helper functions for tests.
Before any fuzzing can be run, build.sh needs to be executed, which has the following dependencies:
After the buildscript was successfully executed, the implementation directory should be populated, there'll be a echidna-init.json file and a ganache instance will still be running in the background.
# Simple fuzzing with Echidna:
echidna --contract Test --config echidna.yaml src/test/example/BytesLib.sol
# Differential fuzzing against another implementation with incompatible Solidity version via initialization file:
echidna --contract Test --config echidna.yaml src/test/example/BytesLib-BytesUtil-diff.sol
# Differential fuzzing against an executable via FFI shell command execution:
echidna --contract Test --config echidna.yaml src/test/example/BytesLib-FFI-diff.sol
*The FFI cheatcode is experimental in Echidna and only available when compiling with PR#750
# Simple fuzzing with Foundry:
forge test --match-test test_BytesLib_slice
# Differential fuzzing against another implementation with incompatible Solidity version via ganache fork:
forge test --fork-url http://127.0.0.1:8545/ --match-path src/test/example/BytesLib-BytesUtil-diff.sol
# Differential fuzzing against an executable via FFI shell command execution:
forge test --match-path src/test/example/BytesLib-FFI-diff.sol
Note that forge will appear to be stuck, but it's actually running 999999999 tests as configured in foundry.toml. This is intended to be kept running on servers for hours. If you instead want to run quick tests, eg. for CI, adjust the configuration according to your needs.
# Call function of exposed library and show execution trace:
forge script --sig "slice(bytes,uint256,uint256)" --target-contract ExposedBytesLib -vvvv src/expose/example/BytesLib.sol 0x010203 1 1
# Manually execute a testcase to reproduce an issue:
forge script --fork-url http://127.0.0.1:8545/ --sig "test_BytesLib_BytesUtil_diff_slice(bytes,uint256,uint256)" --target-contract Test -vvvv src/test/example/BytesLib-BytesUtil-diff.sol 0x010203 1 1
This is a template repository intended to ease fuzzing components of Solidity projects, especially libraries.
Check the echidna.yaml and foundry.toml configuration files.
Edit the build.sh file and adjust it for your usecase
Take a look at the example testcases and write your own.
Don't forget to document the intention, setup and commands for your fuzzing campaign.
9 commits
1 commits
Solidity
68.8%
Shell
25.6%
JavaScript
5.6%
Template repository intended to ease fuzzing components of Solidity projects, especially libraries.
Solidity
216
10 commits
updated Dec 25, 2023
DESCRIPTION_HERE
src
│
├── echidna.yaml # Configuration file for Echidna.
├── foundry.toml # Configuration file for Foundry.
├── build.sh # Buildscript for downloading, compiling, initializing, ...
├── implementation # Implementations to fuzz (downloaded by buildscript).
│ └── ...
├── expose # Expose functions of libraries for tests.
│ └── ...
├── interface # Interfaces for accessing exposers with incompatible Solidity versions.
│ └── ...
└── test # Actual fuzzing testcases.
├── ...
├── addresses.sol # Addresses of incompatible libs, generated by buildscript.
└── helpers.sol # Reusable helper functions for tests.
Before any fuzzing can be run, build.sh needs to be executed, which has the following dependencies:
After the buildscript was successfully executed, the implementation directory should be populated, there'll be a echidna-init.json file and a ganache instance will still be running in the background.
# Simple fuzzing with Echidna:
echidna --contract Test --config echidna.yaml src/test/example/BytesLib.sol
# Differential fuzzing against another implementation with incompatible Solidity version via initialization file:
echidna --contract Test --config echidna.yaml src/test/example/BytesLib-BytesUtil-diff.sol
# Differential fuzzing against an executable via FFI shell command execution:
echidna --contract Test --config echidna.yaml src/test/example/BytesLib-FFI-diff.sol
*The FFI cheatcode is experimental in Echidna and only available when compiling with PR#750
# Simple fuzzing with Foundry:
forge test --match-test test_BytesLib_slice
# Differential fuzzing against another implementation with incompatible Solidity version via ganache fork:
forge test --fork-url http://127.0.0.1:8545/ --match-path src/test/example/BytesLib-BytesUtil-diff.sol
# Differential fuzzing against an executable via FFI shell command execution:
forge test --match-path src/test/example/BytesLib-FFI-diff.sol
Note that forge will appear to be stuck, but it's actually running 999999999 tests as configured in foundry.toml. This is intended to be kept running on servers for hours. If you instead want to run quick tests, eg. for CI, adjust the configuration according to your needs.
# Call function of exposed library and show execution trace:
forge script --sig "slice(bytes,uint256,uint256)" --target-contract ExposedBytesLib -vvvv src/expose/example/BytesLib.sol 0x010203 1 1
# Manually execute a testcase to reproduce an issue:
forge script --fork-url http://127.0.0.1:8545/ --sig "test_BytesLib_BytesUtil_diff_slice(bytes,uint256,uint256)" --target-contract Test -vvvv src/test/example/BytesLib-BytesUtil-diff.sol 0x010203 1 1
This is a template repository intended to ease fuzzing components of Solidity projects, especially libraries.
Check the echidna.yaml and foundry.toml configuration files.
Edit the build.sh file and adjust it for your usecase
Take a look at the example testcases and write your own.
Don't forget to document the intention, setup and commands for your fuzzing campaign.
9 commits
1 commits
Solidity
68.8%
Shell
25.6%
JavaScript
5.6%