-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Replace unused ArrayGet/Set with constrain if possibly out of bo…
…unds (#5691) # Description ## Problem For #5296 ## Summary In DIE, when we find an `ArrayGet/Set` that we could remove, if that instruction might be an index out of bounds we still remove it but leave a constrain check too. ## Additional Context For now the code is a bit messy, I just wanted to get it working first. Also, it's not working for slices yet because we can't insert out of bounds checks if we don't know the slice length. For that we'll need to add the checks like we do for `ArrayGet` for slice (this could be done in a separate PR, though). ## 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
19 changed files
with
415 additions
and
10 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
test_programs/execution_failure/unused_array_get_known_index_out_of_bounds/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 = "unused_array_get_known_index_out_of_bounds" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
Empty file.
4 changes: 4 additions & 0 deletions
4
test_programs/execution_failure/unused_array_get_known_index_out_of_bounds/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() { | ||
let array = [1, 2, 3]; | ||
let _ = array[10]; // Index out of bounds | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/execution_failure/unused_array_get_unknown_index_out_of_bounds/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 = "unused_array_get_unknown_index_out_of_bounds" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
test_programs/execution_failure/unused_array_get_unknown_index_out_of_bounds/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 @@ | ||
x = "10" |
4 changes: 4 additions & 0 deletions
4
test_programs/execution_failure/unused_array_get_unknown_index_out_of_bounds/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(x: Field) { | ||
let array = [1, 2, 3]; | ||
let _ = array[x]; // Index out of bounds | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/execution_failure/unused_array_set_known_index_out_of_bounds/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 = "unused_array_set_known_index_out_of_bounds" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
Empty file.
4 changes: 4 additions & 0 deletions
4
test_programs/execution_failure/unused_array_set_known_index_out_of_bounds/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() { | ||
let mut array = [1, 2, 3]; | ||
array[10] = 1; // Index out of bounds | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/execution_failure/unused_array_set_unknown_index_out_of_bounds/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 = "unused_array_set_unknown_index_out_of_bounds" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
test_programs/execution_failure/unused_array_set_unknown_index_out_of_bounds/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 @@ | ||
x = "10" |
4 changes: 4 additions & 0 deletions
4
test_programs/execution_failure/unused_array_set_unknown_index_out_of_bounds/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(x: Field) { | ||
let mut array = [1, 2, 3]; | ||
array[x] = 1; // Index out of bounds | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/execution_failure/unused_slice_get_known_index_out_of_bounds/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 = "unused_slice_get_known_index_out_of_bounds" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
Empty file.
4 changes: 4 additions & 0 deletions
4
test_programs/execution_failure/unused_slice_get_known_index_out_of_bounds/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() { | ||
let slice = &[1, 2, 3]; | ||
let _ = slice[10]; // Index out of bounds | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/execution_failure/unused_slice_get_unknown_index_out_of_bounds/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 = "unused_slice_get_unknown_index_out_of_bounds" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
test_programs/execution_failure/unused_slice_get_unknown_index_out_of_bounds/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 @@ | ||
x = "10" |
4 changes: 4 additions & 0 deletions
4
test_programs/execution_failure/unused_slice_get_unknown_index_out_of_bounds/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(x: Field) { | ||
let slice = &[1, 2, 3]; | ||
let _ = slice[x]; // Index out of bounds | ||
} |