From 8fea40576f262bd5bb588923c0660d8967404e56 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 3 Apr 2024 19:32:23 +0100 Subject: [PATCH] fix(acvm): Mark outputs of Opcode::Call solvable (#4708) # Description ## Problem\* Resolves No issue as bug found while experimenting ## Summary\* We should mark the outputs of a call as solvable. Otherwise we can potentially have more than one linear term and the outputs of call will not be used by the transformers. The new test `fold_call_witness_condition` would previously error out with the following when `nargo info` was ran: ``` The backend encountered an error: "backend_binary: /home/runner/work/aztec-packages/aztec-packages/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp:57: poly_triple acir_format::serialize_arithmetic_gate(const Program::Expression &): Assertion `(arg.mul_terms.size() <= 1)' failed.\n" ``` Now it successfully calls nargo info on main (we still need to update fetching the info for every circuit). ## 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. --- acvm-repo/acvm/src/compiler/transformers/mod.rs | 6 +++++- .../fold_call_witness_condition/Nargo.toml | 7 +++++++ .../fold_call_witness_condition/Prover.toml | 5 +++++ .../fold_call_witness_condition/src/main.nr | 16 ++++++++++++++++ tooling/debugger/ignored-tests.txt | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test_programs/execution_success/fold_call_witness_condition/Nargo.toml create mode 100644 test_programs/execution_success/fold_call_witness_condition/Prover.toml create mode 100644 test_programs/execution_success/fold_call_witness_condition/src/main.nr diff --git a/acvm-repo/acvm/src/compiler/transformers/mod.rs b/acvm-repo/acvm/src/compiler/transformers/mod.rs index 1ba261b09a3..003cd4279a1 100644 --- a/acvm-repo/acvm/src/compiler/transformers/mod.rs +++ b/acvm-repo/acvm/src/compiler/transformers/mod.rs @@ -142,7 +142,11 @@ pub(super) fn transform_internal( new_acir_opcode_positions.push(acir_opcode_positions[index]); transformed_opcodes.push(opcode); } - Opcode::Call { .. } => { + Opcode::Call { ref outputs, .. } => { + for witness in outputs { + transformer.mark_solvable(*witness); + } + // `Call` does not write values to the `WitnessMap` // A separate ACIR function should have its own respective `WitnessMap` new_acir_opcode_positions.push(acir_opcode_positions[index]); diff --git a/test_programs/execution_success/fold_call_witness_condition/Nargo.toml b/test_programs/execution_success/fold_call_witness_condition/Nargo.toml new file mode 100644 index 00000000000..cedaea348c5 --- /dev/null +++ b/test_programs/execution_success/fold_call_witness_condition/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "fold_call_witness_condition" +type = "bin" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/fold_call_witness_condition/Prover.toml b/test_programs/execution_success/fold_call_witness_condition/Prover.toml new file mode 100644 index 00000000000..8481ce25648 --- /dev/null +++ b/test_programs/execution_success/fold_call_witness_condition/Prover.toml @@ -0,0 +1,5 @@ +# TODO(https://github.com/noir-lang/noir/issues/4707): Change these inputs to fail the assertion in `fn return_value` +# and change `enable` to false. For now we need the inputs to pass as we do not handle predicates with ACIR calls +x = "5" +y = "10" +enable = true \ No newline at end of file diff --git a/test_programs/execution_success/fold_call_witness_condition/src/main.nr b/test_programs/execution_success/fold_call_witness_condition/src/main.nr new file mode 100644 index 00000000000..5dc75e4a99f --- /dev/null +++ b/test_programs/execution_success/fold_call_witness_condition/src/main.nr @@ -0,0 +1,16 @@ +global NUM_RESULTS = 2; +fn main(x: Field, y: pub Field, enable: bool) -> pub [Field; NUM_RESULTS] { + let mut result = [0; NUM_RESULTS]; + for i in 0..NUM_RESULTS { + if enable { + result[i] = return_value(x, y); + } + } + result +} + +#[fold] +fn return_value(x: Field, y: Field) -> Field { + assert(x != y); + x +} diff --git a/tooling/debugger/ignored-tests.txt b/tooling/debugger/ignored-tests.txt index 5a42ef36e7e..4507aeb8545 100644 --- a/tooling/debugger/ignored-tests.txt +++ b/tooling/debugger/ignored-tests.txt @@ -14,3 +14,4 @@ signed_comparison to_bytes_integration fold_basic fold_basic_nested_call +fold_call_witness_condition