-
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.
feat: Add brillig array index check (#4127)
# Description ## Problem\* Adds a runtime length check to avoid out of bounds accesses, to emulate the behavior with ACIR dynamic array accesses. ## Summary\* ## 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
1 parent
09d1d5c
commit c29f85f
Showing
4 changed files
with
55 additions
and
0 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
5 changes: 5 additions & 0 deletions
5
test_programs/noir_test_success/out_of_bounds_alignment/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,5 @@ | ||
[package] | ||
name = "out_of_bounds_alignment" | ||
type = "bin" | ||
authors = [""] | ||
[dependencies] |
Empty file.
17 changes: 17 additions & 0 deletions
17
test_programs/noir_test_success/out_of_bounds_alignment/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 @@ | ||
fn out_of_bounds(arr_1: [Field; 50]) -> Field { | ||
arr_1[50 + 1] | ||
} | ||
|
||
unconstrained fn out_of_bounds_unconstrained_wrapper(arr_1: [Field; 50], arr_2: [Field; 50]) -> Field { | ||
out_of_bounds(arr_1) | ||
} | ||
|
||
#[test(should_fail)] | ||
fn test_acir() { | ||
assert_eq(out_of_bounds([0; 50]), 0); | ||
} | ||
|
||
#[test(should_fail)] | ||
fn test_brillig() { | ||
assert_eq(out_of_bounds_unconstrained_wrapper([0; 50], [0; 50]), 0); | ||
} |