Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.
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
20 changes: 3 additions & 17 deletions acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ mod tests {
use std::collections::BTreeSet;

use super::{
opcodes::{BlackBoxFuncCall, FunctionInput, OracleData},
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, Opcode, PublicInputs,
};
use crate::native_types::{Expression, Witness};
use crate::native_types::Witness;
use acir_field::FieldElement;

fn directive_opcode() -> Opcode {
Expand All @@ -136,25 +136,12 @@ mod tests {
input: FunctionInput { witness: Witness(1), num_bits: 8 },
})
}
fn oracle_opcode() -> Opcode {
Opcode::Oracle(OracleData {
name: String::from("oracle-name"),
inputs: vec![Expression {
mul_terms: vec![(FieldElement::from(123u128), Witness(1), Witness(2))],
linear_combinations: vec![(FieldElement::from(456u128), Witness(34))],
q_c: FieldElement::from(12345678u128),
}],
input_values: vec![],
outputs: vec![Witness(1), Witness(2), Witness(3)],
output_values: vec![],
})
}

#[test]
fn serialization_roundtrip() {
let circuit = Circuit {
current_witness_index: 5,
opcodes: vec![and_opcode(), range_opcode(), oracle_opcode(), directive_opcode()],
opcodes: vec![and_opcode(), range_opcode(), directive_opcode()],
public_parameters: PublicInputs(BTreeSet::from_iter(vec![Witness(2), Witness(12)])),
return_values: PublicInputs(BTreeSet::from_iter(vec![Witness(4), Witness(12)])),
};
Expand Down Expand Up @@ -182,7 +169,6 @@ mod tests {
}),
range_opcode(),
and_opcode(),
oracle_opcode(),
],
public_parameters: PublicInputs(BTreeSet::from_iter(vec![Witness(2)])),
return_values: PublicInputs(BTreeSet::from_iter(vec![Witness(2)])),
Expand Down
8 changes: 0 additions & 8 deletions acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ use serde::{Deserialize, Serialize};

mod black_box_function_call;
mod block;
mod oracle_data;

