Skip to content

Commit

Permalink
Merge branch 'master' into michaeljklein/lambda-calculus-test
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljklein authored Mar 10, 2025
2 parents bdc2680 + 1fa0dd9 commit 8b38b64
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/benchmark_projects.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define: &AZ_COMMIT fd9f1458557f2d67bcf2d58ba4194e000f58600c
define: &AZ_COMMIT f15942770bc391a4d66fe9c23262b755de77f71d
projects:
private-kernel-inner:
repo: AztecProtocol/aztec-packages
Expand Down
2 changes: 1 addition & 1 deletion EXTERNAL_NOIR_LIBRARIES.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define: &AZ_COMMIT fd9f1458557f2d67bcf2d58ba4194e000f58600c
define: &AZ_COMMIT f15942770bc391a4d66fe9c23262b755de77f71d
libraries:
noir_check_shuffle:
repo: noir-lang/noir_check_shuffle
Expand Down
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 @@ pub enum Opcode<F: AcirField> {
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 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> Default for Expression<F> {
}
}

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
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 @@ -84,13 +84,13 @@ impl<F> From<BTreeMap<Witness, F>> for WitnessMap<F> {
}
}

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: Serialize + AcirField> TryFrom<WitnessMap<F>> for Vec<u8> {
}
}

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 @@ -70,13 +70,13 @@ impl<F> From<WitnessMap<F>> for WitnessStack<F> {
}
}

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: Serialize + AcirField> TryFrom<WitnessStack<F>> for Vec<u8> {
}
}

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

0 comments on commit 8b38b64

Please sign in to comment.