diff --git a/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr b/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr index 39dae8786527..a42d80c8019d 100644 --- a/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr +++ b/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr @@ -11,7 +11,7 @@ use crate::context::{ use crate::oracle::arguments::pack_arguments; use crate::hash::hash_args; -trait CallInterface { +trait CallInterface { fn get_original(self) -> fn[Env](T) -> P; fn get_args(self) -> [Field] { @@ -35,13 +35,13 @@ trait CallInterface { } } -impl CallInterface for PrivateCallInterface { +impl CallInterface for PrivateCallInterface { fn get_original(self) -> fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs { self.original } } -struct PrivateCallInterface { +struct PrivateCallInterface { target_contract: AztecAddress, selector: FunctionSelector, name: str, @@ -51,8 +51,8 @@ struct PrivateCallInterface { is_static: bool } -impl PrivateCallInterface { - pub fn call(self, context: &mut PrivateContext) -> T where T: Deserialize { +impl PrivateCallInterface { + pub fn call(self, context: &mut PrivateContext) -> T where T: Deserialize { assert(self.args_hash == pack_arguments(self.args)); let returns = context.call_private_function_with_packed_args( self.target_contract, @@ -65,26 +65,26 @@ impl PrivateCallInterface { unpacked } - pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { + pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { assert(self.args_hash == pack_arguments(self.args)); let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false); returns.unpack_into() } - pub fn delegate_call(self, context: &mut PrivateContext) -> T where T: Deserialize { + pub fn delegate_call(self, context: &mut PrivateContext) -> T where T: Deserialize { assert(self.args_hash == pack_arguments(self.args)); let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, false, true); returns.unpack_into() } } -impl CallInterface for PrivateVoidCallInterface { +impl CallInterface for PrivateVoidCallInterface { fn get_original(self) -> fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs { self.original } } -struct PrivateVoidCallInterface { +struct PrivateVoidCallInterface { target_contract: AztecAddress, selector: FunctionSelector, name: str, @@ -94,7 +94,7 @@ struct PrivateVoidCallInterface { is_static: bool } -impl PrivateVoidCallInterface { +impl PrivateVoidCallInterface { pub fn call(self, context: &mut PrivateContext) { assert(self.args_hash == pack_arguments(self.args)); context.call_private_function_with_packed_args( @@ -117,13 +117,13 @@ impl PrivateVoidCallInterface { } } -impl CallInterface for PrivateStaticCallInterface { +impl CallInterface for PrivateStaticCallInterface { fn get_original(self) -> fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs { self.original } } -struct PrivateStaticCallInterface { +struct PrivateStaticCallInterface { target_contract: AztecAddress, selector: FunctionSelector, name: str, @@ -133,21 +133,21 @@ struct PrivateStaticCallInterface { is_static: bool } -impl PrivateStaticCallInterface { - pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { +impl PrivateStaticCallInterface { + pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { assert(self.args_hash == pack_arguments(self.args)); let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false); returns.unpack_into() } } -impl CallInterface for PrivateStaticVoidCallInterface { +impl CallInterface for PrivateStaticVoidCallInterface { fn get_original(self) -> fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs { self.original } } -struct PrivateStaticVoidCallInterface { +struct PrivateStaticVoidCallInterface { target_contract: AztecAddress, selector: FunctionSelector, name: str, @@ -157,20 +157,20 @@ struct PrivateStaticVoidCallInterface { is_static: bool } -impl PrivateStaticVoidCallInterface { +impl PrivateStaticVoidCallInterface { pub fn view(self, context: &mut PrivateContext) { assert(self.args_hash == pack_arguments(self.args)); context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false).assert_empty(); } } -impl CallInterface for PublicCallInterface { +impl CallInterface for PublicCallInterface { fn get_original(self) -> fn[Env](PublicContextInputs) -> T { self.original } } -struct PublicCallInterface { +struct PublicCallInterface { target_contract: AztecAddress, selector: FunctionSelector, name: str, @@ -180,23 +180,23 @@ struct PublicCallInterface { is_static: bool } -impl PublicCallInterface { +impl PublicCallInterface { pub fn with_gas(self: &mut Self, gas_opts: GasOpts) -> &mut Self { self.gas_opts = gas_opts; self } - pub fn call(self, context: &mut PublicContext) -> T where T: Deserialize { + pub fn call(self, context: &mut PublicContext) -> T where T: Deserialize { let returns = context.call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); returns.deserialize_into() } - pub fn view(self, context: &mut PublicContext) -> T where T: Deserialize { + pub fn view(self, context: &mut PublicContext) -> T where T: Deserialize { let returns = context.static_call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); returns.deserialize_into() } - pub fn delegate_call(self, context: &mut PublicContext) -> T where T: Deserialize { + pub fn delegate_call(self, context: &mut PublicContext) -> T where T: Deserialize { let returns = context.delegate_call_public_function(self.target_contract, self.selector, self.args); returns.deserialize_into() } @@ -238,13 +238,13 @@ impl PublicCallInterface { } } -impl CallInterface for PublicVoidCallInterface { +impl CallInterface for PublicVoidCallInterface { fn get_original(self) -> fn[Env](PublicContextInputs) -> () { self.original } } -struct PublicVoidCallInterface { +struct PublicVoidCallInterface { target_contract: AztecAddress, selector: FunctionSelector, name: str, @@ -254,7 +254,7 @@ struct PublicVoidCallInterface { gas_opts: GasOpts } -impl PublicVoidCallInterface { +impl PublicVoidCallInterface { pub fn with_gas(self: &mut Self, gas_opts: GasOpts) -> &mut Self { self.gas_opts = gas_opts; self @@ -312,13 +312,13 @@ impl PublicVoidCallInterface { } } -impl CallInterface for PublicStaticCallInterface { +impl CallInterface for PublicStaticCallInterface { fn get_original(self) -> fn[Env](PublicContextInputs) -> T { self.original } } -struct PublicStaticCallInterface { +struct PublicStaticCallInterface { target_contract: AztecAddress, selector: FunctionSelector, name: str, @@ -328,13 +328,13 @@ struct PublicStaticCallInterface { gas_opts: GasOpts } -impl PublicStaticCallInterface { +impl PublicStaticCallInterface { pub fn with_gas(self: &mut Self, gas_opts: GasOpts) -> &mut Self { self.gas_opts = gas_opts; self } - pub fn view(self, context: &mut PublicContext) -> T where T: Deserialize { + pub fn view(self, context: &mut PublicContext) -> T where T: Deserialize { let returns = context.static_call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); let unpacked: T = returns.deserialize_into(); unpacked @@ -353,13 +353,13 @@ impl PublicStaticCallInterface { } } -impl CallInterface for PublicStaticVoidCallInterface { +impl CallInterface for PublicStaticVoidCallInterface { fn get_original(self) -> fn[Env](PublicContextInputs) -> () { self.original } } -struct PublicStaticVoidCallInterface { +struct PublicStaticVoidCallInterface { target_contract: AztecAddress, selector: FunctionSelector, name: str, @@ -369,7 +369,7 @@ struct PublicStaticVoidCallInterface { gas_opts: GasOpts } -impl PublicStaticVoidCallInterface { +impl PublicStaticVoidCallInterface { pub fn with_gas(self: &mut Self, gas_opts: GasOpts) -> &mut Self { self.gas_opts = gas_opts; self diff --git a/noir-projects/aztec-nr/aztec/src/context/packed_returns.nr b/noir-projects/aztec-nr/aztec/src/context/packed_returns.nr index 1a56313d063b..418320270f12 100644 --- a/noir-projects/aztec-nr/aztec/src/context/packed_returns.nr +++ b/noir-projects/aztec-nr/aztec/src/context/packed_returns.nr @@ -18,13 +18,13 @@ impl PackedReturns { self.packed_returns } - pub fn unpack(self) -> [Field; N] { + pub fn unpack(self) -> [Field; N] { let unpacked: [Field; N] = unpack_returns(self.packed_returns); assert_eq(self.packed_returns, hash_args_array(unpacked)); unpacked } - pub fn unpack_into(self) -> T where T: Deserialize { + pub fn unpack_into(self) -> T where T: Deserialize { let unpacked: [Field; N] = self.unpack(); Deserialize::deserialize(unpacked) } diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 2612118ef4aa..c381f9866aef 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -262,7 +262,12 @@ impl PrivateContext { // NB: A randomness value of 0 signals that the kernels should not mask the contract address // used in siloing later on e.g. 'handshaking' contract w/ known address. - pub fn emit_raw_event_log_with_masked_address(&mut self, randomness: Field, log: [u8; M], log_hash: Field) { + pub fn emit_raw_event_log_with_masked_address( + &mut self, + randomness: Field, + log: [u8; M], + log_hash: Field + ) { let counter = self.next_counter(); let contract_address = self.this_address(); let len = log.len() as Field + 4; @@ -272,7 +277,7 @@ impl PrivateContext { emit_encrypted_event_log(contract_address, randomness, log, counter); } - pub fn emit_raw_note_log(&mut self, note_hash_counter: u32, log: [u8; M], log_hash: Field) { + pub fn emit_raw_note_log(&mut self, note_hash_counter: u32, log: [u8; M], log_hash: Field) { let counter = self.next_counter(); let len = log.len() as Field + 4; let side_effect = NoteLogHash { value: log_hash, counter, length: len, note_hash_counter }; @@ -281,7 +286,7 @@ impl PrivateContext { emit_encrypted_note_log(note_hash_counter, log, counter); } - pub fn call_private_function( + pub fn call_private_function( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -292,7 +297,7 @@ impl PrivateContext { self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, false, false) } - pub fn static_call_private_function( + pub fn static_call_private_function( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -303,7 +308,7 @@ impl PrivateContext { self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, true, false) } - pub fn delegate_call_private_function( + pub fn delegate_call_private_function( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -330,7 +335,7 @@ impl PrivateContext { self.call_private_function_with_packed_args(contract_address, function_selector, 0, true, false) } - pub fn delegate_call_private_function_no_args( + pub fn delegate_call_private_function_no_args( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector @@ -419,7 +424,7 @@ impl PrivateContext { PackedReturns::new(item.public_inputs.returns_hash) } - pub fn call_public_function( + pub fn call_public_function( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -430,7 +435,7 @@ impl PrivateContext { self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, false) } - pub fn static_call_public_function( + pub fn static_call_public_function( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -441,7 +446,7 @@ impl PrivateContext { self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, true, false) } - pub fn delegate_call_public_function( + pub fn delegate_call_public_function( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -508,7 +513,7 @@ impl PrivateContext { self.public_call_stack_hashes.push(item.get_compressed().hash()); } - pub fn set_public_teardown_function( + pub fn set_public_teardown_function( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -519,7 +524,7 @@ impl PrivateContext { self.set_public_teardown_function_with_packed_args(contract_address, function_selector, args_hash, false, false) } - pub fn set_public_teardown_function_with_packed_args( + pub fn set_public_teardown_function_with_packed_args( &mut self, contract_address: AztecAddress, function_selector: FunctionSelector, diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index a9a060c42f67..7a5267c7b747 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -15,7 +15,7 @@ impl PublicContext { PublicContext { inputs } } - pub fn emit_unencrypted_log(&mut self, log: T) where T: Serialize { + pub fn emit_unencrypted_log(&mut self, log: T) where T: Serialize { emit_unencrypted_log(Serialize::serialize(log).as_slice()); } @@ -64,7 +64,7 @@ impl PublicContext { send_l2_to_l1_msg(recipient, content); } - fn call_public_function( + fn call_public_function( self: &mut Self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -84,7 +84,7 @@ impl PublicContext { FunctionReturns::new(data_to_return) } - fn static_call_public_function( + fn static_call_public_function( self: &mut Self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -102,7 +102,7 @@ impl PublicContext { FunctionReturns::new(data_to_return) } - fn delegate_call_public_function( + fn delegate_call_public_function( self: &mut Self, contract_address: AztecAddress, function_selector: FunctionSelector, @@ -165,19 +165,19 @@ impl PublicContext { da_gas_left() } - fn raw_storage_read(_self: Self, storage_slot: Field) -> [Field; N] { + fn raw_storage_read(_self: Self, storage_slot: Field) -> [Field; N] { storage_read(storage_slot) } - fn storage_read(self, storage_slot: Field) -> T where T: Deserialize { + fn storage_read(self, storage_slot: Field) -> T where T: Deserialize { T::deserialize(self.raw_storage_read(storage_slot)) } - fn raw_storage_write(_self: Self, storage_slot: Field, values: [Field; N]) { + fn raw_storage_write(_self: Self, storage_slot: Field, values: [Field; N]) { storage_write(storage_slot, values); } - fn storage_write(self, storage_slot: Field, value: T) where T: Serialize { + fn storage_write(self, storage_slot: Field, value: T) where T: Serialize { self.raw_storage_write(storage_slot, value.serialize()); } } @@ -257,7 +257,7 @@ unconstrained fn l1_to_l2_msg_exists(msg_hash: Field, msg_leaf_index: Field) -> unconstrained fn send_l2_to_l1_msg(recipient: EthAddress, content: Field) { send_l2_to_l1_msg_opcode(recipient, content) } -unconstrained fn call( +unconstrained fn call( gas: [Field; 2], address: AztecAddress, args: [Field], @@ -265,7 +265,7 @@ unconstrained fn call( ) -> ([Field; RET_SIZE], u8) { call_opcode(gas, address, args, function_selector) } -unconstrained fn call_static( +unconstrained fn call_static( gas: [Field; 2], address: AztecAddress, args: [Field], @@ -274,11 +274,11 @@ unconstrained fn call_static( call_static_opcode(gas, address, args, function_selector) } -unconstrained fn storage_read(storage_slot: Field) -> [Field; N] { - storage_read_opcode(storage_slot, N) +unconstrained fn storage_read(storage_slot: Field) -> [Field; N] { + storage_read_opcode(storage_slot, N as Field) } -unconstrained fn storage_write(storage_slot: Field, values: [Field; N]) { +unconstrained fn storage_write(storage_slot: Field, values: [Field; N]) { storage_write_opcode(storage_slot, values); } @@ -353,7 +353,7 @@ unconstrained fn l1_to_l2_msg_exists_opcode(msg_hash: Field, msg_leaf_index: Fie unconstrained fn send_l2_to_l1_msg_opcode(recipient: EthAddress, content: Field) {} #[oracle(avmOpcodeCall)] -unconstrained fn call_opcode( +unconstrained fn call_opcode( gas: [Field; 2], // gas allocation: [l2_gas, da_gas] address: AztecAddress, args: [Field], @@ -363,7 +363,7 @@ unconstrained fn call_opcode( // ^ return data ^ success #[oracle(avmOpcodeStaticCall)] -unconstrained fn call_static_opcode( +unconstrained fn call_static_opcode( gas: [Field; 2], // gas allocation: [l2_gas, da_gas] address: AztecAddress, args: [Field], @@ -373,16 +373,16 @@ unconstrained fn call_static_opcode( // ^ return data ^ success #[oracle(avmOpcodeStorageRead)] -unconstrained fn storage_read_opcode(storage_slot: Field, length: Field) -> [Field; N] {} +unconstrained fn storage_read_opcode(storage_slot: Field, length: Field) -> [Field; N] {} #[oracle(avmOpcodeStorageWrite)] -unconstrained fn storage_write_opcode(storage_slot: Field, values: [Field; N]) {} +unconstrained fn storage_write_opcode(storage_slot: Field, values: [Field; N]) {} -struct FunctionReturns { +struct FunctionReturns { values: [Field; N] } -impl FunctionReturns { +impl FunctionReturns { pub fn new(values: [Field; N]) -> FunctionReturns { FunctionReturns { values } } diff --git a/noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr b/noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr index eedd97aa8d66..b66989afd244 100644 --- a/noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr @@ -37,11 +37,14 @@ impl UnconstrainedContext { self.chain_id } - unconstrained fn raw_storage_read(self: Self, storage_slot: Field) -> [Field; N] { + unconstrained fn raw_storage_read(self: Self, storage_slot: Field) -> [Field; N] { storage_read(self.this_address(), storage_slot, self.block_number()) } - unconstrained fn storage_read(self, storage_slot: Field) -> T where T: Deserialize { + unconstrained fn storage_read( + self, + storage_slot: Field + ) -> T where T: Deserialize { T::deserialize(self.raw_storage_read(storage_slot)) } } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr index ff7a24502e84..df556ef8c22a 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr @@ -5,7 +5,7 @@ use crate::{ }; use dep::protocol_types::{address::AztecAddress, point::Point, hash::sha256_to_field}; -unconstrained fn compute_unconstrained( +unconstrained fn compute_unconstrained( contract_address: AztecAddress, randomness: Field, ovsk_app: Field, @@ -25,7 +25,7 @@ unconstrained fn compute_unconstrained( ) } -fn compute( +fn compute( contract_address: AztecAddress, randomness: Field, ovsk_app: Field, @@ -47,7 +47,7 @@ fn compute( (encrypted_log, log_hash) } -fn emit_with_keys( +fn emit_with_keys( context: &mut PrivateContext, randomness: Field, event: Event, @@ -62,7 +62,7 @@ fn emit_with_keys( context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash); } -pub fn encode_and_encrypt_event( +pub fn encode_and_encrypt_event( context: &mut PrivateContext, ov: AztecAddress, iv: AztecAddress @@ -76,7 +76,7 @@ pub fn encode_and_encrypt_event( } } -pub fn encode_and_encrypt_event_unconstrained( +pub fn encode_and_encrypt_event_unconstrained( context: &mut PrivateContext, ov: AztecAddress, iv: AztecAddress @@ -90,7 +90,7 @@ pub fn encode_and_encrypt_event_unconstrained( } } -pub fn encode_and_encrypt_event_with_randomness( +pub fn encode_and_encrypt_event_with_randomness( context: &mut PrivateContext, randomness: Field, ov: AztecAddress, @@ -104,7 +104,7 @@ pub fn encode_and_encrypt_event_with_randomness( } } -pub fn encode_and_encrypt_event_with_randomness_unconstrained( +pub fn encode_and_encrypt_event_with_randomness_unconstrained( context: &mut PrivateContext, randomness: Field, ov: AztecAddress, @@ -118,7 +118,7 @@ pub fn encode_and_encrypt_event_with_randomness_unconstrained } } -pub fn encode_and_encrypt_event_with_keys( +pub fn encode_and_encrypt_event_with_keys( context: &mut PrivateContext, ovpk: Point, ivpk: Point, @@ -130,7 +130,7 @@ pub fn encode_and_encrypt_event_with_keys( } } -pub fn encode_and_encrypt_event_with_keys_unconstrained( +pub fn encode_and_encrypt_event_with_keys_unconstrained( context: &mut PrivateContext, ovpk: Point, ivpk: Point, @@ -142,7 +142,7 @@ pub fn encode_and_encrypt_event_with_keys_unconstrained( } } -pub fn encode_and_encrypt_event_with_keys_with_randomness( +pub fn encode_and_encrypt_event_with_keys_with_randomness( context: &mut PrivateContext, randomness: Field, ovpk: Point, @@ -154,7 +154,7 @@ pub fn encode_and_encrypt_event_with_keys_with_randomness( } } -pub fn encode_and_encrypt_event_with_keys_with_randomness_unconstrained( +pub fn encode_and_encrypt_event_with_keys_with_randomness_unconstrained( context: &mut PrivateContext, randomness: Field, ovpk: Point, diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr index 69e6dc449f51..3b9122568b99 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr @@ -7,7 +7,7 @@ use dep::protocol_types::{ constants::MAX_NOTE_HASHES_PER_CALL, utils::arrays::find_index }; -unconstrained fn compute_unconstrained( +unconstrained fn compute_unconstrained( contract_address: AztecAddress, storage_slot: Field, ovsk_app: Field, @@ -27,7 +27,7 @@ unconstrained fn compute_unconstrained( ) } -fn compute( +fn compute( contract_address: AztecAddress, storage_slot: Field, ovsk_app: Field, @@ -49,7 +49,7 @@ fn compute( (encrypted_log, log_hash) } -fn emit_with_keys( +fn emit_with_keys( context: &mut PrivateContext, note: Note, ovpk: Point, @@ -85,7 +85,7 @@ fn emit_with_keys( context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash); } -pub fn encode_and_encrypt_note( +pub fn encode_and_encrypt_note( context: &mut PrivateContext, ov: AztecAddress, iv: AztecAddress @@ -98,7 +98,7 @@ pub fn encode_and_encrypt_note( } } -pub fn encode_and_encrypt_note_unconstrained( +pub fn encode_and_encrypt_note_unconstrained( context: &mut PrivateContext, ov: AztecAddress, iv: AztecAddress @@ -111,7 +111,7 @@ pub fn encode_and_encrypt_note_unconstrained( } } -pub fn encode_and_encrypt_note_with_keys( +pub fn encode_and_encrypt_note_with_keys( context: &mut PrivateContext, ovpk: Point, ivpk: Point, @@ -122,7 +122,7 @@ pub fn encode_and_encrypt_note_with_keys( } } -pub fn encode_and_encrypt_note_with_keys_unconstrained( +pub fn encode_and_encrypt_note_with_keys_unconstrained( context: &mut PrivateContext, ovpk: Point, ivpk: Point, diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr index d6a86136c9e1..bc5053150e3b 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr @@ -5,17 +5,20 @@ use dep::protocol_types::{scalar::Scalar, point::Point}; use std::aes128::aes128_encrypt; use crate::keys::point_to_symmetric_key::point_to_symmetric_key; -struct EncryptedLogIncomingBody { +struct EncryptedLogIncomingBody { plaintext: [u8; M] } -impl EncryptedLogIncomingBody { - pub fn from_note(note: T, storage_slot: Field) -> Self where T: NoteInterface { +impl EncryptedLogIncomingBody { + pub fn from_note(note: T, storage_slot: Field) -> Self where T: NoteInterface { let mut plaintext = note.to_be_bytes(storage_slot); EncryptedLogIncomingBody { plaintext } } - pub fn from_event(event: T, randomness: Field) -> Self where T: EventInterface { + pub fn from_event( + event: T, + randomness: Field + ) -> Self where T: EventInterface { let mut plaintext = event.private_to_be_bytes(randomness); EncryptedLogIncomingBody { plaintext } } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr index aaddb85dad08..99afdce4af76 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr @@ -15,7 +15,7 @@ use crate::encrypted_logs::{ outgoing_body::EncryptedLogOutgoingBody }; -pub fn compute_encrypted_event_log( +pub fn compute_encrypted_event_log( contract_address: AztecAddress, randomness: Field, ovsk_app: Field, @@ -68,7 +68,7 @@ pub fn compute_encrypted_event_log( encrypted_bytes } -pub fn compute_encrypted_note_log( +pub fn compute_encrypted_note_log( contract_address: AztecAddress, storage_slot: Field, ovsk_app: Field, diff --git a/noir-projects/aztec-nr/aztec/src/event/event_interface.nr b/noir-projects/aztec-nr/aztec/src/event/event_interface.nr index a27bbe3700c8..58a7ea2ba794 100644 --- a/noir-projects/aztec-nr/aztec/src/event/event_interface.nr +++ b/noir-projects/aztec-nr/aztec/src/event/event_interface.nr @@ -1,6 +1,6 @@ use dep::protocol_types::abis::event_selector::EventSelector; -trait EventInterface { +trait EventInterface { fn private_to_be_bytes(self, randomness: Field) -> [u8; NB]; fn to_be_bytes(self) -> [u8; MB]; fn get_event_type_id() -> EventSelector; diff --git a/noir-projects/aztec-nr/aztec/src/hash.nr b/noir-projects/aztec-nr/aztec/src/hash.nr index 7028c4e00941..7e68dfc2efeb 100644 --- a/noir-projects/aztec-nr/aztec/src/hash.nr +++ b/noir-projects/aztec-nr/aztec/src/hash.nr @@ -12,7 +12,7 @@ pub fn compute_secret_hash(secret: Field) -> Field { pedersen_hash([secret], GENERATOR_INDEX__SECRET_HASH) } -pub fn compute_unencrypted_log_hash( +pub fn compute_unencrypted_log_hash( contract_address: AztecAddress, log: T ) -> Field where T: ToBytesForUnencryptedLog { @@ -92,14 +92,14 @@ impl ArgsHasher { self.fields = self.fields.push_back(field); } - pub fn add_multiple(&mut self, fields: [Field; N]) { + pub fn add_multiple(&mut self, fields: [Field; N]) { for i in 0..N { self.fields = self.fields.push_back(fields[i]); } } } -pub fn hash_args_array(args: [Field; N]) -> Field { +pub fn hash_args_array(args: [Field; N]) -> Field { hash_args(args.as_slice()) } diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr index e1051b269d92..b1176829c76f 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr @@ -10,7 +10,7 @@ use crate::oracle; mod test; -fn extract_property_value_from_selector( +fn extract_property_value_from_selector( serialized_note: [Field; N], selector: PropertySelector ) -> Field { @@ -31,7 +31,7 @@ fn extract_property_value_from_selector( value_field } -fn check_note_header( +fn check_note_header( context: PrivateContext, storage_slot: Field, note: Note @@ -42,7 +42,10 @@ fn check_note_header( assert(header.storage_slot == storage_slot, "Mismatch note header storage slot."); } -fn check_note_fields(serialized_note: [Field; N], selects: BoundedVec, N>) { +fn check_note_fields( + serialized_note: [Field; N], + selects: BoundedVec, N> +) { for i in 0..selects.len { let select = selects.get_unchecked(i).unwrap_unchecked(); let value_field = extract_property_value_from_selector(serialized_note, select.property_selector); @@ -67,7 +70,7 @@ fn check_note_fields(serialized_note: [Field; N], selects: BoundedVec( +fn check_notes_order( fields_0: [Field; N], fields_1: [Field; N], sorts: BoundedVec, N> @@ -86,7 +89,7 @@ fn check_notes_order( } } -pub fn get_note( +pub fn get_note( context: &mut PrivateContext, storage_slot: Field ) -> Note where Note: NoteInterface { @@ -100,7 +103,7 @@ pub fn get_note( note } -pub fn get_notes( +pub fn get_notes( context: &mut PrivateContext, storage_slot: Field, options: NoteGetterOptions @@ -110,7 +113,7 @@ pub fn get_notes( constrain_get_notes_internal(context, storage_slot, opt_notes, options) } -fn constrain_get_notes_internal( +fn constrain_get_notes_internal( context: &mut PrivateContext, storage_slot: Field, opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], @@ -154,7 +157,7 @@ fn constrain_get_notes_internal( notes } -unconstrained fn get_note_internal(storage_slot: Field) -> Note where Note: NoteInterface { +unconstrained fn get_note_internal(storage_slot: Field) -> Note where Note: NoteInterface { let placeholder_note = [Option::none()]; let placeholder_fields = [0; GET_NOTE_ORACLE_RETURN_LENGTH]; let placeholder_note_length = [0; N]; @@ -179,7 +182,7 @@ unconstrained fn get_note_internal(storage_slot: Field) -> Note wher )[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular). } -unconstrained fn get_notes_internal( +unconstrained fn get_notes_internal( storage_slot: Field, options: NoteGetterOptions ) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] where Note: NoteInterface { @@ -211,7 +214,7 @@ unconstrained fn get_notes_internal( ) } -unconstrained pub fn view_notes( +unconstrained pub fn view_notes( storage_slot: Field, options: NoteViewerOptions ) -> BoundedVec where Note: NoteInterface { @@ -250,7 +253,7 @@ unconstrained pub fn view_notes( notes } -unconstrained fn flatten_options( +unconstrained fn flatten_options( selects: BoundedVec, N>, sorts: BoundedVec, N> ) -> (u8, [u8; N], [u8; N], [u8; N], [Field; N], [u8; N], [u8; N], [u8; N], [u8; N], [u8; N]) { diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter/test.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter/test.nr index 4699cc9a3fd8..04780f6bceb9 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter/test.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter/test.nr @@ -21,7 +21,10 @@ fn build_valid_note(value: Field) -> MockNote { MockNote::new(value).contract_address(cheatcodes::get_contract_address()).storage_slot(storage_slot).build() } -fn assert_equivalent_vec_and_array(vec: BoundedVec, arr: [Option; N]) where T: Eq { +fn assert_equivalent_vec_and_array( + vec: BoundedVec, + arr: [Option; N] +) where T: Eq { let mut count = 0; for i in 0..N { diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr index 04b44f47fc9e..7bc535b052ff 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr @@ -70,7 +70,7 @@ global NoteStatus = NoteStatusEnum { // TODO 4217: add 'NULLIFIED' }; -fn return_all_notes( +fn return_all_notes( notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], _p: Field ) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] { @@ -78,7 +78,7 @@ fn return_all_notes( } // docs:start:NoteGetterOptions -struct NoteGetterOptions { +struct NoteGetterOptions { selects: BoundedVec, N>, sorts: BoundedVec, N>, limit: u32, @@ -93,7 +93,7 @@ struct NoteGetterOptions { // The database-level configurations are applied first: // `selects` to specify fields, `sorts` to establish sorting criteria, `offset` to skip items, and `limit` to cap the result size. // And finally, a custom filter to refine the outcome further. -impl NoteGetterOptions { +impl NoteGetterOptions { // This function initializes a NoteGetterOptions that simply returns the maximum number of notes allowed in a call. pub fn new() -> NoteGetterOptions where Note: NoteInterface { NoteGetterOptions { diff --git a/noir-projects/aztec-nr/aztec/src/note/note_interface.nr b/noir-projects/aztec-nr/aztec/src/note/note_interface.nr index 3c5eac669ea8..317059d90e97 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_interface.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_interface.nr @@ -2,7 +2,7 @@ use crate::context::PrivateContext; use crate::note::note_header::NoteHeader; // docs:start:note_interface -trait NoteInterface { +trait NoteInterface { fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field); fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field); diff --git a/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr b/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr index dbdccc19cce8..8c1a106ff533 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr @@ -5,7 +5,7 @@ use crate::note::note_interface::NoteInterface; use crate::note::constants::MAX_NOTES_PER_PAGE; // docs:start:NoteViewerOptions -struct NoteViewerOptions { +struct NoteViewerOptions { selects: BoundedVec, N>, sorts: BoundedVec, N>, limit: u32, @@ -14,7 +14,7 @@ struct NoteViewerOptions { } // docs:end:NoteViewerOptions -impl NoteViewerOptions { +impl NoteViewerOptions { pub fn new() -> NoteViewerOptions where Note: NoteInterface { NoteViewerOptions { selects: BoundedVec::new(), diff --git a/noir-projects/aztec-nr/aztec/src/note/utils.nr b/noir-projects/aztec-nr/aztec/src/note/utils.nr index 23f58f8906cf..45326beaf8c5 100644 --- a/noir-projects/aztec-nr/aztec/src/note/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/note/utils.nr @@ -16,14 +16,14 @@ pub fn compute_inner_note_hash_from_preimage(storage_slot: Field, note_content_h ) } -fn compute_inner_note_hash(note: Note) -> Field where Note: NoteInterface { +fn compute_inner_note_hash(note: Note) -> Field where Note: NoteInterface { let header = note.get_header(); let note_hash = note.compute_note_content_hash(); compute_inner_note_hash_from_preimage(header.storage_slot, note_hash) } -pub fn compute_siloed_nullifier( +pub fn compute_siloed_nullifier( note_with_header: Note, context: &mut PrivateContext ) -> Field where Note: NoteInterface { @@ -46,14 +46,14 @@ fn compute_note_hash_for_read_request_from_innter_and_nonce( } } -pub fn compute_note_hash_for_read_request(note: Note) -> Field where Note: NoteInterface { +pub fn compute_note_hash_for_read_request(note: Note) -> Field where Note: NoteInterface { let inner_note_hash = compute_inner_note_hash(note); let nonce = note.get_header().nonce; compute_note_hash_for_read_request_from_innter_and_nonce(inner_note_hash, nonce) } -pub fn compute_note_hash_for_consumption(note: Note) -> Field where Note: NoteInterface { +pub fn compute_note_hash_for_consumption(note: Note) -> Field where Note: NoteInterface { let header = note.get_header(); // There are 3 cases for reading a note intended for consumption: // 1. The note was inserted in this transaction, and is transient. @@ -83,7 +83,7 @@ pub fn compute_note_hash_for_consumption(note: Note) -> Field where } } -pub fn compute_note_hash_and_optionally_a_nullifier( +pub fn compute_note_hash_and_optionally_a_nullifier( deserialize_content: fn([Field; N]) -> T, note_header: NoteHeader, compute_nullifier: bool, diff --git a/noir-projects/aztec-nr/aztec/src/oracle/arguments.nr b/noir-projects/aztec-nr/aztec/src/oracle/arguments.nr index b9cdaae384eb..278a646da1ee 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/arguments.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/arguments.nr @@ -1,5 +1,5 @@ #[oracle(packArgumentsArray)] -unconstrained fn pack_arguments_array_oracle(_args: [Field; N]) -> Field {} +unconstrained fn pack_arguments_array_oracle(_args: [Field; N]) -> Field {} #[oracle(packArguments)] unconstrained fn pack_arguments_oracle(_args: [Field]) -> Field {} @@ -9,7 +9,7 @@ unconstrained fn pack_arguments_oracle(_args: [Field]) -> Field {} /// - When the external call is made later, the simulator will know what the values unpack to. /// - This oracle will not be required in public vm functions, as the vm will keep track of arguments /// itself. -unconstrained pub fn pack_arguments_array(args: [Field; N]) -> Field { +unconstrained pub fn pack_arguments_array(args: [Field; N]) -> Field { pack_arguments_array_oracle(args) } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr b/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr index 3532baec2230..3208c4396a8c 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr @@ -1,8 +1,12 @@ #[oracle(aes128Encrypt)] -pub fn aes128_encrypt_oracle(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8; M] {} +pub fn aes128_encrypt_oracle( + input: [u8; N], + iv: [u8; 16], + key: [u8; 16] +) -> [u8; M] {} // AES 128 CBC with PKCS7 is padding to multiples of 16 bytes so M has to be a multiple of 16! // (e.g. from 65 bytes long input you get 80 bytes long output and M has to be set to `80`) -unconstrained pub fn aes128_encrypt(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8; M] { +unconstrained pub fn aes128_encrypt(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8; M] { aes128_encrypt_oracle(input, iv, key) } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr index 92b2d80086ed..4ed39cd3ce98 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr @@ -10,19 +10,19 @@ global ARCHIVE_TREE_ID = 4; // // Another way to do it would be to add "type_hint: [Field; T]" as argument to `get_membership_witness` but that's // a bit too boilerplatey for my taste. -struct MembershipWitness { +struct MembershipWitness { index: Field, path: [Field; N], } #[oracle(getMembershipWitness)] -unconstrained fn get_membership_witness_oracle( +unconstrained fn get_membership_witness_oracle( _block_number: u32, _tree_id: Field, _leaf_value: Field ) -> [Field; M] {} -unconstrained pub fn get_membership_witness( +unconstrained pub fn get_membership_witness( block_number: u32, tree_id: Field, leaf_value: Field @@ -33,7 +33,7 @@ unconstrained pub fn get_membership_witness( // Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr -unconstrained pub fn get_note_hash_membership_witness( +unconstrained pub fn get_note_hash_membership_witness( block_number: u32, leaf_value: Field ) -> MembershipWitness { diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_sibling_path.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_sibling_path.nr index 44b5446355a9..4788897dd083 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_sibling_path.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_sibling_path.nr @@ -1,9 +1,9 @@ use dep::protocol_types::constants::PUBLIC_DATA_TREE_HEIGHT; #[oracle(getSiblingPath)] -unconstrained fn get_sibling_path_oracle(_block_number: u32, _tree_id: Field, _leaf_index: Field) -> [Field; N] {} +unconstrained fn get_sibling_path_oracle(_block_number: u32, _tree_id: Field, _leaf_index: Field) -> [Field; N] {} -unconstrained pub fn get_sibling_path( +unconstrained pub fn get_sibling_path( block_number: u32, tree_id: Field, leaf_index: Field diff --git a/noir-projects/aztec-nr/aztec/src/oracle/logs.nr b/noir-projects/aztec-nr/aztec/src/oracle/logs.nr index 2a0d9a39f578..e1384ffc17a4 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/logs.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/logs.nr @@ -2,9 +2,9 @@ use dep::protocol_types::{address::AztecAddress, point::Point}; // = 480 + 32 * N bytes #[oracle(emitEncryptedNoteLog)] -unconstrained fn emit_encrypted_note_log_oracle(_note_hash_counter: u32, _encrypted_note: [u8; M], _counter: u32) {} +unconstrained fn emit_encrypted_note_log_oracle(_note_hash_counter: u32, _encrypted_note: [u8; M], _counter: u32) {} -unconstrained pub fn emit_encrypted_note_log( +unconstrained pub fn emit_encrypted_note_log( note_hash_counter: u32, encrypted_note: [u8; M], counter: u32 @@ -13,14 +13,9 @@ unconstrained pub fn emit_encrypted_note_log( } #[oracle(emitEncryptedEventLog)] -unconstrained fn emit_encrypted_event_log_oracle( - _contract_address: AztecAddress, - _randomness: Field, - _encrypted_event: [u8; M], - _counter: u32 -) {} +unconstrained fn emit_encrypted_event_log_oracle(_contract_address: AztecAddress, _randomness: Field, _encrypted_event: [u8; M], _counter: u32) {} -unconstrained pub fn emit_encrypted_event_log( +unconstrained pub fn emit_encrypted_event_log( contract_address: AztecAddress, randomness: Field, encrypted_event: [u8; M], @@ -31,7 +26,7 @@ unconstrained pub fn emit_encrypted_event_log( // = 480 + 32 * N bytes #[oracle(computeEncryptedNoteLog)] -unconstrained fn compute_encrypted_note_log_oracle( +unconstrained fn compute_encrypted_note_log_oracle( _contract_address: AztecAddress, _storage_slot: Field, _note_type_id: Field, @@ -42,7 +37,7 @@ unconstrained fn compute_encrypted_note_log_oracle( _preimage: [Field; N] ) -> [u8; M] {} -unconstrained pub fn compute_encrypted_note_log( +unconstrained pub fn compute_encrypted_note_log( contract_address: AztecAddress, storage_slot: Field, note_type_id: Field, @@ -66,7 +61,7 @@ unconstrained pub fn compute_encrypted_note_log( // = 480 + 32 * N bytes #[oracle(computeEncryptedEventLog)] -unconstrained fn compute_encrypted_event_log_oracle( +unconstrained fn compute_encrypted_event_log_oracle( _contract_address: AztecAddress, _randomness: Field, _event_type_id: Field, @@ -77,7 +72,7 @@ unconstrained fn compute_encrypted_event_log_oracle( _preimage: [Field; N] ) -> [u8; M] {} -unconstrained pub fn compute_encrypted_event_log( +unconstrained pub fn compute_encrypted_event_log( contract_address: AztecAddress, randomness: Field, event_type_id: Field, @@ -111,8 +106,12 @@ unconstrained pub fn emit_unencrypted_log_private_internal( } #[oracle(emitContractClassUnencryptedLog)] -unconstrained fn emit_contract_class_unencrypted_log_private(contract_address: AztecAddress, message: [Field; N], counter: u32) -> Field {} +unconstrained fn emit_contract_class_unencrypted_log_private( + contract_address: AztecAddress, + message: [Field; N], + counter: u32 +) -> Field {} -unconstrained pub fn emit_contract_class_unencrypted_log_private_internal(contract_address: AztecAddress, message: [Field; N], counter: u32) -> Field { +unconstrained pub fn emit_contract_class_unencrypted_log_private_internal(contract_address: AztecAddress, message: [Field; N], counter: u32) -> Field { emit_contract_class_unencrypted_log_private(contract_address, message, counter) } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr b/noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr index b874d949afd2..aded9659417e 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr @@ -9,7 +9,7 @@ use dep::protocol_types::address::AztecAddress; // I could have omitted N from the trait, but wanted to keep it strictly for field arrs // TODO(1139): Once we enc inside the circuit, we will no longer need the oracle to return // anything, so we can remove this trait -trait LensForEncryptedLog { +trait LensForEncryptedLog { // N = note preimage input in fields // M = encryption output len in bytes (= 480 + N * 32) fn output_fields(self: [Field; N]) -> [Field; N]; @@ -65,7 +65,7 @@ impl LensForEncryptedLog<12, 864> for [Field; 12] { fn output_bytes(self) -> [u8; 864] {[self[0] as u8; 864]} } -trait LensForEncryptedEvent { +trait LensForEncryptedEvent { // N = event preimage input in bytes // M = encryption output len in bytes (= 480 + M) fn output(self: [u8; N]) -> [u8; M]; @@ -93,7 +93,7 @@ impl LensForEncryptedEvent<256, 672> for [u8; 256] { // This trait defines the length of the inputs in bytes to // the unencrypted log hash fn, where the log can be any type T // as long as the ACVM can convert to fields. -trait ToBytesForUnencryptedLog { +trait ToBytesForUnencryptedLog { // N = preimage input in bytes (32 * num fields or chars) // M = full log input in bytes ( = N + 40 = N + 32 for addr, + 4 for selector, + 4 for len) fn to_be_bytes_arr(self) -> [u8; N]; @@ -114,7 +114,7 @@ impl ToBytesForUnencryptedLog<32, 68> for AztecAddress { fn output_bytes(self) -> [u8; 68] {[self.to_field() as u8; 68]} } -fn arr_to_be_bytes_arr(fields: [Field; L]) -> [u8; N] { +fn arr_to_be_bytes_arr(fields: [Field; L]) -> [u8; N] { let mut bytes: [u8] = &[]; for i in 0..L { // Note that bytes.append() results in bound error @@ -128,7 +128,7 @@ fn arr_to_be_bytes_arr(fields: [Field; L]) -> [u8; N] { // each character of a string is converted into a byte // then an ACVM field via the oracle => we recreate here -fn str_to_be_bytes_arr(string: str) -> [u8; N] { +fn str_to_be_bytes_arr(string: str) -> [u8; N] { let chars_bytes = string.as_bytes(); let mut bytes: [u8] = &[]; for i in 0..L { @@ -356,7 +356,7 @@ impl ToBytesForUnencryptedLog<768, 804> for [Field; 24] { } } -impl ToBytesForUnencryptedLog for str where [Field; L]: ToBytesForUnencryptedLog { +impl ToBytesForUnencryptedLog for str where [Field; L]: ToBytesForUnencryptedLog { fn to_be_bytes_arr(self) -> [u8; N] { str_to_be_bytes_arr(self) } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/notes.nr b/noir-projects/aztec-nr/aztec/src/oracle/notes.nr index 4d7aad6f6e26..9b7755fd1350 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/notes.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/notes.nr @@ -3,7 +3,7 @@ use crate::note::{note_header::NoteHeader, note_interface::NoteInterface}; use dep::protocol_types::{address::AztecAddress, utils::arr_copy_slice}; #[oracle(notifyCreatedNote)] -unconstrained fn notify_created_note_oracle( +unconstrained fn notify_created_note_oracle( _storage_slot: Field, _note_type_id: Field, _serialized_note: [Field; N], @@ -11,7 +11,7 @@ unconstrained fn notify_created_note_oracle( _counter: u32 ) -> Field {} -unconstrained pub fn notify_created_note( +unconstrained pub fn notify_created_note( storage_slot: Field, note_type_id: Field, serialized_note: [Field; N], @@ -28,9 +28,9 @@ unconstrained pub fn notify_created_note( } #[oracle(notifyNullifiedNote)] -unconstrained fn notify_nullified_note_oracle(_nullifier: Field, _inner_note_hash: Field, _counter: u32) -> Field {} +unconstrained fn notify_nullified_note_oracle(_nullifier: Field, _inner_note_hash: Field, _counter: u32) -> Field {} -unconstrained pub fn notify_nullified_note( +unconstrained pub fn notify_nullified_note( nullifier: Field, inner_note_hash: Field, counter: u32 @@ -39,7 +39,7 @@ unconstrained pub fn notify_nullified_note( } #[oracle(getNotes)] -unconstrained fn get_notes_oracle( +unconstrained fn get_notes_oracle( _storage_slot: Field, _num_selects: u8, _select_by_indexes: [u8; N], @@ -58,7 +58,7 @@ unconstrained fn get_notes_oracle( _placeholder_fields: [Field; S] ) -> [Field; S] {} -unconstrained fn get_notes_oracle_wrapper( +unconstrained fn get_notes_oracle_wrapper( storage_slot: Field, num_selects: u8, select_by_indexes: [u8; N], @@ -96,7 +96,7 @@ unconstrained fn get_notes_oracle_wrapper( ) } -unconstrained pub fn get_notes( +unconstrained pub fn get_notes( storage_slot: Field, num_selects: u8, select_by_indexes: [u8; M], diff --git a/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr b/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr index ed56c88fad81..3a632426b196 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr @@ -1,6 +1,6 @@ use dep::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress}; #[oracle(callPublicFunction)] -unconstrained fn call_public_function_oracle( +unconstrained fn call_public_function_oracle( _contract_address: AztecAddress, _function_selector: FunctionSelector, _args_hash: Field, @@ -9,7 +9,7 @@ unconstrained fn call_public_function_oracle( _is_delegate_call: bool ) -> [Field; RETURNS_COUNT] {} -unconstrained pub fn call_public_function_internal( +unconstrained pub fn call_public_function_internal( contract_address: AztecAddress, function_selector: FunctionSelector, args_hash: Field, diff --git a/noir-projects/aztec-nr/aztec/src/oracle/returns.nr b/noir-projects/aztec-nr/aztec/src/oracle/returns.nr index 4c1b325ff95a..c0ed65297617 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/returns.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/returns.nr @@ -1,13 +1,13 @@ #[oracle(packReturns)] -unconstrained fn pack_returns_oracle(_returns: [Field]) -> Field {} +unconstrained fn pack_returns_oracle(_returns: [Field]) -> Field {} unconstrained pub fn pack_returns(returns: [Field]) { let _unused = pack_returns_oracle(returns); } #[oracle(unpackReturns)] -unconstrained fn unpack_returns_oracle(_return_hash: Field) -> [Field; N] {} +unconstrained fn unpack_returns_oracle(_return_hash: Field) -> [Field; N] {} -unconstrained pub fn unpack_returns(return_hash: Field) -> [Field; N] { +unconstrained pub fn unpack_returns(return_hash: Field) -> [Field; N] { unpack_returns_oracle(return_hash) } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/storage.nr b/noir-projects/aztec-nr/aztec/src/oracle/storage.nr index b4a6b1f91024..462740170ed1 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/storage.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/storage.nr @@ -1,22 +1,22 @@ use dep::protocol_types::{address::AztecAddress, traits::Deserialize}; #[oracle(storageRead)] -unconstrained fn storage_read_oracle( - address: Field, - storage_slot: Field, - block_number: Field, - length: Field -) -> [Field; N] {} +unconstrained fn storage_read_oracle(address: Field, storage_slot: Field, block_number: Field, length: Field) -> [Field; N] {} -unconstrained pub fn raw_storage_read( +unconstrained pub fn raw_storage_read( address: AztecAddress, storage_slot: Field, block_number: u32 ) -> [Field; N] { - storage_read_oracle(address.to_field(), storage_slot, block_number as Field, N) + storage_read_oracle( + address.to_field(), + storage_slot, + block_number as Field, + N as Field + ) } -unconstrained pub fn storage_read( +unconstrained pub fn storage_read( address: AztecAddress, storage_slot: Field, block_number: u32 diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr index c94b8a25bfa1..7902602ca09e 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr @@ -26,7 +26,7 @@ impl PrivateSet { // docs:end:new } -impl PrivateSet where Note: NoteInterface { +impl PrivateSet where Note: NoteInterface { // docs:start:insert_from_public pub fn insert_from_public(self, note: &mut Note) { create_note_hash_from_public(self.context, self.storage_slot, note); @@ -34,7 +34,7 @@ impl PrivateSet where Note: NoteInterface< // docs:end:insert_from_public } -impl PrivateSet where Note: NoteInterface + Eq { +impl PrivateSet where Note: NoteInterface + Eq { // docs:start:insert pub fn insert(self, note: &mut Note) -> NoteEmission { create_note(self.context, self.storage_slot, note) @@ -61,7 +61,7 @@ impl PrivateSet where Note: NoteInterface // docs:end:get_notes } -impl PrivateSet where Note: NoteInterface { +impl PrivateSet where Note: NoteInterface { // docs:start:view_notes unconstrained pub fn view_notes( self, diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr index 87cd38f1b12b..685e2e64f0be 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr @@ -25,10 +25,10 @@ struct SharedMutable { // // TODO https://github.com/AztecProtocol/aztec-packages/issues/5736: change the storage allocation scheme so that we // can actually use it here -impl Storage for SharedMutable {} +impl Storage for SharedMutable {} // TODO: extract into a utils module once we can do arithmetic on generics, i.e. https://github.com/noir-lang/noir/issues/4784 -fn concat_arrays(arr_n: [Field; N], arr_m: [Field; M]) -> [Field; O] { +fn concat_arrays(arr_n: [Field; N], arr_m: [Field; M]) -> [Field; O] { assert_eq(N + M, O); let mut out: [Field; O] = [0; O]; for i in 0..N { @@ -51,7 +51,7 @@ fn concat_arrays(arr_n: [Field; N], arr_m: [Field; M]) -> [Field; O] { // future, so that they can guarantee the value will not have possibly changed by then (because of the delay). // The delay for changing a value is initially equal to INITIAL_DELAY, but can be changed by calling // `schedule_delay_change`. -impl SharedMutable where T: ToField + FromField + Eq { +impl SharedMutable where T: ToField + FromField + Eq { pub fn new(context: Context, storage_slot: Field) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); Self { context, storage_slot } @@ -127,7 +127,7 @@ impl SharedMutable where T } } -impl SharedMutable where T: ToField + FromField + Eq { +impl SharedMutable where T: ToField + FromField + Eq { pub fn schedule_value_change(self, new_value: T) { let mut value_change = self.read_value_change(); let delay_change = self.read_delay_change(); @@ -199,7 +199,7 @@ impl SharedMutable where } } -impl SharedMutable where T: ToField + FromField + Eq { +impl SharedMutable where T: ToField + FromField + Eq { pub fn get_current_value_in_private(self) -> T { // When reading the current value in private we construct a historical state proof for the public value. // However, since this value might change, we must constrain the maximum transaction block number as this proof @@ -225,7 +225,7 @@ impl SharedMutable wher } } -impl SharedMutable where T: ToField + FromField + Eq { +impl SharedMutable where T: ToField + FromField + Eq { unconstrained pub fn get_current_value_in_unconstrained(self) -> T { let block_number = self.context.block_number() as u32; self.read_value_change().get_current_at(block_number) @@ -236,7 +236,7 @@ impl SharedMutable whe } } -unconstrained fn get_public_storage_hints( +unconstrained fn get_public_storage_hints( address: AztecAddress, storage_slot: Field, block_number: u32 diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr index e230ebbab672..68c402f25b0c 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr @@ -42,12 +42,17 @@ unconstrained pub fn get_public_context_inputs() -> PublicContextInputs { oracle_get_public_context_inputs() } -unconstrained pub fn deploy(path: str, initializer: str, args: [Field], public_keys_hash: Field) -> ContractInstance { +unconstrained pub fn deploy( + path: str, + initializer: str, + args: [Field], + public_keys_hash: Field +) -> ContractInstance { let instance_fields = oracle_deploy(path, initializer, args, public_keys_hash); ContractInstance::deserialize(instance_fields) } -unconstrained pub fn direct_storage_write(contract_address: AztecAddress, storage_slot: Field, fields: [Field; N]) { +unconstrained pub fn direct_storage_write(contract_address: AztecAddress, storage_slot: Field, fields: [Field; N]) { let _hash = direct_storage_write_oracle(contract_address, storage_slot, fields); } @@ -145,7 +150,7 @@ fn oracle_get_private_context_inputs(historical_block_number: u32) -> PrivateCon fn oracle_get_public_context_inputs() -> PublicContextInputs {} #[oracle(deploy)] -fn oracle_deploy( +fn oracle_deploy( path: str, initializer: str, args: [Field], @@ -153,7 +158,7 @@ fn oracle_deploy( ) -> [Field; CONTRACT_INSTANCE_LENGTH] {} #[oracle(directStorageWrite)] -fn direct_storage_write_oracle( +fn direct_storage_write_oracle( _contract_address: AztecAddress, _storage_slot: Field, _values: [Field; N] diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr index b6238d4e02d8..35df950bc501 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr @@ -121,11 +121,11 @@ impl TestEnvironment { address } - fn deploy(self, path: str) -> Deployer { + fn deploy(self, path: str) -> Deployer { Deployer { path, public_keys_hash: 0 } } - fn call_private( + fn call_private( self, call_interface: C ) -> T where C: CallInterface, T: Deserialize { @@ -147,7 +147,7 @@ impl TestEnvironment { PackedReturns::new(public_inputs.returns_hash).unpack_into() } - fn call_private_void( + fn call_private_void( self, call_interface: C ) where C: CallInterface { @@ -169,7 +169,10 @@ impl TestEnvironment { PackedReturns::new(public_inputs.returns_hash).assert_empty(); } - fn call_public(self, call_interface: C) -> T where C: CallInterface { + fn call_public( + self, + call_interface: C + ) -> T where C: CallInterface { let original_fn = call_interface.get_original(); let original_msg_sender = cheatcodes::get_msg_sender(); let original_contract_address = cheatcodes::get_contract_address(); @@ -191,7 +194,10 @@ impl TestEnvironment { result } - fn assert_public_call_fails(self, call_interface: C) where C: CallInterface { + fn assert_public_call_fails( + self, + call_interface: C + ) where C: CallInterface { cheatcodes::assert_public_call_fails( call_interface.get_contract_address(), call_interface.get_selector(), @@ -199,7 +205,10 @@ impl TestEnvironment { ); } - fn assert_private_call_fails(self, call_interface: C) where C: CallInterface { + fn assert_private_call_fails( + self, + call_interface: C + ) where C: CallInterface { cheatcodes::assert_private_call_fails( call_interface.get_contract_address(), call_interface.get_selector(), @@ -210,7 +219,7 @@ impl TestEnvironment { ); } - pub fn store_note_in_cache( + pub fn store_note_in_cache( self, note: &mut Note, storage_slot: Field, diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr index 12b5fddf2633..bc2c6d66325f 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr @@ -29,13 +29,13 @@ pub fn apply_side_effects_private(contract_address: AztecAddress, public_inputs: cheatcodes::add_note_hashes(contract_address, note_hashes); } -struct Deployer { +struct Deployer { path: str, public_keys_hash: Field } -impl Deployer { - pub fn with_private_initializer( +impl Deployer { + pub fn with_private_initializer( self, call_interface: C ) -> ContractInstance where C: CallInterface { @@ -64,7 +64,7 @@ impl Deployer { instance } - pub fn with_public_initializer( + pub fn with_public_initializer( self, call_interface: C ) -> ContractInstance where C: CallInterface { diff --git a/noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.nr b/noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.nr index 95d5c4b68ae6..8f977dc71edc 100644 --- a/noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.nr @@ -4,7 +4,7 @@ use crate::{ }; use dep::protocol_types::{address::AztecAddress, traits::Serialize}; -fn emit( +fn emit( context: &mut PublicContext, event: Event ) where Event: EventInterface, Event: Serialize, [Field; N]: LensForEventSelector { @@ -23,7 +23,7 @@ fn emit( context.emit_unencrypted_log(emitted_log); } -pub fn encode_event(context: &mut PublicContext) -> fn[(&mut PublicContext,)](Event) -> () where Event: EventInterface, Event: Serialize, [Field; N]: LensForEventSelector { +pub fn encode_event(context: &mut PublicContext) -> fn[(&mut PublicContext,)](Event) -> () where Event: EventInterface, Event: Serialize, [Field; N]: LensForEventSelector { | e: Event | { emit( context, @@ -32,7 +32,7 @@ pub fn encode_event(context: &mut PublicContext) -> fn[ } } -trait LensForEventSelector { +trait LensForEventSelector { // N = event preimage input in fields // M = event preimage input in fields + event selector as field fn output(self: [Field; N]) -> [Field; M]; diff --git a/noir-projects/aztec-nr/aztec/src/utils/mod.nr b/noir-projects/aztec-nr/aztec/src/utils/mod.nr index bdc40229f0ee..0c6276fad787 100644 --- a/noir-projects/aztec-nr/aztec/src/utils/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/utils/mod.nr @@ -7,13 +7,13 @@ mod test; // input: [some(3), none(), some(1)] // this returns // collapsed: [3, 1] -pub fn collapse(input: [Option; N]) -> BoundedVec where T: Eq { +pub fn collapse(input: [Option; N]) -> BoundedVec where T: Eq { let (collapsed, collapsed_to_input_index_mapping) = get_collapse_hints(input); verify_collapse_hints(input, collapsed, collapsed_to_input_index_mapping); collapsed } -fn verify_collapse_hints( +fn verify_collapse_hints( input: [Option; N], collapsed: BoundedVec, collapsed_to_input_index_mapping: BoundedVec @@ -69,7 +69,7 @@ fn verify_collapse_hints( // Therefore, the collapsed array is correct. } -unconstrained fn get_collapse_hints(input: [Option; N]) -> (BoundedVec, BoundedVec) { +unconstrained fn get_collapse_hints(input: [Option; N]) -> (BoundedVec, BoundedVec) { let mut collapsed: BoundedVec = BoundedVec::new(); let mut collapsed_to_input_index_mapping: BoundedVec = BoundedVec::new(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/event_selector.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/event_selector.nr index eca5867114b3..063e186006ac 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/event_selector.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/event_selector.nr @@ -51,7 +51,7 @@ impl EventSelector { Self { inner: value } } - pub fn from_signature(signature: str) -> Self { + pub fn from_signature(signature: str) -> Self { let bytes = signature.as_bytes(); let hash = std::hash::keccak256(bytes, bytes.len() as u32); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr index 57be8ba02789..9e3ba609118f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr @@ -51,7 +51,7 @@ impl FunctionSelector { Self { inner: value } } - pub fn from_signature(signature: str) -> Self { + pub fn from_signature(signature: str) -> Self { let bytes = signature.as_bytes(); let hash = std::hash::keccak256(bytes, bytes.len() as u32); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr index 30b4241e89ac..da4d4dca2122 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr @@ -25,7 +25,7 @@ impl Verifiable for KernelData { } impl KernelData { - fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { + fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { let index_hint = find_index_hint(allowed_indices, self.vk_index); assert_eq(allowed_indices[index_hint], self.vk_index, "Invalid vk index"); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr index 781be7d481c3..97b011e639db 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr @@ -16,7 +16,7 @@ struct PrivateKernelData { } impl PrivateKernelData { - fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { + fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { let index_hint = find_index_hint(allowed_indices, self.vk_index); assert_eq(allowed_indices[index_hint], self.vk_index, "Invalid vk index"); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr index 1c434a5a7a6e..66a1e38f4170 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr @@ -25,7 +25,7 @@ impl Verifiable for PublicKernelData { } impl PublicKernelData { - fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { + fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { let index_hint = find_index_hint(allowed_indices, self.vk_index); assert_eq(allowed_indices[index_hint], self.vk_index, "Invalid vk index"); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/debug_log.nr b/noir-projects/noir-protocol-circuits/crates/types/src/debug_log.nr index 6c3726ffa5f6..bccbc9a2adf7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/debug_log.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/debug_log.nr @@ -2,7 +2,7 @@ // WARNING: sometimes when using debug logs the ACVM errors with: `thrown: "solver opcode resolution error: cannot solve opcode: expression has too many unknowns x155"` #[oracle(debugLog)] -unconstrained fn debug_log_oracle(_msg: str, args: [Field]) {} +unconstrained fn debug_log_oracle(_msg: str, args: [Field]) {} /// NOTE: call this with a str msg of form /// "some string with {0} and {1} ... {N}" @@ -11,13 +11,13 @@ unconstrained fn debug_log_oracle(_msg: str, args: [Field]) {} /// Example: /// debug_log_format("get_2(slot:{0}) =>\n\t0:{1}\n\t1:{2}", [storage_slot, note0_hash, note1_hash]); /// debug_log_format("whole array: {}", [e1, e2, e3, e4]); -unconstrained pub fn debug_log_format(msg: str, args: [Field; N]) { +unconstrained pub fn debug_log_format(msg: str, args: [Field; N]) { debug_log_oracle(msg, args.as_slice()); } /// NOTE: call this with a str msg of length > 1 /// Example: /// `debug_log("blah blah this is a debug string");` -unconstrained pub fn debug_log(msg: str) { +unconstrained pub fn debug_log(msg: str) { debug_log_format(msg, []); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr index 947d5e03ce4f..5e98e6f57768 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -16,7 +16,7 @@ use crate::{ }; use std::hash::{pedersen_hash_with_separator, sha256}; -pub fn sha256_to_field(bytes_to_hash: [u8; N]) -> Field { +pub fn sha256_to_field(bytes_to_hash: [u8; N]) -> Field { let sha256_hashed = sha256(bytes_to_hash); let hash_in_a_field = field_from_bytes_32_trunc(sha256_hashed); @@ -248,11 +248,11 @@ pub fn compute_tx_note_logs_hash(logs: [LogHash; MAX_NOTE_ENCRYPTED_LOGS_PER_TX] hash } -pub fn pedersen_hash(inputs: [Field; N], hash_index: u32) -> Field { +pub fn pedersen_hash(inputs: [Field; N], hash_index: u32) -> Field { std::hash::pedersen_hash_with_separator(inputs, hash_index) } -pub fn poseidon2_hash(inputs: [Field; N]) -> Field { +pub fn poseidon2_hash(inputs: [Field; N]) -> Field { std::hash::poseidon2::Poseidon2::hash(inputs, N) } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/append_only_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/append_only_tree.nr index 4e9abf93a2e7..f1a1b2bafa10 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/append_only_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/append_only_tree.nr @@ -3,7 +3,7 @@ use crate::{ merkle_tree::{membership::assert_check_membership, root::root_from_sibling_path} }; -pub fn insert_subtree_to_snapshot_tree( +pub fn insert_subtree_to_snapshot_tree( snapshot: AppendOnlyTreeSnapshot, sibling_path: [Field; N], empty_subtree_root: Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr index f13f79607c05..23d400e0b950 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr @@ -9,7 +9,14 @@ use crate::{ traits::{Empty, Hash, is_empty}, utils::arrays::check_permutation }; -pub fn batch_insert( +pub fn batch_insert< + Value, + Leaf, + let SubtreeWidth: u32, + let SiblingPathLength: u32, + let SubtreeHeight: u32, + let TreeHeight: u32 +>( start_snapshot: AppendOnlyTreeSnapshot, values_to_insert: [Value; SubtreeWidth], sorted_values: [Value; SubtreeWidth], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr index 14bd01ef8f2a..b167fa32ebce 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr @@ -6,12 +6,12 @@ use crate::{ traits::Empty }; -struct MembershipWitness { +struct MembershipWitness { leaf_index: Field, sibling_path: [Field; N] } -impl Empty for MembershipWitness { +impl Empty for MembershipWitness { fn empty() -> Self { MembershipWitness { leaf_index: 0, @@ -20,16 +20,16 @@ impl Empty for MembershipWitness { } } -pub fn check_membership(leaf: Field, index: Field, sibling_path: [Field; N], root: Field) -> bool { +pub fn check_membership(leaf: Field, index: Field, sibling_path: [Field; N], root: Field) -> bool { let calculated_root = root_from_sibling_path(leaf, index, sibling_path); calculated_root == root } -pub fn assert_check_membership(leaf: Field, index: Field, sibling_path: [Field; TREE_HEIGHT], root: Field) { +pub fn assert_check_membership(leaf: Field, index: Field, sibling_path: [Field; TREE_HEIGHT], root: Field) { assert(check_membership(leaf, index, sibling_path, root), "membership check failed"); } -pub fn assert_check_non_membership( +pub fn assert_check_non_membership( key: Field, low_leaf_preimage: LEAF_PREIMAGE, low_leaf_membership_witness: MembershipWitness, @@ -49,7 +49,7 @@ pub fn assert_check_non_membership( // Prove either membership or non-membership depending on the value of `exists`. // If `exists` == false, `key` is not in the tree, `leaf_preimage` and `membership_witness` are for the low leaf. -pub fn conditionally_assert_check_membership( +pub fn conditionally_assert_check_membership( key: Field, exists: bool, leaf_preimage: LEAF_PREIMAGE, @@ -120,7 +120,7 @@ mod tests { TestLeafPreimage { value: 30, next_value: 40 }, ]; - fn build_tree() -> NonEmptyMerkleTree<4, 3, 1, 2> { + fn build_tree() -> NonEmptyMerkleTree<4, 3, 1, 2> { NonEmptyMerkleTree::new( leaf_preimages.map(|leaf_preimage: TestLeafPreimage| leaf_preimage.as_leaf()), [0; 3], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr index 43a03fa5af6e..7076b12ea568 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr @@ -1,12 +1,12 @@ use crate::traits::Empty; use crate::merkle_tree::membership::assert_check_membership; -struct MerkleTree { +struct MerkleTree { leaves: [Field; N], nodes: [Field; N], } -impl Empty for MerkleTree { +impl Empty for MerkleTree { fn empty() -> Self { MerkleTree { leaves: [0; N], @@ -15,7 +15,7 @@ impl Empty for MerkleTree { } } -impl MerkleTree { +impl MerkleTree { pub fn new(leaves: [Field; N]) -> Self { let mut nodes = [0; N]; @@ -44,7 +44,7 @@ impl MerkleTree { if index % 2 == 0 { index + 1 } else { index - 1 } } - fn get_sibling_path(self, leaf_index: u32) -> [Field; K] { + fn get_sibling_path(self, leaf_index: u32) -> [Field; K] { assert_eq(2.pow_32(K as Field), N as Field, "Invalid path length"); let mut path = [0; K]; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/root.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/root.nr index 921510067daf..624e75000e03 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/root.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/root.nr @@ -10,7 +10,11 @@ use crate::{hash::merkle_hash, merkle_tree::merkle_tree::MerkleTree}; // TODO: I'd generally like to avoid u256 for algorithms like // this because it means we never even need to consider cases where // the index is greater than p. -pub fn root_from_sibling_path(leaf: Field, leaf_index: Field, sibling_path: [Field; N]) -> Field { +pub fn root_from_sibling_path( + leaf: Field, + leaf_index: Field, + sibling_path: [Field; N] +) -> Field { let mut node = leaf; let indices = leaf_index.to_le_bits(N); @@ -25,7 +29,7 @@ pub fn root_from_sibling_path(leaf: Field, leaf_index: Field, sibling_path: [ node } -pub fn calculate_subtree_root(leaves: [Field; N]) -> Field { +pub fn calculate_subtree_root(leaves: [Field; N]) -> Field { MerkleTree::new(leaves).get_root() } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/variable_merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/variable_merkle_tree.nr index b2a57d8f2f7c..3fe508fd5668 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/variable_merkle_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/variable_merkle_tree.nr @@ -21,7 +21,7 @@ unconstrained fn get_height(input: u32, start: u8) -> u8 { // Since we cannot isolate branches, it doesn't cost fewer gates than using // MerkleTree on the full array of elements N, but is slightly cheaper on-chain // and cleaner elsewhere. -impl VariableMerkleTree { +impl VariableMerkleTree { // Example - tx_0 with 3 msgs | tx_1 with 2 msgs creates: // // tx0oh tx1oh @@ -106,7 +106,7 @@ mod tests { items } - pub fn generate_full_sha_tree(leaves: [Field; N]) -> MerkleTree { + pub fn generate_full_sha_tree(leaves: [Field; N]) -> MerkleTree { let mut nodes = [0; N]; let total_nodes = N - 1; let half_size = N / 2; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index 73893c3987db..ca6296010b48 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -44,7 +44,7 @@ use crate::{ point::Point }; -fn subarray(arr: [T; N]) -> [T; M] { +fn subarray(arr: [T; N]) -> [T; M] { assert(N >= M, "cannot call subarray on a smaller array"); let mut new_arr = [arr[0]; M]; for i in 0..M { @@ -53,7 +53,7 @@ fn subarray(arr: [T; N]) -> [T; M] { new_arr } -fn vec_reverse(vec: BoundedVec) -> BoundedVec { +fn vec_reverse(vec: BoundedVec) -> BoundedVec { let mut reversed = BoundedVec::new(); let len = vec.len(); for i in 0..N { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr index 19a2073001de..e7bdbc19917f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr @@ -1,6 +1,6 @@ use crate::{merkle_tree::{MerkleTree, calculate_empty_tree_root}, traits::Empty}; -pub fn compute_zero_hashes(mut hashes: [Field; N]) -> [Field; N] { +pub fn compute_zero_hashes(mut hashes: [Field; N]) -> [Field; N] { hashes[0] = std::hash::pedersen_hash([0, 0]); for i in 1..N { @@ -10,8 +10,8 @@ pub fn compute_zero_hashes(mut hashes: [Field; N]) -> [Field; N] { hashes } -impl MerkleTree { - fn update_leaf(&mut self, index: u32, value: Field, _tree_height: [Field; K]) { +impl MerkleTree { + fn update_leaf(&mut self, index: u32, value: Field, _tree_height: [Field; K]) { self.leaves[index] = value; let mut sibling_index = MerkleTree::sibling_index(index); @@ -65,14 +65,14 @@ fn test_merkle_tree_update_leaf_three_layers() { assert_eq(tree.get_root(), calculate_empty_tree_root(3)); } -struct NonEmptyMerkleTree { +struct NonEmptyMerkleTree { subtree: MerkleTree, zero_hashes: [Field; TREE_HEIGHT], left_supertree_branch: [Field; SUPERTREE_HEIGHT], _phantom_subtree_height: [Field; SUBTREE_HEIGHT], } -impl Empty for NonEmptyMerkleTree { +impl Empty for NonEmptyMerkleTree { fn empty() -> Self { NonEmptyMerkleTree { subtree: MerkleTree::empty(), @@ -83,7 +83,7 @@ impl Empty for Non } } -impl NonEmptyMerkleTree { +impl NonEmptyMerkleTree { pub fn new( non_zero_leaves: [Field; SUBTREE_ITEMS], _tree_height: [Field; TREE_HEIGHT], @@ -94,7 +94,7 @@ impl NonEmptyMerkl TREE_HEIGHT, SUPERTREE_HEIGHT + SUBTREE_HEIGHT, "tree height must be the sum of supertree and subtree height" ); assert_eq( - U128::from_integer(SUBTREE_ITEMS), U128::from_integer(1 as u32 << SUBTREE_HEIGHT), "subtree items must be 2^subtree height" + U128::from_integer(SUBTREE_ITEMS), U128::from_integer(1 << SUBTREE_HEIGHT), "subtree items must be 2^subtree height" ); let subtree = MerkleTree::new(non_zero_leaves); @@ -104,7 +104,7 @@ impl NonEmptyMerkl left_supertree_branch[0] = std::hash::pedersen_hash([subtree.get_root(), zero_hashes[SUBTREE_HEIGHT-1]]); for i in 1..left_supertree_branch.len() { // TODO(md): far right of this yuck - left_supertree_branch[i] = std::hash::pedersen_hash([left_supertree_branch[i-1], zero_hashes[(SUBTREE_HEIGHT as u64 -1) + i as u64]]); + left_supertree_branch[i] = std::hash::pedersen_hash([left_supertree_branch[i-1], zero_hashes[SUBTREE_HEIGHT -1 + (i as u8)]]); } NonEmptyMerkleTree { subtree, zero_hashes, left_supertree_branch, _phantom_subtree_height: _subtree_height } @@ -152,7 +152,7 @@ impl NonEmptyMerkl self.left_supertree_branch[0] = std::hash::pedersen_hash([self.subtree.get_root(), self.zero_hashes[SUBTREE_HEIGHT-1]]); for i in 1..self.left_supertree_branch.len() { - self.left_supertree_branch[i] = std::hash::pedersen_hash([self.left_supertree_branch[i-1], self.zero_hashes[SUBTREE_HEIGHT-1+i]]); + self.left_supertree_branch[i] = std::hash::pedersen_hash([self.left_supertree_branch[i-1], self.zero_hashes[SUBTREE_HEIGHT -1 + (i as u8)]]); } } @@ -160,7 +160,7 @@ impl NonEmptyMerkl self.left_supertree_branch[SUPERTREE_HEIGHT - 1] } - pub fn get_next_available_index(self) -> Field { + pub fn get_next_available_index(self) -> u32 { // Silence warning for unused self, pending proper fix. let _ = self; SUBTREE_ITEMS diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr index e3cbe0c49180..7217c8955a21 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr @@ -3,7 +3,7 @@ struct SortedTuple { original_index: u32, } -pub fn sort_high_to_low(values: [T; N], is_less_than: fn(T, T) -> bool) -> [SortedTuple; N] where T: Eq { +pub fn sort_high_to_low(values: [T; N], is_less_than: fn(T, T) -> bool) -> [SortedTuple; N] where T: Eq { let mut sorted_tuples = [SortedTuple { value: values[0], original_index: 0 }; N]; for i in 0..N { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/utils.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/utils.nr index bc95d59c4cba..c5187420b292 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/utils.nr @@ -1,6 +1,6 @@ use crate::traits::{Empty, is_empty}; -fn count_non_empty_elements(array: [T; N]) -> u64 where T: Empty + Eq { +fn count_non_empty_elements(array: [T; N]) -> u32 where T: Empty + Eq { let mut length = 0; for elem in array { if !is_empty(elem) { @@ -10,7 +10,7 @@ fn count_non_empty_elements(array: [T; N]) -> u64 where T: Empty + Eq { length } -pub fn assert_array_eq(array: [T; N], expected: [T; S]) where T: Empty + Eq { +pub fn assert_array_eq(array: [T; N], expected: [T; S]) where T: Empty + Eq { assert_eq(count_non_empty_elements(expected), S, "cannot expect empty element in the result"); assert_eq(count_non_empty_elements(array), S, "mismatch array lengths"); for i in 0..S { @@ -20,7 +20,7 @@ pub fn assert_array_eq(array: [T; N], expected: [T; S]) where T: Empty // Swap two items in a BoundedVec. // Useful when we want to shuffle side effects, which by default are ordered by counters when we add mock data to FixtureBuilder. -pub fn swap_items(vec: &mut BoundedVec, from_index: u64, to_index: u64) { +pub fn swap_items(vec: &mut BoundedVec, from_index: u32, to_index: u32) { let tmp = vec.storage[from_index]; vec.storage[from_index] = vec.storage[to_index]; vec.storage[to_index] = tmp; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index 5a9c351fc9b0..774197d30821 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -27,7 +27,7 @@ pub fn is_empty(item: T) -> bool where T: Empty + Eq { item.eq(T::empty()) } -pub fn is_empty_array(array: [T; N]) -> bool where T: Empty + Eq { +pub fn is_empty_array(array: [T; N]) -> bool where T: Empty + Eq { array.all(|elem| is_empty(elem)) } @@ -55,7 +55,7 @@ impl ToField for U128 { self.to_integer() } } -impl ToField for str { +impl ToField for str { fn to_field(self) -> Field { assert(N < 32, "String doesn't fit in a field, consider using Serialize instead"); field_from_bytes(self.as_bytes(), true) @@ -84,17 +84,17 @@ impl FromField for U128 { } // docs:start:serialize -trait Serialize { +trait Serialize { fn serialize(self) -> [Field; N]; } // docs:end:serialize -impl Serialize for [Field; N] { +impl Serialize for [Field; N] { fn serialize(self) -> [Field; N] { self } } -impl Serialize for str { +impl Serialize for str { fn serialize(self) -> [Field; N] { let mut result = [0; N]; let bytes: [u8; N] = self.as_bytes(); @@ -106,12 +106,12 @@ impl Serialize for str { } // docs:start:deserialize -trait Deserialize { +trait Deserialize { fn deserialize(fields: [Field; N]) -> Self; } // docs:end:deserialize -impl Deserialize for [Field; N] { +impl Deserialize for [Field; N] { fn deserialize(fields: [Field; N]) -> Self { fields } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr index d306726a26fc..9c2d8786cbe3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr @@ -19,7 +19,7 @@ use sort_get_split_order_hints::{sort_get_split_order_hints_asc, sort_get_split_ use crate::traits::{Empty, is_empty}; use crate::abis::side_effect::{Positioned, Ordered}; -pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Empty + Eq { +pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Empty + Eq { let mut len = 0; for elem in array { if !is_empty(elem) { @@ -30,7 +30,10 @@ pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Em BoundedVec { storage: array, len } } -unconstrained fn filter_array_to_bounded_vec_unsafe(arr: [T; N], should_propagate: [bool; N]) -> BoundedVec { +unconstrained fn filter_array_to_bounded_vec_unsafe( + arr: [T; N], + should_propagate: [bool; N] +) -> BoundedVec { let mut vec = BoundedVec::new(); for i in 0..N { if should_propagate[i] { @@ -40,7 +43,7 @@ unconstrained fn filter_array_to_bounded_vec_unsafe(arr: [T; N], should_pr vec } -pub fn filter_array_to_bounded_vec(arr: [T; N], should_propagate: [bool; N]) -> BoundedVec where T: Eq { +pub fn filter_array_to_bounded_vec(arr: [T; N], should_propagate: [bool; N]) -> BoundedVec where T: Eq { let vec_hint = filter_array_to_bounded_vec_unsafe(arr, should_propagate); let mut verifying_index = 0; @@ -55,7 +58,7 @@ pub fn filter_array_to_bounded_vec(arr: [T; N], should_propagate: [bool; N vec_hint } -unconstrained pub fn find_index_hint(array: [T; N], find: T) -> u32 where T: Eq { +unconstrained pub fn find_index_hint(array: [T; N], find: T) -> u32 where T: Eq { let mut index = 0; for i in 0..array.len() { if array[i] == find { @@ -68,7 +71,7 @@ unconstrained pub fn find_index_hint(array: [T; N], find: T) -> u32 where // Routine which validates that all zero values of an array form a contiguous region at the end, i.e., // of the form: [*,*,*...,0,0,0,0] where any * is non-zero. Note that a full array of non-zero values is // valid. -pub fn validate_array(array: [T; N]) -> u32 where T: Empty + Eq { +pub fn validate_array(array: [T; N]) -> u32 where T: Empty + Eq { let mut seen_empty = false; let mut length = 0; for i in 0..N { @@ -82,7 +85,7 @@ pub fn validate_array(array: [T; N]) -> u32 where T: Empty + Eq { length } -unconstrained fn count_non_empty_elements(array: [T; N]) -> u32 where T: Empty + Eq { +unconstrained fn count_non_empty_elements(array: [T; N]) -> u32 where T: Empty + Eq { let mut length = 0; let mut seen_empty = false; for elem in array { @@ -97,7 +100,7 @@ unconstrained fn count_non_empty_elements(array: [T; N]) -> u32 where T: E // Helper function to count the number of non-empty elements in a validated array. // Important: Only use it for validated arrays: validate_array(array) should be true. -pub fn array_length(array: [T; N]) -> u32 where T: Empty + Eq { +pub fn array_length(array: [T; N]) -> u32 where T: Empty + Eq { let length = count_non_empty_elements(array); if length != 0 { assert(!is_empty(array[length - 1])); @@ -109,7 +112,7 @@ pub fn array_length(array: [T; N]) -> u32 where T: Empty + Eq { } // Deprecated. Use tests/utils/assert_array_eq instead. -pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Empty + Eq { +pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Empty + Eq { let mut eq = array_length(array) == S; for i in 0..S { @@ -119,7 +122,7 @@ pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Empty eq } -pub fn find_index(array: [T; N], find: fn[Env](T) -> bool) -> u32 { +pub fn find_index(array: [T; N], find: fn[Env](T) -> bool) -> u32 { let mut index = N; for i in 0..N { if (index == N) & find(array[i]) { @@ -129,7 +132,7 @@ pub fn find_index(array: [T; N], find: fn[Env](T) -> bool) -> u32 { index } -pub fn array_cp(array: [T; N]) -> [T; S] where T: Empty { +pub fn array_cp(array: [T; N]) -> [T; S] where T: Empty { let mut result: [T; S] = [T::empty(); S]; for i in 0..S { result[i] = array[i]; @@ -137,7 +140,7 @@ pub fn array_cp(array: [T; N]) -> [T; S] where T: Empty { result } -pub fn array_concat(array1: [T; N], array2: [T; M]) -> [T; S] { +pub fn array_concat(array1: [T; N], array2: [T; M]) -> [T; S] { assert_eq(N + M, S, "combined array length does not match return array length"); let mut result = [array1[0]; S]; for i in 1..N { @@ -149,7 +152,7 @@ pub fn array_concat(array1: [T; N], array2: [T; M]) -> [T; S] { result } -pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Empty + Eq { +pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Empty + Eq { let mut result: [T; N] = [T::empty(); N]; let mut i = 0; for elem in array1 { @@ -167,7 +170,7 @@ pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Empt result } -pub fn check_permutation( +pub fn check_permutation( original_array: [T; N], permuted_array: [T; N], original_indexes: [u32; N] @@ -182,7 +185,7 @@ pub fn check_permutation( } } -pub fn assert_deduped_array( +pub fn assert_deduped_array( original_array: [T; N], deduped_array: [T; N], run_lengths: [u32; N] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_sorted_array.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_sorted_array.nr index 4a1edc2598ab..5485c6eafe31 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_sorted_array.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_sorted_array.nr @@ -1,6 +1,6 @@ use crate::{abis::side_effect::Ordered, traits::{Empty, is_empty}, utils::arrays::sort_get_order_hints::OrderHint}; -pub fn assert_sorted_array( +pub fn assert_sorted_array( original_array: [T; N], sorted_array: [T; N], sorted_indexes: [u32; N], @@ -25,7 +25,7 @@ pub fn assert_sorted_array( } // original_array must be valid, i.e. validate_array(original_array) == true -pub fn assert_sorted_array_with_order_hints( +pub fn assert_sorted_array_with_order_hints( original_array: [T; N], sorted_array: [T; N], hints: [OrderHint; N] @@ -144,7 +144,7 @@ mod tests { } } - struct TestDataBuilder { + struct TestDataBuilder { original_array: [T; N], sorted_array: [T; N], hints: [OrderHint; N], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_sorted_transformed_value_array.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_sorted_transformed_value_array.nr index c07e2d54c43a..a1a2b00e9fbb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_sorted_transformed_value_array.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_sorted_transformed_value_array.nr @@ -2,7 +2,7 @@ use crate::{abis::side_effect::Ordered, traits::{Empty, is_empty}, utils::arrays // original_array must be valid, i.e. validate_array(original_array) == true // transformed_value_array must be verified against original_array before calling this function. -pub fn assert_sorted_transformed_value_array( +pub fn assert_sorted_transformed_value_array( original_array: [T; N], transformed_value_array: [S; N], sorted_transformed_value_array: [S; N], @@ -75,7 +75,7 @@ mod tests { TestValue { name: item.name, total: item.price + item.tax } } - struct TestDataBuilder { + struct TestDataBuilder { original_array: [T; N], transformed_value_array: [S; N], sorted_transformed_value_array: [S; N], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_split_sorted_transformed_value_arrays.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_split_sorted_transformed_value_arrays.nr index 13213932d66c..8908ac21375e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_split_sorted_transformed_value_arrays.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_split_sorted_transformed_value_arrays.nr @@ -5,7 +5,7 @@ use crate::{ // original_array must be valid, i.e. validate_array(original_array) == true // transformed_value_array must be verified against original_array before calling this function. -fn assert_split_sorted_transformed_value_arrays( +fn assert_split_sorted_transformed_value_arrays( original_array: [T; N], transformed_value_array: [S; N], split_counter: u32, @@ -66,7 +66,7 @@ fn assert_split_sorted_transformed_value_arrays( assert_eq(num_non_empty_values_gte, num_gte, "mismatch number of values gte"); } -pub fn assert_split_sorted_transformed_value_arrays_asc( +pub fn assert_split_sorted_transformed_value_arrays_asc( original_array: [T; N], transformed_value_array: [S; N], split_counter: u32, @@ -87,7 +87,7 @@ pub fn assert_split_sorted_transformed_value_arrays_asc( ); } -pub fn assert_split_sorted_transformed_value_arrays_desc( +pub fn assert_split_sorted_transformed_value_arrays_desc( original_array: [T; N], transformed_value_array: [S; N], split_counter: u32, @@ -174,7 +174,7 @@ mod tests { TestItem::empty() ]; - struct TestDataBuilder { + struct TestDataBuilder { original_array: [T; N], transformed_value_array: [S; N], sorted_transformed_value_array_lt: [S; N], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_by_counters.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_by_counters.nr index 9c83a138f264..771879bbc605 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_by_counters.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_by_counters.nr @@ -8,14 +8,14 @@ pub fn order_by_counters_empty_padded_desc(a: T, b: T) -> bool where T: Order is_empty(b) | (!is_empty(a) & !is_empty(b) & a.counter() > b.counter()) } -fn sort_by(array: [T; N], ordering: fn(T, T) -> bool) -> [T; N] { +fn sort_by(array: [T; N], ordering: fn(T, T) -> bool) -> [T; N] { array.sort_via(|a, b| ordering(a, b)) } -pub fn sort_by_counters_asc(array: [T; N]) -> [T; N] where T: Ordered + Eq + Empty { +pub fn sort_by_counters_asc(array: [T; N]) -> [T; N] where T: Ordered + Eq + Empty { sort_by(array, order_by_counters_empty_padded_asc) } -pub fn sort_by_counters_desc(array: [T; N]) -> [T; N] where T: Ordered + Eq + Empty { +pub fn sort_by_counters_desc(array: [T; N]) -> [T; N] where T: Ordered + Eq + Empty { sort_by(array, order_by_counters_empty_padded_desc) } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_order_hints.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_order_hints.nr index 5163b3bc7f78..bbf8d9f0fd1e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_order_hints.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_order_hints.nr @@ -23,7 +23,7 @@ impl Eq for OrderHint { } } -pub fn sort_get_order_hints( +pub fn sort_get_order_hints( array: [T; N], ordering: fn(T, T) -> bool ) -> [OrderHint; N] where T: Ordered + Eq + Empty { @@ -42,11 +42,11 @@ pub fn sort_get_order_hints( hints } -pub fn sort_get_order_hints_asc(array: [T; N]) -> [OrderHint; N] where T: Ordered + Eq + Empty { +pub fn sort_get_order_hints_asc(array: [T; N]) -> [OrderHint; N] where T: Ordered + Eq + Empty { sort_get_order_hints(array, order_by_counters_empty_padded_asc) } -pub fn sort_get_order_hints_desc(array: [T; N]) -> [OrderHint; N] where T: Ordered + Eq + Empty { +pub fn sort_get_order_hints_desc(array: [T; N]) -> [OrderHint; N] where T: Ordered + Eq + Empty { sort_get_order_hints(array, order_by_counters_empty_padded_desc) } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_sorted_hints.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_sorted_hints.nr index 6fdde87227a1..cbbf8c5c76e1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_sorted_hints.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_sorted_hints.nr @@ -3,12 +3,12 @@ use crate::{ utils::arrays::{sort_get_sorted_tuple::{sort_get_sorted_tuple, SortedTuple}} }; -struct SortedResult { +struct SortedResult { sorted_array: [T; N], sorted_index_hints: [u32; N], } -pub fn sort_get_sorted_hints( +pub fn sort_get_sorted_hints( values: [T; N], ordering: fn(T, T) -> bool ) -> SortedResult where T: Eq + Empty { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_sorted_tuple.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_sorted_tuple.nr index 848933a97637..6460a883fedd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_sorted_tuple.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_sorted_tuple.nr @@ -1,9 +1,9 @@ struct SortedTuple { elem: T, - original_index: u64, + original_index: u32, } -pub fn sort_get_sorted_tuple(array: [T; N], ordering: fn[Env](T, T) -> bool) -> [SortedTuple; N] { +pub fn sort_get_sorted_tuple(array: [T; N], ordering: fn[Env](T, T) -> bool) -> [SortedTuple; N] { let mut tuples = [SortedTuple { elem: array[0], original_index: 0 }; N]; for i in 0..N { tuples[i] = SortedTuple { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_split_order_hints.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_split_order_hints.nr index 448e649d4012..1fa12e193fa7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_split_order_hints.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_get_split_order_hints.nr @@ -6,19 +6,19 @@ use crate::{ } }; -struct SplitOrderHints { +struct SplitOrderHints { sorted_counters_lt: [u32; N], sorted_counters_gte: [u32; N], sorted_indexes: [u32; N], } -impl SplitOrderHints { +impl SplitOrderHints { pub fn empty() -> SplitOrderHints { SplitOrderHints { sorted_counters_lt: [0; N], sorted_counters_gte: [0; N], sorted_indexes: [0; N] } } } -impl Eq for SplitOrderHints { +impl Eq for SplitOrderHints { fn eq(self, other: Self) -> bool { (self.sorted_counters_lt == other.sorted_counters_lt) & (self.sorted_counters_gte == other.sorted_counters_gte) @@ -26,7 +26,7 @@ impl Eq for SplitOrderHints { } } -fn sort_get_split_order_hints( +fn sort_get_split_order_hints( array: [T; N], split_counter: u32, ascending: bool @@ -67,14 +67,14 @@ fn sort_get_split_order_hints( SplitOrderHints { sorted_counters_lt, sorted_counters_gte, sorted_indexes } } -pub fn sort_get_split_order_hints_asc( +pub fn sort_get_split_order_hints_asc( array: [T; N], split_counter: u32 ) -> SplitOrderHints where T: Ordered + Eq + Empty { sort_get_split_order_hints(array, split_counter, true) } -pub fn sort_get_split_order_hints_desc( +pub fn sort_get_split_order_hints_desc( array: [T; N], split_counter: u32 ) -> SplitOrderHints where T: Ordered + Eq + Empty { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/field.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/field.nr index 7433a17839c5..c9b4125018c9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/field.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/field.nr @@ -1,4 +1,4 @@ -pub fn field_from_bytes(bytes: [u8; N], big_endian: bool) -> Field { +pub fn field_from_bytes(bytes: [u8; N], big_endian: bool) -> Field { assert(bytes.len() < 32, "field_from_bytes: N must be less than 32"); let mut as_field = 0; let mut offset = 1; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/mod.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/mod.nr index 88624e254760..f81cbafdf323 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/mod.nr @@ -12,7 +12,7 @@ pub fn conditional_assign(predicate: bool, lhs: Field, rhs: Field) -> Field { if predicate { lhs } else { rhs } } -pub fn arr_copy_slice(src: [T; N], mut dst: [T; M], offset: u32) -> [T; M] { +pub fn arr_copy_slice(src: [T; N], mut dst: [T; M], offset: u32) -> [T; M] { let iterator_len = if N > M { M } else { N }; for i in 0..iterator_len { dst[i] = src[i + offset]; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/reader.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/reader.nr index fb5801317a24..f537f0c9bcec 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/reader.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/reader.nr @@ -1,9 +1,9 @@ -struct Reader { +struct Reader { data: [Field; N], offset: u32, } -impl Reader { +impl Reader { pub fn new(data: [Field; N]) -> Self { Self { data, offset: 0 } } @@ -22,7 +22,7 @@ impl Reader { self.read() as bool } - pub fn read_array(&mut self, mut result: [Field; K]) -> [Field; K] { + pub fn read_array(&mut self, mut result: [Field; K]) -> [Field; K] { for i in 0..K { result[i] = self.data[self.offset + i]; } @@ -31,12 +31,12 @@ impl Reader { } // TODO(#4394) - pub fn read_struct(&mut self, deserialise: fn([Field; K]) -> T) -> T { + pub fn read_struct(&mut self, deserialise: fn([Field; K]) -> T) -> T { let result = deserialise(self.read_array([0; K])); result } - pub fn read_struct_array(&mut self, deserialise: fn([Field; K]) -> T, mut result: [T; C]) -> [T; C] { + pub fn read_struct_array(&mut self, deserialise: fn([Field; K]) -> T, mut result: [T; C]) -> [T; C] { for i in 0..C { result[i] = self.read_struct(deserialise); }