-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssa): Handle array arguments to side effectual constrain statemen…
…ts (#3740) …ffects # Description ## Problem\* Resolves the error that occurs in this PR (#3739) No issue as was discovered and fixed quickly. ## Summary\* Using an array as an argument in a side effectual constrain statement will cause this panic: ``` Message: internal error: entered unreachable code: Can only cast to a numeric Location: compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs:1652 ``` Here is an example program which would previously fail that is included as a regression test: ``` struct Bar { inner: [u32; 3], } fn main(y: pub u32) { let bar = Bar { inner: [100, 101, 102] }; // The assert inside the if should be hit if y < 10 { assert(bar.inner == [100, 101, 102]); } // The assert inside the if should not be hit if y > 10 { assert(bar.inner == [0, 1, 2]); } } ``` Without this fix it is not possible to constrain arrays inside of if statements based upon witness conditions. ## Additional Context ## 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.
- Loading branch information
Showing
4 changed files
with
111 additions
and
15 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
7 changes: 7 additions & 0 deletions
7
test_programs/execution_success/side_effects_constrain_array/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 = "side_effects_constrain_array" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.20.0" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
test_programs/execution_success/side_effects_constrain_array/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 @@ | ||
y = "3" |
17 changes: 17 additions & 0 deletions
17
test_programs/execution_success/side_effects_constrain_array/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,17 @@ | ||
struct Bar { | ||
inner: [Field; 3], | ||
} | ||
|
||
fn main(y: pub u32) { | ||
let bar = Bar { inner: [100, 101, 102] }; | ||
|
||
// The assert inside the if should be hit | ||
if y < 10 { | ||
assert(bar.inner == [100, 101, 102]); | ||
} | ||
|
||
// The assert inside the if should not be hit | ||
if y > 10 { | ||
assert(bar.inner == [0, 1, 2]); | ||
} | ||
} |