-
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(acir): Array dynamic flatten (#4351)
# Description ## Problem\* Resolves #4258 ## Summary\* There are some instances where we want to flatten a single AcirValue into its AcirVars. We were operating under the assumption that we cannot flatten dynamic arrays. I have changed the `flatten` method to be on an `AcirContext` so that we can read from dynamic memory when appropriate. I have added two tests performing what is done in the issue. 1. Returning a dynamic array from main 2. Preparing a dynamic array as inputs to a black box function ## Additional Context Further investigation should be done to see if we should fully remove the `flatten()` method on `AcirValue` and move to only using the `flatten` which lives on the AcirContext. I chose to leave that for separate work though and scope this PR to just the bug fix in the issue. ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** 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. --------- Co-authored-by: Tom French <tom@tomfren.ch>
- Loading branch information
1 parent
14a371c
commit b2aaeab
Showing
14 changed files
with
98 additions
and
20 deletions.
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
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
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
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
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
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
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/array_dynamic_blackbox_input/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 = "array_dynamic_blackbox_input" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.23.0" | ||
|
||
[dependencies] |
4 changes: 4 additions & 0 deletions
4
test_programs/execution_success/array_dynamic_blackbox_input/Prover.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,4 @@ | ||
index = "1" | ||
leaf = ["51", "109", "224", "175", "60", "42", "79", "222", "117", "255", "174", "79", "126", "242", "74", "34", "100", "35", "20", "200", "109", "89", "191", "219", "41", "10", "118", "217", "165", "224", "215", "109"] | ||
path = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] | ||
root = ["243", "212", "223", "132", "202", "119", "167", "60", "162", "158", "66", "192", "88", "114", "34", "191", "202", "195", "19", "102", "150", "88", "222", "176", "35", "51", "110", "97", "204", "224", "253", "171"] |
27 changes: 27 additions & 0 deletions
27
test_programs/execution_success/array_dynamic_blackbox_input/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,27 @@ | ||
fn main(leaf: [u8; 32], path: [u8; 64], index: u32, root: [u8; 32]) { | ||
compute_root(leaf, path, index, root); | ||
} | ||
|
||
fn compute_root(leaf: [u8; 32], path: [u8; 64], _index: u32, root: [u8; 32]) { | ||
let mut current = leaf; | ||
let mut index = _index; | ||
|
||
for i in 0..2 { | ||
let mut hash_input = [0; 64]; | ||
let offset = i * 32; | ||
let is_right = (index & 1) != 0; | ||
let a = if is_right { 32 } else { 0 }; | ||
let b = if is_right { 0 } else { 32 }; | ||
|
||
for j in 0..32 { | ||
hash_input[j + a] = current[j]; | ||
hash_input[j + b] = path[offset + j]; | ||
} | ||
|
||
current = dep::std::hash::sha256(hash_input); | ||
index = index >> 1; | ||
} | ||
|
||
// Regression for issue #4258 | ||
assert(root == current); | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/execution_success/array_dynamic_main_output/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 = "array_dynamic_main_output" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.23.0" | ||
|
||
[dependencies] |
2 changes: 2 additions & 0 deletions
2
test_programs/execution_success/array_dynamic_main_output/Prover.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,2 @@ | ||
index = "5" | ||
x = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] |
4 changes: 4 additions & 0 deletions
4
test_programs/execution_success/array_dynamic_main_output/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,4 @@ | ||
fn main(mut x: [Field; 10], index: u8) -> pub [Field; 10] { | ||
x[index] = 0; | ||
x | ||
} |
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