From 656a7d6c1e0c3597a61c3606e3155a70032c1599 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 21 Aug 2024 13:53:27 -0400 Subject: [PATCH] fix(acvm): Clear ACIR call stack after successful circuit execution (#5783) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description ## Problem\* Resolves No issue as small issue found while working on bug related to brillig. ## Summary\* Changing `fold_nested_brillig_assert_fail` to the following main (where we expect the second call to fail): ```rust fn main(x: Field) { assert(1 == fold_conditional_wrapper(!x as bool)); assert(1 == fold_conditional_wrapper(x as bool)); } ``` would lead to this call stack: ``` error: Failed to solve program: 'Failed to solve brillig function' ┌─ /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:27:12 │ 27 │ assert(x); │ - │ = Call stack: 1. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:6:17 2. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:12:5 3. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:7:17 4. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:12:5 5. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:18:9 6. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:23:5 7. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:27:12 ``` These lines should not be included and reference the successful call before the second one: ``` 1. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:6:17 2. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:12:5 ``` The following change now has the correct call stack: ```rust error: Failed to solve program: 'Failed to solve brillig function' ┌─ /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:27:12 │ 27 │ assert(x); │ - │ = Call stack: 1. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:7:17 2. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:12:5 3. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:18:9 4. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:23:5 5. /mnt/user-data/maxim/noir/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr:27:12 ``` ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [ ] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- .../fold_nested_brillig_assert_fail/src/main.nr | 1 + tooling/nargo/src/ops/execute.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr b/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr index 21fd4006c2a..1c1563ffe1d 100644 --- a/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr +++ b/test_programs/execution_failure/fold_nested_brillig_assert_fail/src/main.nr @@ -3,6 +3,7 @@ // The features being tested is using assert on brillig that is triggered through nested ACIR calls. // We want to make sure we get a call stack from the original call in main to the failed assert. fn main(x: Field) { + assert(1 == fold_conditional_wrapper(!x as bool)); assert(1 == fold_conditional_wrapper(x as bool)); } diff --git a/tooling/nargo/src/ops/execute.rs b/tooling/nargo/src/ops/execute.rs index 2e214c4e425..5a43b1c2f9c 100644 --- a/tooling/nargo/src/ops/execute.rs +++ b/tooling/nargo/src/ops/execute.rs @@ -167,6 +167,10 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver, E: ForeignCallExecutor> } } } + // Clear the call stack if we have succeeded in executing the circuit. + // This needs to be done or else all successful ACIR call stacks will also be + // included in a failure case. + self.call_stack.clear(); Ok(acvm.finalize()) }