CNTG is a project that uses Large Language Models (LLMs) to automatically generate invariants for C/C++ programs and insert them into the source code. This helps developers create high-quality unit tests and improve program reliability.
First, you need to install the dependencies. You can use the following command to install the dependencies:
pip install -r requirements.txt1. Configure LLM Provider
CNTG supports Gemini and OpenAI. Configure via environment variables (recommended: .env).
Gemini example:
export LLM_PROVIDER=gemini
export GEMINI_API_KEY="Your-api-key"
# Optional: export GEMINI_MODEL="gemini-2.5-pro"OpenAI example:
export LLM_PROVIDER=openai
export OPENAI_API_KEY="Your-api-key"
# Optional: export OPENAI_MODEL="o1"2. Prepare Seeds
At the root of the CNTG project, create a directory named Original_seed and put all your original seeds generated by PromptFuzz into it. Then create a directory named modified_seed to store the modified seeds.
3. Convert Seeds Run the following command to remove if branches from seeds:
python3 convert.pyConverted seeds will appear in the modified_seed/ directory.
4. Generate Invariants Run the following command to generate invariants for the modified seeds:
python3 scripts/main.py --lib_name- ✅ Successful programs with invariants are saved in successful_programs/
- ❌ Programs that failed will be stored in error_programs/, each containing an error message
CNTG/
├── modified_seed/ # Converted seeds without if branches
├── successful_programs/ # Programs with inserted invariants
└── error_programs/ # Programs that failed to generate invariantsImportant: The CNTG project now uses relative paths and can be placed anywhere on your system. However, certain dependencies must be in specific locations relative to the CNTG directory:
For libraries that require local builds (lcms, libaom, libpcap), the following directory structure is expected:
your-workspace/
├── CNTG/ # This project
├── output/
│ └── build/
│ ├── lcms/ # LCMS library build
│ │ ├── include/
│ │ └── src/lcms/
│ └── libpcap/ # libpcap library build
│ ├── include/
│ └── work/build/
├── aom/ # AOM source code
└── aom_build/ # AOM build directory
├── config/
└── libaom.a
For system-installed libraries (zlib, libpng, cJSON, re2, sqlite3), they should be available via standard system paths or as configured in your environment.
- All paths are now relative, making the project portable across different systems
- Ensure you have the necessary permissions and API access to use your selected LLM provider
- You can re-run
scripts/main.pymultiple times; Programs will not overwrite existing files - Make sure the required library dependencies are built and placed in the correct relative locations as shown above