pub use black_box_function_call::{BlackBoxFuncCall, FunctionInput};
pub use block::{BlockId, MemOp, MemoryBlock};
pub use oracle_data::OracleData;

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum Opcode {
Expand All @@ -37,7 +35,6 @@ pub enum Opcode {
// TODO(#319): Review this comment and generalize it to be useful for other backends.
// RAM is required for acvm-backend-barretenberg as dynamic memory implementation in Barretenberg requires an initialization phase and can only handle constant values for operations.
RAM(MemoryBlock),
Oracle(OracleData),
Brillig(Brillig),
}

Expand All @@ -52,7 +49,6 @@ impl Opcode {
Opcode::Block(_) => "block",
Opcode::RAM(_) => "ram",
Opcode::ROM(_) => "rom",
Opcode::Oracle(data) => &data.name,
Opcode::Brillig(_) => "brillig",
}
}
Expand Down Expand Up @@ -150,10 +146,6 @@ impl std::fmt::Display for Opcode {
write!(f, "RAM ")?;
write!(f, "(id: {}, len: {}) ", block.id.0, block.trace.len())
}
Opcode::Oracle(data) => {
write!(f, "ORACLE: ")?;
write!(f, "{data}")
}
Opcode::Brillig(brillig) => {
write!(f, "BRILLIG: ")?;
writeln!(f, "inputs: {:?}", brillig.inputs)?;
Expand Down
41 changes: 0 additions & 41 deletions acir/src/circuit/opcodes/oracle_data.rs

This file was deleted.

4 changes: 1 addition & 3 deletions acvm/src/compiler/transformers/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ impl FallbackTransformer {
| Opcode::Brillig(_)
| Opcode::Block(_)
| Opcode::ROM(_)
| Opcode::RAM(_)
| Opcode::Oracle { .. } => {
| Opcode::RAM(_) => {
// directive, arithmetic expression or blocks are handled by acvm
// The oracle opcode is assumed to be supported.
acir_supported_opcodes.push(opcode);
continue;
}
Expand Down
54 changes: 13 additions & 41 deletions acvm/src/pwg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
use crate::{Language, PartialWitnessGenerator};
use acir::{
brillig_vm::ForeignCallResult,
circuit::brillig::Brillig,
circuit::opcodes::{Opcode, OracleData},
circuit::{brillig::Brillig, Opcode},
native_types::{Expression, Witness, WitnessMap},
BlackBoxFunc, FieldElement,
};

use self::{
arithmetic::ArithmeticSolver, brillig::BrilligSolver, directives::solve_directives,
oracle::OracleSolver,
};
use self::{arithmetic::ArithmeticSolver, brillig::BrilligSolver, directives::solve_directives};

use thiserror::Error;

Expand All @@ -25,7 +21,6 @@ mod directives;
// black box functions
mod blackbox;
mod block;
mod oracle;

// Re-export `Blocks` so that it can be passed to `pwg::solve`
pub use block::Blocks;
Expand All @@ -36,17 +31,12 @@ pub enum PartialWitnessGeneratorStatus {
/// All opcodes have been solved.
Solved,

/// The `PartialWitnessGenerator` has encountered a request for [oracle data][Opcode::Oracle] or a Brillig [foreign call][acir::brillig_vm::Opcode::ForeignCall].
///
/// Both of these opcodes require information from outside of the ACVM to be inserted before restarting execution.
/// [`Opcode::Oracle`] and [`Opcode::Brillig`] opcodes require the return values to be inserted slightly differently.
/// `Oracle` opcodes expect their return values to be written directly into the witness map whereas a `Brillig` foreign call
/// result is inserted into the `Brillig` opcode which made the call using [`UnresolvedBrilligCall::resolve`].
/// (Note: this means that the updated opcode must then be passed back into the ACVM to be processed further.)
/// The `PartialWitnessGenerator` has encountered a request for a Brillig [foreign call][acir::brillig_vm::Opcode::ForeignCall]
/// to retrieve information from outside of the ACVM.
/// The result of the foreign call is inserted into the `Brillig` opcode which made the call using [`UnresolvedBrilligCall::resolve`].
///
/// Once this is done, the `PartialWitnessGenerator` can be restarted to solve the remaining opcodes.
RequiresOracleData {
required_oracle_data: Vec<OracleData>,
/// Once this is done, the `PartialWitnessGenerator` can be restarted to solve the new set of opcodes.
RequiresForeignCall {
unsolved_opcodes: Vec<Opcode>,
unresolved_brillig_calls: Vec<UnresolvedBrilligCall>,
},
Expand Down Expand Up @@ -104,14 +94,12 @@ pub fn solve(
mut opcode_to_solve: Vec<Opcode>,
) -> Result<PartialWitnessGeneratorStatus, OpcodeResolutionError> {
let mut unresolved_opcodes: Vec<Opcode> = Vec::new();
let mut unresolved_oracles: Vec<OracleData> = Vec::new();
let mut unresolved_brillig_calls: Vec<UnresolvedBrilligCall> = Vec::new();
while !opcode_to_solve.is_empty() || !unresolved_oracles.is_empty() {
while !opcode_to_solve.is_empty() {
unresolved_opcodes.clear();
let mut stalled = true;
let mut opcode_not_solvable = None;
for opcode in &opcode_to_solve {
let mut solved_oracle_data = None;
let resolution = match opcode {
Opcode::Arithmetic(expr) => ArithmeticSolver::solve(initial_witness, expr),
Opcode::BlackBoxFuncCall(bb_func) => {
Expand All @@ -121,12 +109,6 @@ pub fn solve(
Opcode::Block(block) | Opcode::ROM(block) | Opcode::RAM(block) => {
blocks.solve(block.id, &block.trace, initial_witness)
}
Opcode::Oracle(data) => {
let mut data_clone = data.clone();
let result = OracleSolver::solve(initial_witness, &mut data_clone)?;
solved_oracle_data = Some(data_clone);
Ok(result)
}
Opcode::Brillig(brillig) => BrilligSolver::solve(initial_witness, brillig),
};
match resolution {
Expand All @@ -135,12 +117,7 @@ pub fn solve(
}
Ok(OpcodeResolution::InProgress) => {
stalled = false;
// InProgress Oracles must be externally re-solved
if let Some(oracle) = solved_oracle_data {
unresolved_oracles.push(oracle);
} else {
unresolved_opcodes.push(opcode.clone());
}
unresolved_opcodes.push(opcode.clone());
}
Ok(OpcodeResolution::InProgressBrillig(oracle_wait_info)) => {
stalled = false;
Expand All @@ -162,22 +139,17 @@ pub fn solve(
// We push those opcodes not solvable to the back as
// it could be because the opcodes are out of order, i.e. this assignment
// relies on a later opcodes' results
if let Some(oracle_data) = solved_oracle_data {
unresolved_opcodes.push(Opcode::Oracle(oracle_data));
} else {
unresolved_opcodes.push(opcode.clone());
}
unresolved_opcodes.push(opcode.clone());
}
Err(OpcodeResolutionError::OpcodeNotSolvable(_)) => {
unreachable!("ICE - Result should have been converted to GateResolution")
}
Err(err) => return Err(err),
}
}
// We have oracles that must be externally resolved
if !unresolved_oracles.is_empty() || !unresolved_brillig_calls.is_empty() {
return Ok(PartialWitnessGeneratorStatus::RequiresOracleData {
required_oracle_data: unresolved_oracles,
// We have foreign calls that must be externally resolved
if !unresolved_brillig_calls.is_empty() {
return Ok(PartialWitnessGeneratorStatus::RequiresForeignCall {
unsolved_opcodes: unresolved_opcodes,
unresolved_brillig_calls,
});
Expand Down
44 changes: 0 additions & 44 deletions acvm/src/pwg/oracle.rs

This file was deleted.

Loading