Skip to content

Commit

Permalink
chore(debugger): Inject abstract foreign call executor to debugger (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mverzilli authored Nov 24, 2023
1 parent 73f5b47 commit 2f3fd75
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
26 changes: 21 additions & 5 deletions tooling/debugger/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -24,7 +24,7 @@ pub(super) enum DebugCommandResult {
pub(super) struct DebugContext<'a, B: BlackBoxFunctionSolver> {
acvm: ACVM<'a, B>,
brillig_solver: Option<BrilligSolver<'a, B>>,
foreign_call_executor: DefaultForeignCallExecutor,
foreign_call_executor: Box<dyn ForeignCallExecutor + 'a>,
debug_artifact: &'a DebugArtifact,
breakpoints: HashSet<OpcodeLocation>,
}
Expand All @@ -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<dyn ForeignCallExecutor + 'a>,
) -> 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(),
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 };
Expand Down
13 changes: 9 additions & 4 deletions tooling/debugger/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2f3fd75

Please sign in to comment.