-
Notifications
You must be signed in to change notification settings - Fork 387
fix(acir): Use types on dynamic arrays #4364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0500c88
use acir types for dynamic array
vezenovm 692d200
reduce diff
vezenovm 3d42c1a
cargo fmt and clippy
vezenovm 6f826fd
chore: nits
TomAFrench 0cb1654
chore: nit
TomAFrench b2ff529
chore: cargo fmt
TomAFrench 3c01836
add extra test
vezenovm 85be04d
update comment for value_types
vezenovm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
7 changes: 7 additions & 0 deletions
7
test_programs/execution_success/array_dynamic_blackbox_input/Nargo.toml
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
| 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.24.0" | ||
|
|
||
| [dependencies] |
4 changes: 4 additions & 0 deletions
4
test_programs/execution_success/array_dynamic_blackbox_input/Prover.toml
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
| 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 = [79, 230, 126, 184, 98, 125, 226, 58, 117, 45, 140, 15, 72, 118, 89, 173, 117, 161, 166, 0, 214, 125, 13, 16, 113, 81, 173, 156, 97, 15, 57, 216] |
27 changes: 27 additions & 0 deletions
27
test_programs/execution_success/array_dynamic_blackbox_input/src/main.nr
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
| 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_nested_blackbox_input/Nargo.toml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [package] | ||
| name = "array_dynamic_nested_blackbox_input" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=0.24.0" | ||
|
|
||
| [dependencies] |
23 changes: 23 additions & 0 deletions
23
test_programs/execution_success/array_dynamic_nested_blackbox_input/Prover.toml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| y = "3" | ||
| hash_result = [50, 53, 90, 252, 105, 236, 223, 30, 135, 229, 193, 172, 51, 139, 8, 32, 188, 104, 151, 115, 129, 168, 27, 71, 203, 47, 40, 228, 89, 177, 129, 100] | ||
|
|
||
| [[x]] | ||
| a = "1" | ||
| b = ["2", "3", "20"] | ||
|
|
||
| [x.bar] | ||
| inner = ["100", "101", "102"] | ||
|
|
||
| [[x]] | ||
| a = "4" # idx = 3, flattened start idx = 7 | ||
| b = ["5", "6", "21"] # idx = 4, flattened start idx = 8 | ||
|
|
||
| [x.bar] | ||
| inner = ["103", "104", "105"] # idx = 5, flattened start idx = 11 | ||
|
|
||
| [[x]] | ||
| a = "7" | ||
| b = ["8", "9", "22"] | ||
|
|
||
| [x.bar] | ||
| inner = ["106", "107", "108"] |
20 changes: 20 additions & 0 deletions
20
test_programs/execution_success/array_dynamic_nested_blackbox_input/src/main.nr
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| struct Bar { | ||
| inner: [u8; 3], | ||
| } | ||
|
|
||
| struct Foo { | ||
| a: Field, | ||
| b: [Field; 3], | ||
| bar: Bar, | ||
| } | ||
|
|
||
| fn main(mut x: [Foo; 3], y: pub Field, hash_result: pub [u8; 32]) { | ||
| // Simple dynamic array set for entire inner most array | ||
| x[y - 1].bar.inner = [106, 107, 10]; | ||
| let mut hash_input = x[y - 1].bar.inner; | ||
| // Make sure that we are passing a dynamic array to the black box function call | ||
| // by setting the array using a dynamic index here | ||
| hash_input[y - 1] = 0; | ||
| let hash = dep::std::hash::sha256(hash_input); | ||
| assert_eq(hash, hash_result); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.