From 2f28012b6ff837a66bb04f97322606bb73df15bd Mon Sep 17 00:00:00 2001 From: Martin Verzilli Date: Thu, 23 Nov 2023 18:30:21 +0100 Subject: [PATCH] Inject abstract foreign call executor to debugger --- tooling/debugger/src/context.rs | 26 +++++++++++++++++++++----- tooling/debugger/src/repl.rs | 13 +++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/tooling/debugger/src/context.rs b/tooling/debugger/src/context.rs index 40507aaed3a..35cfba497f0 100644 --- a/tooling/debugger/src/context.rs +++ b/tooling/debugger/src/context.rs @@ -8,7 +8,7 @@ use acvm::{BlackBoxFunctionSolver, FieldElement}; use nargo::artifacts::debug::DebugArtifact; use nargo::errors::{ExecutionError, Location}; -use nargo::ops::{DefaultForeignCallExecutor, ForeignCallExecutor}; +use nargo::ops::ForeignCallExecutor; use nargo::NargoError; use std::collections::{hash_set::Iter, HashSet}; @@ -24,7 +24,7 @@ pub(super) enum DebugCommandResult { pub(super) struct DebugContext<'a, B: BlackBoxFunctionSolver> { acvm: ACVM<'a, B>, brillig_solver: Option>, - foreign_call_executor: DefaultForeignCallExecutor, + foreign_call_executor: Box, debug_artifact: &'a DebugArtifact, breakpoints: HashSet, } @@ -35,11 +35,12 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { circuit: &'a Circuit, debug_artifact: &'a DebugArtifact, initial_witness: WitnessMap, + foreign_call_executor: Box, ) -> Self { Self { acvm: ACVM::new(blackbox_solver, &circuit.opcodes, initial_witness), brillig_solver: None, - foreign_call_executor: DefaultForeignCallExecutor::new(true), + foreign_call_executor, debug_artifact, breakpoints: HashSet::new(), } @@ -370,6 +371,8 @@ fn test_resolve_foreign_calls_stepping_into_brillig() { native_types::Expression, }; + use nargo::ops::DefaultForeignCallExecutor; + let fe_0 = FieldElement::zero(); let fe_1 = FieldElement::one(); let w_x = Witness(1); @@ -404,7 +407,13 @@ fn test_resolve_foreign_calls_stepping_into_brillig() { let initial_witness = BTreeMap::from([(Witness(1), fe_1)]).into(); - let mut context = DebugContext::new(blackbox_solver, circuit, debug_artifact, initial_witness); + let mut context = DebugContext::new( + blackbox_solver, + circuit, + debug_artifact, + initial_witness, + Box::new(DefaultForeignCallExecutor::new(true)), + ); assert_eq!(context.get_current_opcode_location(), Some(OpcodeLocation::Acir(0))); @@ -449,6 +458,7 @@ fn test_break_brillig_block_while_stepping_acir_opcodes() { native_types::Expression, }; use acvm::brillig_vm::brillig::BinaryFieldOp; + use nargo::ops::DefaultForeignCallExecutor; let fe_0 = FieldElement::zero(); let fe_1 = FieldElement::one(); @@ -502,7 +512,13 @@ fn test_break_brillig_block_while_stepping_acir_opcodes() { let initial_witness = BTreeMap::from([(Witness(1), fe_1), (Witness(2), fe_1)]).into(); - let mut context = DebugContext::new(blackbox_solver, circuit, debug_artifact, initial_witness); + let mut context = DebugContext::new( + blackbox_solver, + circuit, + debug_artifact, + initial_witness, + Box::new(DefaultForeignCallExecutor::new(true)), + ); // set breakpoint let breakpoint_location = OpcodeLocation::Brillig { acir_index: 0, brillig_index: 1 }; diff --git a/tooling/debugger/src/repl.rs b/tooling/debugger/src/repl.rs index 23abe83c38d..cb6539cbdb1 100644 --- a/tooling/debugger/src/repl.rs +++ b/tooling/debugger/src/repl.rs @@ -4,8 +4,7 @@ use acvm::acir::circuit::{Circuit, Opcode, OpcodeLocation}; use acvm::acir::native_types::{Witness, WitnessMap}; use acvm::{BlackBoxFunctionSolver, FieldElement}; -use nargo::artifacts::debug::DebugArtifact; -use nargo::NargoError; +use nargo::{artifacts::debug::DebugArtifact, ops::DefaultForeignCallExecutor, NargoError}; use easy_repl::{command, CommandStatus, Repl}; use std::cell::RefCell; @@ -33,8 +32,13 @@ impl<'a, B: BlackBoxFunctionSolver> ReplDebugger<'a, B> { debug_artifact: &'a DebugArtifact, initial_witness: WitnessMap, ) -> Self { - let context = - DebugContext::new(blackbox_solver, circuit, debug_artifact, initial_witness.clone()); + let context = DebugContext::new( + blackbox_solver, + circuit, + debug_artifact, + initial_witness.clone(), + Box::new(DefaultForeignCallExecutor::new(true)), + ); Self { context, blackbox_solver, @@ -274,6 +278,7 @@ impl<'a, B: BlackBoxFunctionSolver> ReplDebugger<'a, B> { self.circuit, self.debug_artifact, self.initial_witness.clone(), + Box::new(DefaultForeignCallExecutor::new(true)), ); for opcode_location in breakpoints { self.context.add_breakpoint(opcode_location);