diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index 4e20c24aabb8..b3a2dffeada3 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -238,7 +238,7 @@ describe('ACIR public execution simulator', () => { globalVariables.timestamp.value, ), ]); - }); + }, 20000); }); describe('Public -> Private / Cross Chain messaging', () => { diff --git a/yarn-project/noir-contracts/README.md b/yarn-project/noir-contracts/README.md index 0d0f8435b7bc..3549d2cb0e19 100644 --- a/yarn-project/noir-contracts/README.md +++ b/yarn-project/noir-contracts/README.md @@ -2,6 +2,10 @@ This package contains the source code and the Aztec ABIs for the example contracts used in tests. +## Disclaimer + +Please note that any example contract set out herein is provided solely for informational purposes only and does not constitute any inducement to use or deploy. Any implementation of any such contract with an interface or any other infrastructure should be used in accordance with applicable laws and regulations. + ## Setup ### Installing Noir diff --git a/yarn-project/noir-contracts/src/contracts/child_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/child_contract/src/main.nr index 75594e801775..7d80aaaeffd1 100644 --- a/yarn-project/noir-contracts/src/contracts/child_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/child_contract/src/main.nr @@ -22,7 +22,7 @@ contract Child { ) -> distinct pub abi::PrivateCircuitPublicInputs { let mut context = Context::new(inputs, abi::hash_args([input])); - context.return_values = context.return_values.push(input + inputs.private_global_variables.chain_id + inputs.private_global_variables.version); + context.return_values.push(input + inputs.private_global_variables.chain_id + inputs.private_global_variables.version); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() diff --git a/yarn-project/noir-contracts/src/contracts/easy_zk_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/easy_zk_token_contract/src/main.nr index 3c990a5c8b4a..bc5dc86f9f6e 100644 --- a/yarn-project/noir-contracts/src/contracts/easy_zk_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/easy_zk_token_contract/src/main.nr @@ -36,9 +36,9 @@ contract EasyZkToken { let storage = Storage::init(); let balances = storage.balances; - context = balances.at(owner).add(context, initial_supply, owner); + balances.at(owner).add(&mut context, initial_supply, owner); - context = emit_unencrypted_log(context, "Balance set in constructor"); + emit_unencrypted_log(&mut context, "Balance set in constructor"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() @@ -57,9 +57,9 @@ contract EasyZkToken { let storage = Storage::init(); let balances = storage.balances; - context = balances.at(owner).add(context, amount, owner); + balances.at(owner).add(&mut context, amount, owner); - context = emit_unencrypted_log(context, "Coins minted"); + emit_unencrypted_log(&mut context, "Coins minted"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() @@ -79,11 +79,11 @@ contract EasyZkToken { let storage = Storage::init(); let balances = storage.balances; - context = balances.at(sender).sub(context, amount, sender); + balances.at(sender).sub(&mut context, amount, sender); - context = balances.at(recipient).add(context, amount, recipient); + balances.at(recipient).add(&mut context, amount, recipient); - context = emit_unencrypted_log(context, "Coins transferred"); + emit_unencrypted_log(&mut context, "Coins transferred"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() diff --git a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index 37cf727db00e..47d7810b7545 100644 --- a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -62,9 +62,8 @@ impl EcdsaPublicKeyNote { ])[0] } - fn set_header(mut self: Self, header: NoteHeader) -> Self { + fn set_header(&mut self, header: NoteHeader) { self.header = header; - self } fn dummy() -> Self { @@ -125,8 +124,8 @@ fn get_header(note: EcdsaPublicKeyNote) -> NoteHeader { note.header } -fn set_header(note: EcdsaPublicKeyNote, header: NoteHeader) -> EcdsaPublicKeyNote { - note.set_header(header) +fn set_header(note: &mut EcdsaPublicKeyNote, header: NoteHeader) { + note.set_header(header); } global EcdsaPublicKeyNoteInterface = NoteInterface { diff --git a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr index b01f905a6a87..3ec00e6695c2 100644 --- a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr @@ -40,14 +40,13 @@ contract EcdsaAccount { // Initialise context // 71 = ENTRYPOINT_PAYLOAD_SIZE(7) + 64 let mut args: BoundedVec = BoundedVec::new(0); - args = args.push_array(payload.serialize()); - for byte in signature { args = args.push(byte as Field); } + args.push_array(payload.serialize()); + for byte in signature { args.push(byte as Field); } let mut context = Context::new(inputs, abi::hash_args(args.storage)); // Load public key from storage let storage = Storage::init(); - let (context_1, public_key) = storage.public_key.get_note(context); - context = context_1; + let public_key = storage.public_key.get_note(&mut context); // Verify payload signature using Ethereum's signing scheme let payload_bytes: [u8; entrypoint::ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES] = payload.to_be_bytes(); @@ -61,7 +60,8 @@ contract EcdsaAccount { // debug_log::debug_log_array_with_prefix("challenge", challenge); // debug_log::debug_log_array_with_prefix("signature", signature); - context = payload.execute_calls(context); + payload.execute_calls(&mut context); + context.finish() } @@ -74,16 +74,16 @@ contract EcdsaAccount { let storage = Storage::init(); let mut args: BoundedVec = BoundedVec::new(0); - for byte in signing_pub_key_x { args = args.push(byte as Field); } - for byte in signing_pub_key_y { args = args.push(byte as Field); } + for byte in signing_pub_key_x { args.push(byte as Field); } + for byte in signing_pub_key_y { args.push(byte as Field); } let mut context = Context::new(inputs, abi::hash_args(args.storage)); let this = inputs.call_context.storage_contract_address; - let pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this); - context = storage.public_key.initialise(context, pub_key_note); + let mut pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, inputs.call_context.storage_contract_address); + storage.public_key.initialise(&mut context, &mut pub_key_note); - context = emit_encrypted_log( - context, + emit_encrypted_log( + &mut context, this, storage.public_key.storage_slot, this, diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr index 44dd5228a8bc..0e4f63d4e161 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr @@ -12,9 +12,9 @@ contract Lending { create_nullifier::create_nullifier, }; use dep::aztec::public_call_stack_item::{ + PublicCallStackItem, call_public_function, - call_public_function_no_args, - PublicCallStackItem + call_public_function_no_args, }; use crate::storage::{Storage, Tot, Account}; @@ -80,7 +80,7 @@ contract Lending { owner: Field, amount: Field ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ secret, owner, amount @@ -97,11 +97,10 @@ contract Lending { // Unshield tokens into this contract. // _deposit(account, amount) - let (_callStackItem, mut context) = PublicCallStackItem::call( + let _callStackItem = context.call_public_function( inputs.call_context.storage_contract_address, 3009041984, - [account, amount], - initialContext + [account, amount] ); context.finish() @@ -138,18 +137,17 @@ contract Lending { secret: Field, amount: Field ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ secret, amount ])); let me = inputs.call_context.msg_sender; let account = Account::new(me, secret).key(); - let (_callStackItem, mut context) = PublicCallStackItem::call( + let _callStackItem = context.call_public_function( inputs.call_context.storage_contract_address, 1065861440, - [account, amount], - initialContext + [account, amount] ); context.finish() @@ -196,7 +194,7 @@ contract Lending { secret: Field, amount: Field ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ secret, amount ])); @@ -204,11 +202,10 @@ contract Lending { let me = inputs.call_context.msg_sender; let account = Account::new(me, secret).key(); - let (_callStackItem, mut context) = PublicCallStackItem::call( + let _callStackItem = context.call_public_function( inputs.call_context.storage_contract_address, 1462609836, - [account, amount], - initialContext + [account, amount] ); context.finish() @@ -253,7 +250,7 @@ contract Lending { owner: Field, amount: Field ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ secret, owner, amount @@ -269,11 +266,10 @@ contract Lending { // @todo @lherskind Transfer tokens from me to this contract. - let (_callStackItem, mut context) = PublicCallStackItem::call( + let _callStackItem = context.call_public_function( inputs.call_context.storage_contract_address, 3985016136, - [account, amount], - initialContext + [account, amount] ); context.finish() diff --git a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr index 3294332ff875..2ac049893af0 100644 --- a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr @@ -67,7 +67,7 @@ contract NonNativeToken { let mut context = Context::new(inputs, abi::hash_args([initial_supply, owner])); let balance = storage.balances.at(owner); - context = send_note(context, balance, initial_supply, owner); + send_note(&mut context, balance, initial_supply, owner); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() @@ -97,11 +97,10 @@ contract NonNativeToken { let content_hash = get_mint_content_hash(amount, owner, canceller); // Get the l1 message from an oracle call - let updated_context = context.consume_l1_to_l2_message(inputs, msg_key, content_hash, secret); - context = updated_context; + context.consume_l1_to_l2_message(inputs, msg_key, content_hash, secret); let balance = storage.balances.at(owner); - context = send_note(context, balance, amount, owner); + send_note(&mut context, balance, amount, owner); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() @@ -126,10 +125,10 @@ contract NonNativeToken { ])); let sender_balance = storage.balances.at(sender); - context = spend_notes(context, sender_balance, amount, sender); + spend_notes(&mut context, sender_balance, amount, sender); let content = get_withdraw_content_hash(amount, recipient, callerOnL1); - context = context.message_portal(content); + context.message_portal(content); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() @@ -215,10 +214,10 @@ contract NonNativeToken { // Gets the set of sender's notes and picks 2 of those. let sender_balance = storage.balances.at(sender); - context = spend_notes(context, sender_balance, amount, sender); + spend_notes(&mut context, sender_balance, amount, sender); let balance = storage.balances.at(recipient); - context = send_note(context, balance, amount, recipient); + send_note(&mut context, balance, amount, recipient); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() @@ -266,11 +265,11 @@ contract NonNativeToken { // Assert that the note exists within the tree let public_note = TransparentNote::new_from_secret(amount, secret); - context = public_note.consume_in_secret(context, inputs.roots.private_data_tree_root, secret); + public_note.consume_in_secret(&mut context, inputs.roots.private_data_tree_root, secret); // Mint the tokens let balance = storage.balances.at(owner); - context = send_note(context, balance, amount, owner); + send_note(&mut context, balance, amount, owner); context.finish() } @@ -288,7 +287,7 @@ contract NonNativeToken { // Remove user balance let sender_balance = storage.balances.at(owner); - context = spend_notes(context, sender_balance, amount, owner); + spend_notes(&mut context, sender_balance, amount, owner); // enqueue a public function to perform the public state update. let thisAddress = inputs.call_context.storage_contract_address; @@ -296,8 +295,7 @@ contract NonNativeToken { // addUnshieldedBalance selector (in decimal) // recompute by: `cast keccak addUnshieldedBalance(field,field)` -> convert to decimal let pubEntryPointSelector = 753269941; - let (_callStackItem1, mut context1) = PublicCallStackItem::call(thisAddress, pubEntryPointSelector, [amount, recipient], context); - context = context1; + let _callStackItem1 = context.call_public_function(thisAddress, pubEntryPointSelector, [amount, recipient]); context.finish() } diff --git a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/transparent_note.nr b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/transparent_note.nr index 27d19b7a134f..93b6a5ce3071 100644 --- a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/transparent_note.nr +++ b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/transparent_note.nr @@ -36,12 +36,12 @@ impl TransparentNote { pedersen([self.amount, self.secretHash])[0] } - fn consume_in_secret(self: Self, mut context: Context, root: Field, secret: Field) -> Context { + fn consume_in_secret(self: Self, context: &mut Context, root: Field, secret: Field) { // Get the commitment value (before silo) let commitment = self.get_commitment(); // Let the kernel perform the read. - context = context.push_read_request(commitment); + context.push_read_request(commitment); // Get the commitment data, (where it is in the db) let commitment_oracle_call = get_commitment(commitment); @@ -50,7 +50,7 @@ impl TransparentNote { assert(root == commitment_data.root); // Calculate the nullifier - self.emit_nullifier(context, secret, commitment, commitment_data.leaf_index) + self.emit_nullifier(context, secret, commitment, commitment_data.leaf_index); } fn compute_secret_hash(secret: Field) -> Field { @@ -63,7 +63,7 @@ impl TransparentNote { assert(self.secretHash == hash); } - fn emit_nullifier(_self: Self, mut context: Context, secret: Field, siloed_commitment: Field, index: Field) -> Context { + fn emit_nullifier(_self: Self, context: &mut Context, secret: Field, siloed_commitment: Field, index: Field) { // Create a nullifier for the message based on its index in the tree let nullifier = pedersen([secret, siloed_commitment, index])[0]; diff --git a/yarn-project/noir-contracts/src/contracts/parent_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/parent_contract/src/main.nr index cd3ae8e6baf4..49577f87b8eb 100644 --- a/yarn-project/noir-contracts/src/contracts/parent_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/parent_contract/src/main.nr @@ -4,9 +4,6 @@ contract Parent { use dep::aztec::abi::PrivateContextInputs; use dep::aztec::abi::PublicContextInputs; use dep::aztec::context::Context; - use dep::aztec::oracle::public_call; - use dep::aztec::private_call_stack_item::PrivateCallStackItem; - use dep::aztec::public_call_stack_item::PublicCallStackItem; use dep::aztec::public_call_stack_item::call_public_function; fn constructor( @@ -21,17 +18,17 @@ contract Parent { targetContract: Field, targetSelector: Field, ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ targetContract, targetSelector, ])); // Call the target private function - let (callStackItem, mut context) = PrivateCallStackItem::call(targetContract, targetSelector, [0], initialContext); + let callStackItem = context.call_private_function(targetContract, targetSelector, [0]); // Copy the return value from the call to this function's return values let result = callStackItem.public_inputs.return_values[0]; - context.return_values = context.return_values.push(result); + context.return_values.push(result); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() @@ -55,13 +52,13 @@ contract Parent { targetSelector: Field, targetValue: Field, ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ targetContract, targetSelector, targetValue, ])); - let (_callStackItem, mut context) = PublicCallStackItem::call(targetContract, targetSelector, [targetValue], initialContext); + let _callStackItem = context.call_public_function(targetContract, targetSelector, [targetValue]); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() @@ -74,19 +71,19 @@ contract Parent { targetSelector: Field, targetValue: Field, ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut context0 = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ targetContract, targetSelector, targetValue, ])); // Enqueue the first public call - let (callStackItem1, context1) = PublicCallStackItem::call(targetContract, targetSelector, [targetValue], context0); + let callStackItem1 = context.call_public_function(targetContract, targetSelector, [targetValue]); // Enqueue the second public call - let (_callStackItem2, context2) = PublicCallStackItem::call(targetContract, targetSelector, [callStackItem1.public_inputs.return_values[0]], context1); + let _callStackItem2 = context.call_public_function(targetContract, targetSelector, [callStackItem1.public_inputs.return_values[0]]); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. - context2.finish() + context.finish() } // Private function to enqueue a call to the pubEntryPoint function of this same contract, passing the target arguments provided @@ -96,7 +93,7 @@ contract Parent { targetSelector: Field, targetValue: Field, ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ targetContract, targetSelector, targetValue, @@ -104,10 +101,10 @@ contract Parent { let pubEntryPointSelector = 3221316504; let thisAddress = inputs.call_context.storage_contract_address; - let (_callStackItem1, mut context1) = PublicCallStackItem::call(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue], initialContext); + let _callStackItem = context.call_public_function(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue]); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. - context1.finish() + context.finish() } // Private function to enqueue two calls to the pubEntryPoint function of this same contract, passing the target arguments provided @@ -117,7 +114,7 @@ contract Parent { targetSelector: Field, targetValue: Field, ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ targetContract, targetSelector, targetValue, @@ -126,11 +123,11 @@ contract Parent { let pubEntryPointSelector = 3221316504; let thisAddress = inputs.call_context.storage_contract_address; - let (_callStackItem1, mut context1) = PublicCallStackItem::call(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue], initialContext); + let _callStackItem1 = context.call_public_function(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue]); - let (_callStackItem2, mut context2) = PublicCallStackItem::call(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue + 1], context1); + let _callStackItem2 = context.call_public_function(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue + 1]); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. - context2.finish() + context.finish() } -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/pending_commitments_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/pending_commitments_contract/src/main.nr index ce6478fd4e75..39e9717581fd 100644 --- a/yarn-project/noir-contracts/src/contracts/pending_commitments_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/pending_commitments_contract/src/main.nr @@ -41,8 +41,6 @@ contract PendingCommitments { inputs: PrivateContextInputs //*********************************/ ) -> distinct pub abi::PrivateCircuitPublicInputs { - let storage = Storage::init(); - //let context = Context::new(inputs, abi::hash_args([])); let context = Context::new(inputs, 0); context.finish() } @@ -61,22 +59,21 @@ contract PendingCommitments { let mut context = Context::new(inputs, abi::hash_args([amount, owner])); let owner_balance = storage.balances.at(owner); - let note = ValueNote::new(amount, owner); + let mut note = ValueNote::new(amount, owner); // Insert note and emit encrypted note preimage via oracle call - context = owner_balance.insert(context, note); + owner_balance.insert(&mut context, &mut note); let options = NoteGetterOptions::with_filter(get_2_notes, 0); // get note inserted above - let (context_tmp, got_notes) = owner_balance.get_notes(context, options); - context = context_tmp; + let got_notes = owner_balance.get_notes(&mut context, options); assert(note.value == got_notes[0].value); assert(!got_notes[1].is_real); - context.return_values = context.return_values.push(got_notes[0].value); + context.return_values.push(got_notes[0].value); - context = owner_balance.remove(context, got_notes[0]); + owner_balance.remove(&mut context, got_notes[0]); context.finish() } @@ -97,18 +94,17 @@ contract PendingCommitments { let options = NoteGetterOptions::with_filter(get_2_notes, 0); // get note (note inserted at bottom of function shouldn't exist yet) - let (context_tmp, got_notes) = owner_balance.get_notes(context, options); - context = context_tmp; + let got_notes = owner_balance.get_notes(&mut context, options); assert(!got_notes[0].is_real); assert(got_notes[0].value == 0); assert(!got_notes[1].is_real); - context.return_values = context.return_values.push(got_notes[0].value); + context.return_values.push(got_notes[0].value); // Insert note and emit encrypted note preimage via oracle call - let note = ValueNote::new(amount, owner); - context = owner_balance.insert(context, note); + let mut note = ValueNote::new(amount, owner); + owner_balance.insert(&mut context, &mut note); context.finish() } @@ -126,10 +122,10 @@ contract PendingCommitments { let mut context = Context::new(inputs, abi::hash_args([amount, owner])); let owner_balance = storage.balances.at(owner); - let note = ValueNote::new(amount, owner); + let mut note = ValueNote::new(amount, owner); // Insert note and emit encrypted note preimage via oracle call - context = owner_balance.insert(context, note); + owner_balance.insert(&mut context, &mut note); context.finish() } @@ -149,15 +145,14 @@ contract PendingCommitments { let owner_balance = storage.balances.at(owner); let options = NoteGetterOptions::with_filter(get_2_notes, 0); - let (context_tmp, got_notes) = owner_balance.get_notes(context, options); - context = context_tmp; + let got_notes = owner_balance.get_notes(&mut context, options); assert(expected_value == got_notes[0].value); assert(!got_notes[1].is_real); - context.return_values = context.return_values.push(got_notes[0].value); + context.return_values.push(got_notes[0].value); - context = owner_balance.remove(context, got_notes[0]); + owner_balance.remove(&mut context, got_notes[0]); context.finish() } @@ -176,8 +171,7 @@ contract PendingCommitments { let owner_balance = storage.balances.at(owner); let options = NoteGetterOptions::with_filter(get_2_notes, 0); - let (context_tmp, got_notes) = owner_balance.get_notes(context, options); - context = context_tmp; + let got_notes = owner_balance.get_notes(&mut context, options); assert(!got_notes[0].is_real); assert(!got_notes[1].is_real); @@ -206,14 +200,11 @@ contract PendingCommitments { args[1] = owner; // nested call to create/insert note - let (_callStackItem1, mut context_tmp0) = PrivateCallStackItem::call(inputs.call_context.storage_contract_address, insert_fn_selector, args, context); - context = context_tmp0; + let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, insert_fn_selector, args); // nested call to read that note / pending commitment - let (_callStackItem2, mut context_tmp1) = PrivateCallStackItem::call(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, args, context); - context = context_tmp1; + let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, args); // nested call to confirm that balance is zero - let (_callStackItem3, mut context_tmp2) = PrivateCallStackItem::call(inputs.call_context.storage_contract_address, get_note_zero_fn_selector, [owner], context); - context = context_tmp2; + let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, get_note_zero_fn_selector, [owner]); context.finish() } diff --git a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr index b08a3a336a02..111b4178f751 100644 --- a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr +++ b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr @@ -36,9 +36,8 @@ impl AddressNote { ])[0] } - fn set_header(mut self: Self, header: NoteHeader) -> Self { + fn set_header(&mut self, header: NoteHeader) { self.header = header; - self } fn dummy() -> Self { @@ -84,8 +83,8 @@ fn get_header(note: AddressNote) -> NoteHeader { note.header } -fn set_header(note: AddressNote, header: NoteHeader) -> AddressNote { - note.set_header(header) +fn set_header(note: &mut AddressNote, header: NoteHeader) { + note.set_header(header); } global AddressNoteInterface = NoteInterface { diff --git a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/main.nr index bfed8f7a24b0..7ca90f91b8e7 100644 --- a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/main.nr @@ -38,17 +38,17 @@ contract PokeableToken { let storage = Storage::init(); let mut context = Context::new(inputs, abi::hash_args([initial_supply, sender, recipient, poker])); - let sender_note = AddressNote::new(sender); - let recipient_note = AddressNote::new(recipient); + let mut sender_note = AddressNote::new(sender); + let mut recipient_note = AddressNote::new(recipient); - context = storage.sender.initialise(context, sender_note); - context = storage.recipient.initialise(context, recipient_note); + storage.sender.initialise(&mut context, &mut sender_note); + storage.recipient.initialise(&mut context, &mut recipient_note); let pokerEncPubKey = get_public_key_non_contract_account(poker); let this = inputs.call_context.storage_contract_address; - context = emit_encrypted_log( - context, + emit_encrypted_log( + &mut context, this, storage.sender.storage_slot, poker, @@ -56,8 +56,8 @@ contract PokeableToken { sender_note.serialise(), ); - context = emit_encrypted_log( - context, + emit_encrypted_log( + &mut context, this, storage.recipient.storage_slot, poker, @@ -67,7 +67,7 @@ contract PokeableToken { // Insert new note to a set of user notes and emit the newly created encrypted note preimage via oracle call. let sender_balance = storage.balances.at(sender); - context = send_note(context, sender_balance, initial_supply, sender); + send_note(&mut context, sender_balance, initial_supply, sender); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() @@ -83,18 +83,15 @@ contract PokeableToken { let mut context = Context::new(inputs, 0); // Since there are no arguments, we can just 0 as the args hash. let storage = Storage::init(); - let (context_1, sender) = storage.sender.get_note(context); - context = context_1; + let sender = storage.sender.get_note(&mut context); - let (context_2, recipient) = storage.recipient.get_note(context); - context = context_2; + let recipient = storage.recipient.get_note(&mut context); // Pick from the set of sender's notes. let sender_balance = storage.balances.at(sender.address); let options = NoteGetterOptions::with_filter(get_2_notes, 0); - let (mut new_context, notes) = sender_balance.get_notes(context, options); - context = new_context; + let notes = sender_balance.get_notes(&mut context, options); let note1 = notes[0]; let note2 = notes[1]; @@ -102,12 +99,12 @@ contract PokeableToken { let note_sum = note1.value + note2.value; // Removes the 2 notes from the sender's set of notes. - context = sender_balance.remove(context, note1); - context = sender_balance.remove(context, note2); + sender_balance.remove(&mut context, note1); + sender_balance.remove(&mut context, note2); // Create new note for the recipient. let recipient_balance = storage.balances.at(recipient.address); - context = send_note(context, recipient_balance, note_sum, recipient.address); + send_note(&mut context, recipient_balance, note_sum, recipient.address); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_multi_key_account_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/schnorr_multi_key_account_contract/src/main.nr index ba5b4dfc810c..79ef688d47d2 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_multi_key_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_multi_key_account_contract/src/main.nr @@ -35,14 +35,13 @@ contract SchnorrMultiKeyAccount { // Initialize context // 71 = ENTRYPOINT_PAYLOAD_SIZE(7) + 64 let mut args: BoundedVec = BoundedVec::new(0); - args = args.push_array(payload.serialize()); - for byte in signature { args = args.push(byte as Field); } + args.push_array(payload.serialize()); + for byte in signature { args.push(byte as Field); } let mut context = Context::new(inputs, abi::hash_args(args.storage)); // Load public key from storage let storage = Storage::init(); - let (context_1, public_key) = storage.signing_public_key.get_note(context); - context = context_1; + let public_key = storage.signing_public_key.get_note(&mut context); // Verify payload signature // TODO: Use pedersen to make the payload hash cheaper to compute @@ -54,7 +53,7 @@ contract SchnorrMultiKeyAccount { assert(verification == true); // Execute calls - context = payload.execute_calls(context); + payload.execute_calls(&mut context); context.finish() } @@ -70,11 +69,11 @@ contract SchnorrMultiKeyAccount { let mut context = Context::new(inputs, abi::hash_args([signing_pub_key_x, signing_pub_key_y])); let this = inputs.call_context.storage_contract_address; - let pub_key_note = PublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this); - context = storage.signing_public_key.initialise(context, pub_key_note); + let mut pub_key_note = PublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this); + storage.signing_public_key.initialise(&mut context, &mut pub_key_note); - context = emit_encrypted_log( - context, + emit_encrypted_log( + &mut context, this, storage.signing_public_key.storage_slot, this, diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_multi_key_account_contract/src/public_key_note.nr b/yarn-project/noir-contracts/src/contracts/schnorr_multi_key_account_contract/src/public_key_note.nr index c78a5592ad5b..ab54500684d7 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_multi_key_account_contract/src/public_key_note.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_multi_key_account_contract/src/public_key_note.nr @@ -41,9 +41,8 @@ impl PublicKeyNote { ])[0] } - fn set_header(mut self: Self, header: NoteHeader) -> Self { + fn set_header(&mut self, header: NoteHeader) { self.header = header; - self } fn dummy() -> Self { @@ -93,8 +92,8 @@ fn get_header(note: PublicKeyNote) -> NoteHeader { note.header } -fn set_header(note: PublicKeyNote, header: NoteHeader) -> PublicKeyNote { - note.set_header(header) +fn set_header(note: &mut PublicKeyNote, header: NoteHeader) { + note.set_header(header); } global PublicKeyNoteInterface = NoteInterface { diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main.nr index dc7b21fe8ade..de0d06cd68d0 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main.nr @@ -25,10 +25,10 @@ contract SchnorrSingleKeyAccount { // Initialize context // 136 = ENTRYPOINT_PAYLOAD_SIZE(7) + 64 + 64 + 1 let mut args: BoundedVec = BoundedVec::new(0); - args = args.push_array(payload.serialize()); - for byte in owner { args = args.push(byte as Field); } - for byte in signature { args = args.push(byte as Field); } - args = args.push(partial_address); + args.push_array(payload.serialize()); + for byte in owner { args.push(byte as Field); } + for byte in signature { args.push(byte as Field); } + args.push(partial_address); let mut context = Context::new(inputs, abi::hash_args(args.storage)); // Verify payload signature @@ -58,7 +58,7 @@ contract SchnorrSingleKeyAccount { assert(reproduced_address == inputs.call_context.storage_contract_address); // Execute calls - context = payload.execute_calls(context); + payload.execute_calls(&mut context); context.finish() } diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr index e4aa51947f25..4580fc44c299 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr @@ -28,7 +28,7 @@ contract Test { ) -> distinct pub abi::PrivateCircuitPublicInputs { let mut context = Context::new(inputs, abi::hash_args([address])); let pub_key = get_public_key(address); - context.return_values = context.return_values.push_array([pub_key.x, pub_key.y]); + context.return_values.push_array([pub_key.x, pub_key.y]); context.finish() } diff --git a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr index bfd320e9591e..7d63646ce210 100644 --- a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr @@ -42,7 +42,7 @@ contract Uniswap { l1UniswapPortal: Field, // L1 address of uniswap portal contract callerOnL1: Field, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) ) -> distinct pub abi::PrivateCircuitPublicInputs { - let mut initialContext = Context::new(inputs, abi::hash_args([ + let mut context = Context::new(inputs, abi::hash_args([ withdrawFnSelector, inputAsset, inputAssetPortalAddress, @@ -63,15 +63,15 @@ contract Uniswap { // inputAsset.withdraw(inputAmount, sender, recipient=l1UniswapPortal, callerOnL1=l1UniswapPortal) // only uniswap portal can call this (done to safeguard ordering of message consumption) // ref: https://docs.aztec.network/aztec/how-it-works/l1-l2-messaging#designated-caller - let (callStackItem, mut context) = PrivateCallStackItem::call(inputAsset, withdrawFnSelector, [ + let callStackItem = context.call_private_function(inputAsset, withdrawFnSelector, [ inputAmount, sender, l1UniswapPortal, l1UniswapPortal, - ], initialContext); + ]); let result = callStackItem.public_inputs.return_values[0]; - context.return_values = context.return_values.push(result); + context.return_values.push(result); // Send the swap message to L1 portal let content_hash = _compute_swap_content_hash( @@ -86,7 +86,7 @@ contract Uniswap { cancellerForL1ToL2Message, callerOnL1, ); - context = context.message_portal(content_hash); + context.message_portal(content_hash); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() diff --git a/yarn-project/noir-contracts/src/contracts/zk_token_contract/src/claim_note.nr b/yarn-project/noir-contracts/src/contracts/zk_token_contract/src/claim_note.nr index beed05598d10..0e156bef1bcf 100644 --- a/yarn-project/noir-contracts/src/contracts/zk_token_contract/src/claim_note.nr +++ b/yarn-project/noir-contracts/src/contracts/zk_token_contract/src/claim_note.nr @@ -61,9 +61,8 @@ impl ClaimNote { self.value == 0 } - fn set_header(mut self: Self, header: NoteHeader) -> Self { + fn set_header(&mut self, header: NoteHeader) { self.header = header; - self } } @@ -95,7 +94,7 @@ fn get_header(note: ClaimNote) -> NoteHeader { note.header } -fn set_header(note: ClaimNote, header: NoteHeader) -> ClaimNote { +fn set_header(note: &mut ClaimNote, header: NoteHeader) { note.set_header(header) } diff --git a/yarn-project/noir-contracts/src/contracts/zk_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/zk_token_contract/src/main.nr index 0e1cd942771f..6cfc3eb0d46c 100644 --- a/yarn-project/noir-contracts/src/contracts/zk_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/zk_token_contract/src/main.nr @@ -13,12 +13,9 @@ contract ZkToken { use dep::aztec::abi::PrivateContextInputs; use dep::aztec::context::Context; use dep::aztec::note::{ - note_header::{NoteHeader}, + note_header::NoteHeader, utils as note_utils, }; - use dep::aztec::types::point::Point; - use dep::aztec::state_vars::map::Map; - use dep::aztec::state_vars::set::Set; use dep::aztec::log::emit_unencrypted_log; use crate::storage::Storage; @@ -32,7 +29,7 @@ contract ZkToken { inputs: PrivateContextInputs, //*********************************/ initial_supply: Field, - owner: Field, + owner: Field ) -> distinct pub abi::PrivateCircuitPublicInputs { let storage = Storage::init(); let mut context = Context::new(inputs, abi::hash_args([initial_supply, owner])); @@ -40,8 +37,8 @@ contract ZkToken { // Insert new note to a set of user notes and emit the newly created encrypted note preimage via oracle call. let owner_balance = storage.balances.at(owner); if (initial_supply != 0) { - context = send_note(context, owner_balance, initial_supply, owner); - context = emit_unencrypted_log(context, "Balance set in constructor"); + send_note(&mut context, owner_balance, initial_supply, owner); + emit_unencrypted_log(&mut context, "Balance set in constructor"); } // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. @@ -55,15 +52,15 @@ contract ZkToken { inputs: PrivateContextInputs, //*********************************/ amount: Field, - owner: Field, + owner: Field ) -> distinct pub abi::PrivateCircuitPublicInputs { let storage = Storage::init(); let mut context = Context::new(inputs, abi::hash_args([amount, owner])); // Insert new note to a set of user notes and emit the newly created encrypted note preimage via oracle call. let owner_balance = storage.balances.at(owner); - context = send_note(context, owner_balance, amount, owner); - context = emit_unencrypted_log(context, "Coins minted"); + send_note(&mut context, owner_balance, amount, owner); + emit_unencrypted_log(&mut context, "Coins minted"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() @@ -84,13 +81,13 @@ contract ZkToken { // Pick from the set of sender's notes to spend amount. let sender_balance = storage.balances.at(sender); - context = spend_notes(context, sender_balance, amount, sender); + spend_notes(&mut context, sender_balance, amount, sender); // Creates new note for the recipient. let recipient_balance = storage.balances.at(recipient); - context = send_note(context, recipient_balance, amount, recipient); + send_note(&mut context, recipient_balance, amount, recipient); - context = emit_unencrypted_log(context, "Coins transferred"); + emit_unencrypted_log(&mut context, "Coins transferred"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() @@ -103,7 +100,7 @@ contract ZkToken { //*********************************/ amounts: [Field; 2], secrets: [Field; 2], - sender: Field, + sender: Field ) -> distinct pub abi::PrivateCircuitPublicInputs { let storage = Storage::init(); let mut context = Context::new(inputs, abi::hash_args([amounts[0], amounts[1], secrets[0], secrets[1], sender])); @@ -111,16 +108,16 @@ contract ZkToken { // Pick from the set of sender's notes to spend amount. let sender_balance = storage.balances.at(sender); let total = amounts[0] + amounts[1]; - context = spend_notes(context, sender_balance, total, sender); + spend_notes(&mut context, sender_balance, total, sender); // Create claim notes. let claims = storage.claims; - let note0 = ClaimNote::new(amounts[0], secrets[0]); - let note1 = ClaimNote::new(amounts[1], secrets[1]); + let mut note0 = ClaimNote::new(amounts[0], secrets[0]); + let mut note1 = ClaimNote::new(amounts[1], secrets[1]); // Insert the new claim notes to the set. - context = claims.insert(context, note0); - context = claims.insert(context, note1); + claims.insert(&mut context, &mut note0); + claims.insert(&mut context, &mut note1); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() @@ -133,21 +130,19 @@ contract ZkToken { //*********************************/ amount: Field, secret: Field, - owner: Field, + owner: Field ) -> distinct pub abi::PrivateCircuitPublicInputs { let storage = Storage::init(); let mut context = Context::new(inputs, abi::hash_args([amount, secret, owner])); // Remove the claim note if it exists in the set. let mut note = ClaimNote::new(amount, secret); - let (new_context, note_with_header) = storage.claims.assert_contains(context, note); - context = new_context; - note = note_with_header; - context = storage.claims.remove(context, note); + storage.claims.assert_contains(&mut context, &mut note); + storage.claims.remove(&mut context, note); // Send the value note. let balance = storage.balances.at(owner); - context = send_note(context, balance, amount, owner); + send_note(&mut context, balance, amount, owner); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() diff --git a/yarn-project/noir-libs/easy-private-state/src/easy_private_state.nr b/yarn-project/noir-libs/easy-private-state/src/easy_private_state.nr index d83ee0327f6d..363101c3ef0f 100644 --- a/yarn-project/noir-libs/easy-private-state/src/easy_private_state.nr +++ b/yarn-project/noir-libs/easy-private-state/src/easy_private_state.nr @@ -36,19 +36,19 @@ impl EasyPrivateUint { // Very similar to `send_note`. fn add( self, - mut context: Context, + context: &mut Context, addend: u120, owner: Field, - ) -> Context { + ) { // Creates new note for the owner. - let addend_note = ValueNote::new(addend as Field, owner); + let mut addend_note = ValueNote::new(addend as Field, owner); // Insert the new note to the owner's set of notes. - context = self.set.insert(context, addend_note); + self.set.insert(context, &mut addend_note); // Emit the newly created encrypted note preimages via oracle calls. let owner_key = get_public_key(owner); - context = emit_encrypted_log( + emit_encrypted_log( context, context.inputs.call_context.storage_contract_address, self.set.storage_slot, @@ -56,20 +56,17 @@ impl EasyPrivateUint { owner_key, addend_note.serialise(), ); - - context } // Very similar to `spend_note`. fn sub( self, - mut context: Context, + context: &mut Context, subtrahend: u120, owner: Field, - ) -> Context { + ) { let options = NoteGetterOptions::with_filter(get_2_notes, 0); - let (mut new_context, notes) = self.set.get_notes(context, options); - context = new_context; + let notes = self.set.get_notes(context, options); let note1 = notes[0]; let note2 = notes[1]; @@ -89,13 +86,13 @@ impl EasyPrivateUint { assert(minuend >= subtrahend); // Removes the 2 notes from the owner's set of notes. - context = self.set.remove(context, note1); - context = self.set.remove(context, note2); + self.set.remove(context, note1); + self.set.remove(context, note2); // Creates change note for the owner. let result = minuend - subtrahend; - let result_note = ValueNote::new(result as Field, owner); - context = self.set.insert(context, result_note); + let mut result_note = ValueNote::new(result as Field, owner); + self.set.insert(context, &mut result_note); // Emit the newly created encrypted note preimages via oracle calls. let mut encrypted_data = [0; VALUE_NOTE_LEN]; @@ -105,7 +102,7 @@ impl EasyPrivateUint { let owner_key = get_public_key(owner); - context = emit_encrypted_log( + emit_encrypted_log( context, context.inputs.call_context.storage_contract_address, self.set.storage_slot, @@ -113,8 +110,6 @@ impl EasyPrivateUint { owner_key, encrypted_data, ); - - context } } diff --git a/yarn-project/noir-libs/noir-aztec/src/abi.nr b/yarn-project/noir-libs/noir-aztec/src/abi.nr index 8c8b9dacfadf..c5c7ca7c75f5 100644 --- a/yarn-project/noir-libs/noir-aztec/src/abi.nr +++ b/yarn-project/noir-libs/noir-aztec/src/abi.nr @@ -195,48 +195,47 @@ struct PrivateCircuitPublicInputs { impl PrivateCircuitPublicInputs { fn hash(self) -> Field { let mut fields: BoundedVec = BoundedVec::new(0); - fields = fields.push(self.call_context.hash()); - fields = fields.push(self.args_hash); - fields = fields.push_array(self.return_values); - fields = fields.push_array(self.read_requests); - fields = fields.push_array(self.new_commitments); - fields = fields.push_array(self.new_nullifiers); - fields = fields.push_array(self.nullified_commitments); - fields = fields.push_array(self.private_call_stack); - fields = fields.push_array(self.public_call_stack); - fields = fields.push_array(self.new_l2_to_l1_msgs); - fields = fields.push_array(self.encrypted_logs_hash); - fields = fields.push_array(self.unencrypted_logs_hash); - fields = fields.push(self.encrypted_log_preimages_length); - fields = fields.push(self.unencrypted_log_preimages_length); - fields = fields.push_array(self.commitment_trees_roots.serialize()); - fields = fields.push(self.contract_deployment_data.hash()); - fields = fields.push(self.chain_id); - fields = fields.push(self.version); + fields.push(self.call_context.hash()); + fields.push(self.args_hash); + fields.push_array(self.return_values); + fields.push_array(self.read_requests); + fields.push_array(self.new_commitments); + fields.push_array(self.new_nullifiers); + fields.push_array(self.nullified_commitments); + fields.push_array(self.private_call_stack); + fields.push_array(self.public_call_stack); + fields.push_array(self.new_l2_to_l1_msgs); + fields.push_array(self.encrypted_logs_hash); + fields.push_array(self.unencrypted_logs_hash); + fields.push(self.encrypted_log_preimages_length); + fields.push(self.unencrypted_log_preimages_length); + fields.push_array(self.commitment_trees_roots.serialize()); + fields.push(self.contract_deployment_data.hash()); + fields.push(self.chain_id); + fields.push(self.version); dep::std::hash::pedersen_with_separator(fields.storage, GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS)[0] } fn serialize(self) -> [Field; PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); - fields = fields.push_array(self.call_context.serialize()); - fields = fields.push(self.args_hash); - fields = fields.push_array(self.return_values); - fields = fields.push_array(self.read_requests); - fields = fields.push_array(self.new_commitments); - fields = fields.push_array(self.new_nullifiers); - fields = fields.push_array(self.nullified_commitments); - fields = fields.push_array(self.private_call_stack); - fields = fields.push_array(self.public_call_stack); - fields = fields.push_array(self.new_l2_to_l1_msgs); - fields = fields.push_array(self.encrypted_logs_hash); - fields = fields.push_array(self.unencrypted_logs_hash); - fields = fields.push(self.encrypted_log_preimages_length); - fields = fields.push(self.unencrypted_log_preimages_length); - fields = fields.push_array(self.commitment_trees_roots.serialize()); - fields = fields.push_array(self.contract_deployment_data.serialize()); - fields = fields.push(self.chain_id); - fields = fields.push(self.version); + fields.push_array(self.call_context.serialize()); + fields.push(self.args_hash); + fields.push_array(self.return_values); + fields.push_array(self.read_requests); + fields.push_array(self.new_commitments); + fields.push_array(self.new_nullifiers); + fields.push_array(self.private_call_stack); + fields.push_array(self.public_call_stack); + fields.push_array(self.new_l2_to_l1_msgs); + fields.push_array(self.encrypted_logs_hash); + fields.push_array(self.unencrypted_logs_hash); + fields.push(self.encrypted_log_preimages_length); + fields.push(self.unencrypted_log_preimages_length); + fields.push_array(self.commitment_trees_roots.serialize()); + fields.push_array(self.contract_deployment_data.serialize()); + fields.push(self.chain_id); + fields.push(self.version); fields.storage } } @@ -302,51 +301,51 @@ impl PublicCircuitPublicInputs { fn hash(self) -> Field { let mut inputs: BoundedVec = BoundedVec::new(0); - inputs = inputs.push(self.call_context.hash()); - inputs = inputs.push(self.args_hash); - inputs = inputs.push_array(self.return_values); + inputs.push(self.call_context.hash()); + inputs.push(self.args_hash); + inputs.push_array(self.return_values); for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { - inputs = inputs.push(self.contract_storage_update_requests[i].hash()); + inputs.push(self.contract_storage_update_requests[i].hash()); } for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { - inputs = inputs.push(self.contract_storage_read[i].hash()); + inputs.push(self.contract_storage_read[i].hash()); } - inputs = inputs.push_array(self.public_call_stack); - inputs = inputs.push_array(self.new_commitments); - inputs = inputs.push_array(self.new_nullifiers); - inputs = inputs.push_array(self.new_l2_to_l1_msgs); + inputs.push_array(self.public_call_stack); + inputs.push_array(self.new_commitments); + inputs.push_array(self.new_nullifiers); + inputs.push_array(self.new_l2_to_l1_msgs); // We do not include commitment_trees_roots since it's not in the cpp hash - // inputs = inputs.push(self.commitment_trees_roots.hash()); + // inputs.push(self.commitment_trees_roots.hash()); - inputs = inputs.push_array(self.unencrypted_logs_hash); - inputs = inputs.push(self.unencrypted_log_preimages_length); - inputs = inputs.push(self.historic_public_data_tree_root); - inputs = inputs.push(self.prover_address); + inputs.push_array(self.unencrypted_logs_hash); + inputs.push(self.unencrypted_log_preimages_length); + inputs.push(self.historic_public_data_tree_root); + inputs.push(self.prover_address); dep::std::hash::pedersen_with_separator(inputs.storage, GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS)[0] } fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); - fields = fields.push_array(self.call_context.serialize()); - fields = fields.push(self.args_hash); - fields = fields.push_array(self.return_values); + fields.push_array(self.call_context.serialize()); + fields.push(self.args_hash); + fields.push_array(self.return_values); for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { - fields = fields.push_array(self.contract_storage_update_requests[i].serialize()); + fields.push_array(self.contract_storage_update_requests[i].serialize()); } for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { - fields = fields.push_array(self.contract_storage_read[i].serialize()); + fields.push_array(self.contract_storage_read[i].serialize()); } - fields = fields.push_array(self.public_call_stack); - fields = fields.push_array(self.new_commitments); - fields = fields.push_array(self.new_nullifiers); - fields = fields.push_array(self.new_l2_to_l1_msgs); - fields = fields.push_array(self.unencrypted_logs_hash); - fields = fields.push(self.unencrypted_log_preimages_length); - fields = fields.push_array(self.commitment_trees_roots.serialize()); - fields = fields.push(self.historic_public_data_tree_root); - fields = fields.push(self.prover_address); + fields.push_array(self.public_call_stack); + fields.push_array(self.new_commitments); + fields.push_array(self.new_nullifiers); + fields.push_array(self.new_l2_to_l1_msgs); + fields.push_array(self.unencrypted_logs_hash); + fields.push(self.unencrypted_log_preimages_length); + fields.push_array(self.commitment_trees_roots.serialize()); + fields.push(self.historic_public_data_tree_root); + fields.push(self.prover_address); fields.storage } } diff --git a/yarn-project/noir-libs/noir-aztec/src/context.nr b/yarn-project/noir-libs/noir-aztec/src/context.nr index a650eacb0aa8..0b1c41ad28b1 100644 --- a/yarn-project/noir-libs/noir-aztec/src/context.nr +++ b/yarn-project/noir-libs/noir-aztec/src/context.nr @@ -1,22 +1,54 @@ -use crate::types::vec::BoundedVec; use crate::constants_gen::{ - RETURN_VALUES_LENGTH, - MAX_READ_REQUESTS_PER_CALL, + EMPTY_NULLIFIED_COMMITMENT, MAX_NEW_COMMITMENTS_PER_CALL, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_NULLIFIERS_PER_CALL, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, - MAX_NEW_L2_TO_L1_MSGS_PER_CALL, - EMPTY_NULLIFIED_COMMITMENT, + MAX_PUBLIC_DATA_READS_PER_CALL, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, + MAX_READ_REQUESTS_PER_CALL, NUM_FIELDS_PER_SHA256, + RETURN_VALUES_LENGTH, }; + use crate::abi; +use crate::abi::{ + empty_commitment_trees_roots, + empty_contract_storage_read, + empty_contract_storage_update_request, + hash_args, + CallContext, + ContractDeploymentData, + CommitmentTreesRoots, + FunctionData, + PrivateCircuitPublicInputs, + PublicCircuitPublicInputs, +}; + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) // use dep::std::collections::vec::Vec; // l1 to l2 messaging use crate::messaging::process_l1_to_l2_message; +use crate::private_call_stack_item::PrivateCallStackItem; +use crate::public_call_stack_item::PublicCallStackItem; + +use crate::types::{ + vec::BoundedVec, + point::Point, +}; + +use crate::utils::arr_copy_slice; + +use crate::oracle::{ + arguments, + call_private_function::call_private_function_internal, + public_call::call_public_function_internal, + enqueue_public_function_call::enqueue_public_function_call_internal, +}; + // When finished, one can call .finish() to convert back to the abi struct Context { @@ -94,43 +126,210 @@ impl Context { priv_circuit_pub_inputs } - fn push_read_request(mut self: Self, read_request: Field) -> Self { - self.read_requests = self.read_requests.push(read_request); - self + fn push_read_request(&mut self, read_request: Field) { + self.read_requests.push(read_request); } - fn push_new_note_hash(mut self: Self, note_hash: Field) -> Self { - self.new_commitments = self.new_commitments.push(note_hash); - self + fn push_new_note_hash(&mut self, note_hash: Field) { + self.new_commitments.push(note_hash); } - fn push_new_nullifier(mut self: Self, nullifier: Field, nullified_commitment: Field) -> Self { - self.new_nullifiers = self.new_nullifiers.push(nullifier); - self.nullified_commitments = self.nullified_commitments.push(nullified_commitment); - self + fn push_new_nullifier(&mut self, nullifier: Field, nullified_commitment: Field) { + self.new_nullifiers.push(nullifier); + self.nullified_commitments.push(nullified_commitment); } - fn message_portal(mut self: Self, msg: Field) -> Self { - self.new_l2_to_l1_msgs = self.new_l2_to_l1_msgs.push(msg); - self + fn message_portal(&mut self, msg: Field) { + self.new_l2_to_l1_msgs.push(msg); } // PrivateContextInputs must be temporarily passed in to prevent too many unknowns // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned - fn consume_l1_to_l2_message(mut self: Self, inputs: abi::PrivateContextInputs, msg_key: Field, content: Field, secret: Field) -> Context { + fn consume_l1_to_l2_message(&mut self, inputs: abi::PrivateContextInputs, msg_key: Field, content: Field, secret: Field) { let nullifier = process_l1_to_l2_message(inputs.roots.l1_to_l2_messages_tree_root, inputs.call_context.storage_contract_address, msg_key, content, secret); // Push nullifier (and the "commitment" corresponding to this can be "empty") self.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT) } - fn accumulate_encrypted_logs(mut self: Self, log: [Field; N]) -> Self { + fn accumulate_encrypted_logs(&mut self, log: [Field; N]) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) - self } - fn accumulate_unencrypted_logs(mut self: Self, log: T) -> Self { + fn accumulate_unencrypted_logs(&mut self, log: T) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) - self + } + + fn call_private_function( + &mut self, + contract_address: Field, + function_selector: Field, + args: [Field; ARGS_COUNT] + ) -> PrivateCallStackItem { + let args_hash = hash_args(args); + assert(args_hash == arguments::pack_arguments(args)); + self.call_private_function_with_packed_args(contract_address, function_selector, args_hash) + } + + fn call_private_function_with_packed_args( + &mut self, + contract_address: Field, + function_selector: Field, + args_hash: Field + ) -> PrivateCallStackItem { + let fields = call_private_function_internal( + contract_address, + function_selector, + args_hash + ); + let item = PrivateCallStackItem { + contract_address: fields[0], + function_data: FunctionData { + function_selector: fields[1], + is_internal: fields[2] as bool, + is_private: fields[3] as bool, + is_constructor: fields[4] as bool, + }, + public_inputs: PrivateCircuitPublicInputs { + call_context: CallContext { + msg_sender : fields[5], + storage_contract_address : fields[6], + portal_contract_address : fields[7], + + is_delegate_call : fields[8] as bool, + is_static_call : fields[9] as bool, + is_contract_deployment: fields[10] as bool, + }, + // TODO handle the offsets as a variable incremented during extraction? + args_hash: fields[11], + return_values: arr_copy_slice(fields, [0; RETURN_VALUES_LENGTH], 12), + read_requests: arr_copy_slice(fields, [0; MAX_READ_REQUESTS_PER_CALL], 16), + new_commitments: arr_copy_slice(fields, [0; MAX_NEW_COMMITMENTS_PER_CALL], 20), + new_nullifiers: arr_copy_slice(fields, [0; MAX_NEW_NULLIFIERS_PER_CALL], 24), + nullified_commitments: arr_copy_slice(fields, [0; MAX_NEW_NULLIFIERS_PER_CALL], 28), + private_call_stack: arr_copy_slice(fields, [0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], 32), + public_call_stack: arr_copy_slice(fields, [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], 36), + new_l2_to_l1_msgs: arr_copy_slice(fields, [0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL], 40), + encrypted_logs_hash: arr_copy_slice(fields, [0; NUM_FIELDS_PER_SHA256], 42), + unencrypted_logs_hash: arr_copy_slice(fields, [0; NUM_FIELDS_PER_SHA256], 44), + encrypted_log_preimages_length: fields[46], + unencrypted_log_preimages_length: fields[47], + commitment_trees_roots: CommitmentTreesRoots { + // Must match order in `private_circuit_public_inputs.hpp` + private_data_tree_root : fields[48], + nullifier_tree_root : fields[49], + contract_tree_root : fields[50], + l1_to_l2_messages_tree_root : fields[51], + blocks_tree_root : fields[52], + }, + contract_deployment_data: ContractDeploymentData { + deployer_public_key: Point::new(fields[53], fields[54]), + constructor_vk_hash : fields[55], + function_tree_root : fields[56], + contract_address_salt : fields[57], + portal_contract_address : fields[58], + }, + chain_id: fields[59], + version: fields[60], + }, + is_execution_request: fields[61] as bool, + }; + assert(contract_address == item.contract_address); + assert(function_selector == item.function_data.function_selector); + + assert(args_hash == item.public_inputs.args_hash); + + assert(item.is_execution_request == false); + + // Assert that the call context of the enqueued call generated by the oracle matches our request. + // We are issuing a regular call which is not delegate, static, or deployment. We also constrain + // the msg_sender in the nested call to be equal to our address, and the execution context address + // for the nested call to be equal to the address we actually called. + assert(item.public_inputs.call_context.is_delegate_call == false); + assert(item.public_inputs.call_context.is_static_call == false); + assert(item.public_inputs.call_context.is_contract_deployment == false); + assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address); + assert(item.public_inputs.call_context.storage_contract_address == contract_address); + + self.private_call_stack.push(item.hash()); + + item + } + + fn call_public_function( + &mut self, + contract_address: Field, + function_selector: Field, + args: [Field; ARGS_COUNT] + ) -> PublicCallStackItem { + let args_hash = hash_args(args); + assert(args_hash == arguments::pack_arguments(args)); + self.call_public_function_with_packed_args(contract_address, function_selector, args_hash) + } + + fn call_public_function_with_packed_args( + &mut self, + contract_address: Field, + function_selector: Field, + args_hash: Field + ) -> PublicCallStackItem { + let fields = enqueue_public_function_call_internal( + contract_address, + function_selector, + args_hash + ); + let item = PublicCallStackItem { + contract_address: fields[0], + function_data: FunctionData { + function_selector: fields[1], + is_internal: fields[2] as bool, + is_private: fields[3] as bool, + is_constructor: fields[4] as bool, + }, + public_inputs: PublicCircuitPublicInputs { + call_context: CallContext { + msg_sender : fields[5], + storage_contract_address : fields[6], + portal_contract_address : fields[7], + + is_delegate_call : fields[8] as bool, + is_static_call : fields[9] as bool, + is_contract_deployment: fields[10] as bool, + }, + args_hash: fields[11], + return_values: [0; RETURN_VALUES_LENGTH], + contract_storage_update_requests: [empty_contract_storage_update_request(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_read: [empty_contract_storage_read(); MAX_PUBLIC_DATA_READS_PER_CALL], + public_call_stack: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], + new_commitments: [0; MAX_NEW_COMMITMENTS_PER_CALL], + new_nullifiers: [0; MAX_NEW_NULLIFIERS_PER_CALL], + new_l2_to_l1_msgs:[0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + unencrypted_logs_hash:[0; NUM_FIELDS_PER_SHA256], + unencrypted_log_preimages_length: 0, + commitment_trees_roots: empty_commitment_trees_roots(), + historic_public_data_tree_root: 0, + prover_address: 0, + }, + is_execution_request: true, + }; + + assert(contract_address == item.contract_address); + assert(function_selector == item.function_data.function_selector); + + assert(args_hash == item.public_inputs.args_hash); + + // Assert that the call context of the enqueued call generated by the oracle matches our request. + // We are issuing a regular call which is not delegate, static, or deployment. We also constrain + // the msg_sender in the nested call to be equal to our address, and the execution context address + // for the nested call to be equal to the address we actually called. + assert(item.public_inputs.call_context.is_delegate_call == false); + assert(item.public_inputs.call_context.is_static_call == false); + assert(item.public_inputs.call_context.is_contract_deployment == false); + assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address); + assert(item.public_inputs.call_context.storage_contract_address == contract_address); + + self.public_call_stack.push(item.hash()); + + item } } diff --git a/yarn-project/noir-libs/noir-aztec/src/entrypoint.nr b/yarn-project/noir-libs/noir-aztec/src/entrypoint.nr index e06232c55028..322c857d200f 100644 --- a/yarn-project/noir-libs/noir-aztec/src/entrypoint.nr +++ b/yarn-project/noir-libs/noir-aztec/src/entrypoint.nr @@ -43,10 +43,10 @@ impl EntrypointPayload { // Serializes the entrypoint struct fn serialize(self) -> [Field; ENTRYPOINT_PAYLOAD_SIZE] { let mut fields: BoundedVec = BoundedVec::new(0); - fields = fields.push_array(self.flattened_args_hashes); - fields = fields.push_array(self.flattened_selectors); - fields = fields.push_array(self.flattened_targets); - fields = fields.push(self.nonce); + fields.push_array(self.flattened_args_hashes); + fields.push_array(self.flattened_selectors); + fields.push_array(self.flattened_targets); + fields.push(self.nonce); fields.storage } @@ -88,14 +88,13 @@ impl EntrypointPayload { } // Executes all private and public calls - fn execute_calls(self, mut context: Context) -> Context { + fn execute_calls(self, context: &mut Context) { for i in 0..ACCOUNT_MAX_PRIVATE_CALLS { let target_address = self.flattened_targets[i]; if target_address != 0 { let function_selector = self.flattened_selectors[i]; let args_hash = self.flattened_args_hashes[i]; - let (_callStackItem, updated_context) = PrivateCallStackItem::call_with_packed_args(target_address, function_selector, args_hash, context); - context = updated_context; + let _callStackItem = context.call_private_function_with_packed_args(target_address, function_selector, args_hash); } } for i in ACCOUNT_MAX_PRIVATE_CALLS..ACCOUNT_MAX_CALLS { @@ -103,11 +102,9 @@ impl EntrypointPayload { if target_address != 0 { let function_selector = self.flattened_selectors[i]; let args_hash = self.flattened_args_hashes[i]; - let (_callStackItem, updated_context) = PublicCallStackItem::call_with_packed_args(target_address, function_selector, args_hash, context); - context = updated_context; + let _callStackItem = context.call_public_function_with_packed_args(target_address, function_selector, args_hash); } } - context } // TODO: This function returns all zeroes. Figure out why! diff --git a/yarn-project/noir-libs/noir-aztec/src/log.nr b/yarn-project/noir-libs/noir-aztec/src/log.nr index 28540bb743af..161850fe6330 100644 --- a/yarn-project/noir-libs/noir-aztec/src/log.nr +++ b/yarn-project/noir-libs/noir-aztec/src/log.nr @@ -3,23 +3,21 @@ use crate::oracle; use crate::types::point::Point; fn emit_encrypted_log( - mut context: Context, + context: &mut Context, contract_address: Field, storage_slot: Field, owner: Field, encryption_pub_key: Point, log: [Field; N], -) -> Context { +) { let _ = oracle::logs::emit_encrypted_log(contract_address, storage_slot, owner, encryption_pub_key, log); - context = context.accumulate_encrypted_logs(log); - context + context.accumulate_encrypted_logs(log); } fn emit_unencrypted_log( - mut context: Context, + context: &mut Context, log: T, -) -> Context { +) { let _ = oracle::logs::emit_unencrypted_log(log); - context = context.accumulate_unencrypted_logs(log); - context + context.accumulate_unencrypted_logs(log); } diff --git a/yarn-project/noir-libs/noir-aztec/src/note/lifecycle.nr b/yarn-project/noir-libs/noir-aztec/src/note/lifecycle.nr index e02c35c56d8d..ce4e9db4bf93 100644 --- a/yarn-project/noir-libs/noir-aztec/src/note/lifecycle.nr +++ b/yarn-project/noir-libs/noir-aztec/src/note/lifecycle.nr @@ -8,34 +8,34 @@ use crate::oracle::notes::{notify_created_note, notify_nullified_note}; use crate::constants_gen::EMPTY_NULLIFIED_COMMITMENT; fn create_note( - mut context: Context, + context: &mut Context, storage_slot: Field, - mut note: Note, + note: &mut Note, note_interface: NoteInterface, -) -> Context { +) { let mut inner_note_hash = 0; let is_dummy = note_interface.is_dummy; - if is_dummy(note) == false { + if is_dummy(*note) == false { let contract_address = context.inputs.call_context.storage_contract_address; let header = NoteHeader { contract_address, storage_slot, nonce: 0 }; let set_header = note_interface.set_header; - note = set_header(note, header); - inner_note_hash = compute_inner_note_hash(note_interface, note); + set_header(note, header); + inner_note_hash = compute_inner_note_hash(note_interface, *note); let serialise = note_interface.serialise; - let preimage = serialise(note); + let preimage = serialise(*note); assert(notify_created_note(storage_slot, preimage, inner_note_hash) == 0); } - context.push_new_note_hash(inner_note_hash) + context.push_new_note_hash(inner_note_hash); } fn destroy_note( - mut context: Context, + context: &mut Context, storage_slot: Field, note: Note, note_interface: NoteInterface, -) -> Context { +) { let mut nullifier = 0; let mut nullified_commitment = 0; let is_dummy = note_interface.is_dummy; @@ -54,6 +54,5 @@ fn destroy_note( nullified_commitment = EMPTY_NULLIFIED_COMMITMENT; } - context.push_new_nullifier(nullifier, nullified_commitment) } \ No newline at end of file diff --git a/yarn-project/noir-libs/noir-aztec/src/note/note_getter.nr b/yarn-project/noir-libs/noir-aztec/src/note/note_getter.nr index 462043c2ba4f..3ba4b62c7dfe 100644 --- a/yarn-project/noir-libs/noir-aztec/src/note/note_getter.nr +++ b/yarn-project/noir-libs/noir-aztec/src/note/note_getter.nr @@ -27,15 +27,14 @@ fn check_note_header( } fn ensure_note_exists( - mut context: Context, + context: &mut Context, storage_slot: Field, note_interface: NoteInterface, - note: Note, -) -> (Context, Note) { - let mut note_with_header = note; + note: &mut Note, +) { let mut unique_note_hash = 0; let is_dummy = note_interface.is_dummy; - if is_dummy(note) == false { + if is_dummy(*note) == false { // Get a note from oracle and early out if it doesn't exist. let saved_note = get_note_internal(storage_slot, note_interface); assert(is_dummy(saved_note) == false); @@ -43,51 +42,50 @@ fn ensure_note_exists( // Only copy over the header to the original note to make sure the preimage is the same. let get_header = note_interface.get_header; let set_header = note_interface.set_header; - let header = get_header(saved_note); - note_with_header = set_header(note, header); + let note_header = get_header(saved_note); + set_header(note, note_header); - check_note_header(context, storage_slot, note_interface, note_with_header); + check_note_header(*context, storage_slot, note_interface, *note); - unique_note_hash = compute_unique_note_hash(note_interface, note_with_header); + unique_note_hash = compute_unique_note_hash(note_interface, *note); }; - context = context.push_read_request(unique_note_hash); - (context, note_with_header) + context.push_read_request(unique_note_hash); } fn get_note( - mut context: Context, + context: &mut Context, storage_slot: Field, note_interface: NoteInterface, -) -> (Context, Note) { +) -> Note { let note = get_note_internal(storage_slot, note_interface); let mut unique_note_hash = 0; let is_dummy = note_interface.is_dummy; if is_dummy(note) == false { - check_note_header(context, storage_slot, note_interface, note); + check_note_header(*context, storage_slot, note_interface, note); unique_note_hash = compute_unique_note_hash(note_interface, note); }; - context = context.push_read_request(unique_note_hash); - (context, note) + context.push_read_request(unique_note_hash); + note } fn get_notes( - mut context: Context, + context: &mut Context, storage_slot: Field, note_interface: NoteInterface, options: NoteGetterOptions, -) -> (Context, [Note; S]) { +) -> [Note; S] { let notes = get_notes_internal(storage_slot, note_interface, options); let is_dummy = note_interface.is_dummy; for i in 0..notes.len() { let note = notes[i]; let mut unique_note_hash = 0; if is_dummy(note) == false { - check_note_header(context, storage_slot, note_interface, note); + check_note_header(*context, storage_slot, note_interface, note); unique_note_hash = compute_unique_note_hash(note_interface, note); }; - context = context.push_read_request(unique_note_hash); + context.push_read_request(unique_note_hash); }; - (context, notes) + notes } unconstrained fn get_note_internal( diff --git a/yarn-project/noir-libs/noir-aztec/src/note/note_interface.nr b/yarn-project/noir-libs/noir-aztec/src/note/note_interface.nr index 260034def518..4f073e30a7cb 100644 --- a/yarn-project/noir-libs/noir-aztec/src/note/note_interface.nr +++ b/yarn-project/noir-libs/noir-aztec/src/note/note_interface.nr @@ -15,5 +15,5 @@ struct NoteInterface { get_header: fn (Note) -> NoteHeader, - set_header: fn (Note, NoteHeader) -> Note, + set_header: fn (&mut Note, NoteHeader) -> (), } diff --git a/yarn-project/noir-libs/noir-aztec/src/note/utils.nr b/yarn-project/noir-libs/noir-aztec/src/note/utils.nr index 1221a48f4f24..44c236ae6a0d 100644 --- a/yarn-project/noir-libs/noir-aztec/src/note/utils.nr +++ b/yarn-project/noir-libs/noir-aztec/src/note/utils.nr @@ -50,7 +50,7 @@ fn compute_note_hash_and_nullifier( let deserialise = note_interface.deserialise; let set_header = note_interface.set_header; let mut note = deserialise(arr_copy_slice(preimage, [0; N], 0)); - note = set_header(note, note_header); + set_header(&mut note, note_header); let compute_note_hash = note_interface.compute_note_hash; let note_hash = compute_note_hash(note); diff --git a/yarn-project/noir-libs/noir-aztec/src/oracle/notes.nr b/yarn-project/noir-libs/noir-aztec/src/oracle/notes.nr index 9dc0b2e5a192..3b0f58ceca16 100644 --- a/yarn-project/noir-libs/noir-aztec/src/oracle/notes.nr +++ b/yarn-project/noir-libs/noir-aztec/src/oracle/notes.nr @@ -83,7 +83,8 @@ unconstrained fn get_notes( let preimage = arr_copy_slice(fields, [0; N], read_offset + 1); let mut note = deserialise(preimage); - notes[i] = set_header(note, header); + set_header(&mut note, header); + notes[i] = note; }; }; notes diff --git a/yarn-project/noir-libs/noir-aztec/src/private_call_stack_item.nr b/yarn-project/noir-libs/noir-aztec/src/private_call_stack_item.nr index c097c9093bd2..77d702667b62 100644 --- a/yarn-project/noir-libs/noir-aztec/src/private_call_stack_item.nr +++ b/yarn-project/noir-libs/noir-aztec/src/private_call_stack_item.nr @@ -1,17 +1,6 @@ -use crate::abi::CallContext; -use crate::abi::hash_args; -use crate::abi::ContractDeploymentData; use crate::abi::FunctionData; -use crate::context::Context; use crate::abi::PrivateCircuitPublicInputs; -use crate::abi::CommitmentTreesRoots; -use crate::types::vec::BoundedVec; -use crate::types::point::Point; -use crate::utils::arr_copy_slice; -use crate::constants_gen; - -use crate::oracle::call_private_function::call_private_function_internal; -use crate::oracle::arguments; +use crate::constants_gen::GENERATOR_INDEX__CALL_STACK_ITEM; struct PrivateCallStackItem { contract_address: Field, @@ -21,101 +10,11 @@ struct PrivateCallStackItem { } impl PrivateCallStackItem { - fn call( - contract_address: Field, - function_selector: Field, - args: [Field; ARGS_COUNT], - mut context: Context) -> (Self, Context) { - let args_hash = hash_args(args); - assert(args_hash == arguments::pack_arguments(args)); - PrivateCallStackItem::call_with_packed_args(contract_address, function_selector, args_hash, context) - } - - fn call_with_packed_args(contract_address: Field, function_selector: Field, args_hash: Field, mut context: Context) -> (Self, Context) { - let fields = call_private_function_internal( - contract_address, - function_selector, - args_hash - ); - let item = PrivateCallStackItem { - contract_address: fields[0], - function_data: FunctionData { - function_selector: fields[1], - is_internal: fields[2] as bool, - is_private: fields[3] as bool, - is_constructor: fields[4] as bool, - }, - public_inputs: PrivateCircuitPublicInputs { - call_context: CallContext { - msg_sender : fields[5], - storage_contract_address : fields[6], - portal_contract_address : fields[7], - - is_delegate_call : fields[8] as bool, - is_static_call : fields[9] as bool, - is_contract_deployment: fields[10] as bool, - }, - // TODO handle the offsets as a variable incremented during extraction? - args_hash: fields[11], - return_values: arr_copy_slice(fields, [0; constants_gen::RETURN_VALUES_LENGTH], 12), - read_requests: arr_copy_slice(fields, [0; constants_gen::MAX_READ_REQUESTS_PER_CALL], 16), - new_commitments: arr_copy_slice(fields, [0; constants_gen::MAX_NEW_COMMITMENTS_PER_CALL], 20), - new_nullifiers: arr_copy_slice(fields, [0; constants_gen::MAX_NEW_NULLIFIERS_PER_CALL], 24), - nullified_commitments: arr_copy_slice(fields, [0; constants_gen::MAX_NEW_NULLIFIERS_PER_CALL], 28), - private_call_stack: arr_copy_slice(fields, [0; constants_gen::MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], 32), - public_call_stack: arr_copy_slice(fields, [0; constants_gen::MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], 36), - new_l2_to_l1_msgs: arr_copy_slice(fields, [0; constants_gen::MAX_NEW_L2_TO_L1_MSGS_PER_CALL], 40), - encrypted_logs_hash: arr_copy_slice(fields, [0; constants_gen::NUM_FIELDS_PER_SHA256], 42), - unencrypted_logs_hash: arr_copy_slice(fields, [0; constants_gen::NUM_FIELDS_PER_SHA256], 44), - encrypted_log_preimages_length: fields[46], - unencrypted_log_preimages_length: fields[47], - commitment_trees_roots: CommitmentTreesRoots { - // Must match order in `private_circuit_public_inputs.hpp` - private_data_tree_root : fields[48], - nullifier_tree_root : fields[49], - contract_tree_root : fields[50], - l1_to_l2_messages_tree_root : fields[51], - blocks_tree_root : fields[52], - }, - contract_deployment_data: ContractDeploymentData { - deployer_public_key: Point::new(fields[53], fields[54]), - constructor_vk_hash : fields[55], - function_tree_root : fields[56], - contract_address_salt : fields[57], - portal_contract_address : fields[58], - }, - chain_id: fields[59], - version: fields[60], - }, - is_execution_request: fields[61] as bool, - }; - assert(contract_address == item.contract_address); - assert(function_selector == item.function_data.function_selector); - - assert(args_hash == item.public_inputs.args_hash); - - assert(item.is_execution_request == false); - - // Assert that the call context of the enqueued call generated by the oracle matches our request. - // We are issuing a regular call which is not delegate, static, or deployment. We also constrain - // the msg_sender in the nested call to be equal to our address, and the execution context address - // for the nested call to be equal to the address we actually called. - assert(item.public_inputs.call_context.is_delegate_call == false); - assert(item.public_inputs.call_context.is_static_call == false); - assert(item.public_inputs.call_context.is_contract_deployment == false); - assert(item.public_inputs.call_context.msg_sender == context.inputs.call_context.storage_contract_address); - assert(item.public_inputs.call_context.storage_contract_address == contract_address); - - context.private_call_stack = context.private_call_stack.push(item.hash()); - - (item, context) - } - fn hash(self) -> Field { dep::std::hash::pedersen_with_separator([ self.contract_address, self.function_data.hash(), self.public_inputs.hash(), - ], constants_gen::GENERATOR_INDEX__CALL_STACK_ITEM)[0] + ], GENERATOR_INDEX__CALL_STACK_ITEM)[0] } } \ No newline at end of file diff --git a/yarn-project/noir-libs/noir-aztec/src/public_call_stack_item.nr b/yarn-project/noir-libs/noir-aztec/src/public_call_stack_item.nr index d87ecec64edb..7942f16032a1 100644 --- a/yarn-project/noir-libs/noir-aztec/src/public_call_stack_item.nr +++ b/yarn-project/noir-libs/noir-aztec/src/public_call_stack_item.nr @@ -1,27 +1,21 @@ -use crate::abi::CallContext; -use crate::abi::hash_args; -use crate::abi::ContractDeploymentData; -use crate::context::Context; -use crate::abi::PublicCircuitPublicInputs; -use crate::abi::FunctionData; -use crate::types::vec::BoundedVec; -use crate::utils::arr_copy_slice; +use crate::{ + abi, + abi::{ + PublicCircuitPublicInputs, + FunctionData, + }, +}; use crate::constants_gen::{ RETURN_VALUES_LENGTH, - MAX_NEW_COMMITMENTS_PER_CALL, - MAX_NEW_NULLIFIERS_PER_CALL, - MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, - MAX_PUBLIC_DATA_READS_PER_CALL, - MAX_NEW_L2_TO_L1_MSGS_PER_CALL, - NUM_FIELDS_PER_SHA256, GENERATOR_INDEX__CALL_STACK_ITEM, }; // oracles -use crate::oracle::enqueue_public_function_call::enqueue_public_function_call_internal; -use crate::oracle::public_call::call_public_function_internal; -use crate::oracle::arguments; +use crate::oracle::{ + enqueue_public_function_call::enqueue_public_function_call_internal, + public_call::call_public_function_internal, + arguments, +}; struct PublicCallStackItem { contract_address: Field, @@ -31,77 +25,6 @@ struct PublicCallStackItem { } impl PublicCallStackItem { - fn call( - contract_address: Field, - function_selector: Field, - args: [Field; ARGS_COUNT], - mut context: Context) -> (Self, Context) { - let args_hash = hash_args(args); - assert(args_hash == arguments::pack_arguments(args)); - PublicCallStackItem::call_with_packed_args(contract_address, function_selector, args_hash, context) - } - - fn call_with_packed_args(contract_address: Field, function_selector: Field, args_hash: Field, mut context: Context) -> (Self, Context) { - let fields = enqueue_public_function_call_internal( - contract_address, - function_selector, - args_hash - ); - let item = PublicCallStackItem { - contract_address: fields[0], - function_data: FunctionData { - function_selector: fields[1], - is_internal: fields[2] as bool, - is_private: fields[3] as bool, - is_constructor: fields[4] as bool, - }, - public_inputs: PublicCircuitPublicInputs { - call_context: CallContext { - msg_sender : fields[5], - storage_contract_address : fields[6], - portal_contract_address : fields[7], - - is_delegate_call : fields[8] as bool, - is_static_call : fields[9] as bool, - is_contract_deployment: fields[10] as bool, - }, - args_hash: fields[11], - return_values: [0; RETURN_VALUES_LENGTH], - contract_storage_update_requests: [crate::abi::empty_contract_storage_update_request(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - contract_storage_read: [crate::abi::empty_contract_storage_read(); MAX_PUBLIC_DATA_READS_PER_CALL], - public_call_stack: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], - new_commitments: [0; MAX_NEW_COMMITMENTS_PER_CALL], - new_nullifiers: [0; MAX_NEW_NULLIFIERS_PER_CALL], - new_l2_to_l1_msgs:[0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL], - unencrypted_logs_hash:[0; NUM_FIELDS_PER_SHA256], - unencrypted_log_preimages_length: 0, - commitment_trees_roots: crate::abi::empty_commitment_trees_roots(), - historic_public_data_tree_root: 0, - prover_address: 0, - }, - is_execution_request: true, - }; - - assert(contract_address == item.contract_address); - assert(function_selector == item.function_data.function_selector); - - assert(args_hash == item.public_inputs.args_hash); - - // Assert that the call context of the enqueued call generated by the oracle matches our request. - // We are issuing a regular call which is not delegate, static, or deployment. We also constrain - // the msg_sender in the nested call to be equal to our address, and the execution context address - // for the nested call to be equal to the address we actually called. - assert(item.public_inputs.call_context.is_delegate_call == false); - assert(item.public_inputs.call_context.is_static_call == false); - assert(item.public_inputs.call_context.is_contract_deployment == false); - assert(item.public_inputs.call_context.msg_sender == context.inputs.call_context.storage_contract_address); - assert(item.public_inputs.call_context.storage_contract_address == contract_address); - - context.public_call_stack = context.public_call_stack.push(item.hash()); - - (item, context) - } - fn hash(self) -> Field { dep::std::hash::pedersen_with_separator([ self.contract_address, @@ -111,13 +34,13 @@ impl PublicCallStackItem { } } - +// An open function doesn't have a context, so we call this pure function instead of going via Context. fn call_public_function( contract_address: Field, function_selector: Field, args: [Field; N], ) -> [Field; RETURN_VALUES_LENGTH] { - let args_hash = hash_args(args); + let args_hash = abi::hash_args(args); assert(args_hash == arguments::pack_arguments(args)); call_public_function_internal( contract_address, diff --git a/yarn-project/noir-libs/noir-aztec/src/state_vars/immutable_singleton.nr b/yarn-project/noir-libs/noir-aztec/src/state_vars/immutable_singleton.nr index f01d2073dbc9..ebeee8a3d2de 100644 --- a/yarn-project/noir-libs/noir-aztec/src/state_vars/immutable_singleton.nr +++ b/yarn-project/noir-libs/noir-aztec/src/state_vars/immutable_singleton.nr @@ -24,19 +24,19 @@ impl ImmutableSingleton { oracle::notes::is_nullifier_emitted(nullifier) } - fn initialise(self, mut context: Context, note: Note) -> Context { + fn initialise(self, context: &mut Context, note: &mut Note) { // Nullify the storage slot. let nullifier = self.compute_initialisation_nullifier(); - context = context.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT); + context.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT); - create_note(context, self.storage_slot, note, self.note_interface) + create_note(context, self.storage_slot, note, self.note_interface); } fn compute_initialisation_nullifier(self) -> Field { pedersen_with_separator([self.storage_slot], GENERATOR_INDEX__INITIALISATION_NULLIFIER)[0] } - fn get_note(self, mut context: Context) -> (Context, Note) { + fn get_note(self, context: &mut Context) -> Note { let storage_slot = self.storage_slot; get_note(context, storage_slot, self.note_interface) } diff --git a/yarn-project/noir-libs/noir-aztec/src/state_vars/set.nr b/yarn-project/noir-libs/noir-aztec/src/state_vars/set.nr index b42d7ba27115..df3025a6e769 100644 --- a/yarn-project/noir-libs/noir-aztec/src/state_vars/set.nr +++ b/yarn-project/noir-libs/noir-aztec/src/state_vars/set.nr @@ -17,8 +17,8 @@ impl Set { Set { storage_slot, note_interface } } - fn insert(self, context: Context, mut note: Note) -> Context { - create_note(context, self.storage_slot, note, self.note_interface) + fn insert(self, context: &mut Context, note: &mut Note) { + create_note(context, self.storage_slot, note, self.note_interface); } fn insert_from_public(self, note: Note) { @@ -27,21 +27,21 @@ impl Set { create_commitment(note_hash); } - fn assert_contains(self, context: Context, note: Note) -> (Context, Note) { - ensure_note_exists(context, self.storage_slot, self.note_interface, note) + fn assert_contains(self, context: &mut Context, note: &mut Note) { + ensure_note_exists(context, self.storage_slot, self.note_interface, note); } - fn remove(self, context: Context, note: Note) -> Context { - destroy_note(context, self.storage_slot, note, self.note_interface) + fn remove(self, context: &mut Context, note: Note) { + destroy_note(context, self.storage_slot, note, self.note_interface); } fn get_notes( self, - mut context: Context, + context: &mut Context, options: NoteGetterOptions, - ) -> (Context, [Note; S]) { + ) -> [Note; S] { let storage_slot = self.storage_slot; - let (new_context, notes) = get_notes(context, storage_slot, self.note_interface, options); - (new_context, notes) + let notes = get_notes(context, storage_slot, self.note_interface, options); + notes } } diff --git a/yarn-project/noir-libs/noir-aztec/src/state_vars/singleton.nr b/yarn-project/noir-libs/noir-aztec/src/state_vars/singleton.nr index 4212ca9c1419..510bad40512f 100644 --- a/yarn-project/noir-libs/noir-aztec/src/state_vars/singleton.nr +++ b/yarn-project/noir-libs/noir-aztec/src/state_vars/singleton.nr @@ -1,10 +1,14 @@ use dep::std::hash::pedersen_with_separator; use crate::context::Context; use crate::oracle; -use crate::note::lifecycle::create_note; -use crate::note::lifecycle::destroy_note; -use crate::note::note_getter::get_note; -use crate::note::note_interface::NoteInterface; +use crate::note::{ + lifecycle::{ + create_note, + destroy_note, + }, + note_getter::get_note, + note_interface::NoteInterface, +}; use crate::constants_gen::{ GENERATOR_INDEX__INITIALISATION_NULLIFIER, EMPTY_NULLIFIED_COMMITMENT, @@ -25,42 +29,38 @@ impl Singleton { oracle::notes::is_nullifier_emitted(nullifier) } - fn initialise(self, mut context: Context, note: Note) -> Context { + fn initialise(self, context: &mut Context, note: &mut Note) { // Nullify the storage slot. let nullifier = self.compute_initialisation_nullifier(); - context = context.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT); + context.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT); - create_note(context, self.storage_slot, note, self.note_interface) + create_note(context, self.storage_slot, note, self.note_interface); } fn compute_initialisation_nullifier(self) -> Field { pedersen_with_separator([self.storage_slot], GENERATOR_INDEX__INITIALISATION_NULLIFIER)[0] } - fn replace(self, mut context: Context, new_note: Note) -> (Context, Note) { - let (new_context, prev_note) = get_note(context, self.storage_slot, self.note_interface); - context = new_context; + fn replace(self, context: &mut Context, new_note: &mut Note) { + let prev_note = get_note(context, self.storage_slot, self.note_interface); // Nullify previous note. - context = destroy_note(context, self.storage_slot, prev_note, self.note_interface); + destroy_note(context, self.storage_slot, prev_note, self.note_interface); // Add replacement note. - context = create_note(context, self.storage_slot, new_note, self.note_interface); - - (context, prev_note) + create_note(context, self.storage_slot, new_note, self.note_interface); } - fn get_note(self, mut context: Context) -> (Context, Note) { - let (new_context, note) = get_note(context, self.storage_slot, self.note_interface); - context = new_context; + fn get_note(self, context: &mut Context) -> Note { + let mut note = get_note(context, self.storage_slot, self.note_interface); // Nullify current note to make sure it's reading the latest note. - context = destroy_note(context, self.storage_slot, note, self.note_interface); + destroy_note(context, self.storage_slot, note, self.note_interface); // Add the same note again. // Because a nonce is added to every note in the kernel, its nullifier will be different. - context = create_note(context, self.storage_slot, note, self.note_interface); + create_note(context, self.storage_slot, &mut note, self.note_interface); - (context, note) + note } } \ No newline at end of file diff --git a/yarn-project/noir-libs/noir-aztec/src/types/vec.nr b/yarn-project/noir-libs/noir-aztec/src/types/vec.nr index 1f98e9cc9dcf..4cb9ce09cbbe 100644 --- a/yarn-project/noir-libs/noir-aztec/src/types/vec.nr +++ b/yarn-project/noir-libs/noir-aztec/src/types/vec.nr @@ -14,30 +14,28 @@ impl BoundedVec { self.storage[index] } - fn push(mut self: Self, elem: T) -> Self { + fn push(&mut self, elem: T) { assert(self.len as u64 < MaxLen as u64); self.storage[self.len] = elem; self.len += 1; - self } - fn push_array(mut self: Self, array: [T; Len]) -> Self { + fn push_array(&mut self, array: [T; Len]) { let newLen = self.len + array.len(); assert(newLen as u64 <= MaxLen as u64); for i in 0..array.len() { self.storage[self.len + i] = array[i]; } self.len = newLen; - self } - fn pop(mut self: Self) -> (Self, T) { + fn pop(&mut self) -> T { assert(self.len as u64 > 0); let elem = self.storage[self.len - 1]; self.len -= 1; - (self, elem) + elem } } diff --git a/yarn-project/noir-libs/value-note/src/utils.nr b/yarn-project/noir-libs/value-note/src/utils.nr index 042e05531737..d48cd84c9fbb 100644 --- a/yarn-project/noir-libs/value-note/src/utils.nr +++ b/yarn-project/noir-libs/value-note/src/utils.nr @@ -10,14 +10,13 @@ use crate::{ }; fn spend_notes( - mut context: Context, + context: &mut Context, balance: Set, amount: Field, owner: Field, -) -> Context { +) { let options = NoteGetterOptions::with_filter(get_2_notes, 0); - let (mut new_context, notes) = balance.get_notes(context, options); - context = new_context; + let notes = balance.get_notes(context, options); let note1 = notes[0]; let note2 = notes[1]; @@ -30,13 +29,13 @@ fn spend_notes( assert(sum as u120 >= amount as u120); // Removes the 2 notes from the owner's set of notes. - context = balance.remove(context, note1); - context = balance.remove(context, note2); + balance.remove(context, note1); + balance.remove(context, note2); // Creates change note for the owner. let change_value = sum - amount; - let change_note = ValueNote::new(change_value, owner); - context = balance.insert(context, change_note); + let mut change_note = ValueNote::new(change_value, owner); + balance.insert(context, &mut change_note); // Emit the newly created encrypted note preimages via oracle calls. let mut encrypted_data = [0; VALUE_NOTE_LEN]; @@ -45,7 +44,7 @@ fn spend_notes( }; let encryption_pub_key = get_public_key(owner); - context = emit_encrypted_log( + emit_encrypted_log( context, context.inputs.call_context.storage_contract_address, balance.storage_slot, @@ -53,25 +52,23 @@ fn spend_notes( encryption_pub_key, encrypted_data, ); - - context } fn send_note( - mut context: Context, + context: &mut Context, balance: Set, amount: Field, recipient: Field, -) -> Context { +) { // Creates new note for the recipient. - let note = ValueNote::new(amount, recipient); + let mut note = ValueNote::new(amount, recipient); // Insert the new note to the recipient's set of notes. - context = balance.insert(context, note); + balance.insert(context, &mut note); // Emit the newly created encrypted note preimages via oracle calls. let encryption_pub_key = get_public_key(recipient); - context = emit_encrypted_log( + emit_encrypted_log( context, context.inputs.call_context.storage_contract_address, balance.storage_slot, @@ -79,6 +76,4 @@ fn send_note( encryption_pub_key, note.serialise(), ); - - context } \ No newline at end of file diff --git a/yarn-project/noir-libs/value-note/src/value_note.nr b/yarn-project/noir-libs/value-note/src/value_note.nr index 51595cf2065d..596dd15f0a94 100644 --- a/yarn-project/noir-libs/value-note/src/value_note.nr +++ b/yarn-project/noir-libs/value-note/src/value_note.nr @@ -87,9 +87,8 @@ impl ValueNote { !self.is_real } - fn set_header(mut self: Self, header: NoteHeader) -> Self { + fn set_header(&mut self, header: NoteHeader) { self.header = header; - self } fn validate(self, sender: Field) { @@ -126,7 +125,7 @@ fn get_header(note: ValueNote) -> NoteHeader { note.header } -fn set_header(note: ValueNote, header: NoteHeader) -> ValueNote { +fn set_header(note: &mut ValueNote, header: NoteHeader) { note.set_header(header) }