diff --git a/yarn-project/aztec-nr/aztec/src/history.nr b/yarn-project/aztec-nr/aztec/src/history.nr index 597196eba97..4fe5f6281cf 100644 --- a/yarn-project/aztec-nr/aztec/src/history.nr +++ b/yarn-project/aztec-nr/aztec/src/history.nr @@ -3,4 +3,4 @@ mod note_inclusion; mod note_validity; mod nullifier_inclusion; mod nullifier_non_inclusion; -mod public_value_inclusion; \ No newline at end of file +mod public_value_inclusion; diff --git a/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr b/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr index 77aa7dc85be..d156618d326 100644 --- a/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr +++ b/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr @@ -23,10 +23,9 @@ pub fn prove_note_commitment_inclusion( // 3) Prove that the commitment is in the note hash tree assert( - block_header.note_hash_tree_root == compute_merkle_root(note_commitment, witness.index, witness.path), - "Proving note inclusion failed" + block_header.note_hash_tree_root + == compute_merkle_root(note_commitment, witness.index, witness.path), "Proving note inclusion failed" ); - // --> Now we have traversed the trees all the way up to archive root. } @@ -39,4 +38,4 @@ pub fn prove_note_inclusion( let note_commitment = compute_unique_siloed_note_hash(note_interface, note_with_header); prove_note_commitment_inclusion(note_commitment, block_number, context); -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/history/note_validity.nr b/yarn-project/aztec-nr/aztec/src/history/note_validity.nr index 47a45547e40..d98a9e87831 100644 --- a/yarn-project/aztec-nr/aztec/src/history/note_validity.nr +++ b/yarn-project/aztec-nr/aztec/src/history/note_validity.nr @@ -16,4 +16,4 @@ pub fn prove_note_validity( ) { prove_note_inclusion(note_interface, note_with_header, block_number, context); prove_note_not_nullified(note_interface, note_with_header, block_number, context); -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr b/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr index fbf194d76d1..882103f7fdf 100644 --- a/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr +++ b/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr @@ -16,15 +16,23 @@ pub fn l1_to_l2_message_getter_len() -> Field { L1_TO_L2_MESSAGE_LENGTH + 1 + L1_TO_L2_MSG_TREE_HEIGHT + 1 } -pub fn make_l1_to_l2_message_getter_data(fields: [Field; N], start: Field, secret: Field) -> L1ToL2MessageGetterData { +pub fn make_l1_to_l2_message_getter_data( + fields: [Field; N], + start: Field, + secret: Field +) -> L1ToL2MessageGetterData { L1ToL2MessageGetterData { - message: L1ToL2Message::deserialize(arr_copy_slice(fields, [0; L1_TO_L2_MESSAGE_LENGTH], start), + message: L1ToL2Message::deserialize( + arr_copy_slice(fields, [0; L1_TO_L2_MESSAGE_LENGTH], start), secret, - fields[start + L1_TO_L2_MESSAGE_LENGTH]), + fields[start + L1_TO_L2_MESSAGE_LENGTH] + ), leaf_index: fields[start + L1_TO_L2_MESSAGE_LENGTH], - sibling_path: arr_copy_slice(fields, + sibling_path: arr_copy_slice( + fields, [0; L1_TO_L2_MSG_TREE_HEIGHT], - L1_TO_L2_MESSAGE_LENGTH + 1), + L1_TO_L2_MESSAGE_LENGTH + 1 + ), root: fields[start + L1_TO_L2_MESSAGE_LENGTH + L1_TO_L2_MSG_TREE_HEIGHT + 1] } } diff --git a/yarn-project/aztec-nr/aztec/src/note/note_getter.nr b/yarn-project/aztec-nr/aztec/src/note/note_getter.nr index 8b59242ba76..15b98f89f30 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_getter.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_getter.nr @@ -16,7 +16,12 @@ use crate::note::{ use crate::oracle; use crate::types::vec::BoundedVec; -fn check_note_header(context: PrivateContext, storage_slot: Field, note_interface: NoteInterface, note: Note) { +fn check_note_header( + context: PrivateContext, + storage_slot: Field, + note_interface: NoteInterface, + note: Note +) { let get_header = note_interface.get_header; let header = get_header(note); let contract_address = context.this_address(); @@ -31,7 +36,11 @@ fn check_note_fields(fields: [Field; N], selects: BoundedVec, } } -fn check_notes_order(fields_0: [Field; N], fields_1: [Field; N], sorts: BoundedVec, N>) { +fn check_notes_order( + fields_0: [Field; N], + fields_1: [Field; N], + sorts: BoundedVec, N> +) { for i in 0..sorts.len { let sort = sorts.get_unchecked(i).unwrap_unchecked(); let eq = fields_0[sort.field_index] == fields_1[sort.field_index]; @@ -44,7 +53,11 @@ fn check_notes_order(fields_0: [Field; N], fields_1: [Field; N], sorts: Bound } } -pub fn get_note(context: &mut PrivateContext, storage_slot: Field, note_interface: NoteInterface) -> Note { +pub fn get_note( + context: &mut PrivateContext, + storage_slot: Field, + note_interface: NoteInterface +) -> Note { let note = get_note_internal(storage_slot, note_interface); check_note_header(*context, storage_slot, note_interface, note); @@ -94,7 +107,8 @@ pub fn get_notes( unconstrained fn get_note_internal(storage_slot: Field, note_interface: NoteInterface) -> Note { let placeholder_note = [Option::none()]; let placeholder_fields = [0; GET_NOTE_ORACLE_RETURN_LENGTH]; - oracle::notes::get_notes(storage_slot, + oracle::notes::get_notes( + storage_slot, note_interface, 0, [], @@ -104,7 +118,8 @@ unconstrained fn get_note_internal(storage_slot: Field, note_interface: 1, // limit 0, // offset placeholder_note, - placeholder_fields)[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular). + placeholder_fields + )[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular). } unconstrained fn get_notes_internal( @@ -115,7 +130,8 @@ unconstrained fn get_notes_internal( let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts); let placeholder_opt_notes = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let placeholder_fields = [0; GET_NOTES_ORACLE_RETURN_LENGTH]; - let opt_notes = oracle::notes::get_notes(storage_slot, + let opt_notes = oracle::notes::get_notes( + storage_slot, note_interface, num_selects, select_by, @@ -125,18 +141,24 @@ unconstrained fn get_notes_internal( options.limit, options.offset, placeholder_opt_notes, - placeholder_fields); + placeholder_fields + ); let filter = options.filter; let filter_args = options.filter_args; filter(opt_notes, filter_args) } -unconstrained pub fn view_notes(storage_slot: Field, note_interface: NoteInterface, options: NoteViewerOptions) -> [Option; MAX_NOTES_PER_PAGE] { +unconstrained pub fn view_notes( + storage_slot: Field, + note_interface: NoteInterface, + options: NoteViewerOptions +) -> [Option; MAX_NOTES_PER_PAGE] { let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts); let placeholder_opt_notes = [Option::none(); MAX_NOTES_PER_PAGE]; let placeholder_fields = [0; VIEW_NOTE_ORACLE_RETURN_LENGTH]; - oracle::notes::get_notes(storage_slot, + oracle::notes::get_notes( + storage_slot, note_interface, num_selects, select_by, @@ -146,10 +168,14 @@ unconstrained pub fn view_notes(storage_slot: Field, note_interface: No options.limit, options.offset, placeholder_opt_notes, - placeholder_fields) + placeholder_fields + ) } -unconstrained fn flatten_options(selects: BoundedVec, N>, sorts: BoundedVec, N>) -> (u8, [u8; N], [Field; N], [u8; N], [u2; N]) { +unconstrained fn flatten_options( + selects: BoundedVec, N>, + sorts: BoundedVec, N> +) -> (u8, [u8; N], [Field; N], [u8; N], [u2; N]) { let mut num_selects = 0; let mut select_by = [0; N]; let mut select_values = [0; N]; diff --git a/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr b/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr index 67dabe8593d..8ceca5eb03e 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr @@ -34,7 +34,10 @@ impl Sort { } } -fn return_all_notes(notes: [Option; MAX_READ_REQUESTS_PER_CALL], _p: Field) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +fn return_all_notes( + notes: [Option; MAX_READ_REQUESTS_PER_CALL], + _p: Field +) -> [Option; MAX_READ_REQUESTS_PER_CALL] { notes } diff --git a/yarn-project/aztec-nr/aztec/src/note/utils.nr b/yarn-project/aztec-nr/aztec/src/note/utils.nr index ac4ab668ad3..d9286fad123 100644 --- a/yarn-project/aztec-nr/aztec/src/note/utils.nr +++ b/yarn-project/aztec-nr/aztec/src/note/utils.nr @@ -70,7 +70,11 @@ pub fn compute_note_hash_for_read_or_nullify(note_interface: NoteInterf } } -pub fn compute_note_hash_and_nullifier(note_interface: NoteInterface, note_header: NoteHeader, serialized_note: [Field; S]) -> [Field; 4] { +pub fn compute_note_hash_and_nullifier( + note_interface: NoteInterface, + note_header: NoteHeader, + serialized_note: [Field; S] +) -> [Field; 4] { let deserialize = note_interface.deserialize; let set_header = note_interface.set_header; let mut note = deserialize(arr_copy_slice(serialized_note, [0; N], 0)); diff --git a/yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr b/yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr index 6250e54b8bb..ce4054e91c6 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr @@ -5,8 +5,16 @@ use dep::protocol_types::{ }; #[oracle(callPrivateFunction)] -fn call_private_function_oracle(_contract_address: AztecAddress, _function_selector: FunctionSelector, _args_hash: Field) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {} +fn call_private_function_oracle( + _contract_address: AztecAddress, + _function_selector: FunctionSelector, + _args_hash: Field +) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {} -unconstrained pub fn call_private_function_internal(contract_address: AztecAddress, function_selector: FunctionSelector, args_hash: Field) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] { +unconstrained pub fn call_private_function_internal( + contract_address: AztecAddress, + function_selector: FunctionSelector, + args_hash: Field +) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] { call_private_function_oracle(contract_address, function_selector, args_hash) } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr b/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr index f18c6a341ea..8259bf2cba0 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr @@ -8,9 +8,9 @@ fn debug_log_format_oracle(_msg: T, _args: [Field; N], _num_args: Field) - #[oracle(debugLog)] fn debug_log_field_oracle(_field: Field) -> Field {} #[oracle(debugLog)] -fn debug_log_array_oracle(_arbitrary_array: [T;N]) -> Field {} +fn debug_log_array_oracle(_arbitrary_array: [T; N]) -> Field {} #[oracle(debugLogWithPrefix)] -fn debug_log_array_with_prefix_oracle(_prefix: S, _arbitrary_array: [T;N]) -> Field {} +fn debug_log_array_with_prefix_oracle(_prefix: S, _arbitrary_array: [T; N]) -> Field {} /// NOTE: call this with a str msg of length > 1 /// Example: diff --git a/yarn-project/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr b/yarn-project/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr index 50fd4bf0d5d..308a75dc5cc 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr @@ -11,8 +11,16 @@ use dep::protocol_types::{ global ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE: Field = 14; #[oracle(enqueuePublicFunctionCall)] -fn enqueue_public_function_call_oracle(_contract_address: AztecAddress, _function_selector: FunctionSelector, _args_hash: Field) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {} +fn enqueue_public_function_call_oracle( + _contract_address: AztecAddress, + _function_selector: FunctionSelector, + _args_hash: Field +) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {} -unconstrained pub fn enqueue_public_function_call_internal(contract_address: AztecAddress, function_selector: FunctionSelector, args_hash: Field) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] { +unconstrained pub fn enqueue_public_function_call_internal( + contract_address: AztecAddress, + function_selector: FunctionSelector, + args_hash: Field +) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] { enqueue_public_function_call_oracle(contract_address, function_selector, args_hash) } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_block_header.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_block_header.nr index 02ace81c360..3977f88108a 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/get_block_header.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_block_header.nr @@ -32,7 +32,9 @@ pub fn get_block_header(block_number: u32, context: PrivateContext) -> BlockHead // 2) Check that the block header block number is more than or equal to the block number we want to prove against // We could not perform the proof otherwise because the archive root from the header would not "contain" the block we want to prove against - assert(block_header_block_number >= block_number, "Block header block number is smaller than the block number we want to prove against"); + assert( + block_header_block_number >= block_number, "Block header block number is smaller than the block number we want to prove against" + ); // 3) Get block header of a given block from oracle let block_header = get_block_header_internal(block_number); @@ -44,7 +46,10 @@ pub fn get_block_header(block_number: u32, context: PrivateContext) -> BlockHead let witness = get_archive_membership_witness(block_header_block_number, block_hash); // 6) Check that the block is in the archive (i.e. the witness is valid) - assert(context.block_header.archive_root == compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in archive failed"); + assert( + context.block_header.archive_root + == compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in archive failed" + ); // 7) Return the block header block_header diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_membership_witness.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_membership_witness.nr index 3e988397cab..d0ae5e8608b 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/get_membership_witness.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_membership_witness.nr @@ -29,19 +29,28 @@ unconstrained pub fn get_membership_witness(block_number: u32, tree_id: Fi MembershipWitness { index: fields[0], path: arr_copy_slice(fields, [0; N], 1) } } -unconstrained pub fn get_contract_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness { +unconstrained pub fn get_contract_membership_witness( + block_number: u32, + leaf_value: Field +) -> MembershipWitness { get_membership_witness(block_number, CONTRACT_TREE_ID, leaf_value) } // Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr -unconstrained pub fn get_note_hash_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness { +unconstrained pub fn get_note_hash_membership_witness( + block_number: u32, + leaf_value: Field +) -> MembershipWitness { get_membership_witness(block_number, NOTE_HASH_TREE_ID, leaf_value) } // There is no `get_public_data_membership_witness` function because it doesn't make sense to be getting a membership // witness for a value in the public data tree. -unconstrained pub fn get_archive_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness { +unconstrained pub fn get_archive_membership_witness( + block_number: u32, + leaf_value: Field +) -> MembershipWitness { get_membership_witness(block_number, ARCHIVE_TREE_ID, leaf_value) } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/notes.nr b/yarn-project/aztec-nr/aztec/src/oracle/notes.nr index 47985474754..88664e64dc8 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/notes.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/notes.nr @@ -47,7 +47,8 @@ unconstrained fn get_notes_oracle_wrapper( mut placeholder_fields: [Field; S] ) -> [Field; S] { let return_size = placeholder_fields.len() as u32; - get_notes_oracle(storage_slot, + get_notes_oracle( + storage_slot, num_selects, select_by, select_values, @@ -56,7 +57,8 @@ unconstrained fn get_notes_oracle_wrapper( limit, offset, return_size, - placeholder_fields) + placeholder_fields + ) } unconstrained pub fn get_notes( @@ -72,7 +74,8 @@ unconstrained pub fn get_notes( mut placeholder_opt_notes: [Option; S], // TODO: Remove it and use `limit` to initialize the note array. placeholder_fields: [Field; NS] // TODO: Remove it and use `limit` to initialize the note array. ) -> [Option; S] { - let fields = get_notes_oracle_wrapper(storage_slot, + let fields = get_notes_oracle_wrapper( + storage_slot, num_selects, select_by, select_values, @@ -80,7 +83,8 @@ unconstrained pub fn get_notes( sort_order, limit, offset, - placeholder_fields); + placeholder_fields + ); let num_notes = fields[0] as u32; let contract_address = AztecAddress::from_field(fields[1]); let deserialize = note_interface.deserialize; diff --git a/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr b/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr index 0b380bb264d..0bc81973675 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr @@ -5,8 +5,16 @@ use dep::protocol_types::{ }; #[oracle(callPublicFunction)] -fn call_public_function_oracle(_contract_address: AztecAddress, _function_selector: FunctionSelector, _args_hash: Field) -> [Field; RETURN_VALUES_LENGTH] {} +fn call_public_function_oracle( + _contract_address: AztecAddress, + _function_selector: FunctionSelector, + _args_hash: Field +) -> [Field; RETURN_VALUES_LENGTH] {} -unconstrained pub fn call_public_function_internal(contract_address: AztecAddress, function_selector: FunctionSelector, args_hash: Field) -> [Field; RETURN_VALUES_LENGTH] { +unconstrained pub fn call_public_function_internal( + contract_address: AztecAddress, + function_selector: FunctionSelector, + args_hash: Field +) -> [Field; RETURN_VALUES_LENGTH] { call_public_function_oracle(contract_address, function_selector, args_hash) } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/storage.nr b/yarn-project/aztec-nr/aztec/src/oracle/storage.nr index b2c2c434c1f..abb7766ba91 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/storage.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/storage.nr @@ -5,7 +5,7 @@ unconstrained fn storage_read_oracle_wrapper(_storage_slot: Field) -> [Field; storage_read_oracle(_storage_slot, N) } -pub fn storage_read(storage_slot: Field, deserialize: fn ([Field; N]) -> T) -> T { +pub fn storage_read(storage_slot: Field, deserialize: fn([Field; N]) -> T) -> T { let fields = storage_read_oracle_wrapper(storage_slot); deserialize(fields) } diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr b/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr index 2fa991f125e..e87555d5a82 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr @@ -2,7 +2,7 @@ use dep::std::option::Option; use dep::protocol_types::{ address::AztecAddress, }; - + use crate::context::{PrivateContext, Context}; use crate::note::{ lifecycle::create_note, diff --git a/yarn-project/aztec-nr/aztec/src/types/type_serialization/address_serialization.nr b/yarn-project/aztec-nr/aztec/src/types/type_serialization/address_serialization.nr index 0441f5b9e2f..4994bdc0437 100644 --- a/yarn-project/aztec-nr/aztec/src/types/type_serialization/address_serialization.nr +++ b/yarn-project/aztec-nr/aztec/src/types/type_serialization/address_serialization.nr @@ -19,4 +19,4 @@ fn serialize(value: AztecAddress) -> [Field; AZTEC_ADDRESS_SERIALIZED_LEN] { global AddressSerializationMethods = TypeSerializationInterface { deserialize, serialize, -}; \ No newline at end of file +}; diff --git a/yarn-project/aztec-nr/field-note/src/field_note.nr b/yarn-project/aztec-nr/field-note/src/field_note.nr index 6e0e133476c..6267a7b6016 100644 --- a/yarn-project/aztec-nr/field-note/src/field_note.nr +++ b/yarn-project/aztec-nr/field-note/src/field_note.nr @@ -76,7 +76,9 @@ fn set_header(note: &mut FieldNote, header: NoteHeader) { } fn broadcast(context: &mut PrivateContext, slot: Field, note: FieldNote) { - assert(false, "FieldNote does not support broadcast. Add it to PXE directly using the `.addNote` function."); + assert( + false, "FieldNote does not support broadcast. Add it to PXE directly using the `.addNote` function." + ); } global FieldNoteMethods = NoteInterface { diff --git a/yarn-project/aztec-nr/value-note/src/filter.nr b/yarn-project/aztec-nr/value-note/src/filter.nr index bd0d3025772..46d3d4ecb2f 100644 --- a/yarn-project/aztec-nr/value-note/src/filter.nr +++ b/yarn-project/aztec-nr/value-note/src/filter.nr @@ -2,7 +2,10 @@ use dep::std::option::Option; use dep::protocol_types::constants::MAX_READ_REQUESTS_PER_CALL; use crate::value_note::ValueNote; -pub fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CALL], min_sum: Field) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_notes_min_sum( + notes: [Option; MAX_READ_REQUESTS_PER_CALL], + min_sum: Field +) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut sum = 0; for i in 0..notes.len() { diff --git a/yarn-project/aztec-nr/value-note/src/utils.nr b/yarn-project/aztec-nr/value-note/src/utils.nr index 889f9a05489..76fcfd217b4 100644 --- a/yarn-project/aztec-nr/value-note/src/utils.nr +++ b/yarn-project/aztec-nr/value-note/src/utils.nr @@ -40,7 +40,11 @@ pub fn decrement(balance: Set, amount: Field, owner: // equal `amount`. // // It returns the decremented amount, which should be less than or equal to max_amount. -pub fn decrement_by_at_most(balance: Set, max_amount: Field, owner: AztecAddress) -> Field { +pub fn decrement_by_at_most( + balance: Set, + max_amount: Field, + owner: AztecAddress +) -> Field { let options = create_note_getter_options_for_decreasing_balance(max_amount); let opt_notes = balance.get_notes(options); @@ -64,7 +68,11 @@ pub fn decrement_by_at_most(balance: Set, max_amount: // Removes the note from the owner's set of notes. // Returns the value of the destroyed note. -pub fn destroy_note(balance: Set, owner: AztecAddress, note: ValueNote) -> Field { +pub fn destroy_note( + balance: Set, + owner: AztecAddress, + note: ValueNote +) -> Field { // Ensure the note is actually owned by the owner (to prevent user from generating a valid proof while // spending someone else's notes). assert(note.owner.eq(owner)); diff --git a/yarn-project/noir-compiler/src/fixtures/test_lib/src/lib.nr b/yarn-project/noir-compiler/src/fixtures/test_lib/src/lib.nr index 5c0b5a621e0..144bcec0532 100644 --- a/yarn-project/noir-compiler/src/fixtures/test_lib/src/lib.nr +++ b/yarn-project/noir-compiler/src/fixtures/test_lib/src/lib.nr @@ -1 +1 @@ -mod module; \ No newline at end of file +mod module; diff --git a/yarn-project/noir-compiler/src/fixtures/test_lib/src/module.nr b/yarn-project/noir-compiler/src/fixtures/test_lib/src/module.nr index 2746c97edf0..f4ad3bff5c9 100644 --- a/yarn-project/noir-compiler/src/fixtures/test_lib/src/module.nr +++ b/yarn-project/noir-compiler/src/fixtures/test_lib/src/module.nr @@ -1 +1 @@ -mod foo; \ No newline at end of file +mod foo; diff --git a/yarn-project/noir-compiler/src/fixtures/test_lib/src/module/foo.nr b/yarn-project/noir-compiler/src/fixtures/test_lib/src/module/foo.nr index e0c82fb1960..0376cd4cb87 100644 --- a/yarn-project/noir-compiler/src/fixtures/test_lib/src/module/foo.nr +++ b/yarn-project/noir-compiler/src/fixtures/test_lib/src/module/foo.nr @@ -1,3 +1,3 @@ pub fn bar(param: Field) -> Field { - dep::std::hash::pedersen_hash([param]) + dep::std::hash::pedersen_hash([param]) } diff --git a/yarn-project/noir-contracts/contracts/card_game_contract/src/game.nr b/yarn-project/noir-contracts/contracts/card_game_contract/src/game.nr index c3aba855f4b..a6b61fa7db4 100644 --- a/yarn-project/noir-contracts/contracts/card_game_contract/src/game.nr +++ b/yarn-project/noir-contracts/contracts/card_game_contract/src/game.nr @@ -33,8 +33,16 @@ global GAME_SERIALIZED_LEN: Field = 15; fn deserializeGame(fields: [Field; GAME_SERIALIZED_LEN]) -> Game { let players = [ - PlayerEntry { address: AztecAddress::from_field(fields[0]), deck_strength: fields[1] as u32, points: fields[2] as u120 }, - PlayerEntry { address: AztecAddress::from_field(fields[3]), deck_strength: fields[4] as u32, points: fields[5] as u120 } + PlayerEntry { + address: AztecAddress::from_field(fields[0]), + deck_strength: fields[1] as u32, + points: fields[2] as u120 + }, + PlayerEntry { + address: AztecAddress::from_field(fields[3]), + deck_strength: fields[4] as u32, + points: fields[5] as u120 + } ]; let rounds_cards = [ Card::from_field(fields[6]), Card::from_field(fields[7]), diff --git a/yarn-project/noir-contracts/contracts/child_contract/src/main.nr b/yarn-project/noir-contracts/contracts/child_contract/src/main.nr index cc8a29e276e..92203904a12 100644 --- a/yarn-project/noir-contracts/contracts/child_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/child_contract/src/main.nr @@ -40,7 +40,9 @@ contract Child { } fn check_sender(call_context: CallContext) { - assert(call_context.msg_sender.eq(call_context.storage_contract_address), "Sender must be this contract"); + assert( + call_context.msg_sender.eq(call_context.storage_contract_address), "Sender must be this contract" + ); } // Returns a sum of the input and the chain id and version of the contract in private circuit public input's return_values. @@ -112,7 +114,12 @@ contract Child { } // TODO: remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented - unconstrained fn compute_note_hash_and_nullifier(contract_address: AztecAddress, nonce: Field, storage_slot: Field, serialized_note: [Field; 0]) -> pub [Field; 4] { + unconstrained fn compute_note_hash_and_nullifier( + contract_address: AztecAddress, + nonce: Field, + storage_slot: Field, + serialized_note: [Field; 0] + ) -> pub [Field; 4] { [0, 0, 0, 0] } } diff --git a/yarn-project/noir-contracts/contracts/docs_example_contract/src/actions.nr b/yarn-project/noir-contracts/contracts/docs_example_contract/src/actions.nr index a542a422838..88f7a9422a1 100644 --- a/yarn-project/noir-contracts/contracts/docs_example_contract/src/actions.nr +++ b/yarn-project/noir-contracts/contracts/docs_example_contract/src/actions.nr @@ -113,7 +113,10 @@ pub fn get_cards( // docs:end:state_vars-SetGet // docs:start:state_vars-SetView -unconstrained pub fn view_cards(state_var: Set, options: NoteViewerOptions) -> [Option; MAX_NOTES_PER_PAGE] { +unconstrained pub fn view_cards( + state_var: Set, + options: NoteViewerOptions +) -> [Option; MAX_NOTES_PER_PAGE] { state_var.view_notes(options) } // docs:end:state_vars-SetView @@ -134,13 +137,20 @@ unconstrained pub fn get_total_points(state_var: Set, a } // docs:start:state_vars-MapAtSingletonInit -pub fn add_new_profile(state_var: Map>, account: AztecAddress, profile: &mut ProfileNote) { +pub fn add_new_profile( + state_var: Map>, + account: AztecAddress, + profile: &mut ProfileNote +) { state_var.at(account.to_field()).initialize(profile, Option::some(account), true); } // docs:end:state_vars-MapAtSingletonInit // docs:start:state_vars-MapAtSingletonGet -pub fn get_profile(state_var: Map>, account: AztecAddress) -> ProfileNote { +pub fn get_profile( + state_var: Map>, + account: AztecAddress +) -> ProfileNote { state_var.at(account.to_field()).get_note(true) } // docs:end:state_vars-MapAtSingletonGet diff --git a/yarn-project/noir-contracts/contracts/docs_example_contract/src/options.nr b/yarn-project/noir-contracts/contracts/docs_example_contract/src/options.nr index 3a93fc918db..c389ed1a7f1 100644 --- a/yarn-project/noir-contracts/contracts/docs_example_contract/src/options.nr +++ b/yarn-project/noir-contracts/contracts/docs_example_contract/src/options.nr @@ -7,19 +7,29 @@ use dep::aztec::note::note_getter_options::{NoteGetterOptions, Sort, SortOrder}; use dep::std::option::Option; // docs:start:state_vars-NoteGetterOptionsSelectSortOffset -pub fn create_account_card_getter_options(account: AztecAddress, offset: u32) -> NoteGetterOptions { +pub fn create_account_card_getter_options( + account: AztecAddress, + offset: u32 +) -> NoteGetterOptions { NoteGetterOptions::new().select(2, account.to_field()).sort(0, SortOrder.DESC).set_offset(offset) } // docs:end:state_vars-NoteGetterOptionsSelectSortOffset // docs:start:state_vars-NoteGetterOptionsMultiSelects -pub fn create_exact_card_getter_options(points: u8, secret: Field, account: AztecAddress) -> NoteGetterOptions { +pub fn create_exact_card_getter_options( + points: u8, + secret: Field, + account: AztecAddress +) -> NoteGetterOptions { NoteGetterOptions::new().select(0, points as Field).select(1, secret).select(2, account.to_field()) } // docs:end:state_vars-NoteGetterOptionsMultiSelects // docs:start:state_vars-OptionFilter -pub fn filter_min_points(cards: [Option; MAX_READ_REQUESTS_PER_CALL], min_points: u8) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_min_points( + cards: [Option; MAX_READ_REQUESTS_PER_CALL], + min_points: u8 +) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected_cards = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut num_selected = 0; for i in 0..cards.len() { diff --git a/yarn-project/noir-contracts/contracts/import_test_contract/src/main.nr b/yarn-project/noir-contracts/contracts/import_test_contract/src/main.nr index bbaff182363..d13468f75a5 100644 --- a/yarn-project/noir-contracts/contracts/import_test_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/import_test_contract/src/main.nr @@ -24,22 +24,24 @@ contract ImportTest { #[aztec(private)] fn main(target: AztecAddress) -> Field { let test_contract_instance = TestPrivateContextInterface::at(target); - let return_values = test_contract_instance.test_code_gen(&mut context, + let return_values = test_contract_instance.test_code_gen( + &mut context, 1, true, 1 as u32, [1, 2], AStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, ADeepStructTestCodeGenStruct { - a_field: 1, - a_bool: true, - a_note: ANoteADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, - many_notes: [ - ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, - ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, - ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 } - ] - }); + a_field: 1, + a_bool: true, + a_note: ANoteADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, + many_notes: [ + ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, + ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, + ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 } + ] + } + ); return_values[0] } diff --git a/yarn-project/noir-contracts/contracts/lending_contract/src/helpers.nr b/yarn-project/noir-contracts/contracts/lending_contract/src/helpers.nr index 26592ff6d66..63e72fc7aa2 100644 --- a/yarn-project/noir-contracts/contracts/lending_contract/src/helpers.nr +++ b/yarn-project/noir-contracts/contracts/lending_contract/src/helpers.nr @@ -15,7 +15,13 @@ pub fn compute_identifier(secret: Field, on_behalf_of: Field, self: Field) -> Fi } } -pub fn covered_by_collateral(price: u120, loan_to_value: u120, collateral: u120, increase: u120, decrease: u120) -> u120 { +pub fn covered_by_collateral( + price: u120, + loan_to_value: u120, + collateral: u120, + increase: u120, + decrease: u120 +) -> u120 { let price_precision = SafeU120 { value: 1000000000 }; let ltv_precision = SafeU120 { value: 10000 }; @@ -34,7 +40,12 @@ struct DebtReturn { static_debt: u120, } -pub fn debt_updates(interest_accumulator: u120, static_debt: u120, increase: u120, decrease: u120) -> DebtReturn { +pub fn debt_updates( + interest_accumulator: u120, + static_debt: u120, + increase: u120, + decrease: u120 +) -> DebtReturn { assert(interest_accumulator > 0); let accumulator_precision = SafeU120 { value: 1000000000 }; diff --git a/yarn-project/noir-contracts/contracts/parent_contract/src/main.nr b/yarn-project/noir-contracts/contracts/parent_contract/src/main.nr index 210216694b7..785aac2e03b 100644 --- a/yarn-project/noir-contracts/contracts/parent_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/parent_contract/src/main.nr @@ -20,7 +20,11 @@ contract Parent { // Public function to directly call another public function to the targetContract using the selector and value provided #[aztec(public)] - fn pubEntryPoint(targetContract: AztecAddress, targetSelector: FunctionSelector, initValue: Field) -> Field { + fn pubEntryPoint( + targetContract: AztecAddress, + targetSelector: FunctionSelector, + initValue: Field + ) -> Field { let return_values = context.call_public_function(targetContract, targetSelector, [initValue]); return_values[0] @@ -28,7 +32,11 @@ contract Parent { // Same as pubEntryPoint, but calls the target contract twice, using the return value from the first invocation as the argument for the second. #[aztec(public)] - fn pubEntryPointTwice(targetContract: AztecAddress, targetSelector: FunctionSelector, initValue: Field) -> Field { + fn pubEntryPointTwice( + targetContract: AztecAddress, + targetSelector: FunctionSelector, + initValue: Field + ) -> Field { let returnValue = context.call_public_function(targetContract, targetSelector, [initValue])[0]; let return_values = context.call_public_function(targetContract, targetSelector, [returnValue]); @@ -37,7 +45,11 @@ contract Parent { // Private function to enqueue a call to the targetContract address using the selector and argument provided #[aztec(private)] - fn enqueueCallToChild(targetContract: AztecAddress, targetSelector: FunctionSelector, targetValue: Field) { + fn enqueueCallToChild( + targetContract: AztecAddress, + targetSelector: FunctionSelector, + targetValue: Field + ) { context.call_public_function(targetContract, targetSelector, [targetValue]); } @@ -53,7 +65,8 @@ contract Parent { let _ret = context.call_private_function( context.this_address(), enqueueCallToChildSelector, - [targetContract.to_field(), targetSelector.to_field(), 10]); + [targetContract.to_field(), targetSelector.to_field(), 10] + ); context.call_public_function(targetContract, targetSelector, [20]); } @@ -61,18 +74,26 @@ contract Parent { // - one issued directly from this function with value 20, // - followed by one through a nested call to enqueueCallToChild with value 10. #[aztec(private)] - fn enqueueCallsToChildWithNestedLast(targetContract: AztecAddress, targetSelector: FunctionSelector) { + fn enqueueCallsToChildWithNestedLast( + targetContract: AztecAddress, + targetSelector: FunctionSelector + ) { context.call_public_function(targetContract, targetSelector, [20]); let enqueueCallToChildSelector = FunctionSelector::from_signature("enqueueCallToChild((Field),(u32),Field)"); let _ret = context.call_private_function( context.this_address(), enqueueCallToChildSelector, - [targetContract.to_field(), targetSelector.to_field(), 10]); + [targetContract.to_field(), targetSelector.to_field(), 10] + ); } // Private function to enqueue a call to the targetContract address using the selector and argument provided #[aztec(private)] - fn enqueueCallToChildTwice(targetContract: AztecAddress, targetSelector: FunctionSelector, targetValue: Field) { + fn enqueueCallToChildTwice( + targetContract: AztecAddress, + targetSelector: FunctionSelector, + targetValue: Field + ) { // Enqueue the first public call context.call_public_function(targetContract, targetSelector, [targetValue]); // Enqueue the second public call @@ -88,9 +109,11 @@ contract Parent { ) { let pubEntryPointSelector = FunctionSelector::from_signature("pubEntryPoint((Field),(u32),Field)"); let thisAddress = context.this_address(); - let _void = context.call_public_function(thisAddress, + let _void = context.call_public_function( + thisAddress, pubEntryPointSelector, - [targetContract.to_field(), targetSelector.to_field(), targetValue]); + [targetContract.to_field(), targetSelector.to_field(), targetValue] + ); } // Private function to enqueue two calls to the pubEntryPoint function of this same contract, passing the target arguments provided @@ -103,12 +126,16 @@ contract Parent { let pubEntryPointSelector = FunctionSelector::from_signature("pubEntryPoint((Field),(u32),Field)"); let thisAddress = context.this_address(); - context.call_public_function(thisAddress, + context.call_public_function( + thisAddress, pubEntryPointSelector, - [targetContract.to_field(), targetSelector.to_field(), targetValue]); + [targetContract.to_field(), targetSelector.to_field(), targetValue] + ); - context.call_public_function(thisAddress, + context.call_public_function( + thisAddress, pubEntryPointSelector, - [targetContract.to_field(), targetSelector.to_field(), targetValue + 1]); + [targetContract.to_field(), targetSelector.to_field(), targetValue + 1] + ); } } diff --git a/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index 579dceff555..86bf2dbf10d 100644 --- a/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -69,7 +69,12 @@ impl PublicKeyNote { } fn deserialize(serialized_note: [Field; PUBLIC_KEY_NOTE_LEN]) -> PublicKeyNote { - PublicKeyNote { x: serialized_note[0], y: serialized_note[1], owner: AztecAddress::from_field(serialized_note[2]), header: NoteHeader::empty() } + PublicKeyNote { + x: serialized_note[0], + y: serialized_note[1], + owner: AztecAddress::from_field(serialized_note[2]), + header: NoteHeader::empty() + } } fn serialize(note: PublicKeyNote) -> [Field; PUBLIC_KEY_NOTE_LEN] { diff --git a/yarn-project/noir-contracts/contracts/test_contract/src/interface.nr b/yarn-project/noir-contracts/contracts/test_contract/src/interface.nr index 40d6de7b70a..cf1657905c2 100644 --- a/yarn-project/noir-contracts/contracts/test_contract/src/interface.nr +++ b/yarn-project/noir-contracts/contracts/test_contract/src/interface.nr @@ -1,5 +1,5 @@ /* Autogenerated file, do not edit! */ - + use dep::std; use dep::aztec::context::{ PrivateContext, PublicContext }; use dep::protocol_types::{ @@ -50,7 +50,6 @@ struct CancellerConsumeMintPublicMessageStruct { inner: Field, } - // Interface for calling Test functions from a private context struct TestPrivateContextInterface { address: AztecAddress, @@ -266,9 +265,6 @@ impl TestPrivateContextInterface { } } - - - // Interface for calling Test functions from a public context struct TestPublicContextInterface { @@ -354,5 +350,4 @@ impl TestPublicContextInterface { } } - - + diff --git a/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/types/balance_set.nr b/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/types/balance_set.nr index 38ca7bb8400..10d4228b0e5 100644 --- a/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/types/balance_set.nr +++ b/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/types/balance_set.nr @@ -112,7 +112,10 @@ impl BalanceSet { } } -pub fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CALL], min_sum: SafeU120) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_notes_min_sum( + notes: [Option; MAX_READ_REQUESTS_PER_CALL], + min_sum: SafeU120 +) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut sum = SafeU120::min(); for i in 0..notes.len() { diff --git a/yarn-project/noir-contracts/contracts/token_contract/src/types/balance_set.nr b/yarn-project/noir-contracts/contracts/token_contract/src/types/balance_set.nr index a5c00d81967..d9273f97682 100644 --- a/yarn-project/noir-contracts/contracts/token_contract/src/types/balance_set.nr +++ b/yarn-project/noir-contracts/contracts/token_contract/src/types/balance_set.nr @@ -114,7 +114,10 @@ impl BalanceSet { } } -pub fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CALL], min_sum: SafeU120) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_notes_min_sum( + notes: [Option; MAX_READ_REQUESTS_PER_CALL], + min_sum: SafeU120 +) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut sum = SafeU120::min(); for i in 0..notes.len() { diff --git a/yarn-project/noir-contracts/contracts/uniswap_contract/src/interfaces.nr b/yarn-project/noir-contracts/contracts/uniswap_contract/src/interfaces.nr index c6d7b3b90e0..f59cc94284a 100644 --- a/yarn-project/noir-contracts/contracts/uniswap_contract/src/interfaces.nr +++ b/yarn-project/noir-contracts/contracts/uniswap_contract/src/interfaces.nr @@ -1,5 +1,5 @@ // docs:start:interfaces - use dep::protocol_types::{ +use dep::protocol_types::{ abis::function_selector::FunctionSelector, address::{ AztecAddress, diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr index 7ce6caf57a0..de3b83f9534 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -79,7 +79,6 @@ impl PrivateKernelInputsInner { } } - mod tests { use crate::private_kernel_inner::PrivateKernelInputsInner; use dep::types::constants::{ @@ -233,10 +232,7 @@ mod tests { builder.previous_kernel.push_private_call_request(hash + 1, false); let previous_kernel = builder.previous_kernel.finish(); - let kernel = PrivateKernelInputsInner { - previous_kernel, - private_call, - }; + let kernel = PrivateKernelInputsInner { previous_kernel, private_call }; let _ = kernel.native_private_kernel_circuit_inner(); } @@ -260,7 +256,7 @@ mod tests { builder.failed(); } - + #[test] fn delegate_call_succeeds() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_delegate_call(); @@ -278,10 +274,7 @@ mod tests { builder.previous_kernel.push_private_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.finish(); - let kernel = PrivateKernelInputsInner { - previous_kernel, - private_call, - }; + let kernel = PrivateKernelInputsInner { previous_kernel, private_call }; let _ = kernel.native_private_kernel_circuit_inner(); } @@ -458,15 +451,12 @@ mod tests { fn input_validation_malformed_arrays_read_requests() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.read_requests.push_array([ - SideEffect { - value: 0, - counter: 0 - }, - SideEffect { - value: 9123, - counter: 1, - }]); + builder.private_call.public_inputs.read_requests.push_array( + [ + SideEffect { value: 0, counter: 0 }, + SideEffect { value: 9123, counter: 1 } + ] + ); builder.failed(); } @@ -475,14 +465,12 @@ mod tests { fn input_validation_malformed_arrays_commitments() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.new_commitments.push_array([ - SideEffect { - value: 0, - counter: 0}, - SideEffect { - value: 9123, - counter: 1, - }]); + builder.private_call.public_inputs.new_commitments.push_array( + [ + SideEffect { value: 0, counter: 0 }, + SideEffect { value: 9123, counter: 1 } + ] + ); builder.failed(); } @@ -491,17 +479,13 @@ mod tests { fn input_validation_malformed_arrays_nullifiers() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.new_nullifiers.push_array([ - SideEffectLinkedToNoteHash { - value: 0, - note_hash: 0, - counter: 0}, - SideEffectLinkedToNoteHash { - value: 12, - note_hash: 0, - counter: 1, - }]); - + builder.private_call.public_inputs.new_nullifiers.push_array( + [ + SideEffectLinkedToNoteHash { value: 0, note_hash: 0, counter: 0 }, + SideEffectLinkedToNoteHash { value: 12, note_hash: 0, counter: 1 } + ] + ); + builder.failed(); } @@ -510,7 +494,7 @@ mod tests { let mut builder = PrivateKernelInnerInputsBuilder::new(); builder.private_call.public_inputs.private_call_stack_hashes.push_array([0, 888]); - + builder.failed(); } @@ -519,7 +503,7 @@ mod tests { let mut builder = PrivateKernelInnerInputsBuilder::new(); builder.private_call.public_inputs.public_call_stack_hashes.push_array([0, 888]); - + builder.failed(); } @@ -528,7 +512,7 @@ mod tests { let mut builder = PrivateKernelInnerInputsBuilder::new(); builder.private_call.public_inputs.new_l2_to_l1_msgs.push_array([0, 888]); - + builder.failed(); } @@ -537,10 +521,7 @@ mod tests { let mut builder = PrivateKernelInnerInputsBuilder::new(); // The current call stack has 1 commitment; - builder.private_call.public_inputs.new_commitments.push(SideEffect { - value: 4321, - counter: 0 - }); + builder.private_call.public_inputs.new_commitments.push(SideEffect { value: 4321, counter: 0 }); // Mock the previous new commitments to be full, therefore no more commitments can be added. let mut full_new_commitments = [SideEffect::empty(); MAX_NEW_COMMITMENTS_PER_TX]; @@ -551,7 +532,7 @@ mod tests { }; } builder.previous_kernel.end.new_commitments.push_array(full_new_commitments); - + builder.failed(); } @@ -590,11 +571,7 @@ mod tests { // tweak read_request so it gives wrong root when paired with its sibling path let read_request = builder.private_call.public_inputs.read_requests.pop(); - builder.private_call.public_inputs.read_requests.push( - SideEffect { - value: read_request.value + 1, - counter: read_request.counter, - }); + builder.private_call.public_inputs.read_requests.push(SideEffect { value: read_request.value + 1, counter: read_request.counter }); builder.failed(); } @@ -723,7 +700,9 @@ mod tests { let public_inputs = builder.execute(); // non-transient read requests are NOT forwarded - assert_eq(struct_array_length(public_inputs.end.read_requests, |r: SideEffect| r.is_empty()), MAX_READ_REQUESTS_PER_CALL); + assert_eq( + struct_array_length(public_inputs.end.read_requests, |r: SideEffect| r.is_empty()), MAX_READ_REQUESTS_PER_CALL + ); } #[test] @@ -744,12 +723,19 @@ mod tests { let prev_unencrypted_logs_hash = [956, 112]; let prev_unencrypted_log_preimages_length = 24; builder.previous_kernel.set_encrypted_logs(prev_encrypted_logs_hash, prev_encrypted_log_preimages_length); - builder.previous_kernel.set_unencrypted_logs(prev_unencrypted_logs_hash, prev_unencrypted_log_preimages_length); + builder.previous_kernel.set_unencrypted_logs( + prev_unencrypted_logs_hash, + prev_unencrypted_log_preimages_length + ); let public_inputs = builder.execute(); - assert_eq(public_inputs.end.encrypted_log_preimages_length, encrypted_log_preimages_length + prev_encrypted_log_preimages_length); - assert_eq(public_inputs.end.unencrypted_log_preimages_length, unencrypted_log_preimages_length + prev_unencrypted_log_preimages_length); + assert_eq( + public_inputs.end.encrypted_log_preimages_length, encrypted_log_preimages_length + prev_encrypted_log_preimages_length + ); + assert_eq( + public_inputs.end.unencrypted_log_preimages_length, unencrypted_log_preimages_length + prev_unencrypted_log_preimages_length + ); let expected_encrypted_logs_hash = compute_logs_hash(prev_encrypted_logs_hash, encrypted_logs_hash); assert_eq(public_inputs.end.encrypted_logs_hash, expected_encrypted_logs_hash); @@ -762,10 +748,7 @@ mod tests { fn creating_new_commitments_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); - builder.private_call.public_inputs.new_commitments.push(SideEffect{ - value: 1, - counter: 0, - }); + builder.private_call.public_inputs.new_commitments.push(SideEffect { value: 1, counter: 0 }); builder.failed(); } @@ -774,11 +757,7 @@ mod tests { fn creating_new_nullifiers_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); - builder.private_call.public_inputs.new_nullifiers.push(SideEffectLinkedToNoteHash{ - value: 1, - note_hash: 0, - counter: 0, - }); + builder.private_call.public_inputs.new_nullifiers.push(SideEffectLinkedToNoteHash { value: 1, note_hash: 0, counter: 0 }); builder.failed(); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-ordering-simulated/src/main.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-ordering-simulated/src/main.nr index 658eaefd334..1e9fd7c6b41 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-ordering-simulated/src/main.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-ordering-simulated/src/main.nr @@ -1,6 +1,6 @@ use dep::private_kernel_lib::PrivateKernelInputsOrdering; use dep::types::KernelCircuitPublicInputsFinal; -unconstrained fn main(input : PrivateKernelInputsOrdering) -> distinct pub KernelCircuitPublicInputsFinal { +unconstrained fn main(input: PrivateKernelInputsOrdering) -> distinct pub KernelCircuitPublicInputsFinal { input.native_private_kernel_circuit_ordering() } diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-ordering/src/main.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-ordering/src/main.nr index 2335f90caa1..e75f866e03e 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-ordering/src/main.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-ordering/src/main.nr @@ -1,6 +1,6 @@ use dep::private_kernel_lib::PrivateKernelInputsOrdering; use dep::types::KernelCircuitPublicInputsFinal; -fn main(input : PrivateKernelInputsOrdering) -> distinct pub KernelCircuitPublicInputsFinal { +fn main(input: PrivateKernelInputsOrdering) -> distinct pub KernelCircuitPublicInputsFinal { input.native_private_kernel_circuit_ordering() } diff --git a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/hash.nr b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/hash.nr index 999d10d1eb6..531fc8f8077 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/hash.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/hash.nr @@ -4,14 +4,17 @@ use dep::types::{ }; pub fn compute_public_data_tree_index(contract_address: AztecAddress, storage_slot: Field) -> Field { - dep::std::hash::pedersen_hash_with_separator([ + dep::std::hash::pedersen_hash_with_separator( + [ contract_address.to_field(), storage_slot - ], GENERATOR_INDEX__PUBLIC_LEAF_INDEX) + ], + GENERATOR_INDEX__PUBLIC_LEAF_INDEX + ) } pub fn compute_public_data_tree_value(value: Field) -> Field { // as it's a public value, it doesn't require hashing. // leaving this function here in case we decide to change this. value -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.nr b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.nr index eafedd0cdfe..7a78633c2e6 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.nr @@ -264,10 +264,7 @@ mod tests { builder.previous_kernel.push_public_call_request(hash + 1, false); let previous_kernel = builder.previous_kernel.finish(); - let kernel = PublicKernelPrivatePreviousInputs { - previous_kernel, - public_call, - }; + let kernel = PublicKernelPrivatePreviousInputs { previous_kernel, public_call }; let _ = kernel.public_kernel_private_previous(); } @@ -309,10 +306,7 @@ mod tests { builder.previous_kernel.push_public_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.finish(); - let kernel = PublicKernelPrivatePreviousInputs { - previous_kernel, - public_call, - }; + let kernel = PublicKernelPrivatePreviousInputs { previous_kernel, public_call }; let _ = kernel.public_kernel_private_previous(); } @@ -409,8 +403,8 @@ mod tests { NewContractData { contract_address: AztecAddress::from_field(123), portal_contract_address: EthAddress::from_field(456), - function_tree_root: 78, - }, + function_tree_root: 78 + } ]; builder.previous_kernel.end.new_contracts.push_array(new_contracts); @@ -431,7 +425,10 @@ mod tests { assert_eq_new_contracts(public_inputs.end.new_contracts, new_contracts); assert_eq_call_requests(public_inputs.end.private_call_stack, []); assert_eq_call_requests(public_inputs.end.public_call_stack, public_call_stack); - assert_eq_public_data_update_requests(public_inputs.end.public_data_update_requests, update_requests); + assert_eq_public_data_update_requests( + public_inputs.end.public_data_update_requests, + update_requests + ); assert_eq_public_data_reads(public_inputs.end.public_data_reads, read_requests); } @@ -489,16 +486,21 @@ mod tests { let prev_unencrypted_logs_hash = [956, 112]; let prev_unencrypted_log_preimages_length = 24; builder.previous_kernel.set_encrypted_logs(prev_encrypted_logs_hash, prev_encrypted_log_preimages_length); - builder.previous_kernel.set_unencrypted_logs(prev_unencrypted_logs_hash, prev_unencrypted_log_preimages_length); + builder.previous_kernel.set_unencrypted_logs( + prev_unencrypted_logs_hash, + prev_unencrypted_log_preimages_length + ); let public_inputs = builder.execute(); assert_eq(public_inputs.end.encrypted_log_preimages_length, prev_encrypted_log_preimages_length); - assert_eq(public_inputs.end.unencrypted_log_preimages_length, unencrypted_log_preimages_length + prev_unencrypted_log_preimages_length); + assert_eq( + public_inputs.end.unencrypted_log_preimages_length, unencrypted_log_preimages_length + prev_unencrypted_log_preimages_length + ); assert_eq(public_inputs.end.encrypted_logs_hash, prev_encrypted_logs_hash); let expected_unencrypted_logs_hash = compute_logs_hash(prev_unencrypted_logs_hash, unencrypted_logs_hash); assert_eq(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash); } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/utils.nr b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/utils.nr index cada7fa7264..2cdd041eb6f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/utils.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/utils.nr @@ -16,7 +16,10 @@ use dep::types::{ }, }; -pub fn compute_public_data_reads(contract_address: AztecAddress, read_requests: [StorageRead; N]) -> [PublicDataRead; N] { +pub fn compute_public_data_reads( + contract_address: AztecAddress, + read_requests: [StorageRead; N] +) -> [PublicDataRead; N] { let mut public_data_reads = [PublicDataRead::empty(); N]; for i in 0..N { let read_request = read_requests[i]; @@ -30,21 +33,20 @@ pub fn compute_public_data_reads(contract_address: AztecAddress, read_request public_data_reads } -pub fn assert_eq_call_requests( - call_requests: [CallRequest; N], - expected: [CallRequest; S], -) { - assert(struct_array_eq( - call_requests, - expected, - |c1: CallRequest, c2: CallRequest| c1.eq(c2), - |c: CallRequest| c.is_empty(), - )); +pub fn assert_eq_call_requests(call_requests: [CallRequest; N], expected: [CallRequest; S]) { + assert( + struct_array_eq( + call_requests, + expected, + |c1: CallRequest, c2: CallRequest| c1.eq(c2), + |c: CallRequest| c.is_empty() + ) + ); } pub fn compute_public_data_update_requests( contract_address: AztecAddress, - update_requests: [StorageUpdateRequest; N], + update_requests: [StorageUpdateRequest; N] ) -> [PublicDataUpdateRequest; N] { let mut public_data_update_requests = [PublicDataUpdateRequest::empty(); N]; for i in 0..N { @@ -60,35 +62,44 @@ pub fn compute_public_data_update_requests( public_data_update_requests } -pub fn assert_eq_public_data_reads(public_data_reads: [PublicDataRead; N], expected: [PublicDataRead; S]) { - assert(struct_array_eq( - public_data_reads, - expected, - |pdr1: PublicDataRead, pdr2: PublicDataRead| pdr1.eq(pdr2), - |pdr: PublicDataRead| pdr.is_empty(), - )); +pub fn assert_eq_public_data_reads( + public_data_reads: [PublicDataRead; N], + expected: [PublicDataRead; S] +) { + assert( + struct_array_eq( + public_data_reads, + expected, + |pdr1: PublicDataRead, pdr2: PublicDataRead| pdr1.eq(pdr2), + |pdr: PublicDataRead| pdr.is_empty() + ) + ); } pub fn assert_eq_public_data_update_requests( public_data_update_requests: [PublicDataUpdateRequest; N], - expected: [PublicDataUpdateRequest; S], + expected: [PublicDataUpdateRequest; S] ) { - assert(struct_array_eq( - public_data_update_requests, - expected, - |r1: PublicDataUpdateRequest, r2: PublicDataUpdateRequest| r1.eq(r2), - |r: PublicDataUpdateRequest| r.is_empty(), - )); + assert( + struct_array_eq( + public_data_update_requests, + expected, + |r1: PublicDataUpdateRequest, r2: PublicDataUpdateRequest| r1.eq(r2), + |r: PublicDataUpdateRequest| r.is_empty() + ) + ); } pub fn assert_eq_new_contracts( new_contracts: [NewContractData; N], - expected: [NewContractData; S], + expected: [NewContractData; S] ) { - assert(struct_array_eq( - new_contracts, - expected, - |c1: NewContractData, c2: NewContractData| c1.eq(c2), - |c: NewContractData| c.is_empty(), - )); -} \ No newline at end of file + assert( + struct_array_eq( + new_contracts, + expected, + |c1: NewContractData, c2: NewContractData| c1.eq(c2), + |c: NewContractData| c.is_empty() + ) + ); +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr index e1de429f5e5..d21bfd612e2 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr @@ -3,4 +3,4 @@ mod append_only_tree_snapshot; mod global_variables; mod constant_rollup_data; mod base_or_merge_rollup_public_inputs; -mod previous_rollup_data; \ No newline at end of file +mod previous_rollup_data; diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/append_only_tree_snapshot.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/append_only_tree_snapshot.nr index cde2d14638f..9b0456ab60e 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/append_only_tree_snapshot.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/append_only_tree_snapshot.nr @@ -7,4 +7,4 @@ impl AppendOnlyTreeSnapshot{ pub fn eq(self, other : AppendOnlyTreeSnapshot) -> bool { (self.root == other.root) & (self.next_available_leaf_index == other.next_available_leaf_index) } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/constant_rollup_data.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/constant_rollup_data.nr index d784b16b5ff..1871a0ec1ff 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/constant_rollup_data.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/constant_rollup_data.nr @@ -23,4 +23,4 @@ impl ConstantRollupData { (self.base_rollup_vk_hash == other.base_rollup_vk_hash) & (self.merge_rollup_vk_hash == other.merge_rollup_vk_hash) } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/global_variables.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/global_variables.nr index 71e88760209..ce4abc63541 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/global_variables.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/global_variables.nr @@ -26,4 +26,4 @@ impl GlobalVariables { (self.block_number == other.block_number) & (self.timestamp == other.timestamp) } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/public_data_tree_leaf.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/public_data_tree_leaf.nr index 31e80079361..05deed5b395 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/public_data_tree_leaf.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/public_data_tree_leaf.nr @@ -33,7 +33,6 @@ struct PublicDataTreeLeaf { value: Field, } - impl PublicDataTreeLeaf { pub fn default() -> Self { Self { diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base.nr index 1bfe7bcc36d..8e8b06724c9 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base.nr @@ -1,4 +1,4 @@ mod base_rollup_inputs; use base_rollup_inputs::BaseRollupInputs; -use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs; \ No newline at end of file +use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs; diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr index b87b3108178..8bb89362048 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -1016,10 +1016,7 @@ mod tests { let new_commitments = [27, 28, 29, 30, 31, 32]; let mut new_commitments_vec = builder.kernel_data.end.new_commitments; for i in 0..new_commitments.len() { - new_commitments_vec.push(SideEffect{ - value: new_commitments[i], - counter: 0, - }); + new_commitments_vec.push(SideEffect { value: new_commitments[i], counter: 0 }); } builder.kernel_data.end.new_commitments = new_commitments_vec; let mut expected_commitments_tree = NonEmptyMerkleTree::new( diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/components.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/components.nr index c6b68ea7718..f73628929ab 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/components.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/components.nr @@ -13,7 +13,10 @@ use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; * - We concat our public inputs * TODO(Kev): This seems similar to the aggregate_proof method in the private-kernel-lib */ -pub fn aggregate_proofs(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs) -> AggregationObject { +pub fn aggregate_proofs( + left: BaseOrMergeRollupPublicInputs, + right: BaseOrMergeRollupPublicInputs +) -> AggregationObject { // TODO: Similar to cpp code this does not do anything. left.end_aggregation_object } @@ -22,8 +25,10 @@ pub fn aggregate_proofs(left : BaseOrMergeRollupPublicInputs, right : BaseOrMerg * Asserts that the rollup types are the same. * Either both merge or both base */ -pub fn assert_both_input_proofs_of_same_rollup_type(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs) -{ +pub fn assert_both_input_proofs_of_same_rollup_type( + left: BaseOrMergeRollupPublicInputs, + right: BaseOrMergeRollupPublicInputs +) { assert(left.rollup_type == right.rollup_type, "input proofs are of different rollup types"); } @@ -31,8 +36,13 @@ pub fn assert_both_input_proofs_of_same_rollup_type(left : BaseOrMergeRollupPubl * Asserts that the rollup subtree heights are the same and returns the height * Returns the height of the rollup subtrees */ -pub fn assert_both_input_proofs_of_same_height_and_return(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs) -> Field { - assert(left.rollup_subtree_height == right.rollup_subtree_height, "input proofs are of different rollup heights"); +pub fn assert_both_input_proofs_of_same_height_and_return( + left: BaseOrMergeRollupPublicInputs, + right: BaseOrMergeRollupPublicInputs +) -> Field { + assert( + left.rollup_subtree_height == right.rollup_subtree_height, "input proofs are of different rollup heights" + ); left.rollup_subtree_height } @@ -40,18 +50,31 @@ pub fn assert_both_input_proofs_of_same_height_and_return(left : BaseOrMergeRoll * Asserts that the constants used in the left and right child are identical * */ -pub fn assert_equal_constants(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs) { +pub fn assert_equal_constants( + left: BaseOrMergeRollupPublicInputs, + right: BaseOrMergeRollupPublicInputs +) { assert(left.constants.eq(right.constants), "input proofs have different constants"); } // asserts that the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they // follow on from one-another). Ensures that right uses the tres that was updated by left. -pub fn assert_prev_rollups_follow_on_from_each_other(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs) -{ - assert(left.end_note_hash_tree_snapshot.eq(right.start_note_hash_tree_snapshot), "input proofs have different note hash tree snapshots"); - assert(left.end_nullifier_tree_snapshot.eq(right.start_nullifier_tree_snapshot),"input proofs have different nullifier tree snapshots"); - assert(left.end_contract_tree_snapshot.eq(right.start_contract_tree_snapshot), "input proofs have different contract tree snapshots"); - assert(left.end_public_data_tree_snapshot.eq(right.start_public_data_tree_snapshot), "input proofs have different public data tree snapshots"); +pub fn assert_prev_rollups_follow_on_from_each_other( + left: BaseOrMergeRollupPublicInputs, + right: BaseOrMergeRollupPublicInputs +) { + assert( + left.end_note_hash_tree_snapshot.eq(right.start_note_hash_tree_snapshot), "input proofs have different note hash tree snapshots" + ); + assert( + left.end_nullifier_tree_snapshot.eq(right.start_nullifier_tree_snapshot), "input proofs have different nullifier tree snapshots" + ); + assert( + left.end_contract_tree_snapshot.eq(right.start_contract_tree_snapshot), "input proofs have different contract tree snapshots" + ); + assert( + left.end_public_data_tree_snapshot.eq(right.start_public_data_tree_snapshot), "input proofs have different public data tree snapshots" + ); } /** @@ -60,28 +83,35 @@ pub fn assert_prev_rollups_follow_on_from_each_other(left : BaseOrMergeRollupPub * @param previous_rollup_data * @return calldata hash stored in 2 fields */ -pub fn compute_calldata_hash(previous_rollup_data : [PreviousRollupData ; 2]) -> [Field; NUM_FIELDS_PER_SHA256]{ - accumulate_sha256([ +pub fn compute_calldata_hash(previous_rollup_data: [PreviousRollupData; 2]) -> [Field; NUM_FIELDS_PER_SHA256] { + accumulate_sha256( + [ U128::from_field(previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash[0]), U128::from_field(previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash[1]), U128::from_field(previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash[0]), U128::from_field(previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash[1]) - ]) + ] + ) } pub fn insert_subtree_to_snapshot_tree( - snapshot : AppendOnlyTreeSnapshot, - siblingPath : [Field; N], - emptySubtreeRoot : Field, - subtreeRootToInsert : Field, - subtreeDepth : u8, + snapshot: AppendOnlyTreeSnapshot, + siblingPath: [Field; N], + emptySubtreeRoot: Field, + subtreeRootToInsert: Field, + subtreeDepth: u8 ) -> AppendOnlyTreeSnapshot { // TODO(Lasse): Sanity check len of siblingPath > height of subtree // TODO(Lasse): Ensure height of subtree is correct (eg 3 for commitments, 1 for contracts) let leafIndexAtDepth = snapshot.next_available_leaf_index >> (subtreeDepth as u32); - + // Check that the current root is correct and that there is an empty subtree at the insertion location - assert_check_membership(emptySubtreeRoot, leafIndexAtDepth as Field, siblingPath, snapshot.root); + assert_check_membership( + emptySubtreeRoot, + leafIndexAtDepth as Field, + siblingPath, + snapshot.root + ); // if index of leaf is x, index of its parent is x/2 or x >> 1. We need to find the parent `subtreeDepth` levels up. let new_root = root_from_sibling_path(subtreeRootToInsert, leafIndexAtDepth as Field, siblingPath); @@ -89,5 +119,5 @@ pub fn insert_subtree_to_snapshot_tree( // 2^subtreeDepth is the number of leaves added. 2^x = 1 << x let new_next_available_leaf_index = (snapshot.next_available_leaf_index as u64) + (1 << (subtreeDepth as u64)); - AppendOnlyTreeSnapshot{root: new_root, next_available_leaf_index: new_next_available_leaf_index as u32} -} \ No newline at end of file + AppendOnlyTreeSnapshot { root: new_root, next_available_leaf_index: new_next_available_leaf_index as u32 } +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/hash.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/hash.nr index 55f7d242e7e..76ddcde1060 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/hash.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/hash.nr @@ -1,15 +1,17 @@ use crate::abis::global_variables::GlobalVariables; use dep::types::constants::GENERATOR_INDEX__BLOCK_HASH; - + pub fn compute_block_hash_with_globals( - globals : GlobalVariables, - note_hash_tree_root : Field, - nullifier_tree_root : Field, - contract_tree_root : Field, - l1_to_l2_messages_tree_root : Field, - public_data_tree_root : Field) -> Field { - - let inputs = [globals.hash(), note_hash_tree_root, nullifier_tree_root, contract_tree_root, l1_to_l2_messages_tree_root, public_data_tree_root]; - + globals: GlobalVariables, + note_hash_tree_root: Field, + nullifier_tree_root: Field, + contract_tree_root: Field, + l1_to_l2_messages_tree_root: Field, + public_data_tree_root: Field +) -> Field { + let inputs = [ + globals.hash(), note_hash_tree_root, nullifier_tree_root, contract_tree_root, l1_to_l2_messages_tree_root, public_data_tree_root + ]; + dep::std::hash::pedersen_hash_with_separator(inputs, GENERATOR_INDEX__BLOCK_HASH) -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/indexed_tree.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/indexed_tree.nr index 8396921a23a..d9b76f5ef1a 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/indexed_tree.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/indexed_tree.nr @@ -3,7 +3,12 @@ use crate::merkle_tree::{calculate_subtree, calculate_empty_tree_root}; use dep::types::abis::membership_witness::MembershipWitness; -fn check_permutation(original_array: [T; N], sorted_array: [T; N], indexes: [u32; N], is_equal: fn (T, T) -> bool) { +fn check_permutation( + original_array: [T; N], + sorted_array: [T; N], + indexes: [u32; N], + is_equal: fn(T, T) -> bool +) { let mut seen_value = [false; N]; for i in 0..N { let index = indexes[i]; @@ -16,7 +21,7 @@ fn check_permutation(original_array: [T; N], sorted_array: [T; N], indexes } #[test] -fn check_permutation_basic_test(){ +fn check_permutation_basic_test() { let original_array = [1, 2, 3]; let sorted_array = [3, 1, 2]; let indexes = [2, 0, 1]; @@ -25,7 +30,7 @@ fn check_permutation_basic_test(){ } #[test(should_fail_with = "Duplicated index")] -fn check_permutation_duplicated_index(){ +fn check_permutation_duplicated_index() { let original_array = [0, 1, 0]; let sorted_array = [1, 0, 0]; let indexes = [1, 0, 0]; @@ -34,7 +39,7 @@ fn check_permutation_duplicated_index(){ } #[test(should_fail_with = "Invalid index")] -fn check_permutation_invalid_index(){ +fn check_permutation_invalid_index() { let original_array = [0, 1, 2]; let sorted_array = [1, 0, 0]; let indexes = [1, 0, 2]; @@ -43,24 +48,29 @@ fn check_permutation_invalid_index(){ } pub fn batch_insert( - start_snapshot: AppendOnlyTreeSnapshot, + start_snapshot: AppendOnlyTreeSnapshot, values_to_insert: [Value; SubtreeWidth], sorted_values: [Value; SubtreeWidth], sorted_values_indexes: [u32; SubtreeWidth], new_subtree_sibling_path: [Field; SiblingPathLength], low_leaf_preimages: [Leaf; SubtreeWidth], low_leaf_membership_witnesses: [MembershipWitness; SubtreeWidth], - is_equal: fn (Value, Value) -> bool, - is_empty_value: fn (Value) -> bool, - hash_leaf: fn (Leaf) -> Field, + is_equal: fn(Value, Value) -> bool, + is_empty_value: fn(Value) -> bool, + hash_leaf: fn(Leaf) -> Field, is_valid_low_leaf: fn(Leaf, Value) -> bool, update_low_leaf: fn(Leaf, Value, u32) -> Leaf, - build_insertion_leaf: fn (Value, Leaf) -> Leaf, + build_insertion_leaf: fn(Value, Leaf) -> Leaf, _subtree_height: [Field; SubtreeHeight], - _tree_height: [Field; TreeHeight], + _tree_height: [Field; TreeHeight] ) -> AppendOnlyTreeSnapshot { // A permutation to the values is provided to make the insertion use only one insertion strategy - check_permutation(values_to_insert, sorted_values, sorted_values_indexes, is_equal); + check_permutation( + values_to_insert, + sorted_values, + sorted_values_indexes, + is_equal + ); // Now, update the existing leaves with the new leaves let mut current_tree_root = start_snapshot.root; @@ -72,7 +82,7 @@ pub fn batch_insert> (SubtreeHeight as u32); let new_root = crate::components::root_from_sibling_path(subtree_root, subtree_index as Field, new_subtree_sibling_path); - AppendOnlyTreeSnapshot { - root: new_root, - next_available_leaf_index: start_insertion_index + (values_to_insert.len() as u32), - } + AppendOnlyTreeSnapshot { root: new_root, next_available_leaf_index: start_insertion_index + (values_to_insert.len() as u32) } } diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/merge/merge_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/merge/merge_rollup_inputs.nr index eb82cb61e35..be8b49c73ab 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/merge/merge_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/merge/merge_rollup_inputs.nr @@ -56,9 +56,8 @@ mod tests { use dep::types::hash::accumulate_sha256; use dep::types::utils::uint128::U128; - #[test(should_fail_with="input proofs are of different rollup types")] - fn different_rollup_type_fails(){ + fn different_rollup_type_fails() { let mut inputs = default_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = 1; @@ -66,7 +65,7 @@ mod tests { } #[test(should_fail_with="input proofs are of different rollup heights")] - fn different_height_fails(){ + fn different_height_fails() { let mut inputs = default_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; @@ -74,7 +73,7 @@ mod tests { } #[test(should_fail_with="input proofs have different constants")] - fn constants_different_fails(){ + fn constants_different_fails() { let mut inputs = default_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = 1; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = 0; @@ -82,7 +81,7 @@ mod tests { } #[test(should_fail_with="input proofs have different constants")] - fn constants_different_chain_id_fails(){ + fn constants_different_chain_id_fails() { let mut inputs = default_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.global_variables.chain_id = 1; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.global_variables.chain_id = 0; @@ -90,7 +89,7 @@ mod tests { } #[test(should_fail_with="input proofs have different note hash tree snapshots")] - fn previous_rollups_dont_follow_note_hash(){ + fn previous_rollups_dont_follow_note_hash() { let mut inputs = default_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_note_hash_tree_snapshot.root = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_note_hash_tree_snapshot.root = 1; @@ -98,7 +97,7 @@ mod tests { } #[test(should_fail_with="input proofs have different nullifier tree snapshots")] - fn previous_rollups_dont_follow_nullifier(){ + fn previous_rollups_dont_follow_nullifier() { let mut inputs = default_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot.root = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot.root = 1; @@ -106,7 +105,7 @@ mod tests { } #[test(should_fail_with="input proofs have different contract tree snapshots")] - fn previous_rollups_dont_follow_contracts(){ + fn previous_rollups_dont_follow_contracts() { let mut inputs = default_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot.root = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot.root = 1; @@ -114,11 +113,13 @@ mod tests { } #[test] - fn rollup_fields_are_set_correctly(){ + fn rollup_fields_are_set_correctly() { let mut inputs = default_merge_rollup_inputs(); let mut outputs = inputs.merge_rollup_circuit(); assert_eq(outputs.rollup_type, 1); - assert_eq(outputs.rollup_subtree_height, inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height + 1); + assert_eq( + outputs.rollup_subtree_height, inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height + 1 + ); // set inputs to have a merge rollup type and set the rollup height and test again. inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type = 1; @@ -133,59 +134,79 @@ mod tests { } #[test] - fn start_and_end_snapshots(){ + fn start_and_end_snapshots() { let mut inputs = default_merge_rollup_inputs(); let outputs = inputs.merge_rollup_circuit(); - + assert( - outputs.start_note_hash_tree_snapshot.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_note_hash_tree_snapshot) + outputs.start_note_hash_tree_snapshot.eq( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_note_hash_tree_snapshot + ) ); assert( - outputs.end_note_hash_tree_snapshot.eq(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_note_hash_tree_snapshot) + outputs.end_note_hash_tree_snapshot.eq( + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_note_hash_tree_snapshot + ) ); assert( - outputs.start_nullifier_tree_snapshot.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot) + outputs.start_nullifier_tree_snapshot.eq( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot + ) ); assert( - outputs.end_nullifier_tree_snapshot.eq(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot) + outputs.end_nullifier_tree_snapshot.eq( + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot + ) ); assert( - outputs.start_contract_tree_snapshot.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot) + outputs.start_contract_tree_snapshot.eq( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot + ) ); assert( outputs.end_contract_tree_snapshot.eq(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot) ); assert( - outputs.start_public_data_tree_snapshot.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_public_data_tree_snapshot) + outputs.start_public_data_tree_snapshot.eq( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_public_data_tree_snapshot + ) ); assert( - outputs.end_public_data_tree_snapshot.eq(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_public_data_tree_snapshot) + outputs.end_public_data_tree_snapshot.eq( + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_public_data_tree_snapshot + ) ); } #[test] - fn calldata_hash(){ + fn calldata_hash() { let mut inputs = default_merge_rollup_inputs(); - let expected_calldata_hash = accumulate_sha256([ + let expected_calldata_hash = accumulate_sha256( + [ U128::from_field(0), U128::from_field(1), U128::from_field(2), U128::from_field(3) - ]); + ] + ); let outputs = inputs.merge_rollup_circuit(); assert_eq(outputs.calldata_hash, expected_calldata_hash); } #[test] - fn constants_dont_change(){ + fn constants_dont_change() { let mut inputs = default_merge_rollup_inputs(); let outputs = inputs.merge_rollup_circuit(); - assert(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.eq(outputs.constants)); - assert(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.eq(outputs.constants)); + assert( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.eq(outputs.constants) + ); + assert( + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.eq(outputs.constants) + ); } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root.nr index 7e7bb31f012..f8937f2dada 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root.nr @@ -87,8 +87,7 @@ global NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP_NUM_BYTES = 512; // Computes the messages hash from the leaves array // // Returns the hash split into two field elements -fn compute_messages_hash(leaves : [Field; NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP]) -> [Field;NUM_FIELDS_PER_SHA256] { - +fn compute_messages_hash(leaves: [Field; NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP]) -> [Field; NUM_FIELDS_PER_SHA256] { // Slice variation // let mut hash_input_flattened = []; // for leaf in leaves { @@ -127,7 +126,6 @@ fn test_message_input_flattened_length() { assert(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP * 32 == NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP_NUM_BYTES); } - mod tests { use crate::{ root::{ @@ -140,21 +138,22 @@ mod tests { use dep::types::utils::uint256::U256; use dep::types::hash::accumulate_sha256; - #[test] - fn check_block_hashes_empty_blocks(){ + fn check_block_hashes_empty_blocks() { let expected_messages_hash = U256::from_bytes32(dep::std::hash::sha256([0; NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP_NUM_BYTES])).to_u128_limbs(); - let expected_calldata_hash = accumulate_sha256([ + let expected_calldata_hash = accumulate_sha256( + [ U128::from_field(0), U128::from_field(1), U128::from_field(2), U128::from_field(3) - ]); + ] + ); let inputs = default_root_rollup_inputs(); let outputs = inputs.root_rollup_circuit(); - + // check calldata hash assert_eq(outputs.calldata_hash, expected_calldata_hash); // Check messages hash @@ -162,37 +161,50 @@ mod tests { } #[test] - fn start_and_end_snapshots(){ + fn start_and_end_snapshots() { let inputs = default_root_rollup_inputs(); let outputs = inputs.root_rollup_circuit(); - + assert( - outputs.start_note_hash_tree_snapshot.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_note_hash_tree_snapshot) + outputs.start_note_hash_tree_snapshot.eq( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_note_hash_tree_snapshot + ) ); assert( - outputs.end_note_hash_tree_snapshot.eq(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_note_hash_tree_snapshot) + outputs.end_note_hash_tree_snapshot.eq( + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_note_hash_tree_snapshot + ) ); assert( - outputs.start_nullifier_tree_snapshot.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot) + outputs.start_nullifier_tree_snapshot.eq( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot + ) ); assert( - outputs.end_nullifier_tree_snapshot.eq(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot) + outputs.end_nullifier_tree_snapshot.eq( + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot + ) ); assert( - outputs.start_contract_tree_snapshot.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot) + outputs.start_contract_tree_snapshot.eq( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot + ) ); assert( outputs.end_contract_tree_snapshot.eq(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot) ); assert( - outputs.start_public_data_tree_snapshot.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_public_data_tree_snapshot) + outputs.start_public_data_tree_snapshot.eq( + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_public_data_tree_snapshot + ) ); assert( - outputs.end_public_data_tree_snapshot.eq(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_public_data_tree_snapshot) + outputs.end_public_data_tree_snapshot.eq( + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_public_data_tree_snapshot + ) ); } - -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_inputs.nr index 7426e7dc4bd..2df3c4a6d71 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_inputs.nr @@ -24,4 +24,4 @@ struct RootRollupInputs { // inputs required to add the block hash start_archive_snapshot : AppendOnlyTreeSnapshot, new_archive_sibling_path : [Field; ARCHIVE_HEIGHT], -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_public_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_public_inputs.nr index dda2dd7737f..c8cf7f30a2d 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_public_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_public_inputs.nr @@ -9,7 +9,6 @@ use dep::types::{ }; use dep::types::mocked::AggregationObject; - struct RootRollupPublicInputs { // All below are shared between the base and merge rollups end_aggregation_object : AggregationObject, @@ -36,4 +35,4 @@ struct RootRollupPublicInputs { calldata_hash : [Field; NUM_FIELDS_PER_SHA256], l1_to_l2_messages_hash : [Field; NUM_FIELDS_PER_SHA256], -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests.nr index f77a334506a..ac5ce73d05d 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests.nr @@ -1,4 +1,4 @@ mod merge_rollup_inputs; mod root_rollup_inputs; mod previous_rollup_data; -mod merkle_tree_utils; \ No newline at end of file +mod merkle_tree_utils; diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/merge_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/merge_rollup_inputs.nr index 7ad7e998e37..d0008588978 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/merge_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/merge_rollup_inputs.nr @@ -9,4 +9,4 @@ pub fn default_merge_rollup_inputs() -> MergeRollupInputs { inputs.previous_rollup_data = default_previous_rollup_data(); inputs -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/merkle_tree_utils.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/merkle_tree_utils.nr index daec7a5d104..54941933816 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/merkle_tree_utils.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/merkle_tree_utils.nr @@ -220,4 +220,4 @@ fn test_merkle_tree_set_to_empty() { assert_eq(path[0], 0); assert_eq(path[1], zero_hashes[0]); assert_eq(path[2], zero_hashes[1]); -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/previous_rollup_data.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/previous_rollup_data.nr index d036e1926ac..e07f64166fb 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/previous_rollup_data.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/previous_rollup_data.nr @@ -83,4 +83,4 @@ pub fn default_previous_rollup_data() -> [PreviousRollupData; 2] { previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash = [2, 3]; previous_rollup_data -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/root_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/root_rollup_inputs.nr index 0a095423bc6..dc5e3668f71 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/root_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/tests/root_rollup_inputs.nr @@ -22,7 +22,9 @@ pub fn compute_l1_l2_empty_snapshot() -> (AppendOnlyTreeSnapshot, [Field; L1_TO_ new_l1_to_l2_messages_tree_root_sibling_path[i] = zero_hashes[index]; } - (AppendOnlyTreeSnapshot{ root: zero_hashes[zero_hashes.len() - 1], next_available_leaf_index: 0 }, new_l1_to_l2_messages_tree_root_sibling_path) + ( + AppendOnlyTreeSnapshot { root: zero_hashes[zero_hashes.len() - 1], next_available_leaf_index: 0 }, new_l1_to_l2_messages_tree_root_sibling_path + ) } pub fn compute_archive_snapshot() -> (AppendOnlyTreeSnapshot, [Field; ARCHIVE_HEIGHT]) { @@ -31,10 +33,11 @@ pub fn compute_archive_snapshot() -> (AppendOnlyTreeSnapshot, [Field; ARCHIVE_HE for i in 1..ARCHIVE_HEIGHT { sibling_path[i] = zero_hashes[i-1]; } - (AppendOnlyTreeSnapshot { root: zero_hashes[zero_hashes.len() - 1], next_available_leaf_index: 0 }, sibling_path) + ( + AppendOnlyTreeSnapshot { root: zero_hashes[zero_hashes.len() - 1], next_available_leaf_index: 0 }, sibling_path + ) } - pub fn default_root_rollup_inputs() -> RootRollupInputs { let mut inputs: RootRollupInputs = dep::std::unsafe::zeroed(); let (l1_l2_empty_snapshot, l1_l2_empty_sibling_path) = compute_l1_l2_empty_snapshot(); @@ -50,4 +53,4 @@ pub fn default_root_rollup_inputs() -> RootRollupInputs { inputs.previous_rollup_data = default_previous_rollup_data(); inputs -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-merge/src/main.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-merge/src/main.nr index 740c8739054..fafe08c9296 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-merge/src/main.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-merge/src/main.nr @@ -1,5 +1,5 @@ use dep::rollup_lib::merge::{MergeRollupInputs,BaseOrMergeRollupPublicInputs}; -fn main(inputs : MergeRollupInputs) -> pub BaseOrMergeRollupPublicInputs { +fn main(inputs: MergeRollupInputs) -> pub BaseOrMergeRollupPublicInputs { inputs.merge_rollup_circuit() -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-root/src/main.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-root/src/main.nr index 491026dc814..757a2885a93 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-root/src/main.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-root/src/main.nr @@ -1,5 +1,5 @@ use dep::rollup_lib::root::{RootRollupInputs,RootRollupPublicInputs}; -fn main(inputs : RootRollupInputs) -> pub RootRollupPublicInputs { +fn main(inputs: RootRollupInputs) -> pub RootRollupPublicInputs { inputs.root_rollup_circuit() -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_request.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_request.nr index c878ff8f243..c66972a5319 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_request.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_request.nr @@ -53,4 +53,4 @@ impl CallRequest { & (call_request.start_side_effect_counter == self.start_side_effect_counter) & (call_request.end_side_effect_counter == self.end_side_effect_counter) } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr index 438ae6c61c6..a7f70629711 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr @@ -10,7 +10,6 @@ struct FunctionData { is_constructor : bool, } - impl FunctionData { // A field is ~256 bits // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3057): Since, function data can fit into a Field, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/membership_witness.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/membership_witness.nr index cf216fa441d..1cfe9e6ca69 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/membership_witness.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/membership_witness.nr @@ -55,4 +55,4 @@ struct ReadRequestMembershipWitness { // hint to point kernel to the commitment this rr corresponds to is_transient: bool, hint_to_commitment: Field, -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr index 90b66103547..38e5a899a4f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr @@ -71,10 +71,9 @@ pub fn hash_args(args: [Field; N]) -> Field { } } - // Checks that `value` is a member of a merkle tree with root `root` at position `index` // The witness being the `sibling_path` -pub fn assert_check_membership(value : Field, index : Field, sibling_path : [Field; N], root : Field) { +pub fn assert_check_membership(value: Field, index: Field, sibling_path: [Field; N], root: Field) { let calculated_root = root_from_sibling_path(value, index, sibling_path); assert(calculated_root == root, "membership check failed"); } @@ -89,7 +88,7 @@ pub fn assert_check_membership(value : Field, index : Field, sibling_path : [ // 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); @@ -110,62 +109,76 @@ pub fn root_from_sibling_path(leaf : Field, leaf_index : Field, sibling_path // builds it up. We should build it up and then pass the leaf preimage as a parameter. // We can then choose to have a general method that takes in anything hashable // and deduplicate the logic in `contract_tree_root_from_siblings` -pub fn function_tree_root_from_siblings(selector : FunctionSelector, is_internal : bool, is_private : bool, vk_hash : Field, acir_hash : Field, function_leaf_index : Field, function_leaf_sibling_path : [Field; FUNCTION_TREE_HEIGHT]) -> Field { - let function_leaf_preimage = FunctionLeafPreimage{ - selector: selector, - is_internal : is_internal, - is_private : is_private, - vk_hash : vk_hash, - acir_hash : acir_hash, - }; +pub fn function_tree_root_from_siblings( + selector: FunctionSelector, + is_internal: bool, + is_private: bool, + vk_hash: Field, + acir_hash: Field, + function_leaf_index: Field, + function_leaf_sibling_path: [Field; FUNCTION_TREE_HEIGHT] +) -> Field { + let function_leaf_preimage = FunctionLeafPreimage { selector, is_internal, is_private, vk_hash, acir_hash }; let function_leaf = function_leaf_preimage.hash(); - let function_tree_root = - root_from_sibling_path(function_leaf, function_leaf_index, function_leaf_sibling_path); + let function_tree_root = root_from_sibling_path(function_leaf, function_leaf_index, function_leaf_sibling_path); function_tree_root } // Calculate the contract tree root from the sibling path and leaf preimage. -pub fn contract_tree_root_from_siblings(function_tree_root : Field, storage_contract_address : AztecAddress, portal_contract_address : EthAddress, contract_leaf_index : Field,contract_leaf_sibling_path : [Field; CONTRACT_TREE_HEIGHT]) -> Field { +pub fn contract_tree_root_from_siblings( + function_tree_root: Field, + storage_contract_address: AztecAddress, + portal_contract_address: EthAddress, + contract_leaf_index: Field, + contract_leaf_sibling_path: [Field; CONTRACT_TREE_HEIGHT] +) -> Field { //TODO(Kev): if we use shorthand syntax here, we get an error as expected, // since variable name is `storage_contract_address` but the span is incorrect. - let contract_leaf_preimage = ContractLeafPreimage { contract_address: storage_contract_address, - portal_contract_address, - function_tree_root }; - + let contract_leaf_preimage = ContractLeafPreimage { contract_address: storage_contract_address, portal_contract_address, function_tree_root }; + let contract_leaf = contract_leaf_preimage.hash(); - let computed_contract_tree_root = - root_from_sibling_path(contract_leaf, contract_leaf_index, contract_leaf_sibling_path); - + let computed_contract_tree_root = root_from_sibling_path(contract_leaf, contract_leaf_index, contract_leaf_sibling_path); + computed_contract_tree_root } -pub fn read_request_root_from_siblings(read_request : Field, leaf_index : Field, sibling_path : [Field; NOTE_HASH_TREE_HEIGHT]) -> Field { +pub fn read_request_root_from_siblings( + read_request: Field, + leaf_index: Field, + sibling_path: [Field; NOTE_HASH_TREE_HEIGHT] +) -> Field { root_from_sibling_path(read_request, leaf_index, sibling_path) } -pub fn silo_commitment(address : AztecAddress, inner_commitment : Field) -> Field { - pedersen_hash([ +pub fn silo_commitment(address: AztecAddress, inner_commitment: Field) -> Field { + pedersen_hash( + [ address.to_field(), - inner_commitment, - ], GENERATOR_INDEX__SILOED_COMMITMENT) + inner_commitment + ], + GENERATOR_INDEX__SILOED_COMMITMENT + ) } -pub fn silo_nullifier(address : AztecAddress, nullifier : Field) -> Field { - pedersen_hash([ +pub fn silo_nullifier(address: AztecAddress, nullifier: Field) -> Field { + pedersen_hash( + [ address.to_field(), - nullifier, - ], GENERATOR_INDEX__OUTER_NULLIFIER) + nullifier + ], + GENERATOR_INDEX__OUTER_NULLIFIER + ) } -fn merkle_hash(left : Field, right : Field) -> Field { +fn merkle_hash(left: Field, right: Field) -> Field { pedersen_hash([left, right], 0) } -pub fn stdlib_recursion_verification_key_compress_native_vk(_vk : VerificationKey) -> Field { +pub fn stdlib_recursion_verification_key_compress_native_vk(_vk: VerificationKey) -> Field { // Original cpp code // stdlib::recursion::verification_key::compress_native(private_call.vk, GeneratorIndex::VK); // The above cpp method is only ever called on verification key, so it has been special cased here @@ -174,14 +187,22 @@ pub fn stdlib_recursion_verification_key_compress_native_vk(_vk : VerificationKe } // TODO CPP uses blake2s for this -pub fn compute_new_contract_address_hash(new_contract_address : AztecAddress) -> Field { +pub fn compute_new_contract_address_hash(new_contract_address: AztecAddress) -> Field { dep::std::hash::pedersen_hash([new_contract_address.to_field()]) } -pub fn compute_l2_to_l1_hash(contract_address : AztecAddress, rollup_version_id: Field, portal_contract_address : EthAddress, chain_id : Field, content : Field) -> Field { +pub fn compute_l2_to_l1_hash( + contract_address: AztecAddress, + rollup_version_id: Field, + portal_contract_address: EthAddress, + chain_id: Field, + content: Field +) -> Field { let mut bytes: BoundedVec = BoundedVec::new(0); - let inputs = [contract_address.to_field(), rollup_version_id, portal_contract_address.to_field(), chain_id, content]; + let inputs = [ + contract_address.to_field(), rollup_version_id, portal_contract_address.to_field(), chain_id, content + ]; for i in 0..inputs.len() { // TODO are bytes be in fr.to_buffer() ? let item_bytes = inputs[i].to_be_bytes(32); @@ -193,14 +214,21 @@ pub fn compute_l2_to_l1_hash(contract_address : AztecAddress, rollup_version_id: sha256_to_field(bytes.storage) } -pub fn compute_constructor_hash(function_data : FunctionData, args_hash : Field, constructor_vk_hash : Field) -> Field { +pub fn compute_constructor_hash( + function_data: FunctionData, + args_hash: Field, + constructor_vk_hash: Field +) -> Field { let function_data_hash = function_data.hash(); - pedersen_hash([ + pedersen_hash( + [ function_data_hash, args_hash, constructor_vk_hash - ], GENERATOR_INDEX__CONSTRUCTOR) + ], + GENERATOR_INDEX__CONSTRUCTOR + ) } // sha256 hash is stored in two fields to accommodate all 256-bits of the hash @@ -217,7 +245,7 @@ global NUM_FIELDS_PER_SHA256 : Field = 2; // Returning a Field would be desirable because then this can be replaced with // poseidon without changing the rest of the code // -pub fn accumulate_sha256(input : [U128; 4]) -> [Field; NUM_FIELDS_PER_SHA256] { +pub fn accumulate_sha256(input: [U128; 4]) -> [Field; NUM_FIELDS_PER_SHA256] { // This is a note about the cpp code, since it takes an array of Fields // instead of a U128. // 4 Field elements when converted to bytes will usually @@ -228,7 +256,7 @@ pub fn accumulate_sha256(input : [U128; 4]) -> [Field; NUM_FIELDS_PER_SHA256] { // TODO(David): This does not seem to be getting guaranteed anywhere in the code? // // Concatenate 4 u128 bit integers into a byte array. - let mut hash_input_flattened = [0;64]; + let mut hash_input_flattened = [0; 64]; for offset in 0..4 { let input_as_bytes = input[offset].to_be_bytes(); for byte_index in 0..16 { @@ -241,30 +269,44 @@ pub fn accumulate_sha256(input : [U128; 4]) -> [Field; NUM_FIELDS_PER_SHA256] { U256::from_bytes32(sha_digest).to_u128_limbs() } -pub fn compute_logs_hash(previous_log_hash : [Field;2], current_log_hash : [Field;2]) -> [Field; NUM_FIELDS_PER_SHA256] { - accumulate_sha256([ +pub fn compute_logs_hash( + previous_log_hash: [Field; 2], + current_log_hash: [Field; 2] +) -> [Field; NUM_FIELDS_PER_SHA256] { + accumulate_sha256( + [ U128::from_field(previous_log_hash[0]), U128::from_field(previous_log_hash[1]), U128::from_field(current_log_hash[0]), U128::from_field(current_log_hash[1]) - ]) + ] + ) } -pub fn compute_commitment_nonce(first_nullifier : Field, commitment_index : Field) -> Field { - pedersen_hash([ +pub fn compute_commitment_nonce(first_nullifier: Field, commitment_index: Field) -> Field { + pedersen_hash( + [ first_nullifier, commitment_index - ], GENERATOR_INDEX__COMMITMENT_NONCE) + ], + GENERATOR_INDEX__COMMITMENT_NONCE + ) } pub fn compute_unique_siloed_commitment(nonce: Field, siloed_commitment: Field) -> Field { - pedersen_hash([ + pedersen_hash( + [ nonce, siloed_commitment - ], GENERATOR_INDEX__UNIQUE_COMMITMENT) + ], + GENERATOR_INDEX__UNIQUE_COMMITMENT + ) } -pub fn compute_unique_siloed_commitments(first_nullifier: Field, siloed_commitments: [SideEffect; N]) -> [SideEffect; N] { +pub fn compute_unique_siloed_commitments( + first_nullifier: Field, + siloed_commitments: [SideEffect; N] +) -> [SideEffect; N] { let mut unique_siloed_commitments = [SideEffect::empty(); N]; for i in 0..N { let siloed_commitment = siloed_commitments[i]; @@ -281,4 +323,4 @@ pub fn compute_unique_siloed_commitments(first_nullifier: Field, siloed_commi pub fn pedersen_hash(inputs: [Field; N], hash_index: u32) -> Field { dep::std::hash::pedersen_hash_with_separator(inputs, hash_index) -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/mocked.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/mocked.nr index 7bb5d526f4b..343d15c1eed 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/mocked.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/mocked.nr @@ -9,6 +9,9 @@ struct VerificationKey{} // Perform recursive verification of the previous kernel proof and private call // proof. -pub fn verify_previous_kernel_state(_aggregation_object : AggregationObject, _proof : Proof) -> (bool, AggregationObject) { - (true, AggregationObject{}) +pub fn verify_previous_kernel_state( + _aggregation_object: AggregationObject, + _proof: Proof +) -> (bool, AggregationObject) { + (true, AggregationObject {}) } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests.nr index f7a5602dc00..56e38d577a8 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests.nr @@ -4,4 +4,4 @@ mod previous_kernel_data_builder; mod private_call_data_builder; mod private_circuit_public_inputs_builder; mod public_call_data_builder; -mod public_circuit_public_inputs_builder; \ No newline at end of file +mod public_circuit_public_inputs_builder; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr index 8b824658236..b499d6b1051 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr @@ -21,4 +21,4 @@ global BLOCK_HEADER = BlockHeader { archive_root: 0, public_data_tree_root: 0, global_variables_hash: 0, -}; \ No newline at end of file +}; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contract_functions.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contract_functions.nr index 0e81392c885..04345243cf3 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contract_functions.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contract_functions.nr @@ -23,7 +23,6 @@ global default_constructor = ContractFunction { membership_witness: dep::std::unsafe::zeroed(), }; - // sibling_path taken from __snapshots__/noir_test_gen.test.ts.snap global default_private_function = ContractFunction { data: FunctionData { diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contracts.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contracts.nr index 2ac70bcd438..78a591c64c2 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contracts.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contracts.nr @@ -30,4 +30,4 @@ global parent_contract = ContractData { sibling_path: fixtures::contract_tree::SIBLING_PATHS[1], }, function_tree_root: 0x02b3f6b0a36bd01f08cee2d607dbe08894bb8c58159e87bb17db28cad43291d4, -}; \ No newline at end of file +}; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/note_hash_tree.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/note_hash_tree.nr index e5086e50098..2b3b7f49967 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/note_hash_tree.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/note_hash_tree.nr @@ -4353,4 +4353,4 @@ global SIBLING_PATHS = [ 0x1afb11871cf18149a0e62d57525c03f905c7bca6c0e1dae4b226ea164d198b6a, 0x825ca56349b23727e91399761bff246cd651d9d4190b6304b42df26d8c8a42, ], -]; \ No newline at end of file +]; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/read_requests.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/read_requests.nr index f06f06d5485..dacb83e2707 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/read_requests.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/read_requests.nr @@ -8,42 +8,32 @@ use crate::constants::{ MAX_READ_REQUESTS_PER_CALL, }; -pub fn generate_read_requests(how_many: Field) -> ( - BoundedVec, - BoundedVec -) { +pub fn generate_read_requests(how_many: Field) -> (BoundedVec, BoundedVec) { generate_read_requests_with_config(how_many, false, [0; MAX_READ_REQUESTS_PER_CALL]) } -pub fn generate_transient_read_requests(how_many: Field) -> ( - BoundedVec, - BoundedVec -) { +pub fn generate_transient_read_requests(how_many: Field) -> (BoundedVec, BoundedVec) { generate_read_requests_with_config(how_many, true, [0; MAX_READ_REQUESTS_PER_CALL]) } -pub fn generate_read_requests_with_config(how_many: Field, is_transient: bool, hints_to_commitment: [Field; MAX_READ_REQUESTS_PER_CALL]) -> ( - BoundedVec, - BoundedVec -) { +pub fn generate_read_requests_with_config( + how_many: Field, + is_transient: bool, + hints_to_commitment: [Field; MAX_READ_REQUESTS_PER_CALL] +) -> (BoundedVec, BoundedVec) { let mut read_requests = BoundedVec::new(SideEffect::empty()); let mut read_request_membership_witnesses = BoundedVec::new(dep::std::unsafe::zeroed()); for i in 0..how_many { - read_requests.push( - SideEffect { - value: i + 1, - counter: 0 - }); + read_requests.push(SideEffect { value: i + 1, counter: 0 }); let witness = ReadRequestMembershipWitness { leaf_index: i, sibling_path: fixtures::note_hash_tree::SIBLING_PATHS[i], is_transient, - hint_to_commitment: hints_to_commitment[i], + hint_to_commitment: hints_to_commitment[i] }; - read_request_membership_witnesses.push( - witness); + read_request_membership_witnesses.push(witness); } (read_requests, read_request_membership_witnesses) -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_call_data_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_call_data_builder.nr index f4e38166235..84709242dbf 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_call_data_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_call_data_builder.nr @@ -192,4 +192,4 @@ impl PublicCallDataBuilder { bytecode_hash: self.bytecode_hash, } } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr index 68d42992dc8..adc56745285 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr @@ -65,4 +65,4 @@ impl PublicCircuitPublicInputsBuilder { prover_address: self.prover_address, } } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/testing_harness.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/testing_harness.nr index fde4a7a6f92..da83fe88787 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/testing_harness.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/testing_harness.nr @@ -22,12 +22,12 @@ pub fn build_contract_deployment_data(is_constructor: bool) -> ContractDeploymen pub fn build_tx_context(is_constructor: bool) -> TxContext { let contract_deployment_data = build_contract_deployment_data(is_constructor); - TxContext { + TxContext { is_fee_payment_tx: false, is_rebate_payment_tx: false, is_contract_deployment_tx: is_constructor, contract_deployment_data, chain_id: 1, - version: 0, + version: 0 } } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils.nr index fb8e12010f4..e2f4d5dddda 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils.nr @@ -9,10 +9,6 @@ mod uint128; mod uint256; // if predicate == true then return lhs, else return rhs -pub fn conditional_assign(predicate : bool, lhs : Field, rhs: Field) -> Field { - if predicate{ - lhs - } else { - rhs - } +pub fn conditional_assign(predicate: bool, lhs: Field, rhs: Field) -> Field { + if predicate { lhs } else { rhs } } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/arrays.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/arrays.nr index 95703c90daa..526f444baf7 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/arrays.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/arrays.nr @@ -15,33 +15,32 @@ use crate::utils::bounded_vec::BoundedVec; // if a value can actually be zero. In a future refactor, we can // use the optional type for safety. Doing it now would lead to a worse devex // and would make it harder to sync up with the cpp code. -pub fn is_empty_array(array : [Field; T]) -> bool { +pub fn is_empty_array(array: [Field; T]) -> bool { array.all(|elem| is_empty(elem)) } -fn is_empty(value : Field) -> bool { +fn is_empty(value: Field) -> bool { value == 0 } -pub fn is_empty_struct_array(array : [T; N], - is_empty: fn (T)-> bool) -> bool { +pub fn is_empty_struct_array(array: [T; N], is_empty: fn(T) -> bool) -> bool { array.all(|elem| is_empty(elem)) } // Replace it with `array_to_bounded_vec` when trait is available. -pub fn struct_array_to_bounded_vec(array: [T; N], is_empty_item: fn (T)->bool, empty_item: T) -> BoundedVec { +pub fn struct_array_to_bounded_vec( + array: [T; N], + is_empty_item: fn(T) -> bool, + empty_item: T +) -> BoundedVec { let mut len = 0; for elem in array { if !is_empty_item(elem) { len += 1; } } - - BoundedVec { - storage: array, - len, - empty_value: empty_item, - } + + BoundedVec { storage: array, len, empty_value: empty_item } } pub fn array_to_bounded_vec(array: [Field; N]) -> BoundedVec { @@ -51,12 +50,8 @@ pub fn array_to_bounded_vec(array: [Field; N]) -> BoundedVec { len += 1; } } - - BoundedVec { - storage: array, - len, - empty_value: 0, - } + + BoundedVec { storage: array, len, empty_value: 0 } } // Routine which validates that all zero values of an array form a contiguous region at the end, i.e., @@ -68,7 +63,7 @@ pub fn array_to_bounded_vec(array: [Field; N]) -> BoundedVec { // // TODO: We can possibly optimize this by taking advantage of the fact that adding 0 does not // TODO: change a running sum. -pub fn validate_array(array : [Field;T]) { +pub fn validate_array(array: [Field; T]) { let array_length = array.len(); let mut first_zero_pos = array_length; @@ -103,7 +98,7 @@ pub fn validate_struct_array(array: [T; N], is_empty_item: fn(T) -> bool) // Helper method to determine the number of non-zero/empty elements in a validated array (ie, validate_array(array) // should be true). -pub fn array_length(array : [Field; N]) -> Field { +pub fn array_length(array: [Field; N]) -> Field { let mut length = 0; let mut end = false; for elem in array { @@ -140,8 +135,8 @@ pub fn array_eq(array: [Field; N], expected: [Field; S]) -> bool { pub fn struct_array_eq( array: [T; N], expected: [T; S], - eq: fn (T, T) -> bool, - is_empty_item: fn (T) -> bool, + eq: fn(T, T) -> bool, + is_empty_item: fn(T) -> bool ) -> bool { let length = struct_array_length(array, is_empty_item); let mut ret = length == S; @@ -159,25 +154,25 @@ fn smoke_validate_array() { let valid_array = [0]; validate_array(valid_array); - let valid_array = [1,2,3]; + let valid_array = [1, 2, 3]; validate_array(valid_array); - let valid_array = [1,2,3,0]; + let valid_array = [1, 2, 3, 0]; validate_array(valid_array); - let valid_array = [1,2,3,0,0]; + let valid_array = [1, 2, 3, 0, 0]; validate_array(valid_array); } #[test(should_fail_with = "invalid array")] -fn smoke_validate_array_invalid(){ - let invalid_array = [0,1]; +fn smoke_validate_array_invalid() { + let invalid_array = [0, 1]; validate_array(invalid_array); } #[test(should_fail_with = "invalid array")] -fn smoke_validate_array_invalid_case2(){ - let invalid_array = [0,0,0,0,1]; +fn smoke_validate_array_invalid_case2() { + let invalid_array = [0, 0, 0, 0, 1]; validate_array(invalid_array); } @@ -195,4 +190,4 @@ fn test_array_length() { assert_eq(array_length([123, 456, 0]), 2); assert_eq(array_length([123, 0, 456]), 1); assert_eq(array_length([0, 123, 0, 456]), 0); -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/bounded_vec.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/bounded_vec.nr index c648439e016..e9aa91c26de 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/bounded_vec.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/bounded_vec.nr @@ -1,4 +1,3 @@ - struct BoundedVec { storage: [T; MaxLen], // TODO: change this to return a u64 as Noir now @@ -192,4 +191,4 @@ fn test_vec_any_not_default() { let mut vec: BoundedVec = BoundedVec::new(default_value); vec.push_array([2, 4]); assert(vec.any(|v| v == default_value) == false); -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/uint128.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/uint128.nr index 68f3002aa74..fcaad135ec4 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/uint128.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/uint128.nr @@ -28,4 +28,4 @@ impl U128 { } arr } -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/uint256.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/uint256.nr index ceb5136e25d..82d581796bf 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/uint256.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/uint256.nr @@ -71,8 +71,8 @@ impl U256 { } #[test] -fn smoke_u256_from_bytes32_all_zeroes(){ - let input = [0;32]; +fn smoke_u256_from_bytes32_all_zeroes() { + let input = [0; 32]; let result = U256::from_bytes32(input); assert(result.inner[0] == 0); assert(result.inner[1] == 0); @@ -81,13 +81,14 @@ fn smoke_u256_from_bytes32_all_zeroes(){ } #[test] -fn smoke_u256_from_bytes32_one_zero_zero_zero(){ +fn smoke_u256_from_bytes32_one_zero_zero_zero() { // We want to output [1,0,0,0] - let input = [ 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ]; + let input = [ + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 + ]; let result = U256::from_bytes32(input); assert(result.inner[0] == 1); @@ -97,7 +98,7 @@ fn smoke_u256_from_bytes32_one_zero_zero_zero(){ } #[test] -fn smoke_u256_from_bytes32_test(){ +fn smoke_u256_from_bytes32_test() { /* input: [ 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, @@ -113,15 +114,16 @@ fn smoke_u256_from_bytes32_test(){ inner[2]: 0x1122334455667788 inner[3]: 0x99AABBCCDDEEFF00 */ - let input : [u8;32] = [ 0xAA, 0xBB, 0xCC, 0xDD, - 0xEE, 0xFF, 0x00, 0x11, - 0x22, 0x33, 0x44, 0x55, - 0x66, 0x77, 0x88, 0x99, - 0x11, 0x22, 0x33, 0x44, - 0x55, 0x66, 0x77, 0x88, - 0x99, 0xAA, 0xBB, 0xCC, - 0xDD, 0xEE, 0xFF, 0x00 - ]; + let input : [u8;32] = [ + 0xAA, 0xBB, 0xCC, 0xDD, + 0xEE, 0xFF, 0x00, 0x11, + 0x22, 0x33, 0x44, 0x55, + 0x66, 0x77, 0x88, 0x99, + 0x11, 0x22, 0x33, 0x44, + 0x55, 0x66, 0x77, 0x88, + 0x99, 0xAA, 0xBB, 0xCC, + 0xDD, 0xEE, 0xFF, 0x00 + ]; let result = U256::from_bytes32(input); assert(result.inner[0] == 0xAABBCCDDEEFF0011); diff --git a/yarn-project/package.json b/yarn-project/package.json index acf4b1627f7..041dcde0235 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -7,7 +7,7 @@ "prepare:check": "node ./yarn-project-base/scripts/update_package_jsons.mjs --check && workspaces-to-typescript-project-references --check --tsconfigPath tsconfig.json", "docs": "typedoc --out docs/dist && cd docs && yarn serve", "formatting": "FORCE_COLOR=true yarn workspaces foreach -p -j unlimited -v run formatting", - "formatting:fix": "FORCE_COLOR=true yarn workspaces foreach -p -v run formatting:fix", + "formatting:fix": "./run_nargo_fmt.sh && FORCE_COLOR=true yarn workspaces foreach -p -v run formatting:fix", "lint": "yarn eslint --cache --ignore-pattern l1-artifacts .", "format": "yarn prettier --cache -w .", "test": "FORCE_COLOR=true yarn workspaces foreach --exclude @aztec/aztec3-packages --exclude @aztec/end-to-end --exclude private-token -p -j unlimited -v run test", diff --git a/yarn-project/run_nargo_fmt.sh b/yarn-project/run_nargo_fmt.sh new file mode 100755 index 00000000000..253b53e7ede --- /dev/null +++ b/yarn-project/run_nargo_fmt.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +nargo_executable="$(git rev-parse --show-toplevel)/noir/target/release/nargo" + +# Find all Nargo.toml files and run 'nargo fmt' +find . -name "Nargo.toml" | while read -r file; do + # Extract the directory from the file path + dir=$(dirname "$file") + + # Change into the directory + cd "$dir" || exit + + # Run 'nargo fmt' in the directory and pass in the input param 1 + "$nargo_executable" fmt $1 + + # Change back to the original directory + cd - > /dev/null +done diff --git a/yellow-paper/docs/state/archive.md b/yellow-paper/docs/state/archive.md index ffb84328dc3..3517a2c8026 100644 --- a/yellow-paper/docs/state/archive.md +++ b/yellow-paper/docs/state/archive.md @@ -6,7 +6,7 @@ title: Archive The Archive is an [append-only Merkle tree](./tree_impls.md#append-only-merkle-trees) that stores the headers of all previous blocks in the chain as its leaves. -For most chains this is not required since they are always executing at the head of the chain. However, private execution relies on proofs generated by the user, and since user's don't know the current head they must base their proofs on historical state. By including all prior headers (which include commitments to the state) the Archive allows us to easily prove that the historic state that a transaction was proven upon is valid. +For most chains this is not required since they are always executing at the head of the chain. However, private execution relies on proofs generated by the user, and since users don't know the current head they must base their proofs on historical state. By including all prior headers (which include commitments to the state) the Archive allows us to easily prove that the historic state that a transaction was proven upon is valid. Furthermore, since the Headers include a snapshot of the Archive at the time of insertion, as well as commitments to the block content and global variables, we can use it to prove statements about the state at any given block or even transactions that occurred at specific blocks.