Skip to main content

A tool for automatically generating unit tests from Echidna and Medusa reproducers.

Project description

Slither Static Analysis Framework Logo

Automated tool for generating Foundry unit tests from smart contract fuzzer failed properties

fuzz-utils is a Python tool that generates unit tests from Echidna and Medusa failed properties, using the generated reproducer files. It uses Slither for determining types and jinja2 for generating the test files using string templates.

Disclaimer: Please note that fuzz-utils is under development. Currently, not all Solidity types are supported and some types (like bytes*, and string) might be improperly decoded from the corpora call sequences. We are investigating a better corpus format that will ease the creation of unit tests.

Features

fuzz-utils provides support for:

  • ✔️ Generating Foundry unit tests from the fuzzer corpus of single entry point fuzzing harnesses
  • ✔️ Medusa and Echidna corpora
  • ✔️ Solidity types: bool,uint*, int*, address, struct, enum, single-dimensional fixed-size arrays and dynamic arrays, multi-dimensional fixed-size arrays.

Multi-dimensional dynamic arrays, function pointers, and other more complex types are in the works, but are currently not supported.

Installation and pre-requisites

To install fuzz-utils:

pip install fuzz-utils

These commands will install all the Python libraries and tools required to run fuzz-utils. However, it won't install Echidna or Medusa, so you will need to download and install the latest version yourself from its official releases (Echidna, Medusa).

Example

In order to generate a test file for the BasicTypes.sol contract, based on the Echidna corpus reproducers for this contract (corpus-basic), we need to cd into the tests/test_data directory which contains the Foundry project and run the command:

fuzz-utils ./src/BasicTypes.sol --corpus-dir echidna-corpora/corpus-basic --contract "BasicTypes" --test-directory "./test/" --inheritance-path "../src/" --fuzzer echidna

Running this command should generate a BasicTypes_Echidna_Test.sol file in the tests directory of the Foundry project.

Command-line options

Additional options are available for the script:

  • -cd/--corpus-dir path_to_corpus_dir: The path to the corpus directory relative to the working directory.
  • -c/--contract contract_name: The name of the contract.
  • -td/--test-directory path_to_test_directory: The path to the test directory relative to the working directory.
  • -i/--inheritance-path relative_path_to_contract: The relative path from the test directory to the contract (used for inheritance).
  • -f/--fuzzer fuzzer_name: The name of the fuzzer, currently supported: echidna and medusa

Contributing

For information about how to contribute to this project, check out the CONTRIBUTING guidelines.

License

fuzz-utils is licensed and distributed under the AGPLv3.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fuzz-utils-0.0.1.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

fuzz_utils-0.0.1-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file fuzz-utils-0.0.1.tar.gz.

File metadata

  • Download URL: fuzz-utils-0.0.1.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for fuzz-utils-0.0.1.tar.gz
Algorithm Hash digest
SHA256 682f1afa9f483cfb9a20e13d35152b4c9a1686a9e398ee63e839ef94ff951633
MD5 c98f56130848aa55cfa632014c9abc36
BLAKE2b-256 b9ee657b5f8f8969b52e4a5c6a3e3e72f87a6aad3a31a0cd26c4f52920af8204

See more details on using hashes here.

File details

Details for the file fuzz_utils-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: fuzz_utils-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for fuzz_utils-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01966d2c09f74b6ccf176f5fcdaf43568d94d4c079088406e4c672101ded781b
MD5 d5e6d35b9100e5dacbb7afd820503f37
BLAKE2b-256 c01d163bcc816b309e8fd1fda02142bc8314331fa297799e8958db15b365b287

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page