noir: Init vs Final SSA: array mutation; ACIR and Brillig both wrong
Aim
Discovered testing https://github.com/noir-lang/noir/pull/8216
The following program returns a different result with --minimal-ssa compared to both ACIR and Brillig:
fn main() -> pub [Field; 3] {
let mut a = [10, 20, 30];
a[1] = {
a = {
a[2] = a[0];
[a[0], 40, a[2]]
};
a[1]
};
a
}
Expected Behavior
The expected return value is [10, 40, 10], confirmed by Rust
Bug
$ cargo run -q -p nargo_cli -- execute --skip-underconstrained-check --skip-brillig-constraints-check --silence-warnings --force
[regression_fuzz_testing] Circuit witness successfully solved
[regression_fuzz_testing] Witness saved to target/regression_fuzz_testing.gz
[regression_fuzz_testing] Circuit output: Vec([Field(10), Field(40), Field(30)])
$ cargo run -q -p nargo_cli -- execute --skip-underconstrained-check --skip-brillig-constraints-check --silence-warnings --force --force-brillig
[regression_fuzz_testing] Circuit witness successfully solved
[regression_fuzz_testing] Witness saved to target/regression_fuzz_testing.gz
[regression_fuzz_testing] Circuit output: Vec([Field(10), Field(40), Field(30)])
$ cargo run -q -p nargo_cli -- execute --skip-underconstrained-check --skip-brillig-constraints-check --silence-warnings --force --minimal-ssa
[regression_fuzz_testing] Circuit witness successfully solved
[regression_fuzz_testing] Witness saved to target/regression_fuzz_testing.gz
[regression_fuzz_testing] Circuit output: Vec([Field(10), Field(40), Field(10)])
$
To Reproduce
See above.
Workaround
None
Workaround Description
No response
Additional Context
No response
Project Impact
None
Blocker Context
No response
Nargo Version
nargo version = 1.0.0-beta.4 noirc version = 1.0.0-beta.4+b0d9c680c3e9f6a818382b4f57ae2b5a93c657ab (git version hash: 0879bacabb4dcbf5f436575049b464e8fb35abac, is dirty: true)
NoirJS Version
No response
Proving Backend Tooling & Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (15 by maintainers)
No unfortunately, the shifted offsets are a Brillig only optimization and should never happen earlier. Check out the module comments and tests of that pass to learn more.
The crux of the issue looks to be how we code gen assignments with block expressions.
mem2reg looks fine here, running this in the ssa interpreter (and manually verifying) shows that the result even before
Mem2Reg (1)is still 10, 40, 30: