Skip to content

PrithwishBasuRoy/Veritas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Veritas

Generate correct CNF equations for digital designs (adder, subtractor, multiplexer, multiplier, decoder) and seamlessly convert them all the way to .bench and Verilog (.v)—with a simple CLI workflow.

Veritas leverages the idea that a correct CNF can always be converted to correct Verilog that does not require further testing.


Features

  • CNF generation for common building blocks
  • CNF → .bench conversion
  • .bench simulation (truth-table style)
  • .bench → Verilog conversion
  • Simple, incremental prompting workflow (via gpt-5-mini by default)

Installation

Requires Python 3.8+

Install the OpenAI Python package:

pip install openai

(If you use virtual environments, activate one first.)


Quick Start

  1. Generate a CNF for a design using cli.py
  2. Convert CNF → .bench with CNF_to_bench.py
  3. Simulate the .bench with bench_simulator.py (optional)
  4. Convert .bench → Verilog with bench2verilog.py

1) CNF Generator — cli.py

cli.py incrementally queries an LLM to produce a correct CNF for the chosen design and configuration. This may take a few minutes because it performs multiple LLM interactions to validate the result.

Usage

python cli.py --key <openai_api_key> --design <design name> --type <configuration>

Supported designs & configurations

Design Name Possible configurations
adder 1-bit, 2-bit, 3-bit, 4-bit, 5-bit
subtractor 1-bit, 2-bit, 3-bit, 4-bit, 5-bit
multiplier 1-bit, 2-bit, 3-bit
decoder 1x2, 2x4, 3x8, 4x16, 5x32
multiplexer 2x1, 4x1, 8x1, 16x1, 32x1

Example

python cli.py --key <openai_api_key> --design subtractor --type 3-bit
# Output: subtractor_3-bit.cnf

Output filenames follow the pattern: <design>_<type>.cnf


2) CNF → .bench — CNF_to_bench.py

Convert the generated CNF file into a .bench netlist.

Usage

python CNF_to_bench.py --cnf <design_type.cnf>   --inputs "<comma-separated input names>"   --outputs "<comma-separated output names>"   --out <design_type.bench>

Example

python CNF_to_bench.py --cnf subtractor_3-bit.cnf   --inputs "A0,B0,A1,B1,A2,B2,Din"   --outputs "D0,D1,D2,S2"   --out subtractor_3-bit.bench
# Output: subtractor_3-bit.bench

3) Bench Simulator — bench_simulator.py

Simulate the .bench file to verify expected behavior (optionally produce a table).

Usage

python bench_simulator.py --bench <design_type.bench> --table --inputs <comma-separated input names>

Example

python bench_simulator.py --bench subtractor_3-bit.bench --table --inputs A0,B0,A1,B1,A2,B2,Din

4) .bench → Verilog — bench2verilog.py

Convert a .bench file into an equivalent Verilog module.

Usage

python bench2verilog.py --bench <design_type.bench> --out <design_type.v>

Example

python bench2verilog.py --bench subtractor_3-bit.bench --out subtractor_3-bit.v

Tips & Notes

  • Ensure your OpenAI API key is available and valid (--key flag).
  • Input and output signal names must match the CNF variables when converting to .bench.
  • If you run into environment issues, try an isolated virtual environment:
    python -m venv .venv && source .venv/bin/activate


Project Links

Citation

If you use Veritas in your research, please cite:

@misc{roy2025veritasdeterministicverilogcode,
      title={Veritas: Deterministic Verilog Code Synthesis from LLM-Generated Conjunctive Normal Form}, 
      author={Prithwish Basu Roy and Akashdeep Saha and Manaar Alam and Johann Knechtel and Michail Maniatakos and Ozgur Sinanoglu and Ramesh Karri},
      year={2025},
      eprint={2506.00005},
      archivePrefix={arXiv},
      primaryClass={cs.AR},
      url={https://arxiv.org/abs/2506.00005}, 
}

About

Veritas generates correct CNF equations for various designs like adder, subtractor, multiplexer, multiplicator, decoder. Veritas leverages the idea that correct CNF can always be converted to correct verilog code that does not require further testing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages