Skip to content

Generate invariants for Foundry projects with LLM

Notifications You must be signed in to change notification settings

fuzzland/invgen

Repository files navigation

InvGen

Generate invariants for Foundry projects using LLM + RAG + Chain of Thought. Example output

Install

Ensure you have Node.js and Docker installed. This script will install dependencies and setup Weaviate container.

git clone https://github.com/fuzzland/invgen.git && cd invgen
./setup.sh

Usage

Generate invariants for a given project (e.g. ARK). The project should be a Foundry project and has a setup file with setUp function that deploy the contract-under-test should be provided.

node ./build/src/index.js examples/ark \
    --project-type=foundry \
    --compiler-version=0.8.13 \
    --setup-file=script/ARK.s.sol:InvariantTest \
    --target-file=src/ARK.sol:AbsToken

The generated invariants will be saved in results folder. You can then run the generated invariants by using Foundry or ItyFuzz.

Using Foundry:

forge test --match-test testInvariant

Using ItyFuzz:

ityfuzz evm -m testInvariant -- forge test

Retrain

1. Create Retreival Augmented Generation (RAG) Database

First set up an RAG database as docker container. Notice that this container will use localhost:9400.

# Start Weaviate vector DB
cd weaviate
docker compose up -d

2. Fill RAG Database

You can create your own invariant dataset by putting Foundry projects into invariant_dataset folder or use the one we have collected. To use our dataset, run

wget https://ityfuzz.assets.fuzz.land/db.tar.gz && tar -xzf db.tar.gz

3. Retrain

Run any project with the retrain flag to generate a new model.

node ./build/src/index.js examples/ark \
    --project-type=foundry \
    --compiler-version=0.8.13 \
    --setup-file=script/ARK.s.sol:InvariantTest \
    --target-file=src/ARK.sol:AbsToken
    --retrain # <= add this flag to retrain the model

About

Generate invariants for Foundry projects with LLM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages