Skip to content
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
16 changes: 2 additions & 14 deletions acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,8 @@
impl<F: AcirField> std::fmt::Display for Opcode<F> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Opcode::AssertZero(expr) => {
write!(f, "EXPR [ ")?;
for i in &expr.mul_terms {
write!(f, "({}, _{}, _{}) ", i.0, i.1.witness_index(), i.2.witness_index())?;
}
for i in &expr.linear_combinations {
write!(f, "({}, _{}) ", i.0, i.1.witness_index())?;
}
write!(f, "{}", expr.q_c)?;

write!(f, " ]")
}

Opcode::BlackBoxFuncCall(g) => write!(f, "{g}"),
Opcode::AssertZero(expr) => expr.fmt(f),
Opcode::BlackBoxFuncCall(g) => g.fmt(f),
Opcode::MemoryOp { block_id, op, predicate } => {
write!(f, "MEM ")?;
if let Some(pred) = predicate {
Expand All @@ -168,7 +156,7 @@
match databus {
BlockType::Memory => write!(f, "INIT ")?,
BlockType::CallData(id) => write!(f, "INIT CALLDATA {} ", id)?,
BlockType::ReturnData => write!(f, "INIT RETURNDATA ")?,

Check warning on line 159 in acvm-repo/acir/src/circuit/opcodes.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (RETURNDATA)
}
write!(f, "(id: {}, len: {}) ", block_id.0, init.len())
}
Expand Down
76 changes: 39 additions & 37 deletions acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<F: std::fmt::Display> std::fmt::Display for FunctionInput<F> {
}

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
pub enum BlackBoxFuncCall<F: AcirField> {
pub enum BlackBoxFuncCall<F> {
AES128Encrypt {
inputs: Vec<FunctionInput<F>>,
iv: Box<[FunctionInput<F>; 16]>,
Expand Down Expand Up @@ -216,7 +216,7 @@ pub enum BlackBoxFuncCall<F: AcirField> {
},
}

impl<F: Copy + AcirField> BlackBoxFuncCall<F> {
impl<F> BlackBoxFuncCall<F> {
pub fn get_black_box_func(&self) -> BlackBoxFunc {
match self {
BlackBoxFuncCall::AES128Encrypt { .. } => BlackBoxFunc::AES128Encrypt,
Expand Down Expand Up @@ -246,6 +246,41 @@ impl<F: Copy + AcirField> BlackBoxFuncCall<F> {
self.get_black_box_func().name()
}

pub fn get_outputs_vec(&self) -> Vec<Witness> {
match self {
BlackBoxFuncCall::Blake2s { outputs, .. }
| BlackBoxFuncCall::Blake3 { outputs, .. } => outputs.to_vec(),

BlackBoxFuncCall::Keccakf1600 { outputs, .. } => outputs.to_vec(),

BlackBoxFuncCall::Sha256Compression { outputs, .. } => outputs.to_vec(),

BlackBoxFuncCall::AES128Encrypt { outputs, .. }
| BlackBoxFuncCall::Poseidon2Permutation { outputs, .. } => outputs.to_vec(),

BlackBoxFuncCall::AND { output, .. }
| BlackBoxFuncCall::XOR { output, .. }
| BlackBoxFuncCall::EcdsaSecp256k1 { output, .. }
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output],
BlackBoxFuncCall::MultiScalarMul { outputs, .. }
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } => {
vec![outputs.0, outputs.1, outputs.2]
}
BlackBoxFuncCall::RANGE { .. }
| BlackBoxFuncCall::RecursiveAggregation { .. }
| BlackBoxFuncCall::BigIntFromLeBytes { .. }
| BlackBoxFuncCall::BigIntAdd { .. }
| BlackBoxFuncCall::BigIntSub { .. }
| BlackBoxFuncCall::BigIntMul { .. }
| BlackBoxFuncCall::BigIntDiv { .. } => {
vec![]
}
BlackBoxFuncCall::BigIntToLeBytes { outputs, .. } => outputs.to_vec(),
}
}
}

impl<F: Copy> BlackBoxFuncCall<F> {
pub fn get_inputs_vec(&self) -> Vec<FunctionInput<F>> {
match self {
BlackBoxFuncCall::AES128Encrypt { inputs, .. }
Expand Down Expand Up @@ -333,39 +368,6 @@ impl<F: Copy + AcirField> BlackBoxFuncCall<F> {
}
}

pub fn get_outputs_vec(&self) -> Vec<Witness> {
match self {
BlackBoxFuncCall::Blake2s { outputs, .. }
| BlackBoxFuncCall::Blake3 { outputs, .. } => outputs.to_vec(),

BlackBoxFuncCall::Keccakf1600 { outputs, .. } => outputs.to_vec(),

BlackBoxFuncCall::Sha256Compression { outputs, .. } => outputs.to_vec(),

BlackBoxFuncCall::AES128Encrypt { outputs, .. }
| BlackBoxFuncCall::Poseidon2Permutation { outputs, .. } => outputs.to_vec(),

BlackBoxFuncCall::AND { output, .. }
| BlackBoxFuncCall::XOR { output, .. }
| BlackBoxFuncCall::EcdsaSecp256k1 { output, .. }
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output],
BlackBoxFuncCall::MultiScalarMul { outputs, .. }
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } => {
vec![outputs.0, outputs.1, outputs.2]
}
BlackBoxFuncCall::RANGE { .. }
| BlackBoxFuncCall::RecursiveAggregation { .. }
| BlackBoxFuncCall::BigIntFromLeBytes { .. }
| BlackBoxFuncCall::BigIntAdd { .. }
| BlackBoxFuncCall::BigIntSub { .. }
| BlackBoxFuncCall::BigIntMul { .. }
| BlackBoxFuncCall::BigIntDiv { .. } => {
vec![]
}
BlackBoxFuncCall::BigIntToLeBytes { outputs, .. } => outputs.to_vec(),
}
}

pub fn get_input_witnesses(&self) -> BTreeSet<Witness> {
let mut result = BTreeSet::new();
for input in self.get_inputs_vec() {
Expand Down Expand Up @@ -429,7 +431,7 @@ fn get_outputs_string(outputs: &[Witness]) -> String {
}
}

impl<F: std::fmt::Display + Copy + AcirField> std::fmt::Display for BlackBoxFuncCall<F> {
impl<F: std::fmt::Display + Copy> std::fmt::Display for BlackBoxFuncCall<F> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let uppercase_name = self.name().to_uppercase();
write!(f, "BLACKBOX::{uppercase_name} ")?;
Expand All @@ -454,7 +456,7 @@ impl<F: std::fmt::Display + Copy + AcirField> std::fmt::Display for BlackBoxFunc
}
}

impl<F: std::fmt::Display + Copy + AcirField> std::fmt::Debug for BlackBoxFuncCall<F> {
impl<F: std::fmt::Display + Copy> std::fmt::Debug for BlackBoxFuncCall<F> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self, f)
}
Expand Down
15 changes: 10 additions & 5 deletions acvm-repo/acir/src/native_types/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@
}
}

impl<F: AcirField> std::fmt::Display for Expression<F> {
impl<F: std::fmt::Display> std::fmt::Display for Expression<F> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some(witness) = self.to_witness() {
write!(f, "x{}", witness.witness_index())
} else {
write!(f, "%{:?}%", crate::circuit::opcodes::Opcode::AssertZero(self.clone()))
write!(f, "EXPR [ ")?;
for i in &self.mul_terms {
write!(f, "({}, _{}, _{}) ", i.0, i.1.witness_index(), i.2.witness_index())?;
}
for i in &self.linear_combinations {
write!(f, "({}, _{}) ", i.0, i.1.witness_index())?;
}
write!(f, "{}", self.q_c)?;

write!(f, " ]")
}
}

Expand Down Expand Up @@ -358,7 +363,7 @@
use acir_field::{AcirField, FieldElement};

#[test]
fn add_mul_smoketest() {

Check warning on line 366 in acvm-repo/acir/src/native_types/expression/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (smoketest)
let a = Expression {
mul_terms: vec![(FieldElement::from(2u128), Witness(1), Witness(2))],
..Default::default()
Expand Down
6 changes: 3 additions & 3 deletions acvm-repo/acir/src/native_types/witness_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use acir_field::AcirField;
use flate2::Compression;
use flate2::bufread::GzDecoder;

Check warning on line 9 in acvm-repo/acir/src/native_types/witness_map.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bufread)
use flate2::bufread::GzEncoder;

Check warning on line 10 in acvm-repo/acir/src/native_types/witness_map.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bufread)
use noir_protobuf::ProtoCodec as _;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -84,13 +84,13 @@
}
}

impl<F: Serialize + AcirField> WitnessMap<F> {
impl<F: Serialize> WitnessMap<F> {
pub(crate) fn bincode_serialize(&self) -> Result<Vec<u8>, WitnessMapError> {
bincode::serialize(self).map_err(|e| SerializationError::Deserialize(e.to_string()).into())
}
}

impl<F: AcirField + for<'a> Deserialize<'a>> WitnessMap<F> {
impl<F: for<'a> Deserialize<'a>> WitnessMap<F> {
pub(crate) fn bincode_deserialize(buf: &[u8]) -> Result<Self, WitnessMapError> {
bincode::deserialize(buf).map_err(|e| SerializationError::Deserialize(e.to_string()).into())
}
Expand Down Expand Up @@ -120,7 +120,7 @@
}
}

impl<F: AcirField + for<'a> Deserialize<'a>> TryFrom<&[u8]> for WitnessMap<F> {
impl<F: for<'a> Deserialize<'a>> TryFrom<&[u8]> for WitnessMap<F> {
type Error = WitnessMapError;

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
Expand Down
6 changes: 3 additions & 3 deletions acvm-repo/acir/src/native_types/witness_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use acir_field::AcirField;
use flate2::Compression;
use flate2::bufread::GzDecoder;

Check warning on line 5 in acvm-repo/acir/src/native_types/witness_stack.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bufread)
use flate2::bufread::GzEncoder;

Check warning on line 6 in acvm-repo/acir/src/native_types/witness_stack.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bufread)
use noir_protobuf::ProtoCodec as _;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -70,13 +70,13 @@
}
}

