Skip to content

fix(r1cs-compiler): Remove Duplicate Witness Builders for poseidon2#249

Merged
rose2221 merged 1 commit into
mainfrom
px/fix-poseidon2-duplicate-witness-builders
Jan 8, 2026
Merged

fix(r1cs-compiler): Remove Duplicate Witness Builders for poseidon2#249
rose2221 merged 1 commit into
mainfrom
px/fix-poseidon2-duplicate-witness-builders

Conversation

@Bisht13
Copy link
Copy Markdown
Collaborator

@Bisht13 Bisht13 commented Jan 7, 2026

Summary

Fixes Poseidon2 proving failure ("Some witnesses in w1 are missing") by removing duplicate witness builders for poseidon2 output values.

Problem

Running provekit-cli prove on noir-examples/poseidon2 failed with:

Error: While proving Noir program statement
Caused by: Some witnesses in w1 are missing

Root Cause

Poseidon2 output witnesses had duplicate WitnessBuilder entries:

  1. WitnessBuilder::Acir - created by fetch_r1cs_witness_index() in noir_to_r1cs.rs
  2. WitnessBuilder::Sum - created by add_poseidon2_permutation() in permutation.rs

When WitnessIndexRemapper::new() counted builder outputs, it incremented w1_size for each builder (including duplicates), but the old_to_new HashMap only kept unique mappings. Result: w1_size=369 but only 365 actual mappings, leaving 4 indices unset.

Fix

Removed the redundant WitnessBuilder::Sum entries for poseidon2 outputs. Output witness values come from the ACIR witness map (populated by Bn254BlackBoxSolver). We only need R1CS constraints to verify correctness - matching how add_sha256_compression() handles its outputs.

Testing

All examples pass prepare → prove → verify:

  • poseidon2 (the fixed example)
  • complete_age_check
  • oprf
  • noir_sha256

CI checks pass:

  • cargo fmt --all --check
  • cargo clippy --all-targets --all-features
  • cargo test -p provekit-r1cs-compiler

…utputs

Poseidon2 outputs had both WitnessBuilder::Acir (from fetch_r1cs_witness_index)
and WitnessBuilder::Sum entries, causing WitnessIndexRemapper to inflate w1_size
and leave witness indices unset during solving.

Output values come from the ACIR witness map via the blackbox solver - only
constraints are needed, matching the SHA256 approach.
@Bisht13 Bisht13 force-pushed the px/fix-poseidon2-duplicate-witness-builders branch from bd0bd4f to 57cbea9 Compare January 7, 2026 09:59
@Bisht13 Bisht13 requested a review from rose2221 January 7, 2026 12:30
Copy link
Copy Markdown
Collaborator

@rose2221 rose2221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Could you please update the branch with main before merge?

@rose2221 rose2221 merged commit 13c3b44 into main Jan 8, 2026
4 of 5 checks passed
@rose2221 rose2221 deleted the px/fix-poseidon2-duplicate-witness-builders branch January 8, 2026 08:44
dcbuild3r pushed a commit that referenced this pull request May 16, 2026
…utputs (#249)

Poseidon2 outputs had both WitnessBuilder::Acir (from fetch_r1cs_witness_index)
and WitnessBuilder::Sum entries, causing WitnessIndexRemapper to inflate w1_size
and leave witness indices unset during solving.

Output values come from the ACIR witness map via the blackbox solver - only
constraints are needed, matching the SHA256 approach.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants