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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion avm-transpiler/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
edition = "2018"
edition = "2024"
style_edition = "2024"
use_small_heuristics = "Max"
8 changes: 2 additions & 6 deletions avm-transpiler/src/bit_traits.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use acvm::{acir::brillig::MemoryAddress, AcirField, FieldElement};
use acvm::{AcirField, FieldElement, acir::brillig::MemoryAddress};

fn get_msb(n: u128) -> usize {
if n == 0 {
0
} else {
128 - n.leading_zeros() as usize
}
if n == 0 { 0 } else { 128 - n.leading_zeros() as usize }
}

pub trait BitsQueryable {
Expand Down
2 changes: 1 addition & 1 deletion avm-transpiler/src/procedures/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
bit_traits::bits_needed_for,
instructions::{AvmInstruction, AvmOperand},
opcodes::AvmOpcode,
utils::{make_operand, make_unresolved_pc, UnresolvedPCLocation},
utils::{UnresolvedPCLocation, make_operand, make_unresolved_pc},
};
use fxhash::FxHashMap as HashMap;
use operand_collector::OperandCollector;
Expand Down
2 changes: 1 addition & 1 deletion avm-transpiler/src/procedures/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use compiler::{compile, CompiledProcedure};
use compiler::{CompiledProcedure, compile};
use msm::MSM_ASSEMBLY;
use parser::parse;

Expand Down
41 changes: 26 additions & 15 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ use acvm::acir::brillig::{BitSize, IntegerBitSize, Opcode as BrilligOpcode};
use fxhash::{FxHashMap as HashMap, FxHashSet as HashSet};
use std::collections::BTreeMap;

use acvm::FieldElement;
use acvm::acir::circuit::BrilligOpcodeLocation;
use acvm::brillig_vm::brillig::{
BinaryFieldOp, BinaryIntOp, BlackBoxOp, HeapArray, HeapVector, MemoryAddress, ValueOrArray,
};
use acvm::FieldElement;
use noirc_errors::debug_info::DebugInfo;

use crate::bit_traits::{bits_needed_for, BitsQueryable};
use crate::bit_traits::{BitsQueryable, bits_needed_for};
use crate::instructions::{AddressingModeBuilder, AvmInstruction, AvmOperand, AvmTypeTag};
use crate::opcodes::AvmOpcode;
use crate::procedures::{
compile_procedure, Label as ProcedureLocalLabel, Procedure, SCRATCH_SPACE_START,
Label as ProcedureLocalLabel, Procedure, SCRATCH_SPACE_START, compile_procedure,
};
use crate::utils::{
dbg_print_avm_program, dbg_print_brillig_program, make_operand, make_unresolved_pc,
UnresolvedPCLocation, UNRESOLVED_PC,
UNRESOLVED_PC, UnresolvedPCLocation, dbg_print_avm_program, dbg_print_brillig_program,
make_operand, make_unresolved_pc,
};