impl<F: Serialize + AcirField> WitnessStack<F> {
impl<F: Serialize> WitnessStack<F> {
pub(crate) fn bincode_serialize(&self) -> Result<Vec<u8>, WitnessStackError> {
bincode::serialize(self).map_err(|e| WitnessStackError(e.into()))
}
}

impl<F: AcirField + for<'a> Deserialize<'a>> WitnessStack<F> {
impl<F: for<'a> Deserialize<'a>> WitnessStack<F> {
pub(crate) fn bincode_deserialize(buf: &[u8]) -> Result<Self, WitnessStackError> {
bincode::deserialize(buf).map_err(|e| WitnessStackError(e.into()))
}
Expand Down Expand Up @@ -114,7 +114,7 @@
}
}

impl<F: AcirField + for<'a> Deserialize<'a>> TryFrom<&[u8]> for WitnessStack<F> {
impl<F: for<'a> Deserialize<'a>> TryFrom<&[u8]> for WitnessStack<F> {
type Error = WitnessStackError;

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
Expand Down
5 changes: 1 addition & 4 deletions acvm-repo/acir/src/proto/convert/acir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use noir_protobuf::{ProtoCodec, decode_oneof_map};

use super::ProtoSchema;

impl<F> ProtoCodec<circuit::Circuit<F>, Circuit> for ProtoSchema<F>
where
F: AcirField,
{
impl<F: AcirField> ProtoCodec<circuit::Circuit<F>, Circuit> for ProtoSchema<F> {
fn encode(value: &circuit::Circuit<F>) -> Circuit {
Circuit {
current_witness_index: value.current_witness_index,
Expand Down
10 changes: 3 additions & 7 deletions acvm-repo/acir/src/proto/convert/brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ use crate::proto::brillig::{

use super::ProtoSchema;

impl<F> ProtoCodec<circuit::brillig::BrilligBytecode<F>, BrilligBytecode> for ProtoSchema<F>
where
F: AcirField,
impl<F: AcirField> ProtoCodec<circuit::brillig::BrilligBytecode<F>, BrilligBytecode>
for ProtoSchema<F>
{
fn encode(value: &circuit::brillig::BrilligBytecode<F>) -> BrilligBytecode {
BrilligBytecode { bytecode: Self::encode_vec(&value.bytecode) }
Expand All @@ -28,10 +27,7 @@ where
}
}

impl<F> ProtoCodec<brillig::Opcode<F>, BrilligOpcode> for ProtoSchema<F>
where
F: AcirField,
{
impl<F: AcirField> ProtoCodec<brillig::Opcode<F>, BrilligOpcode> for ProtoSchema<F> {
fn encode(value: &brillig::Opcode<F>) -> BrilligOpcode {
use brillig_opcode::*;

Expand Down
5 changes: 1 addition & 4 deletions acvm-repo/acir/src/proto/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub(crate) struct ProtoSchema<F> {
field: PhantomData<F>,
}

impl<F> ProtoCodec<circuit::Program<F>, Program> for ProtoSchema<F>
where
F: AcirField,
{
impl<F: AcirField> ProtoCodec<circuit::Program<F>, Program> for ProtoSchema<F> {
fn encode(value: &circuit::Program<F>) -> Program {
Program {
functions: Self::encode_vec(&value.functions),
Expand Down
Loading