-
Notifications
You must be signed in to change notification settings - Fork 199
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
fix: always check index out of bounds for arrays and slices #5676
Conversation
Changes to circuit sizes
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
Circuit sizes went up, as expected. In the ones mostly affected I think that's expected. For example But in some cases there are checks that could be removed. In v22 = lt v4, u32 3
jmpif v22 then: b2, else: b3
b2():
v24 = lt v4, u32 3
constrain v24 == u1 1 '"Index out of bounds"'
v25 = array_get v0, index v4 It's checking the |
It's also interesting what happened with fn main(x: Field) {
// x = 3
let array: [[(Field, [Field; 1], [Field; 1]); 1]; 1] = [[(1, [2], [3])]];
let fetched_value = array[x - 3];
assert(fetched_value[0].0 == 1);
assert(fetched_value[0].1[0] == 2);
assert(fetched_value[0].2[0] == 3);
} the compiler notices that the array only has one value, so the acir(inline) fn main f0 {
b0(v0: Field):
v47 = sub v0, Field 3
v48 = cast v47 as u32
constrain v48 == u32 0 '"Index out of bounds"'
return
} The old program was much longer... I don't know if |
Closing because we chose #5691 instead. |
Description
Problem
Resolves #5296
Summary
Always insert an index out of bounds check when accessing or modifying an array or a slice.
Additional Context
None.
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.