Hacking Tools

Program Exposes Unsound And Incomplete Behavior In Compiler

The provided program highlights critical issues within the compiler, exposing both soundness and completeness violations.

These bugs manifest in unexpected behavior during execution and compiler crashes, triggered by seemingly innocuous code changes. This article explores the problem, its symptoms, and implications.

Program Behavior

The program is written in Noir and aims to compute a value, out0, which should consistently return Field(0) regardless of input. However, the actual behavior deviates from expectations:

  1. If executed as-is, the program returns Field(-1) instead of the expected Field(0).
  2. Removing empty else blocks causes a compiler panic with an internal error.
  3. Semantic-equivalent changes to the code—such as modifying conditional checks or rearranging variable declarations—alter the output to the correct Field(0).

The program reveals two types of bugs:

  1. Compiler Completeness Issue: Removing any empty else block results in a crash during execution (nargo execute).
    • The error message indicates an unreachable code path in the compiler’s SSA optimization phase (inlining.rs:504). This suggests that the compiler fails to handle certain edge cases during instruction inlining.
  2. Soundness Violation: The program’s output changes unexpectedly based on minor structural modifications. For example:
    • Replacing (out0 == out0) with (in0 == in0) or (tmp1 == tmp1) fixes the output.
    • Moving let mut tmp2 : Field = 0; to the top of the program also resolves the issue.
    • Removing certain conditions or assertions causes unpredictable behavior.

Uncommenting assertions like assert(out0 == 0, "completeness violation"); or assert(out0 != 0, "soundness violation"); further exposes these problems.

The first assertion fails despite being logically correct, while the second passes erroneously, demonstrating unsound evaluation.

These bugs undermine trust in the compiler’s reliability for critical applications. To reproduce:

  • Create a new Noir project (nargo init).
  • Replace src/main.nr with the provided code.
  • Add a Prover.toml file specifying in0 = "1".
  • Run nargo execute.

Currently, there is no known workaround for these issues. Developers must avoid triggering problematic conditions until a fix is implemented.

This program demonstrates severe flaws in the compiler’s handling of edge cases, affecting both correctness and stability. Addressing these issues is crucial for ensuring reliable execution and soundness in Noir-based projects.

Varshini

Varshini is a Cyber Security expert in Threat Analysis, Vulnerability Assessment, and Research. Passionate about staying ahead of emerging Threats and Technologies.

Recent Posts

cp Command: Copy Files and Directories in Linux

The cp command, short for "copy," is the main Linux utility for duplicating files and directories. Whether…

6 days ago

Image OSINT

Introduction In digital investigations, images often hold more information than meets the eye. With the…

6 days ago

cat Command: Read and Combine File Contents in Linux

The cat command short for concatenate, It is a fast and versatile tool for viewing and merging…

6 days ago

Port In Networking

What is a Port? A port in networking acts like a gateway that directs data…

6 days ago

ls Command: List Directory Contents in Linux

The ls command is fundamental for anyone working with Linux. It’s used to display the files and…

6 days ago

pwd Command: Find Your Location in Linux

The pwd (Print Working Directory) command is essential for navigating the Linux filesystem. It instantly shows your…

7 days ago