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
4 changes: 2 additions & 2 deletions acvm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use acir::{
use indexmap::IndexMap;
use optimizers::GeneralOptimizer;
use thiserror::Error;
use transformers::{CSatTransformer, FallbackTransformer, IsOpcodeSupported, R1CSTransformer};
use transformers::{CSatTransformer, FallbackTransformer, R1CSTransformer};

use self::optimizers::RangeOptimizer;
use self::optimizers::Simplifier;
Expand All @@ -25,7 +25,7 @@ pub enum CompileError {
pub fn compile(
acir: Circuit,
np_language: Language,
is_opcode_supported: IsOpcodeSupported,
is_opcode_supported: impl Fn(&Opcode) -> bool,
simplifier: &Simplifier,
) -> Result<Circuit, CompileError> {
// Instantiate the optimizer.
Expand Down
7 changes: 2 additions & 5 deletions acvm/src/compiler/optimizers/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,7 @@ mod test {
FieldElement,
};

use crate::compiler::{
optimizers::Simplifier,
transformers::{FallbackTransformer, IsOpcodeSupported},
};
use crate::compiler::{optimizers::Simplifier, transformers::FallbackTransformer};

#[test]
fn simplify_test() {
Expand Down Expand Up @@ -479,7 +476,7 @@ mod test {
simplifier.simplify(&mut circuit);
assert_eq!(circuit.len(), 3);
assert_eq!(simplifier.solved_gates.len(), 1);
let support_all: IsOpcodeSupported = |_| true;
let support_all = |_opcode: &Opcode| true;
let mut acir = Circuit::default();
acir.opcodes = circuit;
let acir = FallbackTransformer::transform(acir, support_all, &simplifier).unwrap();
Expand Down
5 changes: 1 addition & 4 deletions acvm/src/compiler/transformers/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ use acir::{
BlackBoxFunc,
};

// A predicate that returns true if the black box function is supported
pub type IsOpcodeSupported = fn(&Opcode) -> bool;

pub struct FallbackTransformer;

impl FallbackTransformer {
//ACIR pass which replace unsupported opcodes using arithmetic fallback
pub fn transform(
acir: Circuit,
is_supported: IsOpcodeSupported,
is_supported: impl Fn(&Opcode) -> bool,
simplifier: &Simplifier,
) -> Result<Circuit, CompileError> {
let mut acir_supported_opcodes = Vec::with_capacity(acir.opcodes.len());
Expand Down
1 change: 0 additions & 1 deletion acvm/src/compiler/transformers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ mod r1cs;

pub use csat::CSatTransformer;
pub use fallback::FallbackTransformer;
pub use fallback::IsOpcodeSupported;
pub use r1cs::R1CSTransformer;
10 changes: 4 additions & 6 deletions acvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ pub trait ProofSystemCompiler {
/// if the language and proof system does not line up.
fn np_language(&self) -> Language;

// Returns true if the backend supports the selected black box function
fn black_box_function_supported(&self, opcode: &BlackBoxFunc) -> bool;
Comment thread
TomAFrench marked this conversation as resolved.
// Returns true if the backend supports the selected opcode
fn supports_opcode(&self, opcode: &Opcode) -> bool;

/// Returns the number of gates in a circuit
fn get_exact_circuit_size(&self, circuit: &Circuit) -> Result<u32, Self::Error>;
Expand Down Expand Up @@ -222,14 +222,12 @@ pub fn checksum_constraint_system(cs: &Circuit) -> u32 {
}

#[deprecated(
note = "For backwards compatibility, this method allows you to derive _sensible_ defaults for black box function support based on the np language. \n Backends should simply specify what they support."
note = "For backwards compatibility, this method allows you to derive _sensible_ defaults for opcode support based on the np language. \n Backends should simply specify what they support."
)]
// This is set to match the previous functionality that we had
// Where we could deduce what opcodes were supported
// by knowing the np complete language
pub fn default_is_opcode_supported(
language: Language,
) -> compiler::transformers::IsOpcodeSupported {
pub fn default_is_opcode_supported(language: Language) -> fn(&Opcode) -> bool {
// R1CS does not support any of the opcode except Arithmetic by default.
// The compiler will replace those that it can -- ie range, xor, and
fn r1cs_is_supported(opcode: &Opcode) -> bool {
Expand Down