Skip to content

Commit

Permalink
fix(acvm): Mark outputs of Opcode::Call solvable (#4708)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

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.
  • Loading branch information
vezenovm authored Apr 3, 2024
1 parent 079cb2a commit 8fea405
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion acvm-repo/acvm/src/compiler/transformers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "fold_call_witness_condition"
type = "bin"
authors = [""]
compiler_version = ">=0.26.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions tooling/debugger/ignored-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ signed_comparison
to_bytes_integration
fold_basic
fold_basic_nested_call
fold_call_witness_condition

0 comments on commit 8fea405

Please sign in to comment.