CorrectBench: Automatic Testbench Generation with Functional Self-Correction using LLMs for HDL Design

Ruidi Qiu, Grace Li Zhang, Rolf Drechsler, Ulf Schlichtmann, Bing Li

TL;DR

CorrectBench is a fully automated framework that uses Large Language Models (LLMs) to generate and functionally correct hardware testbenches using only natural language specifications. By validating testbenches against a "crowd" of imperfect, LLM-generated RTL designs, it successfully catches and fixes functional bugs without human intervention, boosting the testbench pass rate to 70.13% overall and nearly 5x for complex sequential circuits.

What Problem Does This Paper Address?

In digital hardware design, functional simulation via a testbench (TB) is critical to ensure that a Design Under Test (DUT) operates correctly. However, writing these testbenches manually requires significant, highly specialized engineering effort.

While researchers have recently turned to LLMs to automate the generation of Register-Transfer Level (RTL) code and testbenches, LLMs are notoriously prone to hallucinations and "laziness," which introduce subtle functional bugs into the generated code. Prior state-of-the-art automation tools, like AutoBench, only check for syntax errors. If the testbench compiles but contains flawed verification logic, the system cannot detect it. CorrectBench addresses this gap by introducing a closed-loop system for automated functional self-validation and self-correction.

Methods

CorrectBench builds upon the existing AutoBench framework (which generates a raw testbench consisting of a Verilog driver and a Python checker) and introduces a novel validation and correction loop:

The outline of CorrectBench workflow.
  • Scenario-Based Validator: Because a verified "golden" RTL design does not yet exist during the initial generation phase, CorrectBench prompts the LLM to generate a pool of multiple "imperfect" RTL designs based on the specification. Since LLM errors are typically randomly distributed, it is highly unlikely that different iterations will make the exact same functional mistake.
  • RTL-Scenario (RS) Matrix: The framework simulates the generated testbench against all the imperfect RTL designs across various test scenarios. This creates an RS Matrix (visualized below), mapping out which scenarios passed or failed for each design.
Examples of RS Matrices.
  • Validation Criterion: CorrectBench applies a "70%-wrong" heuristic: if more than 70% of the imperfect RTL designs fail a specific test scenario, the testbench scenario itself is flagged as buggy. Conversely, if more than 25% of the RTLs pass all scenarios perfectly, the testbench is directly accepted as correct.
  • Conversational Corrector: If bugs are detected, an Action Agent passes the bug reports to a two-stage LLM corrector. Stage 1 (Reasoning) uses a Chain-of-Thought prompt to force the LLM to diagnose why, where, and how the testbench failed. Stage 2 (Correction) guides the LLM to rewrite the faulty testbench code based on that reasoning. If the correction fails repeatedly, the agent triggers a system "reboot" to regenerate the testbench from scratch.

Datasets

The authors evaluated CorrectBench using the benchmark dataset from AutoBench, which is an extension of the VerilogEval-Human dataset. It consists of 156 Verilog problems sourced from HDLBits, split into:

  • 81 combinational (CMB) problems
  • 75 sequential (SEQ) problems

Evaluation was conducted using the AutoEval framework, which subjects the generated testbenches to 10 mutant (deliberately bugged) golden RTL designs to rigorously verify their error-detection capabilities (the Eval2 metric).

Key Insights and Ideas

  • The Wisdom of the Imperfect Crowd: The core "aha moment" of the paper is that you don't need a perfect reference design to validate a testbench. By exploiting the statistical randomness of LLM errors across a pool of imperfect designs, the true specification emerges as the consensus behavior.
  • Functional vs. Syntactic Feedback: Simply telling an LLM that its code has a syntax error isn't enough to fix logic bugs. Providing the corrector with granular, scenario-specific functional failure data allows the LLM to successfully pinpoint logic flaws in its reference models.
  • Sequential Circuit Breakthrough: Sequential circuits (which involve state transitions over time) are historically difficult for LLMs. The self-correction loop provides its largest benefit here, as sequential bugs often require multi-step reasoning that direct generation completely misses.

Key Results

  • Overall Pass Rate: CorrectBench achieved a comprehensive pass ratio (Eval2) of 70.13% across all 156 tasks, substantially outperforming AutoBench (52.18%) and direct LLM generation (33.33%).
  • Sequential Performance: For complex sequential circuits, CorrectBench achieved a 54.93% pass ratio. This represents a 66.18% relative improvement over AutoBench (33.87%) and is nearly 5 times higher than direct LLM generation (11.47%).
  • High Validation Accuracy: The scenario-based validator achieved an average accuracy of 88.85% in correctly identifying whether a testbench was functionally sound or bugged.
  • LLM Agnostic: The framework was successfully validated across multiple state-of-the-art models, showing consistent performance improvements using GPT-4o, Claude-3.5-Sonnet, and GPT-4o-mini.

Limitations and Future Work

  • High Token and Computational Cost: Simulating a pool of 20 imperfect RTL designs across multiple correction iterations and potential "reboots" results in high LLM token consumption and extended simulation times.
  • Heuristic Thresholds: The "70%-wrong" validation threshold was determined empirically and may need to be dynamically tuned for highly complex or niche hardware architectures.
  • Future Directions: The authors plan to explore advanced validation criteria, incorporate coverage-based metrics (such as line or toggle coverage of the DUT), and extract richer semantic information to improve the corrector's efficiency.

Summary updated

BibTeX
@inproceedings{qiu2025correctbench,
  author = {Ruidi Qiu and Grace Li Zhang and Rolf Drechsler and Ulf Schlichtmann and Bing Li},
  title = {{CorrectBench: Automatic Testbench Generation with Functional Self-Correction using LLMs for HDL Design}},
  booktitle = {DATE},
  year = {2025},
  doi = {10.23919/date64628.2025.10992873},
}
Figure