-
Notifications
You must be signed in to change notification settings - Fork 231
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
Dead Instruction Elimination pass removes out of bounds array sets #5296
Comments
Interesting, it looks like the pass to remove unused code removes the array_set instruction in question since it was unused in the final program. This explains why it also still catches it if that index is later printed out without being mutated first. |
Reduced: fn main() {
let src = [1];
let mut dst = [1];
dst[0] = src[10];
dst[0] = 1; // commenting this line will produce Index Out of Bounds when executing
println(dst[0])
} |
One solution could be to not remove |
This program also doesn't give index out of bounds at runtime, but probably should: fn main() {
let mut dst = [1];
dst[10] = 1;
} |
Posting discussion from scrum for visibility: We are going to try a new approach. Instead of always inserting a length assertion on array gets/sets, when we remove an unused array operation during DIE, we will replace it with a length assertion. This should hopefully let us avoid any extra constraints on dynamic array gets/sets which are still used elsewhere in the circuit. |
…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.
Closed due to #5691 being merged |
Aim
While moving some tests from constrained to
unconstrained
so they run faster (we're only checking function logic and assume circuit generation is fine), the code that used to work started failing with "Array index out of bounds" errors.Expected Behavior
Behavior should be consistent between constrained and unconstrained contexts.
Bug
Out of bounds errors can be masked in certain scenarios, specifically when copying array positions from one to another. However, illegal acceses are always detected as expected in unconstrained functions.
To Reproduce
Project Impact
Nice-to-have
Impact Context
No response
Workaround
None
Workaround Description
No response
Additional Context
No response
Installation Method
Compiled from source
Nargo Version
No response
NoirJS Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: