Skip to content

SecurityLab-UCD/CNTG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CNTG: LLM generate invariants

Project Purpose

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.

Build Instructions

First, you need to install the dependencies. You can use the following command to install the dependencies:

pip install -r requirements.txt

Usage

1. 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.py

Converted 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

Output Structure

CNTG/
 ├── modified_seed/          # Converted seeds without if branches
 ├── successful_programs/    # Programs with inserted invariants
 └── error_programs/         # Programs that failed to generate invariants

Directory Structure Requirements

Important: 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.

Note

  • 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.py multiple 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

About

[ISSRE 2026] LLM-based Invariant testing for Software Functional Bugs

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages