Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use a full BlackBoxFunctionSolver implementation when execution brillig during acirgen #6481

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use acvm::acir::circuit::opcodes::{
};
use acvm::acir::circuit::{AssertionPayload, ExpressionOrMemory, ExpressionWidth, Opcode};
use acvm::brillig_vm::{MemoryValue, VMStatus, VM};
use acvm::BlackBoxFunctionSolver;
use acvm::{
acir::AcirField,
acir::{
Expand Down Expand Up @@ -107,7 +108,9 @@ impl From<NumericType> for AcirType {
/// Context object which holds the relationship between
/// `Variables`(AcirVar) and types such as `Expression` and `Witness`
/// which are placed into ACIR.
pub(crate) struct AcirContext<F: AcirField> {
pub(crate) struct AcirContext<F: AcirField, B: BlackBoxFunctionSolver<F>> {
blackbox_solver: B,

/// Two-way map that links `AcirVar` to `AcirVarData`.
///
/// The vars object is an instance of the `TwoWayMap`, which provides a bidirectional mapping between `AcirVar` and `AcirVarData`.
Expand All @@ -132,7 +135,7 @@ pub(crate) struct AcirContext<F: AcirField> {
pub(crate) warnings: Vec<SsaReport>,
}

impl<F: AcirField> AcirContext<F> {
impl<F: AcirField, B: BlackBoxFunctionSolver<F>> AcirContext<F, B> {
pub(crate) fn set_expression_width(&mut self, expression_width: ExpressionWidth) {
self.expression_width = expression_width;
}
Expand Down Expand Up @@ -1758,8 +1761,8 @@ impl<F: AcirField> AcirContext<F> {
brillig_stdlib_func,
);

fn range_constraint_value<G: AcirField>(
context: &mut AcirContext<G>,
fn range_constraint_value<G: AcirField, C: BlackBoxFunctionSolver<G>>(
context: &mut AcirContext<G, C>,
value: &AcirValue,
) -> Result<(), RuntimeError> {
match value {
Expand Down Expand Up @@ -1878,7 +1881,7 @@ impl<F: AcirField> AcirContext<F> {
inputs: &[BrilligInputs<F>],
outputs_types: &[AcirType],
) -> Option<Vec<AcirValue>> {
let mut memory = (execute_brillig(code, inputs)?).into_iter();
let mut memory = (execute_brillig(code, &self.blackbox_solver, inputs)?).into_iter();

let outputs_var = vecmap(outputs_types.iter(), |output| match output {
AcirType::NumericType(_) => {
Expand Down Expand Up @@ -2164,8 +2167,9 @@ pub(crate) struct AcirVar(usize);
/// Returns the finished state of the Brillig VM if execution can complete.
///
/// Returns `None` if complete execution of the Brillig bytecode is not possible.
fn execute_brillig<F: AcirField>(
fn execute_brillig<F: AcirField, B: BlackBoxFunctionSolver<F>>(
code: &[BrilligOpcode<F>],
blackbox_solver: &B,
inputs: &[BrilligInputs<F>],
) -> Option<Vec<MemoryValue<F>>> {
// Set input values
Expand All @@ -2191,12 +2195,8 @@ fn execute_brillig<F: AcirField>(
}

// Instantiate a Brillig VM given the solved input registers and memory, along with the Brillig bytecode.
//
// We pass a stubbed solver here as a concrete solver implies a field choice which conflicts with this function
// being generic.
let solver = acvm::blackbox_solver::StubbedBlackBoxSolver;
let profiling_active = false;
let mut vm = VM::new(calldata, code, Vec::new(), &solver, profiling_active);
let mut vm = VM::new(calldata, code, Vec::new(), blackbox_solver, profiling_active);

// Run the Brillig VM on these inputs, bytecode, etc!
let vm_status = vm.process_opcodes();
Expand Down
3 changes: 2 additions & 1 deletion compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::brillig::{brillig_gen::brillig_fn::FunctionContext as BrilligFunction
use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport};
pub(crate) use acir_ir::generated_acir::GeneratedAcir;
use acvm::acir::circuit::opcodes::{AcirFunctionId, BlockType};
use bn254_blackbox_solver::Bn254BlackBoxSolver;
use noirc_frontend::monomorphization::ast::InlineType;

use acvm::acir::circuit::brillig::{BrilligBytecode, BrilligFunctionId};
Expand Down Expand Up @@ -156,7 +157,7 @@ struct Context<'a> {
current_side_effects_enabled_var: AcirVar,

/// Manages and builds the `AcirVar`s to which the converted SSA values refer.
acir_context: AcirContext<FieldElement>,
acir_context: AcirContext<FieldElement, Bn254BlackBoxSolver>,

/// Track initialized acir dynamic arrays
///
Expand Down
Loading