From 8d2a2ddcd90053483cc62c2cdf0797bee3490b10 Mon Sep 17 00:00:00 2001 From: guipublic <47281315+guipublic@users.noreply.github.com> Date: Wed, 15 Jan 2025 15:26:53 +0100 Subject: [PATCH] fix: do not remove memory blocks used as brillig input (#7073) --- acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs | 9 ++++++++- .../compile_success_no_bug/regression_7062/Nargo.toml | 7 +++++++ .../compile_success_no_bug/regression_7062/src/main.nr | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test_programs/compile_success_no_bug/regression_7062/Nargo.toml create mode 100644 test_programs/compile_success_no_bug/regression_7062/src/main.nr diff --git a/acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs b/acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs index 1963430210f..1325a3b03cd 100644 --- a/acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs +++ b/acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs @@ -1,4 +1,4 @@ -use acir::circuit::{opcodes::BlockId, Circuit, Opcode}; +use acir::circuit::{brillig::BrilligInputs, opcodes::BlockId, Circuit, Opcode}; use std::collections::HashSet; /// `UnusedMemoryOptimizer` will remove initializations of memory blocks which are unused. @@ -29,6 +29,13 @@ impl UnusedMemoryOptimizer { Opcode::MemoryOp { block_id, .. } => { unused_memory_initialization.remove(block_id); } + Opcode::BrilligCall { inputs, .. } => { + for input in inputs { + if let BrilligInputs::MemoryArray(block) = input { + unused_memory_initialization.remove(block); + } + } + } _ => (), } } diff --git a/test_programs/compile_success_no_bug/regression_7062/Nargo.toml b/test_programs/compile_success_no_bug/regression_7062/Nargo.toml new file mode 100644 index 00000000000..0e11219ad98 --- /dev/null +++ b/test_programs/compile_success_no_bug/regression_7062/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "regression_7062" +type = "bin" +authors = [""] +compiler_version = ">=0.31.0" + +[dependencies] diff --git a/test_programs/compile_success_no_bug/regression_7062/src/main.nr b/test_programs/compile_success_no_bug/regression_7062/src/main.nr new file mode 100644 index 00000000000..c640062b45b --- /dev/null +++ b/test_programs/compile_success_no_bug/regression_7062/src/main.nr @@ -0,0 +1,8 @@ +fn main(args: [Field; 2]) { + /// Safety: n/a + unsafe { store(args) }; + // Dummy test to remove the 'underconstraint bug' + assert(args[0] + args[1] != 0); +} + +pub unconstrained fn store(_: [Field]) {} \ No newline at end of file