fix(r1cs-compiler): Remove Duplicate Witness Builders for poseidon2#249
Merged
Merged
Conversation
…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.
bd0bd4f to
57cbea9
Compare
rose2221
approved these changes
Jan 7, 2026
Collaborator
rose2221
left a comment
There was a problem hiding this comment.
LGTM. Could you please update the branch with main before merge?
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Poseidon2 proving failure ("Some witnesses in w1 are missing") by removing duplicate witness builders for poseidon2 output values.
Problem
Running
provekit-cli proveonnoir-examples/poseidon2failed with:Root Cause
Poseidon2 output witnesses had duplicate
WitnessBuilderentries:WitnessBuilder::Acir- created byfetch_r1cs_witness_index()innoir_to_r1cs.rsWitnessBuilder::Sum- created byadd_poseidon2_permutation()inpermutation.rsWhen
WitnessIndexRemapper::new()counted builder outputs, it incrementedw1_sizefor each builder (including duplicates), but theold_to_newHashMap only kept unique mappings. Result:w1_size=369but only 365 actual mappings, leaving 4 indices unset.Fix
Removed the redundant
WitnessBuilder::Sumentries for poseidon2 outputs. Output witness values come from the ACIR witness map (populated byBn254BlackBoxSolver). We only need R1CS constraints to verify correctness - matching howadd_sha256_compression()handles its outputs.Testing
All examples pass prepare → prove → verify:
poseidon2(the fixed example)complete_age_checkoprfnoir_sha256CI checks pass:
cargo fmt --all --checkcargo clippy --all-targets --all-featurescargo test -p provekit-r1cs-compiler