fix(ssa): Cast to u64 when inserting OOB checks in DIE#10463
Conversation
Changes to circuit sizes
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 81c92d1 | Previous: 2a27b18 | Ratio |
|---|---|---|---|
rollup-block-root-single-tx |
0.003 s |
0.002 s |
1.50 |
rollup-checkpoint-merge |
0.004 s |
0.003 s |
1.33 |
rollup-root |
0.005 s |
0.004 s |
1.25 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 81c92d1 | Previous: 2a27b18 | Ratio |
|---|---|---|---|
test_report_zkpassport_noir_rsa_ |
2 s |
1 s |
2 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(frontend)!: Preserve int type when quoting tokens (noir-lang/noir#10330) fix: check overflow for Pedersen grumpkin scalars (noir-lang/noir#10462) chore(frontend): Various tests in elaborator expressions submodule and minor refactors (noir-lang/noir#10475) chore: bump external pinned commits (noir-lang/noir#10477) fix: disallow keywords in attributes (noir-lang/noir#10473) chore: refactor codegen_control_flow (noir-lang/noir#10320) fix: builtin with body now errors instead of crashing (noir-lang/noir#10474) fix: handle ambiguous trait methods in assumed traits (noir-lang/noir#10468) fix: force_substitute bindings during monomorphization for associated constants (noir-lang/noir#10467) fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors (noir-lang/noir#10335) fix(ssa): Cast to `u64` when inserting OOB checks in DIE (noir-lang/noir#10463) fix: disallow comptime-only types in non-comptime globals (noir-lang/noir#10458) chore(fuzzing): fix default artifact for brillig target (noir-lang/noir#10465) END_COMMIT_OVERRIDE
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(frontend)!: Preserve int type when quoting tokens (noir-lang/noir#10330) fix: check overflow for Pedersen grumpkin scalars (noir-lang/noir#10462) chore(frontend): Various tests in elaborator expressions submodule and minor refactors (noir-lang/noir#10475) chore: bump external pinned commits (noir-lang/noir#10477) fix: disallow keywords in attributes (noir-lang/noir#10473) chore: refactor codegen_control_flow (noir-lang/noir#10320) fix: builtin with body now errors instead of crashing (noir-lang/noir#10474) fix: handle ambiguous trait methods in assumed traits (noir-lang/noir#10468) fix: force_substitute bindings during monomorphization for associated constants (noir-lang/noir#10467) fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors (noir-lang/noir#10335) fix(ssa): Cast to `u64` when inserting OOB checks in DIE (noir-lang/noir#10463) fix: disallow comptime-only types in non-comptime globals (noir-lang/noir#10458) chore(fuzzing): fix default artifact for brillig target (noir-lang/noir#10465) END_COMMIT_OVERRIDE
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(frontend)!: Preserve int type when quoting tokens (noir-lang/noir#10330) fix: check overflow for Pedersen grumpkin scalars (noir-lang/noir#10462) chore(frontend): Various tests in elaborator expressions submodule and minor refactors (noir-lang/noir#10475) chore: bump external pinned commits (noir-lang/noir#10477) fix: disallow keywords in attributes (noir-lang/noir#10473) chore: refactor codegen_control_flow (noir-lang/noir#10320) fix: builtin with body now errors instead of crashing (noir-lang/noir#10474) fix: handle ambiguous trait methods in assumed traits (noir-lang/noir#10468) fix: force_substitute bindings during monomorphization for associated constants (noir-lang/noir#10467) fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors (noir-lang/noir#10335) fix(ssa): Cast to `u64` when inserting OOB checks in DIE (noir-lang/noir#10463) fix: disallow comptime-only types in non-comptime globals (noir-lang/noir#10458) chore(fuzzing): fix default artifact for brillig target (noir-lang/noir#10465) END_COMMIT_OVERRIDE
Description
Problem
Resolves #10307
Summary
Changes the
replace_array_instructions_with_out_of_bounds_checksto cast tou64instead ofu32before putting a constraint on the maximum of the index, which should handle values that have potentially overflown when we calculate the flattened index of composite types.Additional Context
In the failing Noir example, we have the following code:
cis going to be false, so during execution we should always accessa[0], which should be fine, howeverbis a large number, andais a[(bool, bool); 3], which means it has 2 elements per item, so to accessbwe have to look up2*b, which is where the overflow happens:2*b > u32::MAX.Since #10110 we again use unchecked operations to calculate the index, so this overflow will not cause an immediate failure. Instead, we rely on ACIR protecting against OOB lookups during
ArrayGet:The problem is that here the result of the lookup is unused, so the DIE pass removes the lookup, but because it could fail with OOB, it leaves behind a constraint that the index has to be less than 6, which is the number of slots in the array (3*2).
If we look at the generated ACIR opcodes, we see that a range constraint is inserted to check that the result of a division fits into 32 bits:
With the changes in this PR, we'll have the following opcodes instead:
We considered other alternatives:
checked: but this is what we wanted to avoid by introducing theUnfitvalues into the SSA interpretercheckedfor only those indexes which were protected by the array operations we remove in DIE: this would be more complex as we would have to revisit instructions we already inserted when we decide we are removing somethingThe approach in the PR is easy, since it only involves casting the index and the constant before we insert the constraint.
User Documentation
Check one:
PR Checklist
cargo fmton default settings.