enum Label {
Expand Down Expand Up @@ -639,18 +639,19 @@ fn handle_note_hash_exists(
inputs: &[ValueOrArray],
) {
let (note_hash_offset_operand, leaf_index_offset_operand) = match inputs {
[
ValueOrArray::MemoryAddress(nh_offset),
ValueOrArray::MemoryAddress(li_offset)
] => (nh_offset, li_offset),
[ValueOrArray::MemoryAddress(nh_offset), ValueOrArray::MemoryAddress(li_offset)] => {
(nh_offset, li_offset)
}
_ => panic!(
"Transpiler expects ForeignCall::NOTEHASHEXISTS to have 2 inputs of type MemoryAddress, got {:?}", inputs
"Transpiler expects ForeignCall::NOTEHASHEXISTS to have 2 inputs of type MemoryAddress, got {:?}",
inputs
),
};
let exists_offset_operand = match destinations {
[ValueOrArray::MemoryAddress(offset)] => offset,
_ => panic!(
"Transpiler expects ForeignCall::NOTEHASHEXISTS to have 1 output of type MemoryAddress, got {:?}", destinations
"Transpiler expects ForeignCall::NOTEHASHEXISTS to have 1 output of type MemoryAddress, got {:?}",
destinations
),
};
avm_instrs.push(AvmInstruction {
Expand Down Expand Up @@ -750,19 +751,29 @@ fn handle_nullifier_exists(
inputs: &[ValueOrArray],
) {
if destinations.len() != 1 || inputs.len() != 2 {
panic!("Transpiler expects ForeignCall::CHECKNULLIFIEREXISTS to have 1 destinations and 2 inputs, got {} and {}", destinations.len(), inputs.len());
panic!(
"Transpiler expects ForeignCall::CHECKNULLIFIEREXISTS to have 1 destinations and 2 inputs, got {} and {}",
destinations.len(),
inputs.len()
);
}
let nullifier_offset_operand = match &inputs[0] {
ValueOrArray::MemoryAddress(offset) => offset,
_ => panic!("Transpiler does not know how to handle ForeignCall::EMITNOTEHASH with HeapArray/Vector inputs"),
_ => panic!(
"Transpiler does not know how to handle ForeignCall::EMITNOTEHASH with HeapArray/Vector inputs"
),
};
let address_offset_operand = match &inputs[1] {
ValueOrArray::MemoryAddress(offset) => offset,
_ => panic!("Transpiler does not know how to handle ForeignCall::EMITNOTEHASH with HeapArray/Vector inputs"),
_ => panic!(
"Transpiler does not know how to handle ForeignCall::EMITNOTEHASH with HeapArray/Vector inputs"
),
};
let exists_offset_operand = match &destinations[0] {
ValueOrArray::MemoryAddress(offset) => offset,
_ => panic!("Transpiler does not know how to handle ForeignCall::EMITNOTEHASH with HeapArray/Vector inputs"),
_ => panic!(
"Transpiler does not know how to handle ForeignCall::EMITNOTEHASH with HeapArray/Vector inputs"
),
};
avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::NULLIFIEREXISTS,
Expand Down
10 changes: 8 additions & 2 deletions avm-transpiler/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ pub fn extract_brillig_from_acir_program(
let opcodes = &main_function.opcodes;
assert_eq!(opcodes.len(), 1, "An AVM program should only have a single `BrilligCall`");
match opcodes[0] {
Opcode::BrilligCall { id, .. } => assert_eq!(id, BrilligFunctionId(0), "The ID of the `BrilligCall` must be 0 as we have a single `Brillig` function"),
_ => panic!("Tried to extract a Brillig program from its ACIR wrapper opcode, but the opcode doesn't contain Brillig!"),
Opcode::BrilligCall { id, .. } => assert_eq!(
id,
BrilligFunctionId(0),
"The ID of the `BrilligCall` must be 0 as we have a single `Brillig` function"
),
_ => panic!(
"Tried to extract a Brillig program from its ACIR wrapper opcode, but the opcode doesn't contain Brillig!"
),
}
assert_eq!(
program.unconstrained_functions.len(),
Expand Down
3 changes: 2 additions & 1 deletion noir/noir-repo/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
edition = "2018"
edition = "2024"
style_edition = "2024"
use_small_heuristics = "Max"
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/acir/benches/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use std::{collections::BTreeSet, time::Duration};

use acir::{
FieldElement,
circuit::{Circuit, ExpressionWidth, Opcode, Program, PublicInputs},
native_types::{Expression, Witness},
FieldElement,
};

use pprof::criterion::{Output, PProfProfiler};
Expand Down
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{io::prelude::*, num::ParseIntError, str::FromStr};

use base64::Engine;
use flate2::Compression;
use serde::{de::Error as DeserializationError, Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error as DeserializationError};

use std::collections::BTreeSet;

Expand Down Expand Up @@ -375,8 +375,8 @@ mod tests {
use std::collections::BTreeSet;

use super::{
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, Compression, Opcode, PublicInputs,
opcodes::{BlackBoxFuncCall, FunctionInput},
};
use crate::{
circuit::{ExpressionWidth, Program},
Expand Down
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/acir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ mod reflection {

use crate::{
circuit::{
brillig::{BrilligInputs, BrilligOutputs},
opcodes::{BlackBoxFuncCall, BlockType, ConstantOrWitnessEnum, FunctionInput},
AssertionPayload, Circuit, ExpressionOrMemory, ExpressionWidth, Opcode, OpcodeLocation,
Program,
brillig::{BrilligInputs, BrilligOutputs},
opcodes::{BlackBoxFuncCall, BlockType, ConstantOrWitnessEnum, FunctionInput},
},
native_types::{Witness, WitnessMap, WitnessStack},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ impl<F: Ord> Expression<F> {

fn cmp_max(m1: Option<Witness>, m2: Option<Witness>) -> Ordering {
if let Some(m1) = m1 {
if let Some(m2) = m2 {
m1.cmp(&m2)
} else {
Ordering::Greater
}
if let Some(m2) = m2 { m1.cmp(&m2) } else { Ordering::Greater }
} else if m2.is_some() {
Ordering::Less
} else {
Expand Down
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/acir/src/native_types/witness_map.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{
collections::{btree_map, BTreeMap},
collections::{BTreeMap, btree_map},
io::Read,
ops::Index,
};

use flate2::Compression;
use flate2::bufread::GzDecoder;
use flate2::bufread::GzEncoder;
use flate2::Compression;
use serde::{Deserialize, Serialize};
use thiserror::Error;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::io::Read;

use flate2::Compression;
use flate2::bufread::GzDecoder;
use flate2::bufread::GzEncoder;
use flate2::Compression;
use serde::{Deserialize, Serialize};
use thiserror::Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use std::collections::BTreeSet;

use acir::{
circuit::{
Circuit, Opcode, Program, PublicInputs,
brillig::{BrilligBytecode, BrilligFunctionId, BrilligInputs, BrilligOutputs},
opcodes::{AcirFunctionId, BlackBoxFuncCall, BlockId, FunctionInput, MemOp},
Circuit, Opcode, Program, PublicInputs,
},
native_types::{Expression, Witness},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use acir_field::{AcirField, FieldElement};
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{Criterion, criterion_group, criterion_main};
use std::hint::black_box;

fn criterion_benchmark(c: &mut Criterion) {
Expand Down
12 changes: 2 additions & 10 deletions noir/noir-repo/acvm-repo/acir_field/src/field_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ impl<F: PrimeField> From<u32> for FieldElement<F> {

impl<F: PrimeField> From<bool> for FieldElement<F> {
fn from(boolean: bool) -> FieldElement<F> {
if boolean {
FieldElement::one()
} else {
FieldElement::zero()
}
if boolean { FieldElement::one() } else { FieldElement::zero() }
}
}

Expand Down Expand Up @@ -183,11 +179,7 @@ impl<F: PrimeField> AcirField for FieldElement<F> {
/// For example, a max bit size of 254 would give a max byte size of 32.
fn max_num_bytes() -> u32 {
let num_bytes = Self::max_num_bits() / 8;
if Self::max_num_bits() % 8 == 0 {
num_bytes
} else {
num_bytes + 1
}
if Self::max_num_bits() % 8 == 0 { num_bytes } else { num_bytes + 1 }
}

fn modulus() -> BigUint {
Expand Down
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/acvm/src/compiler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;

use acir::{
circuit::{AssertionPayload, Circuit, ExpressionWidth, OpcodeLocation},
AcirField,
circuit::{AssertionPayload, Circuit, ExpressionWidth, OpcodeLocation},
};

// The various passes that we can use over ACIR
Expand All @@ -14,7 +14,7 @@ pub use optimizers::optimize;
use optimizers::optimize_internal;
pub use simulator::CircuitSimulator;
use transformers::transform_internal;
pub use transformers::{transform, MIN_EXPRESSION_WIDTH};
pub use transformers::{MIN_EXPRESSION_WIDTH, transform};

/// This module moves and decomposes acir opcodes. The transformation map allows consumers of this module to map
/// metadata they had about the opcodes to the new opcode structure generated after the transformation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use acir::{
native_types::{Expression, Witness},
AcirField,
native_types::{Expression, Witness},
};
use indexmap::IndexMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::collections::{BTreeMap, BTreeSet, HashMap};

use acir::{
AcirField,
circuit::{
Circuit, Opcode,
brillig::{BrilligInputs, BrilligOutputs},
opcodes::BlockId,
Circuit, Opcode,
},
native_types::{Expression, Witness},
AcirField,
};

use crate::compiler::CircuitSimulator;
Expand Down Expand Up @@ -258,16 +258,16 @@ impl<F: AcirField> MergeExpressionsOptimizer<F> {

#[cfg(test)]
mod tests {
use crate::compiler::{optimizers::MergeExpressionsOptimizer, CircuitSimulator};
use crate::compiler::{CircuitSimulator, optimizers::MergeExpressionsOptimizer};
use acir::{
FieldElement,
acir_field::AcirField,
circuit::{
Circuit, ExpressionWidth, Opcode, PublicInputs,
brillig::{BrilligFunctionId, BrilligOutputs},
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, ExpressionWidth, Opcode, PublicInputs,
},
native_types::{Expression, Witness},
FieldElement,
};
use std::collections::BTreeSet;

Expand Down
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/acvm/src/compiler/optimizers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use acir::{
circuit::{Circuit, Opcode},
AcirField,
circuit::{Circuit, Opcode},
};

// mod constant_backpropagation;
Expand All @@ -17,7 +17,7 @@ use tracing::info;
// use self::constant_backpropagation::ConstantBackpropagationOptimizer;
use self::unused_memory::UnusedMemoryOptimizer;

use super::{transform_assert_messages, AcirTransformationMap};
use super::{AcirTransformationMap, transform_assert_messages};

/// Applies [`ProofSystemCompiler`][crate::ProofSystemCompiler] independent optimizations to a [`Circuit`].
pub fn optimize<F: AcirField>(acir: Circuit<F>) -> (Circuit<F>, AcirTransformationMap) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use acir::{
AcirField,
circuit::{
opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum},
Circuit, Opcode,
opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum},
},
native_types::Witness,
AcirField,
};
use std::collections::{BTreeMap, HashSet};

Expand Down Expand Up @@ -163,12 +163,12 @@ mod tests {

use crate::compiler::optimizers::redundant_range::RangeOptimizer;
use acir::{
FieldElement,
circuit::{
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, ExpressionWidth, Opcode, PublicInputs,
opcodes::{BlackBoxFuncCall, FunctionInput},
},
native_types::{Expression, Witness},
FieldElement,
};

fn test_circuit(ranges: Vec<(Witness, u32)>) -> Circuit<FieldElement> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use acir::circuit::{brillig::BrilligInputs, opcodes::BlockId, Circuit, Opcode};
use acir::circuit::{Circuit, Opcode, brillig::BrilligInputs, opcodes::BlockId};
use std::collections::HashSet;

/// `UnusedMemoryOptimizer` will remove initializations of memory blocks which are unused.
Expand Down
Loading
Loading