Generate invariants for Foundry projects using LLM + RAG + Chain of Thought. Example output
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
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.
forge test --match-test testInvariant
ityfuzz evm -m testInvariant -- forge test
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
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
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