r1cs-compiler: constant-operand branches in AND/XOR black-box handler are unreachable dead code
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
AssertZeroonly, no black-box opcode - One constant + one witness → constant is embedded as a constant-valued witness in the witness table; the ACIR
FunctionInputis aWitnessreference, not aConstant
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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