fix for non-contiguous initial value witnesses in SpiceWitness#254
Merged
Conversation
… formatting - Add trailing newline to bounded-vec/src/main.nr - Add debug_assert to verify initial_value_witnesses.len() == memory_length - Replace eprintln + assert with descriptive assert message in noir_to_r1cs.rs - Revert unrelated variable renames in witness_builder.rs (SpiceMultisetFactor) - Revert unrelated variable renames in prover/witness/ram.rs (Load/Store arms) These changes keep the PR focused on the actual bug fix.
Bisht13
approved these changes
Jan 19, 2026
dcbuild3r
pushed a commit
that referenced
this pull request
May 16, 2026
fix for non-contiguous initial value witnesses in SpiceWitness
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
For Issue #253
Fixes incorrect memory reads in SpiceWitness solver by storing actual witness indices instead of assuming contiguous allocation. The old implementation would read garbage values when memory blocks are initialized with repeated values.
Problem
The
SpiceWitnessesstruct assumed initial value witnesses were stored contiguously starting frominitial_values_start:The solver would then read memory like:
When compiling Noir to R1CS,
fetch_r1cs_witness_index()maps ACIR witnesses to R1CS witnesses. If the same ACIR witness appears multiple times (e.g., initializing an array with zeros), it returns the same R1CS index for all of them.Example:
BoundedVec<u8, 32>initialized with zerosBut the old impl assumed:
What happens when solving:
This causes silent corruption: the prover computes wrong values, and proving fails with cryptic errors or produces invalid proofs.
Fix
Change from a start index to storing the actual witness index for each memory slot:
The solver now reads from the correct locations:
Test Cases Added
bounded-vecTests
BoundedVecconcatenation with conditional increments. This exercises:brillig-unconstrainedTests Brillig (unconstrained) functions that modify arrays, mimicking patterns seen in
sha256stdlib usage.Test
cargo test --package provekit-bench --test compiler -- bounded-veccargo test --package provekit-bench --test compiler -- brillig-unconstrainedcargo test --package provekit-bench --test compiler