How to Set Up and Use the ILF: An AI-based Fuzzer for Ethereum Smart Contracts

Apr 29, 2022 | Blockchain

Are you interested in testing and securing your Ethereum smart contracts? The ILF (Imitation Learning-based Fuzzer) is an innovative tool developed at the SRI Lab, Department of Computer Science, ETH Zurich. This article will guide you through the setup and usage of ILF, along with some troubleshooting tips to ensure a smooth process.

What is ILF?

ILF is an AI-based fuzzer designed to evaluate the security of Ethereum smart contracts. It utilizes a unique fuzzing policy based on imitation learning and neural networks, trained on thousands of high-quality transaction sequences generated through symbolic execution. With ILF, you can fuzz any Ethereum smart contract, obtaining coverage reports and identifying vulnerabilities in your contracts.

Setup Instructions

To get started with ILF, we recommend using a Docker setup. Follow these steps:

  • Build the Docker image by running the command:
  • $ docker build -t ilf .
  • Once built, run the ILF container with:
  • $ docker run -it ilf
  • Alternatively, you can install ILF locally by following the instructions in the Dockerfile.

If you encounter build errors, especially on Apple M chips, refer to issue #21 for guidance.

Usage Instructions

Fuzzing Your Smart Contracts

To fuzz an example provided in the repository using ILF and its pre-trained model, run the following command:

$ python3 -m ilf --proj .examplecrowdsale --contract Crowdsale --fuzzer imitation --model .model --limit 2000

Here are a few alternative fuzzing policies you can choose from:

  • random: A uniformly random fuzzing policy.
  • symbolic: A symbolic execution fuzzing policy using depth-first search.
  • sym_plus: An augmented version that revisits encountered block states.
  • mix: A hybrid approach that randomly selects between imitation and symbolic for each transaction.

Extracting Deployment Transactions

For fuzzing new contracts, you will first need to create a Truffle project. After setting up the project, you can extract deployment transactions using:

$ python3 scriptextract.py --proj examplecrowdsale --port 8545

Ensure that you kill any existing ganache-cli processes that are using the same port before running the script.

Training Your Model

Training the model involves generating a dataset from a set of training contracts. The steps are as follows:

  • Create a directory for your training data:
  • $ mkdir train_data
  • Run the command to generate a small dataset:
  • $ python3 -m ilf --proj .examplecrowdsale --contract Crowdsale --limit 2000 --fuzzer symbolic --dataset_dump_path .train_data/crowdsale.data
  • Select integer and amount values from the training dataset:
  • $ python3 scriptget_int_values.py --train_dir .train_data
  • Finally, train the neural network using:
  • $ python3 -m ilf --fuzzer imitation --train_dir .train_data --model .new_model

Automatically Constructing Truffle Projects

If you’re dealing with a large number of contracts, you might want to automate the construction of Truffle projects. The provided truffle_scripts.tar.gz compresses scripts that help in creating necessary files based on an example format.

Troubleshooting Tips

If you encounter issues during setup or usage, consider the following:

  • Make sure Docker is properly installed and running in your environment.
  • Check your environment variables and configurations for any discrepancies.
  • Refer to the official documentation or GitHub issues for specific error messages you encounter.
  • If you’re still having trouble, leave a message or query in the community support channels for additional assistance.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

With ILF, developers can significantly enhance the security and reliability of their Ethereum smart contracts. By leveraging the power of imitation learning, you can uncover potential vulnerabilities that may otherwise go unnoticed.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox