Skip to content

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

@x-senpai-x

Description

@x-senpai-x

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions