Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
chore!: move default_is_opcode_supported to pwg.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed May 17, 2023
1 parent ca31246 commit c289b51
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
32 changes: 1 addition & 31 deletions acvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ pub mod compiler;
pub mod pwg;

use acir::{
circuit::{
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, Opcode,
},
circuit::{opcodes::FunctionInput, Circuit, Opcode},
native_types::{Witness, WitnessMap},
};
use core::fmt::Debug;
Expand Down Expand Up @@ -249,30 +246,3 @@ pub fn checksum_constraint_system(cs: &Circuit) -> u32 {
hasher.update(&bytes);
hasher.finalize()
}

#[deprecated(
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) -> 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 {
matches!(opcode, Opcode::Arithmetic(_))
}

// PLONK supports most of the opcodes by default
// The ones which are not supported, the acvm compiler will
// attempt to transform into supported gates. If these are also not available
// then a compiler error will be emitted.
fn plonk_is_supported(opcode: &Opcode) -> bool {
!matches!(opcode, Opcode::BlackBoxFuncCall(BlackBoxFuncCall::AES { .. }) | Opcode::Block(_))
}

match language {
Language::R1CS => r1cs_is_supported,
Language::PLONKCSat { .. } => plonk_is_supported,
}
}
31 changes: 29 additions & 2 deletions acvm/src/pwg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Re-usable methods that backends can use to implement their PWG

use crate::PartialWitnessGenerator;
use crate::{Language, PartialWitnessGenerator};
use acir::{
circuit::opcodes::{Opcode, OracleData},
circuit::opcodes::{BlackBoxFuncCall, Opcode, OracleData},
native_types::{Expression, Witness, WitnessMap},
BlackBoxFunc, FieldElement,
};
Expand Down Expand Up @@ -213,6 +213,33 @@ fn insert_value(
Ok(())
}

#[deprecated(
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) -> 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 {
matches!(opcode, Opcode::Arithmetic(_))
}

// PLONK supports most of the opcodes by default
// The ones which are not supported, the acvm compiler will
// attempt to transform into supported gates. If these are also not available
// then a compiler error will be emitted.
fn plonk_is_supported(opcode: &Opcode) -> bool {
!matches!(opcode, Opcode::BlackBoxFuncCall(BlackBoxFuncCall::AES { .. }) | Opcode::Block(_))
}

match language {
Language::R1CS => r1cs_is_supported,
Language::PLONKCSat { .. } => plonk_is_supported,
}
}

#[cfg(test)]
mod test {
use std::collections::BTreeMap;
Expand Down

0 comments on commit c289b51

Please sign in to comment.