-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssa): RC correctness issue (#6134)
# Description ## Problem\* Resolves #6123 ## Summary\* Still a draft as I want to test it a bit more and am not fully sure if it is the best solution. ## Additional Context ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
7 changes: 7 additions & 0 deletions
7
test_programs/execution_success/brillig_rc_regression_6123/Nargo.toml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "brillig_rc_regression_6123" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.34.0" | ||
|
||
[dependencies] |
41 changes: 41 additions & 0 deletions
41
test_programs/execution_success/brillig_rc_regression_6123/src/main.nr
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
struct Builder { | ||
note_hashes: BoundedVec<Field, 2>, | ||
nullifiers: BoundedVec<Field, 2>, | ||
} | ||
|
||
impl Builder { | ||
fn append_note_hashes_with_logs(&mut self, num_note_hashes: u32) { | ||
let index_offset = self.note_hashes.len(); | ||
for i in 0..self.note_hashes.max_len() { | ||
if i < num_note_hashes { | ||
self.add_new_note_hash((index_offset + i) as Field); | ||
} | ||
} | ||
} | ||
|
||
fn add_new_note_hash(&mut self, value: Field) { | ||
self.note_hashes.push(value); | ||
} | ||
} | ||
|
||
fn swap_items<T, let N: u32>(vec: &mut BoundedVec<T, N>, from_index: u32, to_index: u32) { | ||
let tmp = vec.storage[from_index]; | ||
vec.storage[from_index] = vec.storage[to_index]; | ||
vec.storage[to_index] = tmp; | ||
} | ||
|
||
unconstrained fn main() { | ||
let mut builder = Builder { note_hashes: BoundedVec::new(), nullifiers: BoundedVec::new() }; | ||
|
||
builder.append_note_hashes_with_logs(2); | ||
builder.nullifiers.storage[1] = 27; | ||
// Get ordered items before shuffling. | ||
let note_hashes = builder.note_hashes.storage; | ||
let original_first_note_hash = note_hashes[0]; | ||
// Shuffle. | ||
swap_items(&mut builder.note_hashes, 1, 0); | ||
|
||
for i in 0..1 { | ||
assert_eq(note_hashes[i], original_first_note_hash); | ||
} | ||
} |
This file contains 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