worldfnd / worldfnd/provekit

r1cs-compiler: constant-operand branches in AND/XOR black-box handler are unreachable dead code

Open
#378 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Noir
Stars
138
Forks
47
Avg merge
1d 34m
Merged PRs (30d)
6

Description

Description

process_binop_opcode in the R1CS compiler contains match arms for handling ConstantOrACIRWitness::Constant inputs to AND/XOR black-box opcodes. These branches are never reachable in practice because nargo never emits AND/XOR black-box opcodes with constant operands — it either folds them at compile time (both constant) or promotes the constant to a witness (one constant, one witness).

Root Cause

process_binop_opcode has three match arms:

Lines Case
L341–L395 lhs is Constant (nested match on rhs)
L400–L424 lhs is Witness, rhs is Constant
L426–L438 Both are Witnesses (the only reachable arm)

Nargo's behaviour (confirmed via ACIR bytecode inspection):

  • Both constants → computed at compile time → emits AssertZero only, no black-box opcode
  • One constant + one witness → constant is embedded as a constant-valued witness in the witness table; the ACIR FunctionInput is a Witness reference, not a Constant

So ConstantOrACIRWitness::Constant is never produced by nargo for AND/XOR inputs, and lines L341–L395 and L400–L424 are unreachable.

Affected Files
File Notes
provekit/r1cs-compiler/src/noir_to_r1cs.rs#L341-L395 Constant(lhs_c) arm — dead
provekit/r1cs-compiler/src/noir_to_r1cs.rs#L400-L424 Constant(rhs_c) arm — dead

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read process_binop_opcode in provekit/r1cs-compiler/src/noir_to_r1cs.rs, especially the two ConstantOrACIRWitness::Constant arms identified in the issue. Confirm the AND/XOR inputs produced by nargo through the ACIR bytecode behavior described; the work is done when the unreachable branches are removed without affecting the reachable Witness/Witness handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.