From 1c3ea1ed1401a7dbaf809ba91a5500ab2304b71e Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 29 Feb 2024 12:20:43 +0000 Subject: [PATCH 1/7] refactor: removing msg-key --- .../aztec/src/context/private_context.nr | 3 +- .../aztec/src/context/public_context.nr | 3 +- noir-projects/aztec-nr/aztec/src/messaging.nr | 60 +++++++++------- .../aztec/src/messaging/l1_to_l2_message.nr | 38 +++++++--- .../aztec/src/oracle/get_l1_to_l2_message.nr | 6 +- .../src/oracle/get_membership_witness.nr | 1 + .../contracts/gas_token_contract/src/main.nr | 4 +- .../contracts/test_contract/src/interface.nr | 18 ++--- .../contracts/test_contract/src/main.nr | 11 +-- .../token_bridge_contract/src/main.nr | 6 +- .../archiver/src/archiver/archiver.ts | 10 +-- .../archiver/src/archiver/archiver_store.ts | 4 +- .../kv_archiver_store/kv_archiver_store.ts | 6 +- .../kv_archiver_store/message_store.ts | 40 +++++------ .../l1_to_l2_message_store.ts | 20 +++--- .../memory_archiver_store.ts | 14 ++-- .../aztec-node/src/aztec-node/server.ts | 8 +-- yarn-project/aztec.js/src/index.ts | 2 + .../src/interfaces/aztec-node.ts | 4 +- .../circuit-types/src/l1_to_l2_message.ts | 4 +- .../src/e2e_cross_chain_messaging.test.ts | 63 ++++++++++++---- .../e2e_public_cross_chain_messaging.test.ts | 31 +++----- .../e2e_public_to_private_messaging.test.ts | 4 +- .../src/shared/cross_chain_test_harness.ts | 45 ++++++------ .../src/shared/gas_portal_test_harness.ts | 16 ++--- .../end-to-end/src/shared/uniswap_l1_l2.ts | 28 ++------ .../pxe/src/simulator_oracle/index.ts | 6 +- .../src/simulator/public_executor.ts | 6 +- .../simulator/src/acvm/oracle/oracle.ts | 4 +- .../simulator/src/avm/journal/trace_types.ts | 2 +- .../src/client/private_execution.test.ts | 62 +++++----------- .../simulator/src/client/view_data_oracle.ts | 6 +- yarn-project/simulator/src/public/db.ts | 4 +- .../simulator/src/public/index.test.ts | 72 ++++++------------- .../src/public/public_execution_context.ts | 6 +- yarn-project/simulator/src/test/utils.ts | 2 +- 36 files changed, 296 insertions(+), 323 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 7041f079cab..4e9642a63fa 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -237,7 +237,7 @@ impl PrivateContext { // docs:start:context_consume_l1_to_l2_message // docs:start:consume_l1_to_l2_message - pub fn consume_l1_to_l2_message(&mut self, msg_key: Field, content: Field, secret: Field, sender: EthAddress) { + pub fn consume_l1_to_l2_message(&mut self, content: Field, secret: Field, sender: EthAddress) { // docs:end:context_consume_l1_to_l2_message let nullifier = process_l1_to_l2_message( self.historical_header.state.l1_to_l2_message_tree.root, @@ -245,7 +245,6 @@ impl PrivateContext { sender, self.chain_id(), self.version(), - msg_key, content, secret ); diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index f6aaffccd08..9593c3e5919 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -164,7 +164,7 @@ impl PublicContext { self.new_l2_to_l1_msgs.push(message); } - pub fn consume_l1_to_l2_message(&mut self, msg_key: Field, content: Field, secret: Field, sender: EthAddress) { + pub fn consume_l1_to_l2_message(&mut self, content: Field, secret: Field, sender: EthAddress) { let this = (*self).this_address(); let nullifier = process_l1_to_l2_message( self.historical_header.state.l1_to_l2_message_tree.root, @@ -172,7 +172,6 @@ impl PublicContext { sender, self.chain_id(), self.version(), - msg_key, content, secret ); diff --git a/noir-projects/aztec-nr/aztec/src/messaging.nr b/noir-projects/aztec-nr/aztec/src/messaging.nr index caf26c3c0ca..3c01bb7812c 100644 --- a/noir-projects/aztec-nr/aztec/src/messaging.nr +++ b/noir-projects/aztec-nr/aztec/src/messaging.nr @@ -4,10 +4,14 @@ mod l1_to_l2_message_getter_data; use l1_to_l2_message_getter_data::make_l1_to_l2_message_getter_data; use crate::oracle::get_l1_to_l2_message::get_l1_to_l2_message_call; +use crate::oracle::debug_log::debug_log_format; use dep::std::merkle::compute_merkle_root; - -use dep::protocol_types::address::{AztecAddress, EthAddress}; +use crate::messaging::l1_to_l2_message::L1ToL2Message; +use dep::protocol_types::{ + constants::{GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET}, address::{AztecAddress, EthAddress}, + hash::{pedersen_hash} +}; // Returns the nullifier for the message pub fn process_l1_to_l2_message( @@ -16,43 +20,45 @@ pub fn process_l1_to_l2_message( portal_contract_address: EthAddress, chain_id: Field, version: Field, - msg_key: Field, content: Field, secret: Field ) -> Field { - let returned_message = get_l1_to_l2_message_call(msg_key); - let l1_to_l2_message_data = make_l1_to_l2_message_getter_data(returned_message, 0, secret); + debug_log_format("Processing L1 to L2 message: root: {0}", [l1_to_l2_root]); + let msg = L1ToL2Message::new( + portal_contract_address, + chain_id, + storage_contract_address, + version, + content, + secret + ); + let entry_key = msg.hash(); + debug_log_format( + "Entry key = H({0}, {1}, {2}, {3}, {4}, {5}) {6}", + [ + portal_contract_address.to_field(), + chain_id, + storage_contract_address.to_field(), + version, + content, + secret, + entry_key + ] + ); - // Check that the returned message is actually the message we looked up - let msg_hash = l1_to_l2_message_data.message.hash(); - assert(msg_hash == msg_key, "Message not matching requested key"); + // TODO: Massively prune the returned values from the oracle. + let returned_message = get_l1_to_l2_message_call(entry_key); + let l1_to_l2_message_data = make_l1_to_l2_message_getter_data(returned_message, 0, secret); // Check that the message is in the tree + // This is implicitly checking that the values of the message are correct let root = compute_merkle_root( - msg_hash, + entry_key, l1_to_l2_message_data.leaf_index, l1_to_l2_message_data.sibling_path ); assert(root == l1_to_l2_root, "Message not in state"); - // Validate this is the target contract - assert(l1_to_l2_message_data.message.recipient.eq(storage_contract_address), "Invalid recipient"); - - // Validate the sender is the portal contract - assert(l1_to_l2_message_data.message.sender.eq(portal_contract_address), "Invalid sender"); - - // Validate the chain id is correct - assert(l1_to_l2_message_data.message.chainId == chain_id, "Invalid Chainid"); - - // Validate the version is correct - assert(l1_to_l2_message_data.message.version == version, "Invalid Version"); - - // Validate the message hash is correct - assert(l1_to_l2_message_data.message.content == content, "Invalid Content"); - - // Validate the message secret is correct - l1_to_l2_message_data.message.validate_message_secret(); - // Compute Nullifier l1_to_l2_message_data.message.compute_nullifier() } diff --git a/noir-projects/aztec-nr/aztec/src/messaging/l1_to_l2_message.nr b/noir-projects/aztec-nr/aztec/src/messaging/l1_to_l2_message.nr index a8f86a4ddf1..1c6c85167e6 100644 --- a/noir-projects/aztec-nr/aztec/src/messaging/l1_to_l2_message.nr +++ b/noir-projects/aztec-nr/aztec/src/messaging/l1_to_l2_message.nr @@ -4,9 +4,11 @@ use dep::protocol_types::{ hash::{pedersen_hash, sha256_to_field} }; +// TODO(#4833) remove `deadline` and `fee` from the message +// currently hardcoded to max_value and 0 respectively. struct L1ToL2Message { sender: EthAddress, - chainId: Field, + chain_id: Field, recipient: AztecAddress, version: Field, content: Field, @@ -18,6 +20,29 @@ struct L1ToL2Message { } impl L1ToL2Message { + pub fn new( + sender: EthAddress, + chain_id: Field, + recipient: AztecAddress, + version: Field, + content: Field, + secret: Field + ) -> L1ToL2Message { + let secret_hash = pedersen_hash([secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET); + Self { + sender, + chain_id, + recipient, + version, + content, + secret, + secret_hash, + deadline: 4294967295, + fee: 0, + tree_index: 0 + } + } + pub fn deserialize( fields: [Field; L1_TO_L2_MESSAGE_LENGTH], secret: Field, @@ -25,7 +50,7 @@ impl L1ToL2Message { ) -> L1ToL2Message { L1ToL2Message { sender: EthAddress::from_field(fields[0]), - chainId: fields[1], + chain_id: fields[1], recipient: AztecAddress::from_field(fields[2]), version: fields[3], content: fields[4], @@ -37,15 +62,10 @@ impl L1ToL2Message { } } - pub fn validate_message_secret(self: Self) { - let recomputed_hash = pedersen_hash([self.secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET); - assert(self.secret_hash == recomputed_hash, "Invalid message secret"); - } - fn hash(self: Self) -> Field { let mut hash_bytes: [u8; 256] = [0; 256]; let sender_bytes = self.sender.to_field().to_be_bytes(32); - let chainId_bytes = self.chainId.to_be_bytes(32); + let chain_id_bytes = self.chain_id.to_be_bytes(32); let recipient_bytes = self.recipient.to_field().to_be_bytes(32); let version_bytes = self.version.to_be_bytes(32); let content_bytes = self.content.to_be_bytes(32); @@ -55,7 +75,7 @@ impl L1ToL2Message { for i in 0..32 { hash_bytes[i] = sender_bytes[i]; - hash_bytes[i + 32] = chainId_bytes[i]; + hash_bytes[i + 32] = chain_id_bytes[i]; hash_bytes[i + 64] = recipient_bytes[i]; hash_bytes[i + 96] = version_bytes[i]; hash_bytes[i + 128] = content_bytes[i]; diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr index 27f6722ae1b..cc0144e944b 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr @@ -2,8 +2,8 @@ use dep::protocol_types::constants::L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH; // Checks if a msg is within the l1ToL2Msg tree #[oracle(getL1ToL2Message)] -fn get_l1_to_l2_msg_oracle(_msg_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {} +fn get_l1_to_l2_msg_oracle(_entry_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {} -unconstrained pub fn get_l1_to_l2_message_call(msg_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] { - get_l1_to_l2_msg_oracle(msg_key) +unconstrained pub fn get_l1_to_l2_message_call(entry_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] { + get_l1_to_l2_msg_oracle(entry_key) } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr index 1e82b12c91e..9efcdd6cd8e 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr @@ -2,6 +2,7 @@ use dep::protocol_types::{constants::{ARCHIVE_HEIGHT, CONTRACT_TREE_HEIGHT, NOTE global CONTRACT_TREE_ID = 0; global NOTE_HASH_TREE_ID = 2; +global L1_TO_L2_MESSAGE_TREE = 4; global ARCHIVE_TREE_ID = 5; // Note: We have M here because we need to somehow set it when calling get_membership_witness function and one way to diff --git a/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr index 663c2cfbde2..92b53618c7b 100644 --- a/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr @@ -14,11 +14,11 @@ contract GasToken { fn constructor() {} #[aztec(public)] - fn claim_public(to: AztecAddress, amount: Field, canceller: EthAddress, msg_key: Field, secret: Field) { + fn claim_public(to: AztecAddress, amount: Field, canceller: EthAddress, secret: Field) { let content_hash = get_bridge_gas_msg_hash(to, amount, canceller); // Consume message and emit nullifier - context.consume_l1_to_l2_message(msg_key, content_hash, secret, context.this_portal_address()); + context.consume_l1_to_l2_message(content_hash, secret, context.this_portal_address()); let new_balance = storage.balances.at(to).read() + U128::from_integer(amount); storage.balances.at(to).write(new_balance); diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/interface.nr b/noir-projects/noir-contracts/contracts/test_contract/src/interface.nr index 6af1d50e42e..64c3a2d7fc9 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/interface.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/interface.nr @@ -192,15 +192,13 @@ impl TestPrivateContextInterface { secret_hash_for_redeeming_minted_notes: Field, amount: Field, canceller: CancellerConsumeMintPrivateMessageStruct, - msg_key: Field, secret_for_L1_to_L2_message_consumption: Field ) -> [Field; RETURN_VALUES_LENGTH] { - let mut serialized_args = [0; 5]; + let mut serialized_args = [0; 4]; serialized_args[0] = secret_hash_for_redeeming_minted_notes; serialized_args[1] = amount; serialized_args[2] = canceller.inner; - serialized_args[3] = msg_key; - serialized_args[4] = secret_for_L1_to_L2_message_consumption; + serialized_args[3] = secret_for_L1_to_L2_message_consumption; context.call_private_function( self.address, @@ -247,15 +245,13 @@ impl TestPrivateContextInterface { to: ToConsumeMintPublicMessageStruct, amount: Field, canceller: CancellerConsumeMintPublicMessageStruct, - msg_key: Field, secret: Field ) { - let mut serialized_args = [0; 5]; + let mut serialized_args = [0; 4]; serialized_args[0] = to.inner; serialized_args[1] = amount; serialized_args[2] = canceller.inner; - serialized_args[3] = msg_key; - serialized_args[4] = secret; + serialized_args[3] = secret; context.call_public_function( self.address, @@ -352,15 +348,13 @@ impl TestPublicContextInterface { to: ToConsumeMintPublicMessageStruct, amount: Field, canceller: CancellerConsumeMintPublicMessageStruct, - msg_key: Field, secret: Field ) -> [Field; RETURN_VALUES_LENGTH] { - let mut serialized_args = [0; 5]; + let mut serialized_args = [0; 4]; serialized_args[0] = to.inner; serialized_args[1] = amount; serialized_args[2] = canceller.inner; - serialized_args[3] = msg_key; - serialized_args[4] = secret; + serialized_args[3] = secret; context.call_public_function( self.address, diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 15fc502e02a..e0386b0445a 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -263,12 +263,11 @@ contract Test { to: AztecAddress, amount: Field, canceller: EthAddress, - msg_key: Field, secret: Field ) { let content_hash = get_mint_public_content_hash(to, amount, canceller); // Consume message and emit nullifier - context.consume_l1_to_l2_message(msg_key, content_hash, secret, context.this_portal_address()); + context.consume_l1_to_l2_message(content_hash, secret, context.this_portal_address()); } #[aztec(private)] @@ -276,13 +275,11 @@ contract Test { secret_hash_for_redeeming_minted_notes: Field, amount: Field, canceller: EthAddress, - msg_key: Field, secret_for_L1_to_L2_message_consumption: Field ) { // Consume L1 to L2 message and emit nullifier let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, amount, canceller); context.consume_l1_to_l2_message( - msg_key, content_hash, secret_for_L1_to_L2_message_consumption, context.this_portal_address() @@ -291,24 +288,22 @@ contract Test { #[aztec(public)] fn consume_message_from_arbitrary_sender_public( - msg_key: Field, content: Field, secret: Field, sender: EthAddress ) { // Consume message and emit nullifier - context.consume_l1_to_l2_message(msg_key, content, secret, sender); + context.consume_l1_to_l2_message(content, secret, sender); } #[aztec(private)] fn consume_message_from_arbitrary_sender_private( - msg_key: Field, content: Field, secret: Field, sender: EthAddress ) { // Consume message and emit nullifier - context.consume_l1_to_l2_message(msg_key, content, secret, sender); + context.consume_l1_to_l2_message(content, secret, sender); } #[aztec(private)] diff --git a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr index 8a00972b733..ef0322c8ba2 100644 --- a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr @@ -33,11 +33,11 @@ contract TokenBridge { // docs:start:claim_public // Consumes a L1->L2 message and calls the token contract to mint the appropriate amount publicly #[aztec(public)] - fn claim_public(to: AztecAddress, amount: Field, canceller: EthAddress, msg_key: Field, secret: Field) { + fn claim_public(to: AztecAddress, amount: Field, canceller: EthAddress, secret: Field) { let content_hash = get_mint_public_content_hash(to, amount, canceller); // Consume message and emit nullifier - context.consume_l1_to_l2_message(msg_key, content_hash, secret, context.this_portal_address()); + context.consume_l1_to_l2_message(content_hash, secret, context.this_portal_address()); // Mint tokens Token::at(storage.token.read()).mint_public(context, to, amount); @@ -70,13 +70,11 @@ contract TokenBridge { secret_hash_for_redeeming_minted_notes: Field, // secret hash used to redeem minted notes at a later time. This enables anyone to call this function and mint tokens to a user on their behalf amount: Field, canceller: EthAddress, - msg_key: Field, // L1 to L2 message key as derived from the inbox contract secret_for_L1_to_L2_message_consumption: Field // secret used to consume the L1 to L2 message ) { // Consume L1 to L2 message and emit nullifier let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, amount, canceller); context.consume_l1_to_l2_message( - msg_key, content_hash, secret_for_L1_to_L2_message_consumption, context.this_portal_address() diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index dc5ccbe9fd0..5b77bb9fd31 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -217,9 +217,9 @@ export class Archiver implements ArchiveSource { messagesByBlock.set(blockNumber, messages); } - for (const [messageKey, blockNumber] of retrievedCancelledL1ToL2Messages.retrievedData) { + for (const [entryKey, blockNumber] of retrievedCancelledL1ToL2Messages.retrievedData) { const messages = messagesByBlock.get(blockNumber) || [[], []]; - messages[1].push(messageKey); + messages[1].push(entryKey); messagesByBlock.set(blockNumber, messages); } @@ -556,11 +556,11 @@ export class Archiver implements ArchiveSource { /** * Gets the confirmed/consumed L1 to L2 message associated with the given message key - * @param messageKey - The message key. + * @param entryKey - The message key. * @returns The L1 to L2 message (throws if not found). */ - getConfirmedL1ToL2Message(messageKey: Fr): Promise { - return this.store.getConfirmedL1ToL2Message(messageKey); + getConfirmedL1ToL2Message(entryKey: Fr): Promise { + return this.store.getConfirmedL1ToL2Message(entryKey); } getContractClassIds(): Promise { diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index 6052323ad42..bd19250a93c 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -99,10 +99,10 @@ export interface ArchiverDataStore { /** * Gets the confirmed L1 to L2 message corresponding to the given message key. - * @param messageKey - The message key to look up. + * @param entryKey - The message key to look up. * @returns The requested L1 to L2 message or throws if not found. */ - getConfirmedL1ToL2Message(messageKey: Fr): Promise; + getConfirmedL1ToL2Message(entryKey: Fr): Promise; /** * Gets up to `limit` amount of logs starting from `from`. diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts index e5600544617..0a2958a88e6 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts @@ -158,12 +158,12 @@ export class KVArchiverDataStore implements ArchiverDataStore { /** * Gets the confirmed L1 to L2 message corresponding to the given message key. - * @param messageKey - The message key to look up. + * @param entryKey - The message key to look up. * @returns The requested L1 to L2 message or throws if not found. */ - getConfirmedL1ToL2Message(messageKey: Fr): Promise { + getConfirmedL1ToL2Message(entryKey: Fr): Promise { try { - return Promise.resolve(this.#messageStore.getConfirmedMessage(messageKey)); + return Promise.resolve(this.#messageStore.getConfirmedMessage(entryKey)); } catch (err) { return Promise.reject(err); } diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts index 642c90edde3..1ec3ec9b197 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts @@ -60,18 +60,18 @@ export class MessageStore { void this.#lastL1BlockAddingMessages.set(l1BlockNumber); for (const message of messages) { - const messageKey = message.entryKey?.toString(); - if (!messageKey) { + const entryKey = message.entryKey?.toString(); + if (!entryKey) { throw new Error('Message does not have an entry key'); } - void this.#messages.setIfNotExists(messageKey, { + void this.#messages.setIfNotExists(entryKey, { message: message.toBuffer(), fee: message.fee, confirmed: false, }); - void this.#pendingMessagesByFee.update([message.fee, messageKey], 1); + void this.#pendingMessagesByFee.update([message.fee, entryKey], 1); } return true; @@ -93,13 +93,13 @@ export class MessageStore { void this.#lastL1BlockCancellingMessages.set(l1BlockNumber); - for (const messageKey of messageKeys) { - const messageCtx = this.#messages.get(messageKey.toString()); + for (const entryKey of messageKeys) { + const messageCtx = this.#messages.get(entryKey.toString()); if (!messageCtx) { - throw new Error(`Message ${messageKey.toString()} not found`); + throw new Error(`Message ${entryKey.toString()} not found`); } - void this.#pendingMessagesByFee.update([messageCtx.fee, messageKey.toString()], -1); + void this.#pendingMessagesByFee.update([messageCtx.fee, entryKey.toString()], -1); } return true; @@ -114,15 +114,15 @@ export class MessageStore { */ confirmPendingMessages(messageKeys: Fr[]): Promise { return this.db.transaction(() => { - for (const messageKey of messageKeys) { - const messageCtx = this.#messages.get(messageKey.toString()); + for (const entryKey of messageKeys) { + const messageCtx = this.#messages.get(entryKey.toString()); if (!messageCtx) { - throw new Error(`Message ${messageKey.toString()} not found`); + throw new Error(`Message ${entryKey.toString()} not found`); } messageCtx.confirmed = true; - void this.#messages.set(messageKey.toString(), messageCtx); - void this.#pendingMessagesByFee.update([messageCtx.fee, messageKey.toString()], -1); + void this.#messages.set(entryKey.toString(), messageCtx); + void this.#pendingMessagesByFee.update([messageCtx.fee, entryKey.toString()], -1); } return true; @@ -131,17 +131,17 @@ export class MessageStore { /** * Gets the confirmed L1 to L2 message corresponding to the given message key. - * @param messageKey - The message key to look up. + * @param entryKey - The message key to look up. * @returns The requested L1 to L2 message or throws if not found. */ - getConfirmedMessage(messageKey: Fr): L1ToL2Message { - const messageCtx = this.#messages.get(messageKey.toString()); + getConfirmedMessage(entryKey: Fr): L1ToL2Message { + const messageCtx = this.#messages.get(entryKey.toString()); if (!messageCtx) { - throw new Error(`Message ${messageKey.toString()} not found`); + throw new Error(`Message ${entryKey.toString()} not found`); } if (!messageCtx.confirmed) { - throw new Error(`Message ${messageKey.toString()} not confirmed`); + throw new Error(`Message ${entryKey.toString()} not confirmed`); } return L1ToL2Message.fromBuffer(messageCtx.message); @@ -155,11 +155,11 @@ export class MessageStore { getPendingMessageKeysByFee(limit: number): Fr[] { const messageKeys: Fr[] = []; - for (const [[_, messageKey], count] of this.#pendingMessagesByFee.entries({ + for (const [[_, entryKey], count] of this.#pendingMessagesByFee.entries({ reverse: true, })) { // put `count` copies of this message in the result list - messageKeys.push(...Array(count).fill(Fr.fromString(messageKey))); + messageKeys.push(...Array(count).fill(Fr.fromString(entryKey))); if (messageKeys.length >= limit) { break; } diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts index ae6c6988957..fc0e57334b6 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts @@ -14,8 +14,8 @@ export class L1ToL2MessageStore { constructor() {} - addMessage(messageKey: Fr, message: L1ToL2Message) { - const messageKeyBigInt = messageKey.toBigInt(); + addMessage(entryKey: Fr, message: L1ToL2Message) { + const messageKeyBigInt = entryKey.toBigInt(); const msgAndCount = this.store.get(messageKeyBigInt); if (msgAndCount) { msgAndCount.count++; @@ -24,12 +24,12 @@ export class L1ToL2MessageStore { } } - getMessage(messageKey: Fr): L1ToL2Message | undefined { - return this.store.get(messageKey.value)?.message; + getMessage(entryKey: Fr): L1ToL2Message | undefined { + return this.store.get(entryKey.value)?.message; } - getMessageAndCount(messageKey: Fr): L1ToL2MessageAndCount | undefined { - return this.store.get(messageKey.value); + getMessageAndCount(entryKey: Fr): L1ToL2MessageAndCount | undefined { + return this.store.get(entryKey.value); } } @@ -57,13 +57,13 @@ export class PendingL1ToL2MessageStore extends L1ToL2MessageStore { return messages; } - removeMessage(messageKey: Fr) { - // ignore 0 - messageKey is a hash, so a 0 can probabilistically never occur. It is best to skip it. - if (messageKey.equals(Fr.ZERO)) { + removeMessage(entryKey: Fr) { + // ignore 0 - entryKey is a hash, so a 0 can probabilistically never occur. It is best to skip it. + if (entryKey.equals(Fr.ZERO)) { return; } - const messageKeyBigInt = messageKey.value; + const messageKeyBigInt = entryKey.value; const msgAndCount = this.store.get(messageKeyBigInt); if (!msgAndCount) { throw new Error(`Unable to remove message: L1 to L2 Message with key ${messageKeyBigInt} not found in store`); diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index c8db5c84a86..4dcd8e60c8f 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -180,9 +180,9 @@ export class MemoryArchiverStore implements ArchiverDataStore { * @returns True if the operation is successful (always in this implementation). */ public confirmL1ToL2Messages(messageKeys: Fr[]): Promise { - messageKeys.forEach(messageKey => { - this.confirmedL1ToL2Messages.addMessage(messageKey, this.pendingL1ToL2Messages.getMessage(messageKey)!); - this.pendingL1ToL2Messages.removeMessage(messageKey); + messageKeys.forEach(entryKey => { + this.confirmedL1ToL2Messages.addMessage(entryKey, this.pendingL1ToL2Messages.getMessage(entryKey)!); + this.pendingL1ToL2Messages.removeMessage(entryKey); }); return Promise.resolve(true); } @@ -252,13 +252,13 @@ export class MemoryArchiverStore implements ArchiverDataStore { /** * Gets the confirmed L1 to L2 message corresponding to the given message key. - * @param messageKey - The message key to look up. + * @param entryKey - The message key to look up. * @returns The requested L1 to L2 message or throws if not found. */ - public getConfirmedL1ToL2Message(messageKey: Fr): Promise { - const message = this.confirmedL1ToL2Messages.getMessage(messageKey); + public getConfirmedL1ToL2Message(entryKey: Fr): Promise { + const message = this.confirmedL1ToL2Messages.getMessage(entryKey); if (!message) { - throw new Error(`L1 to L2 Message with key ${messageKey.toString()} not found in the confirmed messages store`); + throw new Error(`L1 to L2 Message with key ${entryKey.toString()} not found in the confirmed messages store`); } return Promise.resolve(message); } diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index d31b95afce2..95566b3560f 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -379,13 +379,13 @@ export class AztecNodeService implements AztecNode { /** * Gets a confirmed/consumed L1 to L2 message for the given message key * and its index in the merkle tree. - * @param messageKey - The message key. + * @param entryKey - The message key. * @returns The map containing the message and index. */ - public async getL1ToL2MessageAndIndex(messageKey: Fr): Promise { + public async getL1ToL2MessageAndIndex(entryKey: Fr): Promise { // todo: #697 - make this one lookup. - const index = (await this.findLeafIndex('latest', MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageKey))!; - const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey); + const index = (await this.findLeafIndex('latest', MerkleTreeId.L1_TO_L2_MESSAGE_TREE, entryKey))!; + const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(entryKey); return Promise.resolve(new L1ToL2MessageAndIndex(index, message)); } diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 527391ced3f..ad595229f96 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -89,6 +89,8 @@ export { FunctionCall, GrumpkinPrivateKey, INITIAL_L2_BLOCK_NUM, + L1ToL2Message, + L1Actor, L2Actor, L2Block, L2BlockL2Logs, diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 10123d17b7d..fb55df3205c 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -77,10 +77,10 @@ export interface AztecNode { /** * Gets a confirmed/consumed L1 to L2 message for the given message key (throws if not found). * and its index in the merkle tree - * @param messageKey - The message key. + * @param entryKey - The message key. * @returns The map containing the message and index. */ - getL1ToL2MessageAndIndex(messageKey: Fr): Promise; + getL1ToL2MessageAndIndex(entryKey: Fr): Promise; /** * Returns a sibling path for a leaf in the committed l1 to l2 data tree. diff --git a/yarn-project/circuit-types/src/l1_to_l2_message.ts b/yarn-project/circuit-types/src/l1_to_l2_message.ts index f24312016b5..95a7207ed7d 100644 --- a/yarn-project/circuit-types/src/l1_to_l2_message.ts +++ b/yarn-project/circuit-types/src/l1_to_l2_message.ts @@ -19,10 +19,10 @@ export interface L1ToL2MessageSource { /** * Gets the confirmed L1 to L2 message with the given message key. * i.e. message that has already been consumed by the sequencer and published in an L2 Block - * @param messageKey - The message key. + * @param entryKey - The message key. * @returns The confirmed L1 to L2 message (throws if not found) */ - getConfirmedL1ToL2Message(messageKey: Fr): Promise; + getConfirmedL1ToL2Message(entryKey: Fr): Promise; /** * Gets the number of the latest L2 block processed by the implementation. diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index 4f70efdc5fe..ad81de5cea7 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -4,9 +4,14 @@ import { DebugLogger, EthAddress, Fr, + L1Actor, + L1ToL2Message, + L2Actor, TxStatus, computeAuthWitMessageHash, } from '@aztec/aztec.js'; +import { keccak, sha256 } from '@aztec/foundation/crypto'; +import { serializeToBuffer } from '@aztec/foundation/serialize'; import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts.js'; import { delay, setup } from './fixtures/utils.js'; @@ -67,12 +72,13 @@ describe('e2e_cross_chain_messaging', () => { await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); // 2. Deposit tokens to the TokenPortal - const messageKey = await crossChainTestHarness.sendTokensToPortalPrivate( + const entryKeyInbox = await crossChainTestHarness.sendTokensToPortalPrivate( secretHashForRedeemingMintedNotes, bridgeAmount, secretHashForL2MessageConsumption, ); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount); + expect(await crossChainTestHarness.inbox.read.contains([entryKeyInbox.toString()])).toBeTruthy(); // Wait for the archiver to process the message await delay(5000); /// waiting 5 seconds. @@ -86,7 +92,6 @@ describe('e2e_cross_chain_messaging', () => { await crossChainTestHarness.consumeMessageOnAztecAndMintSecretly( secretHashForRedeemingMintedNotes, bridgeAmount, - messageKey, secretForL2MessageConsumption, ); // tokens were minted privately in a TransparentNote which the owner (person who knows the secret) must redeem: @@ -132,12 +137,13 @@ describe('e2e_cross_chain_messaging', () => { crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); - const messageKey = await crossChainTestHarness.sendTokensToPortalPrivate( + const entryKeyInbox = await crossChainTestHarness.sendTokensToPortalPrivate( secretHashForRedeemingMintedNotes, bridgeAmount, secretHashForL2MessageConsumption, ); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount); + expect(await crossChainTestHarness.inbox.read.contains([entryKeyInbox.toString()])).toBeTruthy(); // Wait for the archiver to process the message await delay(5000); /// waiting 5 seconds. @@ -148,6 +154,22 @@ describe('e2e_cross_chain_messaging', () => { await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, unrelatedMintAmount); // 3. Consume L1-> L2 message and mint private tokens on L2 + const content = Fr.fromBufferReduce( + sha256( + Buffer.concat([ + keccak(Buffer.from('mint_private(bytes32,uint256,address)')).subarray(0, 4), + serializeToBuffer(...[secretHashForL2MessageConsumption, new Fr(bridgeAmount), ethAccount.toBuffer32()]), + ]), + ), + ); + const wrongMessage = new L1ToL2Message( + new L1Actor(crossChainTestHarness.tokenPortalAddress, crossChainTestHarness.publicClient.chain.id), + new L2Actor(l2Bridge.address, 1), + content, + secretHashForL2MessageConsumption, + 2 ** 32 - 1, + 0, + ); // Sending wrong secret hashes should fail: await expect( @@ -157,22 +179,15 @@ describe('e2e_cross_chain_messaging', () => { secretHashForL2MessageConsumption, bridgeAmount, ethAccount, - messageKey, secretForL2MessageConsumption, ) .simulate(), - ).rejects.toThrowError("Invalid Content 'l1_to_l2_message_data.message.content == content'"); + ).rejects.toThrowError(`Message ${wrongMessage.hash().toString()} not found`); // send the right one - const consumptionTx = l2Bridge .withWallet(user2Wallet) - .methods.claim_private( - secretHashForRedeemingMintedNotes, - bridgeAmount, - ethAccount, - messageKey, - secretForL2MessageConsumption, - ) + .methods.claim_private(secretHashForRedeemingMintedNotes, bridgeAmount, ethAccount, secretForL2MessageConsumption) .send(); const consumptionReceipt = await consumptionTx.wait(); expect(consumptionReceipt.status).toBe(TxStatus.MINED); @@ -215,12 +230,13 @@ describe('e2e_cross_chain_messaging', () => { const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] = crossChainTestHarness.generateClaimSecret(); - const messageKey = await crossChainTestHarness.sendTokensToPortalPrivate( + const entryKey = await crossChainTestHarness.sendTokensToPortalPrivate( Fr.random(), bridgeAmount, secretHashForL2MessageConsumption, ); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(0n); + expect(await crossChainTestHarness.inbox.read.contains([entryKey.toString()])).toBeTruthy(); // Wait for the archiver to process the message await delay(5000); /// waiting 5 seconds. @@ -228,12 +244,29 @@ describe('e2e_cross_chain_messaging', () => { // Perform an unrelated transaction on L2 to progress the rollup. Here we mint public tokens. await crossChainTestHarness.mintTokensPublicOnL2(0n); + const content = Fr.fromBufferReduce( + sha256( + Buffer.concat([ + keccak(Buffer.from('mint_public(bytes32,uint256,address)')).subarray(0, 4), + serializeToBuffer(...[ownerAddress, new Fr(bridgeAmount), ethAccount.toBuffer32()]), + ]), + ), + ); + const wrongMessage = new L1ToL2Message( + new L1Actor(crossChainTestHarness.tokenPortalAddress, crossChainTestHarness.publicClient.chain.id), + new L2Actor(l2Bridge.address, 1), + content, + secretHashForL2MessageConsumption, + 2 ** 32 - 1, + 0, + ); + // 3. Consume L1-> L2 message and try to mint publicly on L2 - should fail await expect( l2Bridge .withWallet(user2Wallet) - .methods.claim_public(ownerAddress, bridgeAmount, ethAccount, messageKey, secretForL2MessageConsumption) + .methods.claim_public(ownerAddress, bridgeAmount, ethAccount, secretForL2MessageConsumption) .simulate(), - ).rejects.toThrowError("Invalid Content 'l1_to_l2_message_data.message.content == content'"); + ).rejects.toThrowError(`Message ${wrongMessage.hash().toString()} not found`); }, 120_000); }); diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 8fc15d8de80..8145c85ea9b 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -83,7 +83,7 @@ describe('e2e_public_cross_chain_messaging', () => { await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); // 2. Deposit tokens to the TokenPortal - const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); + await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount); // Wait for the archiver to process the message @@ -96,7 +96,7 @@ describe('e2e_public_cross_chain_messaging', () => { const balanceBefore = unrelatedMintAmount; // 3. Consume L1 -> L2 message and mint public tokens on L2 - await crossChainTestHarness.consumeMessageOnAztecAndMintPublicly(bridgeAmount, messageKey, secret); + await crossChainTestHarness.consumeMessageOnAztecAndMintPublicly(bridgeAmount, secret); await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, balanceBefore + bridgeAmount); const afterBalance = balanceBefore + bridgeAmount; @@ -136,7 +136,7 @@ describe('e2e_public_cross_chain_messaging', () => { const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); - const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); + const entryKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount); // Wait for the archiver to process the message @@ -151,7 +151,7 @@ describe('e2e_public_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user2Wallet) - .methods.claim_public(user2Wallet.getAddress(), bridgeAmount, ethAccount, messageKey, secret) + .methods.claim_public(user2Wallet.getAddress(), bridgeAmount, ethAccount, secret) .simulate(), ).rejects.toThrow("Invalid Content 'l1_to_l2_message_data.message.content == content'"); @@ -159,7 +159,7 @@ describe('e2e_public_cross_chain_messaging', () => { logger("user2 consumes owner's message on L2 Publicly"); const tx = l2Bridge .withWallet(user2Wallet) - .methods.claim_public(ownerAddress, bridgeAmount, ethAccount, messageKey, secret) + .methods.claim_public(ownerAddress, bridgeAmount, ethAccount, secret) .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); @@ -188,7 +188,7 @@ describe('e2e_public_cross_chain_messaging', () => { const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(bridgeAmount); - const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); + const entryKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(0n); // Wait for the archiver to process the message @@ -198,10 +198,7 @@ describe('e2e_public_cross_chain_messaging', () => { await crossChainTestHarness.mintTokensPublicOnL2(0n); await expect( - l2Bridge - .withWallet(user2Wallet) - .methods.claim_private(secretHash, bridgeAmount, ethAccount, messageKey, secret) - .simulate(), + l2Bridge.withWallet(user2Wallet).methods.claim_private(secretHash, bridgeAmount, ethAccount, secret).simulate(), ).rejects.toThrowError("Invalid Content 'l1_to_l2_message_data.message.content == content'"); }, 60_000); @@ -289,7 +286,7 @@ describe('e2e_public_cross_chain_messaging', () => { // We check that the message was correctly injected by checking the emitted event and we store the message key // for later use - let msgKey!: Fr; + let entryKey!: Fr; { const txReceipt = await crossChainTestHarness.publicClient.waitForTransactionReceipt({ hash: txHash, @@ -312,7 +309,7 @@ describe('e2e_public_cross_chain_messaging', () => { expect((topics.args as any).recipient).toBe(recipient); // TODO(#4678): Unify naming of message key/entry key - msgKey = Fr.fromString(topics.args.entryKey!); + entryKey = Fr.fromString(topics.args.entryKey!); } // We wait for the archiver to process the message and we push a block for the message to be confirmed @@ -323,15 +320,9 @@ describe('e2e_public_cross_chain_messaging', () => { // Finally, e consume the L1 -> L2 message using the test contract either from private or public if (isPrivate) { - await testContract.methods - .consume_message_from_arbitrary_sender_private(msgKey, content, secret, sender) - .send() - .wait(); + await testContract.methods.consume_message_from_arbitrary_sender_private(content, secret, sender).send().wait(); } else { - await testContract.methods - .consume_message_from_arbitrary_sender_public(msgKey, content, secret, sender) - .send() - .wait(); + await testContract.methods.consume_message_from_arbitrary_sender_public(content, secret, sender).send().wait(); } }, 60_000, diff --git a/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts index e07a5cf57d4..bfa6f0146d3 100644 --- a/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts @@ -47,7 +47,7 @@ describe('e2e_public_to_private_messaging', () => { const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); - const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); + await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); expect(await underlyingERC20.read.balanceOf([ethAccount.toString()])).toBe(l1TokenBalance - bridgeAmount); // Wait for the archiver to process the message @@ -58,7 +58,7 @@ describe('e2e_public_to_private_messaging', () => { await crossChainTestHarness.mintTokensPublicOnL2(initialBalance); await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, initialBalance); - await crossChainTestHarness.consumeMessageOnAztecAndMintPublicly(bridgeAmount, messageKey, secret); + await crossChainTestHarness.consumeMessageOnAztecAndMintPublicly(bridgeAmount, secret); await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, initialBalance + bridgeAmount); // Create the commitment to be spent in the private domain diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index 03a87acd1da..2cb04e59e67 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -218,7 +218,8 @@ export class CrossChainTestHarness { async mintTokensOnL1(amount: bigint) { this.logger('Minting tokens on L1'); - await this.underlyingERC20.write.mint([this.ethAccount.toString(), amount], {} as any); + const txHash = await this.underlyingERC20.write.mint([this.ethAccount.toString(), amount], {} as any); + await this.publicClient.waitForTransactionReceipt({ hash: txHash }); expect(await this.underlyingERC20.read.balanceOf([this.ethAccount.toString()])).toBe(amount); } @@ -227,7 +228,11 @@ export class CrossChainTestHarness { } async sendTokensToPortalPublic(bridgeAmount: bigint, secretHash: Fr) { - await this.underlyingERC20.write.approve([this.tokenPortalAddress.toString(), bridgeAmount], {} as any); + const txHash1 = await this.underlyingERC20.write.approve( + [this.tokenPortalAddress.toString(), bridgeAmount], + {} as any, + ); + await this.publicClient.waitForTransactionReceipt({ hash: txHash1 }); // Deposit tokens to the TokenPortal const deadline = 2 ** 32 - 1; // max uint32 @@ -240,12 +245,13 @@ export class CrossChainTestHarness { deadline, secretHash.toString(), ] as const; - const { result: messageKeyHex } = await this.tokenPortal.simulate.depositToAztecPublic(args, { + const { result: entryKeyHex } = await this.tokenPortal.simulate.depositToAztecPublic(args, { account: this.ethAccount.toString(), } as any); - await this.tokenPortal.write.depositToAztecPublic(args, {} as any); + const txHash2 = await this.tokenPortal.write.depositToAztecPublic(args, {} as any); + await this.publicClient.waitForTransactionReceipt({ hash: txHash2 }); - return Fr.fromString(messageKeyHex); + return Fr.fromString(entryKeyHex); } async sendTokensToPortalPrivate( @@ -253,8 +259,11 @@ export class CrossChainTestHarness { bridgeAmount: bigint, secretHashForL2MessageConsumption: Fr, ) { - await this.underlyingERC20.write.approve([this.tokenPortalAddress.toString(), bridgeAmount], {} as any); - + const txHash1 = await this.underlyingERC20.write.approve( + [this.tokenPortalAddress.toString(), bridgeAmount], + {} as any, + ); + await this.publicClient.waitForTransactionReceipt({ hash: txHash1 }); // Deposit tokens to the TokenPortal const deadline = 2 ** 32 - 1; // max uint32 @@ -266,12 +275,13 @@ export class CrossChainTestHarness { deadline, secretHashForL2MessageConsumption.toString(), ] as const; - const { result: messageKeyHex } = await this.tokenPortal.simulate.depositToAztecPrivate(args, { + const { result: entryKeyHex } = await this.tokenPortal.simulate.depositToAztecPrivate(args, { account: this.ethAccount.toString(), } as any); - await this.tokenPortal.write.depositToAztecPrivate(args, {} as any); + const txHash2 = await this.tokenPortal.write.depositToAztecPrivate(args, {} as any); + await this.publicClient.waitForTransactionReceipt({ hash: txHash2 }); - return Fr.fromString(messageKeyHex); + return Fr.fromString(entryKeyHex); } async mintTokensPublicOnL2(amount: bigint) { @@ -300,19 +310,12 @@ export class CrossChainTestHarness { async consumeMessageOnAztecAndMintSecretly( secretHashForRedeemingMintedNotes: Fr, bridgeAmount: bigint, - messageKey: Fr, secretForL2MessageConsumption: Fr, ) { this.logger('Consuming messages on L2 secretively'); // Call the mint tokens function on the Aztec.nr contract const consumptionTx = this.l2Bridge.methods - .claim_private( - secretHashForRedeemingMintedNotes, - bridgeAmount, - this.ethAccount, - messageKey, - secretForL2MessageConsumption, - ) + .claim_private(secretHashForRedeemingMintedNotes, bridgeAmount, this.ethAccount, secretForL2MessageConsumption) .send(); const consumptionReceipt = await consumptionTx.wait(); expect(consumptionReceipt.status).toBe(TxStatus.MINED); @@ -320,12 +323,10 @@ export class CrossChainTestHarness { await this.addPendingShieldNoteToPXE(bridgeAmount, secretHashForRedeemingMintedNotes, consumptionReceipt.txHash); } - async consumeMessageOnAztecAndMintPublicly(bridgeAmount: bigint, messageKey: Fr, secret: Fr) { + async consumeMessageOnAztecAndMintPublicly(bridgeAmount: bigint, secret: Fr) { this.logger('Consuming messages on L2 Publicly'); // Call the mint tokens function on the Aztec.nr contract - const tx = this.l2Bridge.methods - .claim_public(this.ownerAddress, bridgeAmount, this.ethAccount, messageKey, secret) - .send(); + const tx = this.l2Bridge.methods.claim_public(this.ownerAddress, bridgeAmount, this.ethAccount, secret).send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); } diff --git a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts index 332b788ecee..6f6aea67170 100644 --- a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts @@ -192,12 +192,12 @@ export class GasBridgingTestHarness { deadline, secretHash.toString(), ] as const; - const { result: messageKeyHex } = await this.tokenPortal.simulate.depositToAztecPublic(args, { + const { result: entryKeyHex } = await this.tokenPortal.simulate.depositToAztecPublic(args, { account: this.ethAccount.toString(), } as any); await this.tokenPortal.write.depositToAztecPublic(args, {} as any); - return Fr.fromString(messageKeyHex); + return Fr.fromString(entryKeyHex); } async sendTokensToPortalPrivate( @@ -218,18 +218,18 @@ export class GasBridgingTestHarness { deadline, secretHashForL2MessageConsumption.toString(), ] as const; - const { result: messageKeyHex } = await this.tokenPortal.simulate.depositToAztecPrivate(args, { + const { result: entryKeyHex } = await this.tokenPortal.simulate.depositToAztecPrivate(args, { account: this.ethAccount.toString(), } as any); await this.tokenPortal.write.depositToAztecPrivate(args, {} as any); - return Fr.fromString(messageKeyHex); + return Fr.fromString(entryKeyHex); } - async consumeMessageOnAztecAndMintPublicly(bridgeAmount: bigint, owner: AztecAddress, messageKey: Fr, secret: Fr) { + async consumeMessageOnAztecAndMintPublicly(bridgeAmount: bigint, owner: AztecAddress, secret: Fr) { this.logger('Consuming messages on L2 Publicly'); // Call the mint tokens function on the Aztec.nr contract - const tx = this.l2Token.methods.claim_public(owner, bridgeAmount, this.ethAccount, messageKey, secret).send(); + const tx = this.l2Token.methods.claim_public(owner, bridgeAmount, this.ethAccount, secret).send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); } @@ -250,7 +250,7 @@ export class GasBridgingTestHarness { await this.mintTokensOnL1(l1TokenBalance); // 2. Deposit tokens to the TokenPortal - const messageKey = await this.sendTokensToPortalPublic(bridgeAmount, owner, secretHash); + await this.sendTokensToPortalPublic(bridgeAmount, owner, secretHash); expect(await this.getL1BalanceOf(this.ethAccount)).toBe(l1TokenBalance - bridgeAmount); // Wait for the archiver to process the message @@ -260,7 +260,7 @@ export class GasBridgingTestHarness { await this.l2Token.methods.check_balance(0).send().wait(); // 3. Consume L1-> L2 message and mint public tokens on L2 - await this.consumeMessageOnAztecAndMintPublicly(bridgeAmount, owner, messageKey, secret); + await this.consumeMessageOnAztecAndMintPublicly(bridgeAmount, owner, secret); await this.expectPublicBalanceOnL2(owner, bridgeAmount); } } diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index e76cef9f711..dd2d892da77 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -161,7 +161,7 @@ export const uniswapL1L2TestSuite = ( const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret(); const [secretForRedeemingWeth, secretHashForRedeemingWeth] = wethCrossChainHarness.generateClaimSecret(); - const messageKey = await wethCrossChainHarness.sendTokensToPortalPrivate( + const entryKey = await wethCrossChainHarness.sendTokensToPortalPrivate( secretHashForRedeemingWeth, wethAmountToBridge, secretHashForMintingWeth, @@ -173,6 +173,7 @@ export const uniswapL1L2TestSuite = ( expect(await wethCrossChainHarness.getL1BalanceOf(wethCrossChainHarness.tokenPortalAddress)).toBe( wethAmountToBridge, ); + expect(await wethCrossChainHarness.inbox.read.contains([entryKey.toString()])).toBe(true); // Wait for the archiver to process the message await sleep(5000); @@ -185,7 +186,6 @@ export const uniswapL1L2TestSuite = ( await wethCrossChainHarness.consumeMessageOnAztecAndMintSecretly( secretHashForRedeemingWeth, wethAmountToBridge, - messageKey, secretForMintingWeth, ); await wethCrossChainHarness.redeemShieldPrivatelyOnL2(wethAmountToBridge, secretForRedeemingWeth); @@ -259,13 +259,9 @@ export const uniswapL1L2TestSuite = ( ownerEthAddress.toString(), true, ] as const; - const { result: depositDaiMessageKeyHex } = await uniswapPortal.simulate.swapPrivate(swapArgs, { - account: ownerEthAddress.toString(), - } as any); // this should also insert a message into the inbox. await uniswapPortal.write.swapPrivate(swapArgs, {} as any); - const depositDaiMessageKey = Fr.fromString(depositDaiMessageKeyHex); // weth was swapped to dai and send to portal const daiL1BalanceOfPortalAfter = await daiCrossChainHarness.getL1BalanceOf( @@ -284,7 +280,6 @@ export const uniswapL1L2TestSuite = ( await daiCrossChainHarness.consumeMessageOnAztecAndMintSecretly( secretHashForRedeemingDai, daiAmountToBridge, - depositDaiMessageKey, secretForDepositingSwappedDai, ); await daiCrossChainHarness.redeemShieldPrivatelyOnL2(daiAmountToBridge, secretForRedeemingDai); @@ -308,7 +303,7 @@ export const uniswapL1L2TestSuite = ( // 1. Approve and deposit weth to the portal and move to L2 const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret(); - const messageKey = await wethCrossChainHarness.sendTokensToPortalPublic( + const entryKey = await wethCrossChainHarness.sendTokensToPortalPublic( wethAmountToBridge, secretHashForMintingWeth, ); @@ -319,6 +314,7 @@ export const uniswapL1L2TestSuite = ( expect(await wethCrossChainHarness.getL1BalanceOf(wethCrossChainHarness.tokenPortalAddress)).toBe( wethAmountToBridge, ); + expect(await wethCrossChainHarness.inbox.read.contains([entryKey.toString()])).toBe(true); // Wait for the archiver to process the message await sleep(5000); @@ -328,11 +324,7 @@ export const uniswapL1L2TestSuite = ( // 2. Claim WETH on L2 logger('Minting weth on L2'); - await wethCrossChainHarness.consumeMessageOnAztecAndMintPublicly( - wethAmountToBridge, - messageKey, - secretForMintingWeth, - ); + await wethCrossChainHarness.consumeMessageOnAztecAndMintPublicly(wethAmountToBridge, secretForMintingWeth); await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, wethAmountToBridge); // Store balances @@ -407,13 +399,9 @@ export const uniswapL1L2TestSuite = ( ownerEthAddress.toString(), true, ] as const; - const { result: depositDaiMessageKeyHex } = await uniswapPortal.simulate.swapPublic(swapArgs, { - account: ownerEthAddress.toString(), - } as any); // this should also insert a message into the inbox. await uniswapPortal.write.swapPublic(swapArgs, {} as any); - const depositDaiMessageKey = Fr.fromString(depositDaiMessageKeyHex); // weth was swapped to dai and send to portal const daiL1BalanceOfPortalAfter = await daiCrossChainHarness.getL1BalanceOf( daiCrossChainHarness.tokenPortalAddress, @@ -428,11 +416,7 @@ export const uniswapL1L2TestSuite = ( // 6. claim dai on L2 logger('Consuming messages to mint dai on L2'); - await daiCrossChainHarness.consumeMessageOnAztecAndMintPublicly( - daiAmountToBridge, - depositDaiMessageKey, - secretForDepositingSwappedDai, - ); + await daiCrossChainHarness.consumeMessageOnAztecAndMintPublicly(daiAmountToBridge, secretForDepositingSwappedDai); await daiCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, daiL2BalanceBeforeSwap + daiAmountToBridge); const wethL2BalanceAfterSwap = await wethCrossChainHarness.getL2PublicBalanceOf(ownerAddress); diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 806e82c14a3..f5fc31e4179 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -131,12 +131,12 @@ export class SimulatorOracle implements DBOracle { * Retrieves the L1ToL2Message associated with a specific message key * Throws an error if the message key is not found * - * @param msgKey - The key of the message to be retrieved + * @param entryKey - The key of the message to be retrieved * @returns A promise that resolves to the message data, a sibling path and the * index of the message in the l1ToL2MessageTree */ - async getL1ToL2Message(msgKey: Fr): Promise> { - const messageAndIndex = await this.aztecNode.getL1ToL2MessageAndIndex(msgKey); + async getL1ToL2Message(entryKey: Fr): Promise> { + const messageAndIndex = await this.aztecNode.getL1ToL2MessageAndIndex(entryKey); const message = messageAndIndex.message; const index = messageAndIndex.index; const siblingPath = await this.aztecNode.getL1ToL2MessageSiblingPath('latest', index); diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index 2d7f539f0e2..63605d3be41 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -217,10 +217,10 @@ export class WorldStatePublicDB implements PublicStateDB { export class WorldStateDB implements CommitmentsDB { constructor(private db: MerkleTreeOperations, private l1ToL2MessageSource: L1ToL2MessageSource) {} - public async getL1ToL2Message(messageKey: Fr): Promise> { + public async getL1ToL2Message(entryKey: Fr): Promise> { // todo: #697 - make this one lookup. - const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey); - const index = (await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageKey.toBuffer()))!; + const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(entryKey); + const index = (await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, entryKey.toBuffer()))!; const siblingPath = await this.db.getSiblingPath( MerkleTreeId.L1_TO_L2_MESSAGE_TREE, index, diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index cf54c90163e..193087b43ab 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -237,8 +237,8 @@ export class Oracle { return toACVMField(exists); } - async getL1ToL2Message([msgKey]: ACVMField[]): Promise { - const message = await this.typedOracle.getL1ToL2Message(fromACVMField(msgKey)); + async getL1ToL2Message([entryKey]: ACVMField[]): Promise { + const message = await this.typedOracle.getL1ToL2Message(fromACVMField(entryKey)); return message.toFields().map(toACVMField); } diff --git a/yarn-project/simulator/src/avm/journal/trace_types.ts b/yarn-project/simulator/src/avm/journal/trace_types.ts index 9fa6f646f33..30d7449bd6e 100644 --- a/yarn-project/simulator/src/avm/journal/trace_types.ts +++ b/yarn-project/simulator/src/avm/journal/trace_types.ts @@ -69,7 +69,7 @@ export type TracedNullifierCheck = { // callPointer: Fr; // portal: Fr; // EthAddress // leafIndex: Fr; -// msgKey: Fr; +// entryKey: Fr; // exists: Fr; // message: []; // omitted from VM public inputs //}; diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index ddcdef091eb..5e40fc98b91 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -151,14 +151,14 @@ describe('Private Execution test suite', () => { // Create a new snapshot. const newSnap = new AppendOnlyTreeSnapshot(Fr.fromBuffer(tree.getRoot(true)), Number(tree.getNumLeaves(true))); - if (name === 'noteHash') { + if (name === 'noteHash' || name === 'l1ToL2Messages') { header = new Header( header.lastArchive, header.contentCommitment, new StateReference( - header.state.l1ToL2MessageTree, + name === 'l1ToL2Messages' ? newSnap : header.state.l1ToL2MessageTree, new PartialStateReference( - newSnap, + name === 'noteHash' ? newSnap : header.state.partial.noteHashTree, header.state.partial.nullifierTree, header.state.partial.contractTree, header.state.partial.publicDataTree, @@ -547,7 +547,7 @@ describe('Private Execution test suite', () => { }); }); - describe('L1 to L2', () => { + describe.only('L1 to L2', () => { const artifact = getFunctionArtifact(TestContractArtifact, 'consume_mint_private_message'); const canceller = EthAddress.random(); let bridgedAmount = 100n; @@ -557,7 +557,6 @@ describe('Private Execution test suite', () => { let crossChainMsgRecipient: AztecAddress | undefined; let crossChainMsgSender: EthAddress | undefined; - let messageKey: Fr | undefined; let preimage: L1ToL2Message; @@ -569,7 +568,6 @@ describe('Private Execution test suite', () => { crossChainMsgRecipient = undefined; crossChainMsgSender = undefined; - messageKey = undefined; }); const computePreimage = () => @@ -585,25 +583,23 @@ describe('Private Execution test suite', () => { secretHashForRedeemingNotes, bridgedAmount, canceller.toField(), - messageKey ?? preimage.hash(), secretForL1ToL2MessageConsumption, ]); - const mockOracles = async () => { - const tree = await insertLeaves([messageKey ?? preimage.hash()], 'l1ToL2Messages'); + const mockOracles = async (updateHeader = true) => { + const tree = await insertLeaves([preimage.hash()], 'l1ToL2Messages'); oracle.getL1ToL2Message.mockImplementation(async () => { - return Promise.resolve(new MessageLoadOracleInputs(preimage, 0n, await tree.getSiblingPath(0n, false))); + return Promise.resolve(new MessageLoadOracleInputs(preimage, 0n, await tree.getSiblingPath(0n, true))); }); + if (updateHeader) { + oracle.getHeader.mockResolvedValue(header); + } }; it('Should be able to consume a dummy cross chain message', async () => { preimage = computePreimage(); - args = computeArgs(); - await mockOracles(); - // Update state - oracle.getHeader.mockResolvedValue(header); const result = await runSimulator({ contractAddress, @@ -621,34 +617,14 @@ describe('Private Execution test suite', () => { expect(newNullifiers).toHaveLength(1); }); - it('Message not matching requested key', async () => { - messageKey = Fr.random(); - - preimage = computePreimage(); - - args = computeArgs(); - - await mockOracles(); - // Update state - oracle.getHeader.mockResolvedValue(header); - - await expect( - runSimulator({ - contractAddress, - artifact, - args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, - txContext: { version: new Fr(1n), chainId: new Fr(1n) }, - }), - ).rejects.toThrowError('Message not matching requested key'); - }); - it('Invalid membership proof', async () => { + // Where is this one failing? Because we are not updating the header? preimage = computePreimage(); args = computeArgs(); - await mockOracles(); + // Don't update the header so the message is not in state + await mockOracles(false); await expect( runSimulator({ @@ -680,7 +656,7 @@ describe('Private Execution test suite', () => { portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), - ).rejects.toThrowError('Invalid recipient'); + ).rejects.toThrowError('Message not in state'); }); it('Invalid sender', async () => { @@ -701,7 +677,7 @@ describe('Private Execution test suite', () => { portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), - ).rejects.toThrowError('Invalid sender'); + ).rejects.toThrowError('Message not in state'); }); it('Invalid chainid', async () => { @@ -721,7 +697,7 @@ describe('Private Execution test suite', () => { portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(2n) }, }), - ).rejects.toThrowError('Invalid Chainid'); + ).rejects.toThrowError('Message not in state'); }); it('Invalid version', async () => { @@ -741,7 +717,7 @@ describe('Private Execution test suite', () => { portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(2n), chainId: new Fr(1n) }, }), - ).rejects.toThrowError('Invalid Version'); + ).rejects.toThrowError('Message not in state'); }); it('Invalid content', async () => { @@ -762,7 +738,7 @@ describe('Private Execution test suite', () => { portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), - ).rejects.toThrowError('Invalid Content'); + ).rejects.toThrowError('Message not in state'); }); it('Invalid Secret', async () => { @@ -783,7 +759,7 @@ describe('Private Execution test suite', () => { portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), - ).rejects.toThrowError('Invalid message secret'); + ).rejects.toThrowError('Message not in state'); }); }); diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index dc98386c3dc..cb3a4bab38e 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -217,11 +217,11 @@ export class ViewDataOracle extends TypedOracle { /** * Fetches the a message from the db, given its key. - * @param msgKey - A buffer representing the message key. + * @param entryKey - A buffer representing the message key. * @returns The l1 to l2 message data */ - public async getL1ToL2Message(msgKey: Fr) { - return await this.db.getL1ToL2Message(msgKey); + public async getL1ToL2Message(entryKey: Fr) { + return await this.db.getL1ToL2Message(entryKey); } /** diff --git a/yarn-project/simulator/src/public/db.ts b/yarn-project/simulator/src/public/db.ts index 7701e32ea6e..d661b28f76e 100644 --- a/yarn-project/simulator/src/public/db.ts +++ b/yarn-project/simulator/src/public/db.ts @@ -71,10 +71,10 @@ export interface CommitmentsDB { /** * Gets a confirmed L1 to L2 message for the given message key. * TODO(Maddiaa): Can be combined with aztec-node method that does the same thing. - * @param msgKey - The message Key. + * @param entryKey - The message Key. * @returns - The l1 to l2 message object */ - getL1ToL2Message(msgKey: Fr): Promise>; + getL1ToL2Message(entryKey: Fr): Promise>; /** * Gets the index of a commitment in the note hash tree. diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index 00bc0791618..69f37c9ed34 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -408,7 +408,6 @@ describe('ACIR public execution simulator', () => { let crossChainMsgRecipient: AztecAddress | undefined; let crossChainMsgSender: EthAddress | undefined; - let messageKey: Fr | undefined; let preimage: L1ToL2Message; let globalVariables: GlobalVariables; @@ -422,7 +421,6 @@ describe('ACIR public execution simulator', () => { crossChainMsgRecipient = undefined; crossChainMsgSender = undefined; - messageKey = undefined; }); const computePreImage = () => @@ -433,14 +431,7 @@ describe('ACIR public execution simulator', () => { secret, ); - const computeArgs = () => - encodeArguments(mintPublicArtifact, [ - tokenRecipient, - bridgedAmount, - canceller, - messageKey ?? preimage.hash(), - secret, - ]); + const computeArgs = () => encodeArguments(mintPublicArtifact, [tokenRecipient, bridgedAmount, canceller, secret]); const computeCallContext = () => CallContext.from({ @@ -464,7 +455,7 @@ describe('ACIR public execution simulator', () => { AztecAddress.ZERO, ); - const mockOracles = () => { + const mockOracles = (updateState = true) => { publicContracts.getBytecode.mockResolvedValue(Buffer.from(mintPublicArtifact.bytecode, 'base64')); publicState.storageRead.mockResolvedValue(Fr.ZERO); @@ -473,7 +464,7 @@ describe('ACIR public execution simulator', () => { .map(f => f.toBuffer()); const siblingPath = new SiblingPath(L1_TO_L2_MSG_TREE_HEIGHT, siblingPathBuffers); - let root = messageKey ?? preimage.hash(); + let root = preimage.hash(); for (const sibling of siblingPathBuffers) { root = pedersenHash([root.toBuffer(), sibling]); } @@ -481,10 +472,12 @@ describe('ACIR public execution simulator', () => { return Promise.resolve(new MessageLoadOracleInputs(preimage, 0n, siblingPath)); }); - return new AppendOnlyTreeSnapshot( - root, - 1, // we set 1 message in the tree - ); + if (updateState) { + header.state.l1ToL2MessageTree = new AppendOnlyTreeSnapshot( + root, + 1, // we set 1 message in the tree + ); + } }; it('Should be able to consume an L1 to L2 message in the public context', async () => { @@ -494,7 +487,7 @@ describe('ACIR public execution simulator', () => { callContext = computeCallContext(); // Prepare the state - header.state.l1ToL2MessageTree = mockOracles(); + mockOracles(); globalVariables = computeGlobalVariables(); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; @@ -503,32 +496,13 @@ describe('ACIR public execution simulator', () => { expect(result.newNullifiers.length).toEqual(1); }); - it('Message not matching requested key', async () => { - // Using a random value for the message key - messageKey = Fr.random(); - - preimage = computePreImage(); - args = computeArgs(); - callContext = computeCallContext(); - - // Prepare the state - header.state.l1ToL2MessageTree = mockOracles(); - globalVariables = computeGlobalVariables(); - - const execution: PublicExecution = { contractAddress, functionData, args, callContext }; - executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError( - 'Message not matching requested key', - ); - }); - it('Invalid membership proof', async () => { preimage = computePreImage(); args = computeArgs(); callContext = computeCallContext(); // Mock oracles but don't update state - mockOracles(); + mockOracles(false); // Prepare the state globalVariables = computeGlobalVariables(); @@ -545,12 +519,12 @@ describe('ACIR public execution simulator', () => { callContext = computeCallContext(); // Prepare the state - header.state.l1ToL2MessageTree = mockOracles(); + mockOracles(); globalVariables = computeGlobalVariables(); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Invalid recipient'); + await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Message not in state'); }); it('Invalid sender', async () => { @@ -560,12 +534,12 @@ describe('ACIR public execution simulator', () => { callContext = computeCallContext(); // Prepare the state - header.state.l1ToL2MessageTree = mockOracles(); + mockOracles(); globalVariables = computeGlobalVariables(); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Invalid sender'); + await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Message not in state'); }); it('Invalid chainid', async () => { @@ -574,13 +548,13 @@ describe('ACIR public execution simulator', () => { callContext = computeCallContext(); // Prepare the state - header.state.l1ToL2MessageTree = mockOracles(); + mockOracles(); globalVariables = computeGlobalVariables(); globalVariables.chainId = Fr.random(); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Invalid Chainid'); + await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Message not in state'); }); it('Invalid version', async () => { @@ -589,13 +563,13 @@ describe('ACIR public execution simulator', () => { callContext = computeCallContext(); // Prepare the state - header.state.l1ToL2MessageTree = mockOracles(); + mockOracles(); globalVariables = computeGlobalVariables(); globalVariables.version = Fr.random(); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Invalid Version'); + await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Message not in state'); }); it('Invalid Content', async () => { @@ -606,12 +580,12 @@ describe('ACIR public execution simulator', () => { callContext = computeCallContext(); // Prepare the state - header.state.l1ToL2MessageTree = mockOracles(); + mockOracles(); globalVariables = computeGlobalVariables(); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Invalid Content'); + await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Message not in state'); }); it('Invalid secret', async () => { @@ -622,12 +596,12 @@ describe('ACIR public execution simulator', () => { callContext = computeCallContext(); // Prepare the state - header.state.l1ToL2MessageTree = mockOracles(); + mockOracles(); globalVariables = computeGlobalVariables(); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Invalid message secret'); + await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError('Message not in state'); }); }); }); diff --git a/yarn-project/simulator/src/public/public_execution_context.ts b/yarn-project/simulator/src/public/public_execution_context.ts index 1e48202703c..1e80a36ec2d 100644 --- a/yarn-project/simulator/src/public/public_execution_context.ts +++ b/yarn-project/simulator/src/public/public_execution_context.ts @@ -86,11 +86,11 @@ export class PublicExecutionContext extends TypedOracle { /** * Fetches the a message from the db, given its key. - * @param msgKey - A buffer representing the message key. + * @param entryKey - A buffer representing the message key. * @returns The l1 to l2 message data */ - public async getL1ToL2Message(msgKey: Fr) { - return await this.commitmentsDb.getL1ToL2Message(msgKey); + public async getL1ToL2Message(entryKey: Fr) { + return await this.commitmentsDb.getL1ToL2Message(entryKey); } /** diff --git a/yarn-project/simulator/src/test/utils.ts b/yarn-project/simulator/src/test/utils.ts index e38b80aaec0..5d9e510e2bc 100644 --- a/yarn-project/simulator/src/test/utils.ts +++ b/yarn-project/simulator/src/test/utils.ts @@ -32,7 +32,7 @@ export const buildL1ToL2Message = ( new L2Actor(targetContract, 1), content, secretHash, - 0, + 2 ** 32 - 1, 0, ); }; From 3f4a922fd59b26c507577d5f33eaa95b50bb4bd5 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 29 Feb 2024 12:59:23 +0000 Subject: [PATCH 2/7] refactor: prune getL1ToL2Message return value --- .../src/core/libraries/ConstantsGen.sol | 2 +- noir-projects/aztec-nr/aztec/src/messaging.nr | 36 +++---------------- .../messaging/l1_to_l2_message_getter_data.nr | 32 ----------------- .../crates/types/src/constants.nr | 2 +- yarn-project/circuits.js/src/constants.gen.ts | 2 +- .../pxe/src/simulator_oracle/index.ts | 3 +- .../src/simulator/public_executor.ts | 4 +-- .../simulator/src/acvm/oracle/typed_oracle.ts | 4 +-- .../src/client/private_execution.test.ts | 2 +- .../simulator/src/public/index.test.ts | 2 +- 10 files changed, 13 insertions(+), 76 deletions(-) delete mode 100644 noir-projects/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 266dfc61d46..d0b7484d108 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -87,7 +87,7 @@ library Constants { 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = 0x0747a20ed0c86035e44ea5606f30de459f40b55c5e82012640aa554546af9044; - uint256 internal constant L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 25; + uint256 internal constant L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 17; uint256 internal constant MAX_NOTE_FIELDS_LENGTH = 20; uint256 internal constant GET_NOTE_ORACLE_RETURN_LENGTH = 23; uint256 internal constant MAX_NOTES_PER_PAGE = 10; diff --git a/noir-projects/aztec-nr/aztec/src/messaging.nr b/noir-projects/aztec-nr/aztec/src/messaging.nr index 3c01bb7812c..05a9fab203c 100644 --- a/noir-projects/aztec-nr/aztec/src/messaging.nr +++ b/noir-projects/aztec-nr/aztec/src/messaging.nr @@ -1,19 +1,11 @@ mod l1_to_l2_message; -mod l1_to_l2_message_getter_data; - -use l1_to_l2_message_getter_data::make_l1_to_l2_message_getter_data; use crate::oracle::get_l1_to_l2_message::get_l1_to_l2_message_call; -use crate::oracle::debug_log::debug_log_format; use dep::std::merkle::compute_merkle_root; use crate::messaging::l1_to_l2_message::L1ToL2Message; -use dep::protocol_types::{ - constants::{GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET}, address::{AztecAddress, EthAddress}, - hash::{pedersen_hash} -}; +use dep::protocol_types::{constants::L1_TO_L2_MSG_TREE_HEIGHT, address::{AztecAddress, EthAddress}, utils::arr_copy_slice}; -// Returns the nullifier for the message pub fn process_l1_to_l2_message( l1_to_l2_root: Field, storage_contract_address: AztecAddress, @@ -23,7 +15,6 @@ pub fn process_l1_to_l2_message( content: Field, secret: Field ) -> Field { - debug_log_format("Processing L1 to L2 message: root: {0}", [l1_to_l2_root]); let msg = L1ToL2Message::new( portal_contract_address, chain_id, @@ -33,32 +24,15 @@ pub fn process_l1_to_l2_message( secret ); let entry_key = msg.hash(); - debug_log_format( - "Entry key = H({0}, {1}, {2}, {3}, {4}, {5}) {6}", - [ - portal_contract_address.to_field(), - chain_id, - storage_contract_address.to_field(), - version, - content, - secret, - entry_key - ] - ); - // TODO: Massively prune the returned values from the oracle. let returned_message = get_l1_to_l2_message_call(entry_key); - let l1_to_l2_message_data = make_l1_to_l2_message_getter_data(returned_message, 0, secret); + let leaf_index = returned_message[0]; + let sibling_path = arr_copy_slice(returned_message, [0; L1_TO_L2_MSG_TREE_HEIGHT], 1); // Check that the message is in the tree // This is implicitly checking that the values of the message are correct - let root = compute_merkle_root( - entry_key, - l1_to_l2_message_data.leaf_index, - l1_to_l2_message_data.sibling_path - ); + let root = compute_merkle_root(entry_key, leaf_index, sibling_path); assert(root == l1_to_l2_root, "Message not in state"); - // Compute Nullifier - l1_to_l2_message_data.message.compute_nullifier() + msg.compute_nullifier() } diff --git a/noir-projects/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr b/noir-projects/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr deleted file mode 100644 index 25da5bfec56..00000000000 --- a/noir-projects/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr +++ /dev/null @@ -1,32 +0,0 @@ -use crate::messaging::l1_to_l2_message::L1ToL2Message; -use dep::protocol_types::{constants::{L1_TO_L2_MSG_TREE_HEIGHT, L1_TO_L2_MESSAGE_LENGTH}, utils::arr_copy_slice}; - -struct L1ToL2MessageGetterData { - message: L1ToL2Message, - sibling_path: [Field; L1_TO_L2_MSG_TREE_HEIGHT], - leaf_index: Field -} - -pub fn l1_to_l2_message_getter_len() -> u64 { - L1_TO_L2_MESSAGE_LENGTH + 1 + L1_TO_L2_MSG_TREE_HEIGHT -} - -pub fn make_l1_to_l2_message_getter_data( - fields: [Field; N], - start: u64, - secret: Field -) -> L1ToL2MessageGetterData { - L1ToL2MessageGetterData { - message: L1ToL2Message::deserialize( - arr_copy_slice(fields, [0; L1_TO_L2_MESSAGE_LENGTH], start), - secret, - fields[start + L1_TO_L2_MESSAGE_LENGTH] - ), - leaf_index: fields[start + L1_TO_L2_MESSAGE_LENGTH], - sibling_path: arr_copy_slice( - fields, - [0; L1_TO_L2_MSG_TREE_HEIGHT], - L1_TO_L2_MESSAGE_LENGTH + 1 - ) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 944f9d3797f..5a9201dbb71 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -130,7 +130,7 @@ global DEPLOYER_CONTRACT_ADDRESS = 0x0747a20ed0c86035e44ea5606f30de459f40b55c5e8 // Some are defined here because Noir doesn't yet support globals referencing other globals yet. // Move these constants to a noir file once the issue below is resolved: // https://github.com/noir-lang/noir/issues/1734 -global L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH: u64 = 25; +global L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH: u64 = 17; global MAX_NOTE_FIELDS_LENGTH: u64 = 20; // GET_NOTE_ORACLE_RETURN_LENGT = MAX_NOTE_FIELDS_LENGTH + 1 + 2 // The plus 1 is 1 extra field for nonce. diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 335d0091ce8..2e9b51a892b 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -72,7 +72,7 @@ export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631n; export const DEPLOYER_CONTRACT_ADDRESS = 0x0747a20ed0c86035e44ea5606f30de459f40b55c5e82012640aa554546af9044n; -export const L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 25; +export const L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 17; export const MAX_NOTE_FIELDS_LENGTH = 20; export const GET_NOTE_ORACLE_RETURN_LENGTH = 23; export const MAX_NOTES_PER_PAGE = 10; diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index f5fc31e4179..d0ef51daaea 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -137,10 +137,9 @@ export class SimulatorOracle implements DBOracle { */ async getL1ToL2Message(entryKey: Fr): Promise> { const messageAndIndex = await this.aztecNode.getL1ToL2MessageAndIndex(entryKey); - const message = messageAndIndex.message; const index = messageAndIndex.index; const siblingPath = await this.aztecNode.getL1ToL2MessageSiblingPath('latest', index); - return new MessageLoadOracleInputs(message, index, siblingPath); + return new MessageLoadOracleInputs(index, siblingPath); } /** diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index 63605d3be41..e75219ebd5f 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -219,14 +219,12 @@ export class WorldStateDB implements CommitmentsDB { public async getL1ToL2Message(entryKey: Fr): Promise> { // todo: #697 - make this one lookup. - const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(entryKey); const index = (await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, entryKey.toBuffer()))!; const siblingPath = await this.db.getSiblingPath( MerkleTreeId.L1_TO_L2_MESSAGE_TREE, index, ); - - return new MessageLoadOracleInputs(message, index, siblingPath); + return new MessageLoadOracleInputs(index, siblingPath); } public async getCommitmentIndex(commitment: Fr): Promise { diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 0bcd1b38f8d..ce60c786e97 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -59,8 +59,6 @@ export interface NoteData { export class MessageLoadOracleInputs { constructor( - /** The message. */ - public message: L1ToL2Message, /** The index of the message commitment in the merkle tree. */ public index: bigint, /** The path in the merkle tree to the message. */ @@ -68,7 +66,7 @@ export class MessageLoadOracleInputs { ) {} toFields(): Fr[] { - return [...this.message.toFields(), new Fr(this.index), ...this.siblingPath.toFields()]; + return [new Fr(this.index), ...this.siblingPath.toFields()]; } } diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 5e40fc98b91..996289a5180 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -589,7 +589,7 @@ describe('Private Execution test suite', () => { const mockOracles = async (updateHeader = true) => { const tree = await insertLeaves([preimage.hash()], 'l1ToL2Messages'); oracle.getL1ToL2Message.mockImplementation(async () => { - return Promise.resolve(new MessageLoadOracleInputs(preimage, 0n, await tree.getSiblingPath(0n, true))); + return Promise.resolve(new MessageLoadOracleInputs(0n, await tree.getSiblingPath(0n, true))); }); if (updateHeader) { oracle.getHeader.mockResolvedValue(header); diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index 69f37c9ed34..ded3eee388c 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -469,7 +469,7 @@ describe('ACIR public execution simulator', () => { root = pedersenHash([root.toBuffer(), sibling]); } commitmentsDb.getL1ToL2Message.mockImplementation(() => { - return Promise.resolve(new MessageLoadOracleInputs(preimage, 0n, siblingPath)); + return Promise.resolve(new MessageLoadOracleInputs(0n, siblingPath)); }); if (updateState) { From 1c366cfd2b6d0bdbcb328bddaaf8c5f5a550f9c7 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 29 Feb 2024 13:32:48 +0000 Subject: [PATCH 3/7] chore: rename the l1 to l2 oracle --- noir-projects/aztec-nr/aztec/src/messaging.nr | 4 ++-- noir-projects/aztec-nr/aztec/src/oracle.nr | 2 +- .../src/oracle/get_l1_to_l2_membership_witness.nr | 9 +++++++++ .../aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr | 9 --------- .../src/e2e_public_cross_chain_messaging.test.ts | 11 +++-------- yarn-project/pxe/src/simulator_oracle/index.ts | 2 +- .../sequencer-client/src/simulator/public_executor.ts | 4 +++- yarn-project/simulator/src/acvm/oracle/oracle.ts | 4 ++-- .../simulator/src/acvm/oracle/typed_oracle.ts | 2 +- .../simulator/src/client/private_execution.test.ts | 2 +- yarn-project/simulator/src/client/view_data_oracle.ts | 4 ++-- yarn-project/simulator/src/public/db.ts | 2 +- yarn-project/simulator/src/public/index.test.ts | 2 +- .../simulator/src/public/public_execution_context.ts | 4 ++-- 14 files changed, 29 insertions(+), 32 deletions(-) create mode 100644 noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_membership_witness.nr delete mode 100644 noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr diff --git a/noir-projects/aztec-nr/aztec/src/messaging.nr b/noir-projects/aztec-nr/aztec/src/messaging.nr index 05a9fab203c..958a5e863f4 100644 --- a/noir-projects/aztec-nr/aztec/src/messaging.nr +++ b/noir-projects/aztec-nr/aztec/src/messaging.nr @@ -1,6 +1,6 @@ mod l1_to_l2_message; -use crate::oracle::get_l1_to_l2_message::get_l1_to_l2_message_call; +use crate::oracle::get_l1_to_l2_membership_witness::get_l1_to_l2_membership_witness; use dep::std::merkle::compute_merkle_root; use crate::messaging::l1_to_l2_message::L1ToL2Message; @@ -25,7 +25,7 @@ pub fn process_l1_to_l2_message( ); let entry_key = msg.hash(); - let returned_message = get_l1_to_l2_message_call(entry_key); + let returned_message = get_l1_to_l2_membership_witness(entry_key); let leaf_index = returned_message[0]; let sibling_path = arr_copy_slice(returned_message, [0; L1_TO_L2_MSG_TREE_HEIGHT], 1); diff --git a/noir-projects/aztec-nr/aztec/src/oracle.nr b/noir-projects/aztec-nr/aztec/src/oracle.nr index 85ab77b60b6..0a88a432d71 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle.nr @@ -7,7 +7,7 @@ mod call_private_function; mod context; mod debug_log; mod get_contract_instance; -mod get_l1_to_l2_message; +mod get_l1_to_l2_membership_witness; mod get_nullifier_membership_witness; mod get_public_data_witness; mod get_membership_witness; diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_membership_witness.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_membership_witness.nr new file mode 100644 index 00000000000..de73fca0c49 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_membership_witness.nr @@ -0,0 +1,9 @@ +use dep::protocol_types::constants::L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH; + +// Checks if a msg is within the l1ToL2Msg tree +#[oracle(getL1ToL2MembershipWitness)] +fn get_l1_to_l2_membership_witness_oracle(_entry_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {} + +unconstrained pub fn get_l1_to_l2_membership_witness(entry_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] { + get_l1_to_l2_membership_witness_oracle(entry_key) +} diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr deleted file mode 100644 index cc0144e944b..00000000000 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr +++ /dev/null @@ -1,9 +0,0 @@ -use dep::protocol_types::constants::L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH; - -// Checks if a msg is within the l1ToL2Msg tree -#[oracle(getL1ToL2Message)] -fn get_l1_to_l2_msg_oracle(_entry_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {} - -unconstrained pub fn get_l1_to_l2_message_call(entry_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] { - get_l1_to_l2_msg_oracle(entry_key) -} diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 8145c85ea9b..3d08e476700 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -136,7 +136,7 @@ describe('e2e_public_cross_chain_messaging', () => { const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); - const entryKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); + await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount); // Wait for the archiver to process the message @@ -188,7 +188,7 @@ describe('e2e_public_cross_chain_messaging', () => { const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(bridgeAmount); - const entryKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); + await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(0n); // Wait for the archiver to process the message @@ -284,9 +284,7 @@ describe('e2e_public_cross_chain_messaging', () => { { value: fee } as any, ); - // We check that the message was correctly injected by checking the emitted event and we store the message key - // for later use - let entryKey!: Fr; + // We check that the message was correctly injected by checking the emitted even { const txReceipt = await crossChainTestHarness.publicClient.waitForTransactionReceipt({ hash: txHash, @@ -307,9 +305,6 @@ describe('e2e_public_cross_chain_messaging', () => { // Note: For whatever reason, viem types "think" that there is no recipient on topics.args. I hack around this // by casting the args to "any" expect((topics.args as any).recipient).toBe(recipient); - - // TODO(#4678): Unify naming of message key/entry key - entryKey = Fr.fromString(topics.args.entryKey!); } // We wait for the archiver to process the message and we push a block for the message to be confirmed diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index d0ef51daaea..df1029d78cc 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -135,7 +135,7 @@ export class SimulatorOracle implements DBOracle { * @returns A promise that resolves to the message data, a sibling path and the * index of the message in the l1ToL2MessageTree */ - async getL1ToL2Message(entryKey: Fr): Promise> { + async getL1ToL2MembershipWitness(entryKey: Fr): Promise> { const messageAndIndex = await this.aztecNode.getL1ToL2MessageAndIndex(entryKey); const index = messageAndIndex.index; const siblingPath = await this.aztecNode.getL1ToL2MessageSiblingPath('latest', index); diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index e75219ebd5f..0e54c2663b2 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -217,7 +217,9 @@ export class WorldStatePublicDB implements PublicStateDB { export class WorldStateDB implements CommitmentsDB { constructor(private db: MerkleTreeOperations, private l1ToL2MessageSource: L1ToL2MessageSource) {} - public async getL1ToL2Message(entryKey: Fr): Promise> { + public async getL1ToL2MembershipWitness( + entryKey: Fr, + ): Promise> { // todo: #697 - make this one lookup. const index = (await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, entryKey.toBuffer()))!; const siblingPath = await this.db.getSiblingPath( diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index 193087b43ab..48824adcae4 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -237,8 +237,8 @@ export class Oracle { return toACVMField(exists); } - async getL1ToL2Message([entryKey]: ACVMField[]): Promise { - const message = await this.typedOracle.getL1ToL2Message(fromACVMField(entryKey)); + async getL1ToL2MembershipWitness([entryKey]: ACVMField[]): Promise { + const message = await this.typedOracle.getL1ToL2MembershipWitness(fromACVMField(entryKey)); return message.toFields().map(toACVMField); } diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index ce60c786e97..9c9c4c71afb 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -162,7 +162,7 @@ export abstract class TypedOracle { throw new Error('Not available.'); } - getL1ToL2Message(_msgKey: Fr): Promise> { + getL1ToL2MembershipWitness(_msgKey: Fr): Promise> { throw new Error('Not available.'); } diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 996289a5180..f9826526687 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -588,7 +588,7 @@ describe('Private Execution test suite', () => { const mockOracles = async (updateHeader = true) => { const tree = await insertLeaves([preimage.hash()], 'l1ToL2Messages'); - oracle.getL1ToL2Message.mockImplementation(async () => { + oracle.getL1ToL2MembershipWitness.mockImplementation(async () => { return Promise.resolve(new MessageLoadOracleInputs(0n, await tree.getSiblingPath(0n, true))); }); if (updateHeader) { diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index cb3a4bab38e..8a68d7441f6 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -220,8 +220,8 @@ export class ViewDataOracle extends TypedOracle { * @param entryKey - A buffer representing the message key. * @returns The l1 to l2 message data */ - public async getL1ToL2Message(entryKey: Fr) { - return await this.db.getL1ToL2Message(entryKey); + public async getL1ToL2MembershipWitness(entryKey: Fr) { + return await this.db.getL1ToL2MembershipWitness(entryKey); } /** diff --git a/yarn-project/simulator/src/public/db.ts b/yarn-project/simulator/src/public/db.ts index d661b28f76e..6d9a19cb2da 100644 --- a/yarn-project/simulator/src/public/db.ts +++ b/yarn-project/simulator/src/public/db.ts @@ -74,7 +74,7 @@ export interface CommitmentsDB { * @param entryKey - The message Key. * @returns - The l1 to l2 message object */ - getL1ToL2Message(entryKey: Fr): Promise>; + getL1ToL2MembershipWitness(entryKey: Fr): Promise>; /** * Gets the index of a commitment in the note hash tree. diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index ded3eee388c..810c0745c01 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -468,7 +468,7 @@ describe('ACIR public execution simulator', () => { for (const sibling of siblingPathBuffers) { root = pedersenHash([root.toBuffer(), sibling]); } - commitmentsDb.getL1ToL2Message.mockImplementation(() => { + commitmentsDb.getL1ToL2MembershipWitness.mockImplementation(() => { return Promise.resolve(new MessageLoadOracleInputs(0n, siblingPath)); }); diff --git a/yarn-project/simulator/src/public/public_execution_context.ts b/yarn-project/simulator/src/public/public_execution_context.ts index 1e80a36ec2d..f3f3e570ca2 100644 --- a/yarn-project/simulator/src/public/public_execution_context.ts +++ b/yarn-project/simulator/src/public/public_execution_context.ts @@ -89,8 +89,8 @@ export class PublicExecutionContext extends TypedOracle { * @param entryKey - A buffer representing the message key. * @returns The l1 to l2 message data */ - public async getL1ToL2Message(entryKey: Fr) { - return await this.commitmentsDb.getL1ToL2Message(entryKey); + public async getL1ToL2MembershipWitness(entryKey: Fr) { + return await this.commitmentsDb.getL1ToL2MembershipWitness(entryKey); } /** From e6e2c59b9032b4df7f74c82693437496e489a582 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 29 Feb 2024 15:37:08 +0000 Subject: [PATCH 4/7] chore: missing throw --- .../sequencer-client/src/simulator/public_executor.ts | 4 +++- yarn-project/simulator/src/acvm/oracle/typed_oracle.ts | 1 - yarn-project/simulator/src/client/private_execution.test.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index 0e54c2663b2..a937c9dca81 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -220,8 +220,10 @@ export class WorldStateDB implements CommitmentsDB { public async getL1ToL2MembershipWitness( entryKey: Fr, ): Promise> { - // todo: #697 - make this one lookup. const index = (await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, entryKey.toBuffer()))!; + if (index === undefined) { + throw new Error(`Message ${entryKey.toString()} not found`); + } const siblingPath = await this.db.getSiblingPath( MerkleTreeId.L1_TO_L2_MESSAGE_TREE, index, diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 9c9c4c71afb..63ed1193d9f 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -1,6 +1,5 @@ import { CompleteAddress, - L1ToL2Message, MerkleTreeId, Note, NoteStatus, diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index f9826526687..36a82c3aa60 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -547,7 +547,7 @@ describe('Private Execution test suite', () => { }); }); - describe.only('L1 to L2', () => { + describe('L1 to L2', () => { const artifact = getFunctionArtifact(TestContractArtifact, 'consume_mint_private_message'); const canceller = EthAddress.random(); let bridgedAmount = 100n; From ecb19b450fbaf9823dbb9a767cf50b8403b240fe Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 29 Feb 2024 21:46:26 +0000 Subject: [PATCH 5/7] chore: purging more msg-key --- .../developers/debugging/sandbox-errors.md | 4 +- l1-contracts/test/portals/GasPortal.sol | 2 +- l1-contracts/test/portals/TokenPortal.sol | 4 +- l1-contracts/test/portals/UniswapPortal.t.sol | 20 +++--- noir-projects/aztec-nr/aztec/src/messaging.nr | 14 ++++ .../archiver/src/archiver/archiver.test.ts | 12 ++-- .../archiver/src/archiver/archiver.ts | 14 ++-- .../archiver/src/archiver/archiver_store.ts | 18 ++--- .../src/archiver/archiver_store_test_suite.ts | 66 +++++++++---------- .../archiver/src/archiver/data_retrieval.ts | 2 +- .../archiver/src/archiver/eth_log_handlers.ts | 2 +- .../kv_archiver_store/kv_archiver_store.ts | 18 ++--- .../kv_archiver_store/message_store.ts | 28 ++++---- .../l1_to_l2_message_store.test.ts | 10 +-- .../l1_to_l2_message_store.ts | 18 ++--- .../memory_archiver_store.ts | 20 +++--- .../aztec-node/src/aztec-node/server.ts | 4 +- .../src/interfaces/aztec-node.ts | 4 +- .../circuit-types/src/l1_to_l2_message.ts | 6 +- .../e2e_public_cross_chain_messaging.test.ts | 50 ++++++++++++-- .../src/integration_archiver_l1_to_l2.test.ts | 4 +- .../pxe/src/simulator_oracle/index.ts | 4 +- .../src/sequencer/sequencer.test.ts | 2 +- .../src/sequencer/sequencer.ts | 10 +-- .../simulator/src/client/view_data_oracle.ts | 2 +- yarn-project/simulator/src/public/db.ts | 4 +- .../src/public/public_execution_context.ts | 2 +- yellow-paper/docs/public-vm/type-structs.md | 2 +- 28 files changed, 200 insertions(+), 146 deletions(-) diff --git a/docs/docs/developers/debugging/sandbox-errors.md b/docs/docs/developers/debugging/sandbox-errors.md index 1eaca0957ba..b6a4f1cef7d 100644 --- a/docs/docs/developers/debugging/sandbox-errors.md +++ b/docs/docs/developers/debugging/sandbox-errors.md @@ -177,9 +177,9 @@ Users may create a proof against a historical state in Aztec. The rollup circuit ## Archiver Errors -- "L1 to L2 Message with key ${messageKey.toString()} not found in the confirmed messages store" - happens when the L1 to L2 message doesn't exist or is "pending", when the user has sent a message on L1 via the Inbox contract but it has yet to be included in an L2 block by the sequencer - user has to wait for sequencer to pick it up and the archiver to sync the respective L2 block. You can get the sequencer to pick it up by doing an arbitrary transaction on L2 (eg send DAI to yourself). This would give the sequencer a transaction to process and as a side effect it would look for any pending messages it should include. +- "L1 to L2 Message with key ${entryKey.toString()} not found in the confirmed messages store" - happens when the L1 to L2 message doesn't exist or is "pending", when the user has sent a message on L1 via the Inbox contract but it has yet to be included in an L2 block by the sequencer - user has to wait for sequencer to pick it up and the archiver to sync the respective L2 block. You can get the sequencer to pick it up by doing an arbitrary transaction on L2 (eg send DAI to yourself). This would give the sequencer a transaction to process and as a side effect it would look for any pending messages it should include. -- "Unable to remove message: L1 to L2 Message with key ${messageKeyBigInt} not found in store" - happens when trying to confirm a non-existent pending message or cancelling such a message. Perhaps the sequencer has already confirmed the message? +- "Unable to remove message: L1 to L2 Message with key ${entryKeyBigInt} not found in store" - happens when trying to confirm a non-existent pending message or cancelling such a message. Perhaps the sequencer has already confirmed the message? - "Block number mismatch: expected ${l2BlockNum} but got ${block.number}" - The archiver keeps track of the next expected L2 block number. It throws this error if it got a different one when trying to sync with the rollup contract's events on L1. diff --git a/l1-contracts/test/portals/GasPortal.sol b/l1-contracts/test/portals/GasPortal.sol index c3bddba93a5..0e36e4522f7 100644 --- a/l1-contracts/test/portals/GasPortal.sol +++ b/l1-contracts/test/portals/GasPortal.sol @@ -90,7 +90,7 @@ contract GasPortal { fee: _fee }); bytes32 entryKey = inbox.cancelL2Message(message, address(this)); - // release the funds to msg.sender (since the content hash (& message key) is derived by hashing the caller, + // release the funds to msg.sender (since the content hash) is derived by hashing the caller, // we confirm that msg.sender is same as `_canceller` supplied when creating the message) underlying.transfer(msg.sender, _amount); return entryKey; diff --git a/l1-contracts/test/portals/TokenPortal.sol b/l1-contracts/test/portals/TokenPortal.sol index 42119952264..4551b27ce18 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -133,7 +133,7 @@ contract TokenPortal { fee: _fee }); bytes32 entryKey = inbox.cancelL2Message(message, address(this)); - // release the funds to msg.sender (since the content hash (& message key) is derived by hashing the caller, + // release the funds to msg.sender (since the content hash (& entry key) is derived by hashing the caller, // we confirm that msg.sender is same as `_canceller` supplied when creating the message) underlying.transfer(msg.sender, _amount); return entryKey; @@ -175,7 +175,7 @@ contract TokenPortal { fee: _fee }); bytes32 entryKey = inbox.cancelL2Message(message, address(this)); - // release the funds to msg.sender (since the content hash (& message key) is derived by hashing the caller, + // release the funds to msg.sender (since the content hash (& entry key) is derived by hashing the caller, // we confirm that msg.sender is same as `_canceller` supplied when creating the message) underlying.transfer(msg.sender, _amount); return entryKey; diff --git a/l1-contracts/test/portals/UniswapPortal.t.sol b/l1-contracts/test/portals/UniswapPortal.t.sol index 454985b248b..25587cc5b89 100644 --- a/l1-contracts/test/portals/UniswapPortal.t.sol +++ b/l1-contracts/test/portals/UniswapPortal.t.sol @@ -154,10 +154,10 @@ contract UniswapPortalTest is Test { entryKey = outbox.computeEntryKey(message); } - function _addMessagesToOutbox(bytes32 daiWithdrawMessageKey, bytes32 swapMessageKey) internal { + function _addMessagesToOutbox(bytes32 daiWithdrawentryKey, bytes32 swapentryKey) internal { bytes32[] memory entryKeys = new bytes32[](2); - entryKeys[0] = daiWithdrawMessageKey; - entryKeys[1] = swapMessageKey; + entryKeys[0] = daiWithdrawentryKey; + entryKeys[1] = swapentryKey; vm.prank(address(rollup)); outbox.sendL1Messages(entryKeys); @@ -246,7 +246,7 @@ contract UniswapPortalTest is Test { bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); - bytes32 l1ToL2MessageKey = uniswapPortal.swapPublic( + bytes32 l1ToL2entryKey = uniswapPortal.swapPublic( address(daiTokenPortal), amount, uniswapFeePool, @@ -264,7 +264,7 @@ contract UniswapPortalTest is Test { // there should be some weth in the weth portal assertGt(WETH9.balanceOf(address(wethTokenPortal)), 0); // there should be a message in the inbox: - assertEq(inbox.get(l1ToL2MessageKey).count, 1); + assertEq(inbox.get(l1ToL2entryKey).count, 1); // there should be no message in the outbox: assertFalse(outbox.contains(daiWithdrawMsgKey)); assertFalse(outbox.contains(swapMsgKey)); @@ -279,7 +279,7 @@ contract UniswapPortalTest is Test { _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); vm.prank(_caller); - bytes32 l1ToL2MessageKey = uniswapPortal.swapPublic( + bytes32 l1ToL2entryKey = uniswapPortal.swapPublic( address(daiTokenPortal), amount, uniswapFeePool, @@ -297,7 +297,7 @@ contract UniswapPortalTest is Test { // there should be some weth in the weth portal assertGt(WETH9.balanceOf(address(wethTokenPortal)), 0); // there should be a message in the inbox: - assertEq(inbox.get(l1ToL2MessageKey).count, 1); + assertEq(inbox.get(l1ToL2entryKey).count, 1); // there should be no message in the outbox: assertFalse(outbox.contains(daiWithdrawMsgKey)); assertFalse(outbox.contains(swapMsgKey)); @@ -357,7 +357,7 @@ contract UniswapPortalTest is Test { bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); - bytes32 l1ToL2MessageKey = uniswapPortal.swapPublic{value: 1 ether}( + bytes32 l1ToL2entryKey = uniswapPortal.swapPublic{value: 1 ether}( address(daiTokenPortal), amount, uniswapFeePool, @@ -376,13 +376,13 @@ contract UniswapPortalTest is Test { // check event was emitted vm.expectEmit(true, false, false, false); // expected event: - emit L1ToL2MessageCancelled(l1ToL2MessageKey); + emit L1ToL2MessageCancelled(l1ToL2entryKey); // perform op // TODO(2167) - Update UniswapPortal properly with new portal standard. bytes32 entryKey = wethTokenPortal.cancelL1ToAztecMessagePublic( aztecRecipient, wethAmountOut, deadlineForL1ToL2Message, secretHash, 1 ether ); - assertEq(entryKey, l1ToL2MessageKey, "returned entry key and calculated entryKey should match"); + assertEq(entryKey, l1ToL2entryKey, "returned entry key and calculated entryKey should match"); assertFalse(inbox.contains(entryKey), "entry still in inbox"); assertEq( WETH9.balanceOf(address(this)), diff --git a/noir-projects/aztec-nr/aztec/src/messaging.nr b/noir-projects/aztec-nr/aztec/src/messaging.nr index 958a5e863f4..32beec4e390 100644 --- a/noir-projects/aztec-nr/aztec/src/messaging.nr +++ b/noir-projects/aztec-nr/aztec/src/messaging.nr @@ -2,6 +2,8 @@ mod l1_to_l2_message; use crate::oracle::get_l1_to_l2_membership_witness::get_l1_to_l2_membership_witness; +use crate::oracle::debug_log::debug_log_format; + use dep::std::merkle::compute_merkle_root; use crate::messaging::l1_to_l2_message::L1ToL2Message; use dep::protocol_types::{constants::L1_TO_L2_MSG_TREE_HEIGHT, address::{AztecAddress, EthAddress}, utils::arr_copy_slice}; @@ -24,6 +26,18 @@ pub fn process_l1_to_l2_message( secret ); let entry_key = msg.hash(); + debug_log_format( + "L1ToL2Message entry_key: H({0}, {1}, {2}, {3}, {4}, {5}) = {6} ", + [ + portal_contract_address.to_field(), + chain_id, + storage_contract_address.to_field(), + version, + content, + secret, + entry_key + ] + ); let returned_message = get_l1_to_l2_membership_witness(entry_key); let leaf_index = returned_message[0]; diff --git a/yarn-project/archiver/src/archiver/archiver.test.ts b/yarn-project/archiver/src/archiver/archiver.test.ts index d5244dddf80..88fb7c7fc4b 100644 --- a/yarn-project/archiver/src/archiver/archiver.test.ts +++ b/yarn-project/archiver/src/archiver/archiver.test.ts @@ -101,12 +101,12 @@ describe('Archiver', () => { // Check that only 2 messages (l1ToL2MessageAddedEvents[3][2] and l1ToL2MessageAddedEvents[3][3]) are pending. // Other two (l1ToL2MessageAddedEvents[3][0..2]) were cancelled. And the previous messages were confirmed. - const expectedPendingMessageKeys = [ + const expectedPendingentryKeys = [ l1ToL2MessageAddedEvents[3][2].args.entryKey, l1ToL2MessageAddedEvents[3][3].args.entryKey, ]; - const actualPendingMessageKeys = (await archiver.getPendingL1ToL2Messages(10)).map(key => key.toString()); - expect(expectedPendingMessageKeys).toEqual(actualPendingMessageKeys); + const actualPendingentryKeys = (await archiver.getPendingL1ToL2EntryKeys(10)).map(key => key.toString()); + expect(expectedPendingentryKeys).toEqual(actualPendingentryKeys); // Expect logs to correspond to what is set by L2Block.random(...) const encryptedLogs = await archiver.getLogs(1, 100, LogType.ENCRYPTED); @@ -199,9 +199,9 @@ describe('Archiver', () => { expect(latestBlockNum).toEqual(numL2BlocksInTest); // Check that the only pending L1 to L2 messages are those from eth bock 102 - const expectedPendingMessageKeys = additionalL1ToL2MessagesBlock102; - const actualPendingMessageKeys = (await archiver.getPendingL1ToL2Messages(100)).map(key => key.toString()); - expect(actualPendingMessageKeys).toEqual(expectedPendingMessageKeys); + const expectedPendingentryKeys = additionalL1ToL2MessagesBlock102; + const actualPendingentryKeys = (await archiver.getPendingL1ToL2EntryKeys(100)).map(key => key.toString()); + expect(actualPendingentryKeys).toEqual(expectedPendingentryKeys); await archiver.stop(); }, 10_000); diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 5b77bb9fd31..1c1241e02ce 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -231,7 +231,7 @@ export class Archiver implements ArchiveSource { `Adding ${newMessages.length} new messages and ${cancelledMessages.length} cancelled messages in L1 block ${l1Block}`, ); await this.store.addPendingL1ToL2Messages(newMessages, l1Block); - await this.store.cancelPendingL1ToL2Messages(cancelledMessages, l1Block); + await this.store.cancelPendingL1ToL2EntryKeys(cancelledMessages, l1Block); } // ********** Events that are processed per L2 block ********** @@ -307,10 +307,10 @@ export class Archiver implements ArchiveSource { ); // from retrieved L2Blocks, confirm L1 to L2 messages that have been published - // from each l2block fetch all messageKeys in a flattened array: + // from each l2block fetch all entryKeys in a flattened array: this.log(`Confirming l1 to l2 messages in store`); for (const block of retrievedBlocks.retrievedData) { - await this.store.confirmL1ToL2Messages(block.body.l1ToL2Messages); + await this.store.confirmL1ToL2EntryKeys(block.body.l1ToL2Messages); } // store retrieved L2 blocks after removing new logs information. @@ -550,13 +550,13 @@ export class Archiver implements ArchiveSource { * @param limit - The number of messages to return. * @returns The requested L1 to L2 messages' keys. */ - getPendingL1ToL2Messages(limit: number): Promise { - return this.store.getPendingL1ToL2MessageKeys(limit); + getPendingL1ToL2EntryKeys(limit: number): Promise { + return this.store.getPendingL1ToL2entryKeys(limit); } /** - * Gets the confirmed/consumed L1 to L2 message associated with the given message key - * @param entryKey - The message key. + * Gets the confirmed/consumed L1 to L2 message associated with the given entry key + * @param entryKey - The entry key. * @returns The L1 to L2 message (throws if not found). */ getConfirmedL1ToL2Message(entryKey: Fr): Promise { diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index bd19250a93c..e8717084417 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -76,30 +76,30 @@ export interface ArchiverDataStore { /** * Remove pending L1 to L2 messages from the store (if they were cancelled). - * @param message - The message keys to be removed from the store. + * @param entryKeys - The entry keys to be removed from the store. * @param l1BlockNumber - The block number of the L1 block that cancelled the messages. * @returns True if the operation is successful. */ - cancelPendingL1ToL2Messages(message: Fr[], l1BlockNumber: bigint): Promise; + cancelPendingL1ToL2EntryKeys(entryKeys: Fr[], l1BlockNumber: bigint): Promise; /** * Messages that have been published in an L2 block are confirmed. * Add them to the confirmed store, also remove them from the pending store. - * @param messageKeys - The message keys to be removed from the store. + * @param entryKeys - The entry keys to be removed from the store. * @returns True if the operation is successful. */ - confirmL1ToL2Messages(messageKeys: Fr[]): Promise; + confirmL1ToL2EntryKeys(entryKeys: Fr[]): Promise; /** * Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee - * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). - * @returns The requested L1 to L2 message keys. + * @param limit - The number of entries to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). + * @returns The requested L1 to L2 entry keys. */ - getPendingL1ToL2MessageKeys(limit: number): Promise; + getPendingL1ToL2entryKeys(limit: number): Promise; /** - * Gets the confirmed L1 to L2 message corresponding to the given message key. - * @param entryKey - The message key to look up. + * Gets the confirmed L1 to L2 message corresponding to the given entry key. + * @param entryKey - The entry key to look up. * @returns The requested L1 to L2 message or throws if not found. */ getConfirmedL1ToL2Message(entryKey: Fr): Promise; diff --git a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts index 012c7576691..05ae6923444 100644 --- a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts +++ b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts @@ -115,7 +115,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch it('returns the L1 block number that most recently cancelled pending messages', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 2n); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 2n); await expect(store.getL1BlockNumber()).resolves.toEqual({ addedBlock: 0n, addedMessages: 1n, @@ -185,7 +185,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch const message = L1ToL2Message.random(Fr.random()); await expect(store.addPendingL1ToL2Messages([message, message], 1n)).resolves.toEqual(true); - await expect(store.getPendingL1ToL2MessageKeys(2)).resolves.toEqual([message.entryKey!, message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!, message.entryKey!]); }); it('allows duplicate pending messages in different blocks', async () => { @@ -193,22 +193,22 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await expect(store.addPendingL1ToL2Messages([message], 1n)).resolves.toEqual(true); await expect(store.addPendingL1ToL2Messages([message], 2n)).resolves.toEqual(true); - await expect(store.getPendingL1ToL2MessageKeys(2)).resolves.toEqual([message.entryKey!, message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!, message.entryKey!]); }); it('is idempotent', async () => { const message = L1ToL2Message.random(Fr.random()); await expect(store.addPendingL1ToL2Messages([message], 1n)).resolves.toEqual(true); await expect(store.addPendingL1ToL2Messages([message], 1n)).resolves.toEqual(false); - await expect(store.getPendingL1ToL2MessageKeys(2)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!]); }); }); - describe('getPendingL1ToL2Messages', () => { + describe('getPendingL1ToL2EntryKeys', () => { it('returns previously stored pending L1 to L2 messages', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await expect(store.getPendingL1ToL2MessageKeys(1)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([message.entryKey!]); }); it('returns messages ordered by fee', async () => { @@ -219,43 +219,43 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await store.addPendingL1ToL2Messages(messages, 1n); messages.sort((a, b) => b.fee - a.fee); - await expect(store.getPendingL1ToL2MessageKeys(messages.length)).resolves.toEqual( + await expect(store.getPendingL1ToL2entryKeys(messages.length)).resolves.toEqual( messages.map(message => message.entryKey!), ); }); it('returns an empty array if no messages are found', async () => { - await expect(store.getPendingL1ToL2MessageKeys(1)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); }); }); - describe('confirmL1ToL2Messages', () => { + describe('confirmL1ToL2EntryKeys', () => { it('updates a message from pending to confirmed', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await expect(store.confirmL1ToL2Messages([message.entryKey!])).resolves.toEqual(true); + await expect(store.confirmL1ToL2EntryKeys([message.entryKey!])).resolves.toEqual(true); }); it('once confirmed, a message is no longer pending', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await store.confirmL1ToL2Messages([message.entryKey!]); - await expect(store.getPendingL1ToL2MessageKeys(1)).resolves.toEqual([]); + await store.confirmL1ToL2EntryKeys([message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); }); it('once confirmed a message can also be pending if added again', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await store.confirmL1ToL2Messages([message.entryKey!]); + await store.confirmL1ToL2EntryKeys([message.entryKey!]); await store.addPendingL1ToL2Messages([message], 2n); - await expect(store.getPendingL1ToL2MessageKeys(2)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!]); }); it('once confirmed a message can remain pending if more of it were pending', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message, message], 1n); - await store.confirmL1ToL2Messages([message.entryKey!]); - await expect(store.getPendingL1ToL2MessageKeys(1)).resolves.toEqual([message.entryKey!]); + await store.confirmL1ToL2EntryKeys([message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([message.entryKey!]); }); }); @@ -263,62 +263,62 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch it('cancels a pending message', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 1n); - await expect(store.getPendingL1ToL2MessageKeys(1)).resolves.toEqual([]); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 1n); + await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); }); it('cancels only one of the pending messages if duplicates exist', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message, message], 1n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 1n); - await expect(store.getPendingL1ToL2MessageKeys(2)).resolves.toEqual([message.entryKey]); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 1n); + await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey]); }); it('once canceled a message can also be pending if added again', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 1n); - await expect(store.getPendingL1ToL2MessageKeys(1)).resolves.toEqual([]); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 1n); + await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); await store.addPendingL1ToL2Messages([message], 2n); - await expect(store.getPendingL1ToL2MessageKeys(1)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([message.entryKey!]); }); it('allows adding and cancelling in the same block', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 1n); - await expect(store.getPendingL1ToL2MessageKeys(1)).resolves.toEqual([]); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 1n); + await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); }); it('allows duplicates cancellations in different positions in the same block', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message, message], 1n); - await store.cancelPendingL1ToL2Messages([message.entryKey!, message.entryKey!], 1n); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!, message.entryKey!], 1n); - await expect(store.getPendingL1ToL2MessageKeys(2)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([]); }); it('allows duplicates cancellations in different blocks', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message, message], 1n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 2n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 3n); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 2n); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 3n); - await expect(store.getPendingL1ToL2MessageKeys(2)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([]); }); it('is idempotent', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message, message], 1n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 2n); - await store.cancelPendingL1ToL2Messages([message.entryKey!], 2n); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 2n); + await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 2n); - await expect(store.getPendingL1ToL2MessageKeys(2)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!]); }); }); diff --git a/yarn-project/archiver/src/archiver/data_retrieval.ts b/yarn-project/archiver/src/archiver/data_retrieval.ts index 636788133a3..ad648de6ccf 100644 --- a/yarn-project/archiver/src/archiver/data_retrieval.ts +++ b/yarn-project/archiver/src/archiver/data_retrieval.ts @@ -154,7 +154,7 @@ export async function retrieveNewPendingL1ToL2Messages( * @param blockUntilSynced - If true, blocks until the archiver has fully synced. * @param searchStartBlock - The block number to use for starting the search. * @param searchEndBlock - The highest block number that we should search up to. - * @returns An array of message keys that were cancelled and next eth block to search from. + * @returns An array of entry keys that were cancelled and next eth block to search from. */ export async function retrieveNewCancelledL1ToL2Messages( publicClient: PublicClient, diff --git a/yarn-project/archiver/src/archiver/eth_log_handlers.ts b/yarn-project/archiver/src/archiver/eth_log_handlers.ts index f7466dade14..bcaf305488e 100644 --- a/yarn-project/archiver/src/archiver/eth_log_handlers.ts +++ b/yarn-project/archiver/src/archiver/eth_log_handlers.ts @@ -46,7 +46,7 @@ export function processPendingL1ToL2MessageAddedLogs( /** * Process newly received L1ToL2MessageCancelled logs. * @param logs - L1ToL2MessageCancelled logs. - * @returns Array of message keys of the L1 to L2 messages that were cancelled + * @returns Array of entry keys of the L1 to L2 messages that were cancelled */ export function processCancelledL1ToL2MessagesLogs( logs: Log[], diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts index 0a2958a88e6..6f9eea16528 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts @@ -128,37 +128,37 @@ export class KVArchiverDataStore implements ArchiverDataStore { /** * Remove pending L1 to L2 messages from the store (if they were cancelled). - * @param messages - The message keys to be removed from the store. + * @param messages - The entry keys to be removed from the store. * @param l1BlockNumber - The L1 block number for which to remove the messages. * @returns True if the operation is successful. */ - cancelPendingL1ToL2Messages(messages: Fr[], l1BlockNumber: bigint): Promise { + cancelPendingL1ToL2EntryKeys(messages: Fr[], l1BlockNumber: bigint): Promise { return Promise.resolve(this.#messageStore.cancelPendingMessages(messages, l1BlockNumber)); } /** * Messages that have been published in an L2 block are confirmed. * Add them to the confirmed store, also remove them from the pending store. - * @param entryKeys - The message keys to be removed from the store. + * @param entryKeys - The entry keys to be removed from the store. * @param blockNumber - The block for which to add the messages. * @returns True if the operation is successful. */ - confirmL1ToL2Messages(entryKeys: Fr[]): Promise { + confirmL1ToL2EntryKeys(entryKeys: Fr[]): Promise { return this.#messageStore.confirmPendingMessages(entryKeys); } /** * Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). - * @returns The requested L1 to L2 message keys. + * @returns The requested L1 to L2 entry keys. */ - getPendingL1ToL2MessageKeys(limit: number): Promise { - return Promise.resolve(this.#messageStore.getPendingMessageKeysByFee(limit)); + getPendingL1ToL2entryKeys(limit: number): Promise { + return Promise.resolve(this.#messageStore.getPendingentryKeysByFee(limit)); } /** - * Gets the confirmed L1 to L2 message corresponding to the given message key. - * @param entryKey - The message key to look up. + * Gets the confirmed L1 to L2 message corresponding to the given entry key. + * @param entryKey - The entry key to look up. * @returns The requested L1 to L2 message or throws if not found. */ getConfirmedL1ToL2Message(entryKey: Fr): Promise { diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts index 1ec3ec9b197..4b0be6012e0 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts @@ -80,11 +80,11 @@ export class MessageStore { /** * Remove pending L1 to L2 messages from the store (if they were cancelled). - * @param messageKeys - The message keys to be removed from the store. + * @param entryKeys - The entry keys to be removed from the store. * @param l1BlockNumber - The L1 block number for which to remove the messages. * @returns True if the operation is successful. */ - cancelPendingMessages(messageKeys: Fr[], l1BlockNumber: bigint): Promise { + cancelPendingMessages(entryKeys: Fr[], l1BlockNumber: bigint): Promise { return this.db.transaction(() => { const lastL1BlockNumber = this.#lastL1BlockCancellingMessages.get() ?? 0n; if (lastL1BlockNumber >= l1BlockNumber) { @@ -93,7 +93,7 @@ export class MessageStore { void this.#lastL1BlockCancellingMessages.set(l1BlockNumber); - for (const entryKey of messageKeys) { + for (const entryKey of entryKeys) { const messageCtx = this.#messages.get(entryKey.toString()); if (!messageCtx) { throw new Error(`Message ${entryKey.toString()} not found`); @@ -109,12 +109,12 @@ export class MessageStore { /** * Messages that have been published in an L2 block are confirmed. * Add them to the confirmed store, also remove them from the pending store. - * @param messageKeys - The message keys to be removed from the store. + * @param entryKeys - The entry keys to be removed from the store. * @returns True if the operation is successful. */ - confirmPendingMessages(messageKeys: Fr[]): Promise { + confirmPendingMessages(entryKeys: Fr[]): Promise { return this.db.transaction(() => { - for (const entryKey of messageKeys) { + for (const entryKey of entryKeys) { const messageCtx = this.#messages.get(entryKey.toString()); if (!messageCtx) { throw new Error(`Message ${entryKey.toString()} not found`); @@ -130,8 +130,8 @@ export class MessageStore { } /** - * Gets the confirmed L1 to L2 message corresponding to the given message key. - * @param entryKey - The message key to look up. + * Gets the confirmed L1 to L2 message corresponding to the given entry key. + * @param entryKey - The entry key to look up. * @returns The requested L1 to L2 message or throws if not found. */ getConfirmedMessage(entryKey: Fr): L1ToL2Message { @@ -150,21 +150,21 @@ export class MessageStore { /** * Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). - * @returns The requested L1 to L2 message keys. + * @returns The requested L1 to L2 entry keys. */ - getPendingMessageKeysByFee(limit: number): Fr[] { - const messageKeys: Fr[] = []; + getPendingentryKeysByFee(limit: number): Fr[] { + const entryKeys: Fr[] = []; for (const [[_, entryKey], count] of this.#pendingMessagesByFee.entries({ reverse: true, })) { // put `count` copies of this message in the result list - messageKeys.push(...Array(count).fill(Fr.fromString(entryKey))); - if (messageKeys.length >= limit) { + entryKeys.push(...Array(count).fill(Fr.fromString(entryKey))); + if (entryKeys.length >= limit) { break; } } - return messageKeys; + return entryKeys; } } diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.test.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.test.ts index 3a60f300409..8335eb0fca8 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.test.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.test.ts @@ -60,12 +60,12 @@ describe('pending_l1_to_l2_message_store', () => { }); it('get messages for an empty store', () => { - expect(store.getMessageKeys(10)).toEqual([]); + expect(store.getentryKeys(10)).toEqual([]); }); - it('getMessageKeys returns an empty array if limit is 0', () => { + it('getentryKeys returns an empty array if limit is 0', () => { store.addMessage(entryKey, msg); - expect(store.getMessageKeys(0)).toEqual([]); + expect(store.getentryKeys(0)).toEqual([]); }); it('get messages for a non-empty store when limit > number of messages in store', () => { @@ -73,7 +73,7 @@ describe('pending_l1_to_l2_message_store', () => { entryKeys.forEach(entryKey => { store.addMessage(entryKey, L1ToL2Message.random()); }); - expect(store.getMessageKeys(10).length).toEqual(5); + expect(store.getentryKeys(10).length).toEqual(5); }); it('get messages returns messages sorted by fees and also includes multiple of the same message', () => { @@ -92,7 +92,7 @@ describe('pending_l1_to_l2_message_store', () => { store.addMessage(entryKey, msg); }); const expectedMessageFees = [4n, 3n, 3n, 3n]; // the top 4. - const receivedMessageFees = store.getMessageKeys(4).map(key => key.value); + const receivedMessageFees = store.getentryKeys(4).map(key => key.value); expect(receivedMessageFees).toEqual(expectedMessageFees); }); }); diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts index fc0e57334b6..1ac914256e3 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts @@ -7,7 +7,7 @@ import { Fr } from '@aztec/foundation/fields'; */ export class L1ToL2MessageStore { /** - * A map containing the message key to the corresponding L1 to L2 + * A map containing the entry key to the corresponding L1 to L2 * messages (and the number of times the message has been seen). */ protected store: Map = new Map(); @@ -15,12 +15,12 @@ export class L1ToL2MessageStore { constructor() {} addMessage(entryKey: Fr, message: L1ToL2Message) { - const messageKeyBigInt = entryKey.toBigInt(); - const msgAndCount = this.store.get(messageKeyBigInt); + const entryKeyBigInt = entryKey.toBigInt(); + const msgAndCount = this.store.get(entryKeyBigInt); if (msgAndCount) { msgAndCount.count++; } else { - this.store.set(messageKeyBigInt, { message, count: 1 }); + this.store.set(entryKeyBigInt, { message, count: 1 }); } } @@ -38,7 +38,7 @@ export class L1ToL2MessageStore { * for removing messages or fetching multiple messages. */ export class PendingL1ToL2MessageStore extends L1ToL2MessageStore { - getMessageKeys(limit: number): Fr[] { + getentryKeys(limit: number): Fr[] { if (limit < 1) { return []; } @@ -63,15 +63,15 @@ export class PendingL1ToL2MessageStore extends L1ToL2MessageStore { return; } - const messageKeyBigInt = entryKey.value; - const msgAndCount = this.store.get(messageKeyBigInt); + const entryKeyBigInt = entryKey.value; + const msgAndCount = this.store.get(entryKeyBigInt); if (!msgAndCount) { - throw new Error(`Unable to remove message: L1 to L2 Message with key ${messageKeyBigInt} not found in store`); + throw new Error(`Unable to remove message: L1 to L2 Message with key ${entryKeyBigInt} not found in store`); } if (msgAndCount.count > 1) { msgAndCount.count--; } else { - this.store.delete(messageKeyBigInt); + this.store.delete(entryKeyBigInt); } } } diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index 4dcd8e60c8f..dcf30bea698 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -157,11 +157,11 @@ export class MemoryArchiverStore implements ArchiverDataStore { /** * Remove pending L1 to L2 messages from the store (if they were cancelled). - * @param messages - The message keys to be removed from the store. + * @param messages - The entry keys to be removed from the store. * @param l1BlockNumber - The L1 block number for which to remove the messages. * @returns True if the operation is successful (always in this implementation). */ - public cancelPendingL1ToL2Messages(messages: Fr[], l1BlockNumber: bigint): Promise { + public cancelPendingL1ToL2EntryKeys(messages: Fr[], l1BlockNumber: bigint): Promise { if (l1BlockNumber <= this.lastL1BlockCancelledMessages) { return Promise.resolve(false); } @@ -176,11 +176,11 @@ export class MemoryArchiverStore implements ArchiverDataStore { /** * Messages that have been published in an L2 block are confirmed. * Add them to the confirmed store, also remove them from the pending store. - * @param messageKeys - The message keys to be removed from the store. + * @param entryKeys - The entry keys to be removed from the store. * @returns True if the operation is successful (always in this implementation). */ - public confirmL1ToL2Messages(messageKeys: Fr[]): Promise { - messageKeys.forEach(entryKey => { + public confirmL1ToL2EntryKeys(entryKeys: Fr[]): Promise { + entryKeys.forEach(entryKey => { this.confirmedL1ToL2Messages.addMessage(entryKey, this.pendingL1ToL2Messages.getMessage(entryKey)!); this.pendingL1ToL2Messages.removeMessage(entryKey); }); @@ -244,15 +244,15 @@ export class MemoryArchiverStore implements ArchiverDataStore { /** * Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). - * @returns The requested L1 to L2 message keys. + * @returns The requested L1 to L2 entry keys. */ - public getPendingL1ToL2MessageKeys(limit: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP): Promise { - return Promise.resolve(this.pendingL1ToL2Messages.getMessageKeys(limit)); + public getPendingL1ToL2entryKeys(limit: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP): Promise { + return Promise.resolve(this.pendingL1ToL2Messages.getentryKeys(limit)); } /** - * Gets the confirmed L1 to L2 message corresponding to the given message key. - * @param entryKey - The message key to look up. + * Gets the confirmed L1 to L2 message corresponding to the given entry key. + * @param entryKey - The entry key to look up. * @returns The requested L1 to L2 message or throws if not found. */ public getConfirmedL1ToL2Message(entryKey: Fr): Promise { diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 95566b3560f..a1dd850558a 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -377,9 +377,9 @@ export class AztecNodeService implements AztecNode { } /** - * Gets a confirmed/consumed L1 to L2 message for the given message key + * Gets a confirmed/consumed L1 to L2 message for the given entry key * and its index in the merkle tree. - * @param entryKey - The message key. + * @param entryKey - The entry key. * @returns The map containing the message and index. */ public async getL1ToL2MessageAndIndex(entryKey: Fr): Promise { diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index fb55df3205c..e3b287c8c43 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -75,9 +75,9 @@ export interface AztecNode { ): Promise>; /** - * Gets a confirmed/consumed L1 to L2 message for the given message key (throws if not found). + * Gets a confirmed/consumed L1 to L2 message for the given entry key (throws if not found). * and its index in the merkle tree - * @param entryKey - The message key. + * @param entryKey - The entry key. * @returns The map containing the message and index. */ getL1ToL2MessageAndIndex(entryKey: Fr): Promise; diff --git a/yarn-project/circuit-types/src/l1_to_l2_message.ts b/yarn-project/circuit-types/src/l1_to_l2_message.ts index 95a7207ed7d..09bbbad70ac 100644 --- a/yarn-project/circuit-types/src/l1_to_l2_message.ts +++ b/yarn-project/circuit-types/src/l1_to_l2_message.ts @@ -14,12 +14,12 @@ export interface L1ToL2MessageSource { * @param limit - The maximum number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). * @returns The requested L1 to L2 messages' keys. */ - getPendingL1ToL2Messages(limit?: number): Promise; + getPendingL1ToL2EntryKeys(limit?: number): Promise; /** - * Gets the confirmed L1 to L2 message with the given message key. + * Gets the confirmed L1 to L2 message with the given entry key. * i.e. message that has already been consumed by the sequencer and published in an L2 Block - * @param entryKey - The message key. + * @param entryKey - The entry key. * @returns The confirmed L1 to L2 message (throws if not found) */ getConfirmedL1ToL2Message(entryKey: Fr): Promise; diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 3d08e476700..22b30fe4038 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -6,12 +6,17 @@ import { DeployL1Contracts, EthAddress, Fr, + L1Actor, + L1ToL2Message, + L2Actor, PXE, TxStatus, computeAuthWitMessageHash, computeMessageSecretHash, sleep, } from '@aztec/aztec.js'; +import { keccak, sha256 } from '@aztec/foundation/crypto'; +import { serializeToBuffer } from '@aztec/foundation/serialize'; import { InboxAbi, OutboxAbi } from '@aztec/l1-artifacts'; import { TestContract } from '@aztec/noir-contracts.js'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; @@ -47,7 +52,7 @@ describe('e2e_public_cross_chain_messaging', () => { user1Wallet = wallets[0]; user2Wallet = wallets[1]; await publicDeployAccounts(wallets[0], accounts.slice(0, 2)); - }); + }, 300_00); beforeEach(async () => { crossChainTestHarness = await CrossChainTestHarness.new( @@ -147,13 +152,30 @@ describe('e2e_public_cross_chain_messaging', () => { await crossChainTestHarness.mintTokensPublicOnL2(unrelatedMintAmount); await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, unrelatedMintAmount); + const content = Fr.fromBufferReduce( + sha256( + Buffer.concat([ + keccak(Buffer.from('mint_public(bytes32,uint256,address)')).subarray(0, 4), + serializeToBuffer(...[user2Wallet.getAddress(), new Fr(bridgeAmount), ethAccount.toBuffer32()]), + ]), + ), + ); + const wrongMessage = new L1ToL2Message( + new L1Actor(crossChainTestHarness.tokenPortalAddress, crossChainTestHarness.publicClient.chain.id), + new L2Actor(l2Bridge.address, 1), + content, + secretHash, + 2 ** 32 - 1, + 0, + ); + // user2 tries to consume this message and minting to itself -> should fail since the message is intended to be consumed only by owner. await expect( l2Bridge .withWallet(user2Wallet) .methods.claim_public(user2Wallet.getAddress(), bridgeAmount, ethAccount, secret) .simulate(), - ).rejects.toThrow("Invalid Content 'l1_to_l2_message_data.message.content == content'"); + ).rejects.toThrow(`Message ${wrongMessage.hash().toString()} not found`); // user2 consumes owner's L1-> L2 message on bridge contract and mints public tokens on L2 logger("user2 consumes owner's message on L2 Publicly"); @@ -197,9 +219,27 @@ describe('e2e_public_cross_chain_messaging', () => { // Perform an unrelated transaction on L2 to progress the rollup. Here we mint public tokens. await crossChainTestHarness.mintTokensPublicOnL2(0n); + // Wrong message hash + const content = Fr.fromBufferReduce( + sha256( + Buffer.concat([ + keccak(Buffer.from('mint_private(bytes32,uint256,address)')).subarray(0, 4), + serializeToBuffer(...[secretHash, new Fr(bridgeAmount), ethAccount.toBuffer32()]), + ]), + ), + ); + const wrongMessage = new L1ToL2Message( + new L1Actor(crossChainTestHarness.tokenPortalAddress, crossChainTestHarness.publicClient.chain.id), + new L2Actor(l2Bridge.address, 1), + content, + secretHash, + 2 ** 32 - 1, + 0, + ); + await expect( l2Bridge.withWallet(user2Wallet).methods.claim_private(secretHash, bridgeAmount, ethAccount, secret).simulate(), - ).rejects.toThrowError("Invalid Content 'l1_to_l2_message_data.message.content == content'"); + ).rejects.toThrowError(`Message ${wrongMessage.hash().toString()} not found`); }, 60_000); // Note: We register one portal address when deploying contract but that address is no-longer the only address @@ -270,8 +310,8 @@ describe('e2e_public_cross_chain_messaging', () => { // The following are arbitrary test values const content = Fr.random(); - const fee = 100_0000n; - const deadline = 4294967295n; + const fee = 0n; + const deadline = 2n ** 32n - 1n; // We inject the message to Inbox const txHash = await inbox.write.sendL2Message( diff --git a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts index c1edff0af93..edc904ebfc9 100644 --- a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts +++ b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts @@ -116,14 +116,14 @@ describe('archiver integration with l1 to l2 messages', () => { await delay(5000); // archiver shouldn't have any pending messages. - expect((await archiver.getPendingL1ToL2Messages(10)).length).toEqual(0); + expect((await archiver.getPendingL1ToL2EntryKeys(10)).length).toEqual(0); }, 80_000); it('archiver handles l1 to l2 message correctly even when l2block has no such messages', async () => { // send a transfer tx to force through rollup with the message included await l2Token.methods.transfer_public(owner, receiver, 0n, 0n).send().wait(); - expect((await archiver.getPendingL1ToL2Messages(10)).length).toEqual(0); + expect((await archiver.getPendingL1ToL2EntryKeys(10)).length).toEqual(0); await expect(archiver.getConfirmedL1ToL2Message(Fr.ZERO)).rejects.toThrow(); }, 30_000); }); diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index df1029d78cc..32525ffd578 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -128,8 +128,8 @@ export class SimulatorOracle implements DBOracle { } /** - * Retrieves the L1ToL2Message associated with a specific message key - * Throws an error if the message key is not found + * Retrieves the L1ToL2Message associated with a specific entry key + * Throws an error if the entry key is not found * * @param entryKey - The key of the message to be retrieved * @returns A promise that resolves to the message data, a sibling path and the diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts index f4987d485b9..ffe8bf2b2eb 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts @@ -82,7 +82,7 @@ describe('sequencer', () => { }); l1ToL2MessageSource = mock({ - getPendingL1ToL2Messages: () => Promise.resolve(Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(Fr.ZERO)), + getPendingL1ToL2EntryKeys: () => Promise.resolve(Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(Fr.ZERO)), getBlockNumber: () => Promise.resolve(lastBlockNumber), }); diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 24bb3375e4c..c44f11a1c3c 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -205,7 +205,7 @@ export class Sequencer { // Get l1 to l2 messages from the contract this.log('Requesting L1 to L2 messages from contract'); - const l1ToL2Messages = await this.getPendingL1ToL2Messages(); + const l1ToL2Messages = await this.getPendingL1ToL2EntryKeys(); this.log('Successfully retrieved L1 to L2 messages from contract'); // Build the new block by running the rollup circuits @@ -371,12 +371,12 @@ export class Sequencer { } /** - * Calls the archiver to pull upto `NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP` message keys + * Calls the archiver to pull upto `NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP` entry keys * (archiver returns the top messages sorted by fees) - * @returns An array of L1 to L2 messages' messageKeys + * @returns An array of L1 to L2 messages' entryKeys */ - protected async getPendingL1ToL2Messages(): Promise { - return await this.l1ToL2MessageSource.getPendingL1ToL2Messages(); + protected async getPendingL1ToL2EntryKeys(): Promise { + return await this.l1ToL2MessageSource.getPendingL1ToL2EntryKeys(); } /** diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index 8a68d7441f6..4c953463ef5 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -217,7 +217,7 @@ export class ViewDataOracle extends TypedOracle { /** * Fetches the a message from the db, given its key. - * @param entryKey - A buffer representing the message key. + * @param entryKey - A buffer representing the entry key. * @returns The l1 to l2 message data */ public async getL1ToL2MembershipWitness(entryKey: Fr) { diff --git a/yarn-project/simulator/src/public/db.ts b/yarn-project/simulator/src/public/db.ts index 6d9a19cb2da..ba901a80854 100644 --- a/yarn-project/simulator/src/public/db.ts +++ b/yarn-project/simulator/src/public/db.ts @@ -69,9 +69,9 @@ export interface PublicContractsDB { /** Database interface for providing access to commitment tree and l1 to l2 message tree (append only data trees). */ export interface CommitmentsDB { /** - * Gets a confirmed L1 to L2 message for the given message key. + * Gets a confirmed L1 to L2 message for the given entry key. * TODO(Maddiaa): Can be combined with aztec-node method that does the same thing. - * @param entryKey - The message Key. + * @param entryKey - The entry key. * @returns - The l1 to l2 message object */ getL1ToL2MembershipWitness(entryKey: Fr): Promise>; diff --git a/yarn-project/simulator/src/public/public_execution_context.ts b/yarn-project/simulator/src/public/public_execution_context.ts index f3f3e570ca2..6f229971b5e 100644 --- a/yarn-project/simulator/src/public/public_execution_context.ts +++ b/yarn-project/simulator/src/public/public_execution_context.ts @@ -86,7 +86,7 @@ export class PublicExecutionContext extends TypedOracle { /** * Fetches the a message from the db, given its key. - * @param entryKey - A buffer representing the message key. + * @param entryKey - A buffer representing the entry key. * @returns The l1 to l2 message data */ public async getL1ToL2MembershipWitness(entryKey: Fr) { diff --git a/yellow-paper/docs/public-vm/type-structs.md b/yellow-paper/docs/public-vm/type-structs.md index c61a52d2070..c973fc3cec4 100644 --- a/yellow-paper/docs/public-vm/type-structs.md +++ b/yellow-paper/docs/public-vm/type-structs.md @@ -19,7 +19,7 @@ This section lists type definitions relevant to AVM State and Circuit I/O. | `callPointer` | `field` | Associates this item with a `TracedContractCall` entry in `worldStateAccessTrace.contractCalls` | | `portal` | `EthAddress` | | | `leafIndex` | `field` | | -| `msgKey` | `field` | The message key which is also the tree leaf value. | +| `msgKey` | `field` | The entry key which is also the tree leaf value. | | `exists` | `field` | | | `message` | `[field; MAX_L1_TO_L2_MESSAGE_LENGTH]` | **Omitted from public inputs** | | `endLifetime` | `field` | Equivalent to `endLifetime` of the containing contract call. | From b7d73ea56c65e713d9b9024d6a28c8a83269d2ab Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 29 Feb 2024 23:15:54 +0000 Subject: [PATCH 6/7] chore: remove unused log and fix find and replace issues --- l1-contracts/test/portals/UniswapPortal.t.sol | 64 +++++++++---------- noir-projects/aztec-nr/aztec/src/messaging.nr | 14 ---- .../archiver/src/archiver/archiver.test.ts | 12 ++-- .../archiver/src/archiver/archiver.ts | 2 +- .../archiver/src/archiver/archiver_store.ts | 2 +- .../src/archiver/archiver_store_test_suite.ts | 34 +++++----- .../kv_archiver_store/kv_archiver_store.ts | 4 +- .../kv_archiver_store/message_store.ts | 2 +- .../l1_to_l2_message_store.test.ts | 10 +-- .../l1_to_l2_message_store.ts | 2 +- .../memory_archiver_store.ts | 4 +- .../simulator/src/acvm/oracle/typed_oracle.ts | 2 +- 12 files changed, 69 insertions(+), 83 deletions(-) diff --git a/l1-contracts/test/portals/UniswapPortal.t.sol b/l1-contracts/test/portals/UniswapPortal.t.sol index 25587cc5b89..45792a2f1bc 100644 --- a/l1-contracts/test/portals/UniswapPortal.t.sol +++ b/l1-contracts/test/portals/UniswapPortal.t.sol @@ -154,10 +154,10 @@ contract UniswapPortalTest is Test { entryKey = outbox.computeEntryKey(message); } - function _addMessagesToOutbox(bytes32 daiWithdrawentryKey, bytes32 swapentryKey) internal { + function _addMessagesToOutbox(bytes32 daiWithdrawEntryKey, bytes32 swapEntryKey) internal { bytes32[] memory entryKeys = new bytes32[](2); - entryKeys[0] = daiWithdrawentryKey; - entryKeys[1] = swapentryKey; + entryKeys[0] = daiWithdrawEntryKey; + entryKeys[1] = swapEntryKey; vm.prank(address(rollup)); outbox.sendL1Messages(entryKeys); @@ -215,10 +215,10 @@ contract UniswapPortalTest is Test { } function testRevertIfSwapParamsDifferentToOutboxMessage() public { - bytes32 daiWithdrawMsgKey = + bytes32 daiWithdrawEntryKey = _createDaiWithdrawMessage(address(uniswapPortal), address(uniswapPortal)); - bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); - _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); + bytes32 swapEntryKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); + _addMessagesToOutbox(daiWithdrawEntryKey, swapEntryKey); bytes32 newAztecRecipient = bytes32(uint256(0x4)); bytes32 entryKeyPortalChecksAgainst = @@ -241,12 +241,12 @@ contract UniswapPortalTest is Test { } function testSwapWithDesignatedCaller() public { - bytes32 daiWithdrawMsgKey = + bytes32 daiWithdrawEntryKey = _createDaiWithdrawMessage(address(uniswapPortal), address(uniswapPortal)); - bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); - _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); + bytes32 swapEntryKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); + _addMessagesToOutbox(daiWithdrawEntryKey, swapEntryKey); - bytes32 l1ToL2entryKey = uniswapPortal.swapPublic( + bytes32 l1ToL2EntryKey = uniswapPortal.swapPublic( address(daiTokenPortal), amount, uniswapFeePool, @@ -264,22 +264,22 @@ contract UniswapPortalTest is Test { // there should be some weth in the weth portal assertGt(WETH9.balanceOf(address(wethTokenPortal)), 0); // there should be a message in the inbox: - assertEq(inbox.get(l1ToL2entryKey).count, 1); + assertEq(inbox.get(l1ToL2EntryKey).count, 1); // there should be no message in the outbox: - assertFalse(outbox.contains(daiWithdrawMsgKey)); - assertFalse(outbox.contains(swapMsgKey)); + assertFalse(outbox.contains(daiWithdrawEntryKey)); + assertFalse(outbox.contains(swapEntryKey)); } function testSwapCalledByAnyoneIfDesignatedCallerNotSet(address _caller) public { vm.assume(_caller != address(uniswapPortal)); - bytes32 daiWithdrawMsgKey = + bytes32 daiWithdrawEntryKey = _createDaiWithdrawMessage(address(uniswapPortal), address(uniswapPortal)); // don't set caller on swapPublic() -> so anyone can call this method. - bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(0)); - _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); + bytes32 swapEntryKey = _createUniswapSwapMessagePublic(aztecRecipient, address(0)); + _addMessagesToOutbox(daiWithdrawEntryKey, swapEntryKey); vm.prank(_caller); - bytes32 l1ToL2entryKey = uniswapPortal.swapPublic( + bytes32 l1ToL2EntryKey = uniswapPortal.swapPublic( address(daiTokenPortal), amount, uniswapFeePool, @@ -297,18 +297,18 @@ contract UniswapPortalTest is Test { // there should be some weth in the weth portal assertGt(WETH9.balanceOf(address(wethTokenPortal)), 0); // there should be a message in the inbox: - assertEq(inbox.get(l1ToL2entryKey).count, 1); + assertEq(inbox.get(l1ToL2EntryKey).count, 1); // there should be no message in the outbox: - assertFalse(outbox.contains(daiWithdrawMsgKey)); - assertFalse(outbox.contains(swapMsgKey)); + assertFalse(outbox.contains(daiWithdrawEntryKey)); + assertFalse(outbox.contains(swapEntryKey)); } function testRevertIfSwapWithDesignatedCallerCalledByWrongCaller(address _caller) public { vm.assume(_caller != address(this)); - bytes32 daiWithdrawMsgKey = + bytes32 daiWithdrawEntryKey = _createDaiWithdrawMessage(address(uniswapPortal), address(uniswapPortal)); - bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); - _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); + bytes32 swapEntryKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); + _addMessagesToOutbox(daiWithdrawEntryKey, swapEntryKey); vm.startPrank(_caller); bytes32 entryKeyPortalChecksAgainst = _createUniswapSwapMessagePublic(aztecRecipient, _caller); @@ -352,12 +352,12 @@ contract UniswapPortalTest is Test { // if the sequencer doesn't consume the L1->L2 message, then `canceller` can // cancel the message and retrieve the funds (instead of them being stuck on the portal) function testMessageToInboxIsCancellable() public { - bytes32 daiWithdrawMsgKey = + bytes32 daiWithdrawEntryKey = _createDaiWithdrawMessage(address(uniswapPortal), address(uniswapPortal)); - bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); - _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); + bytes32 swapEntryKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); + _addMessagesToOutbox(daiWithdrawEntryKey, swapEntryKey); - bytes32 l1ToL2entryKey = uniswapPortal.swapPublic{value: 1 ether}( + bytes32 l1ToL2EntryKey = uniswapPortal.swapPublic{value: 1 ether}( address(daiTokenPortal), amount, uniswapFeePool, @@ -376,13 +376,13 @@ contract UniswapPortalTest is Test { // check event was emitted vm.expectEmit(true, false, false, false); // expected event: - emit L1ToL2MessageCancelled(l1ToL2entryKey); + emit L1ToL2MessageCancelled(l1ToL2EntryKey); // perform op // TODO(2167) - Update UniswapPortal properly with new portal standard. bytes32 entryKey = wethTokenPortal.cancelL1ToAztecMessagePublic( aztecRecipient, wethAmountOut, deadlineForL1ToL2Message, secretHash, 1 ether ); - assertEq(entryKey, l1ToL2entryKey, "returned entry key and calculated entryKey should match"); + assertEq(entryKey, l1ToL2EntryKey, "returned entry key and calculated entryKey should match"); assertFalse(inbox.contains(entryKey), "entry still in inbox"); assertEq( WETH9.balanceOf(address(this)), @@ -393,12 +393,12 @@ contract UniswapPortalTest is Test { } function testRevertIfSwapMessageWasForDifferentPublicOrPrivateFlow() public { - bytes32 daiWithdrawMsgKey = + bytes32 daiWithdrawEntryKey = _createDaiWithdrawMessage(address(uniswapPortal), address(uniswapPortal)); // Create message for `_isPrivateFlow`: - bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); - _addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey); + bytes32 swapEntryKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this)); + _addMessagesToOutbox(daiWithdrawEntryKey, swapEntryKey); bytes32 entryKeyPortalChecksAgainst = _createUniswapSwapMessagePrivate(secretHashForRedeemingMintedNotes, address(this)); diff --git a/noir-projects/aztec-nr/aztec/src/messaging.nr b/noir-projects/aztec-nr/aztec/src/messaging.nr index 32beec4e390..958a5e863f4 100644 --- a/noir-projects/aztec-nr/aztec/src/messaging.nr +++ b/noir-projects/aztec-nr/aztec/src/messaging.nr @@ -2,8 +2,6 @@ mod l1_to_l2_message; use crate::oracle::get_l1_to_l2_membership_witness::get_l1_to_l2_membership_witness; -use crate::oracle::debug_log::debug_log_format; - use dep::std::merkle::compute_merkle_root; use crate::messaging::l1_to_l2_message::L1ToL2Message; use dep::protocol_types::{constants::L1_TO_L2_MSG_TREE_HEIGHT, address::{AztecAddress, EthAddress}, utils::arr_copy_slice}; @@ -26,18 +24,6 @@ pub fn process_l1_to_l2_message( secret ); let entry_key = msg.hash(); - debug_log_format( - "L1ToL2Message entry_key: H({0}, {1}, {2}, {3}, {4}, {5}) = {6} ", - [ - portal_contract_address.to_field(), - chain_id, - storage_contract_address.to_field(), - version, - content, - secret, - entry_key - ] - ); let returned_message = get_l1_to_l2_membership_witness(entry_key); let leaf_index = returned_message[0]; diff --git a/yarn-project/archiver/src/archiver/archiver.test.ts b/yarn-project/archiver/src/archiver/archiver.test.ts index 88fb7c7fc4b..2adcd5cb681 100644 --- a/yarn-project/archiver/src/archiver/archiver.test.ts +++ b/yarn-project/archiver/src/archiver/archiver.test.ts @@ -101,12 +101,12 @@ describe('Archiver', () => { // Check that only 2 messages (l1ToL2MessageAddedEvents[3][2] and l1ToL2MessageAddedEvents[3][3]) are pending. // Other two (l1ToL2MessageAddedEvents[3][0..2]) were cancelled. And the previous messages were confirmed. - const expectedPendingentryKeys = [ + const expectedPendingEntryKeys = [ l1ToL2MessageAddedEvents[3][2].args.entryKey, l1ToL2MessageAddedEvents[3][3].args.entryKey, ]; - const actualPendingentryKeys = (await archiver.getPendingL1ToL2EntryKeys(10)).map(key => key.toString()); - expect(expectedPendingentryKeys).toEqual(actualPendingentryKeys); + const actualPendingEntryKeys = (await archiver.getPendingL1ToL2EntryKeys(10)).map(key => key.toString()); + expect(expectedPendingEntryKeys).toEqual(actualPendingEntryKeys); // Expect logs to correspond to what is set by L2Block.random(...) const encryptedLogs = await archiver.getLogs(1, 100, LogType.ENCRYPTED); @@ -199,9 +199,9 @@ describe('Archiver', () => { expect(latestBlockNum).toEqual(numL2BlocksInTest); // Check that the only pending L1 to L2 messages are those from eth bock 102 - const expectedPendingentryKeys = additionalL1ToL2MessagesBlock102; - const actualPendingentryKeys = (await archiver.getPendingL1ToL2EntryKeys(100)).map(key => key.toString()); - expect(actualPendingentryKeys).toEqual(expectedPendingentryKeys); + const expectedPendingEntryKeys = additionalL1ToL2MessagesBlock102; + const actualPendingEntryKeys = (await archiver.getPendingL1ToL2EntryKeys(100)).map(key => key.toString()); + expect(actualPendingEntryKeys).toEqual(expectedPendingEntryKeys); await archiver.stop(); }, 10_000); diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 1c1241e02ce..5b7ffc3c591 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -551,7 +551,7 @@ export class Archiver implements ArchiveSource { * @returns The requested L1 to L2 messages' keys. */ getPendingL1ToL2EntryKeys(limit: number): Promise { - return this.store.getPendingL1ToL2entryKeys(limit); + return this.store.getPendingL1ToL2EntryKeys(limit); } /** diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index e8717084417..f5449bcc26f 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -95,7 +95,7 @@ export interface ArchiverDataStore { * @param limit - The number of entries to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). * @returns The requested L1 to L2 entry keys. */ - getPendingL1ToL2entryKeys(limit: number): Promise; + getPendingL1ToL2EntryKeys(limit: number): Promise; /** * Gets the confirmed L1 to L2 message corresponding to the given entry key. diff --git a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts index 05ae6923444..be90e7da57c 100644 --- a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts +++ b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts @@ -185,7 +185,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch const message = L1ToL2Message.random(Fr.random()); await expect(store.addPendingL1ToL2Messages([message, message], 1n)).resolves.toEqual(true); - await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!, message.entryKey!]); + await expect(store.getPendingL1ToL2EntryKeys(2)).resolves.toEqual([message.entryKey!, message.entryKey!]); }); it('allows duplicate pending messages in different blocks', async () => { @@ -193,14 +193,14 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await expect(store.addPendingL1ToL2Messages([message], 1n)).resolves.toEqual(true); await expect(store.addPendingL1ToL2Messages([message], 2n)).resolves.toEqual(true); - await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!, message.entryKey!]); + await expect(store.getPendingL1ToL2EntryKeys(2)).resolves.toEqual([message.entryKey!, message.entryKey!]); }); it('is idempotent', async () => { const message = L1ToL2Message.random(Fr.random()); await expect(store.addPendingL1ToL2Messages([message], 1n)).resolves.toEqual(true); await expect(store.addPendingL1ToL2Messages([message], 1n)).resolves.toEqual(false); - await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2EntryKeys(2)).resolves.toEqual([message.entryKey!]); }); }); @@ -208,7 +208,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch it('returns previously stored pending L1 to L2 messages', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); - await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([message.entryKey!]); }); it('returns messages ordered by fee', async () => { @@ -219,13 +219,13 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await store.addPendingL1ToL2Messages(messages, 1n); messages.sort((a, b) => b.fee - a.fee); - await expect(store.getPendingL1ToL2entryKeys(messages.length)).resolves.toEqual( + await expect(store.getPendingL1ToL2EntryKeys(messages.length)).resolves.toEqual( messages.map(message => message.entryKey!), ); }); it('returns an empty array if no messages are found', async () => { - await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([]); }); }); @@ -240,7 +240,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); await store.confirmL1ToL2EntryKeys([message.entryKey!]); - await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([]); }); it('once confirmed a message can also be pending if added again', async () => { @@ -248,14 +248,14 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await store.addPendingL1ToL2Messages([message], 1n); await store.confirmL1ToL2EntryKeys([message.entryKey!]); await store.addPendingL1ToL2Messages([message], 2n); - await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2EntryKeys(2)).resolves.toEqual([message.entryKey!]); }); it('once confirmed a message can remain pending if more of it were pending', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message, message], 1n); await store.confirmL1ToL2EntryKeys([message.entryKey!]); - await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([message.entryKey!]); }); }); @@ -264,14 +264,14 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 1n); - await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([]); }); it('cancels only one of the pending messages if duplicates exist', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message, message], 1n); await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 1n); - await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey]); + await expect(store.getPendingL1ToL2EntryKeys(2)).resolves.toEqual([message.entryKey]); }); it('once canceled a message can also be pending if added again', async () => { @@ -279,17 +279,17 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await store.addPendingL1ToL2Messages([message], 1n); await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 1n); - await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([]); await store.addPendingL1ToL2Messages([message], 2n); - await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([message.entryKey!]); }); it('allows adding and cancelling in the same block', async () => { const message = L1ToL2Message.random(Fr.random()); await store.addPendingL1ToL2Messages([message], 1n); await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 1n); - await expect(store.getPendingL1ToL2entryKeys(1)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([]); }); it('allows duplicates cancellations in different positions in the same block', async () => { @@ -298,7 +298,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await store.cancelPendingL1ToL2EntryKeys([message.entryKey!, message.entryKey!], 1n); - await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2EntryKeys(2)).resolves.toEqual([]); }); it('allows duplicates cancellations in different blocks', async () => { @@ -308,7 +308,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 2n); await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 3n); - await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([]); + await expect(store.getPendingL1ToL2EntryKeys(2)).resolves.toEqual([]); }); it('is idempotent', async () => { @@ -318,7 +318,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 2n); await store.cancelPendingL1ToL2EntryKeys([message.entryKey!], 2n); - await expect(store.getPendingL1ToL2entryKeys(2)).resolves.toEqual([message.entryKey!]); + await expect(store.getPendingL1ToL2EntryKeys(2)).resolves.toEqual([message.entryKey!]); }); }); diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts index 6f9eea16528..27f7073109a 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts @@ -152,8 +152,8 @@ export class KVArchiverDataStore implements ArchiverDataStore { * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). * @returns The requested L1 to L2 entry keys. */ - getPendingL1ToL2entryKeys(limit: number): Promise { - return Promise.resolve(this.#messageStore.getPendingentryKeysByFee(limit)); + getPendingL1ToL2EntryKeys(limit: number): Promise { + return Promise.resolve(this.#messageStore.getPendingEntryKeysByFee(limit)); } /** diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts index 4b0be6012e0..e9e13392991 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts @@ -152,7 +152,7 @@ export class MessageStore { * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). * @returns The requested L1 to L2 entry keys. */ - getPendingentryKeysByFee(limit: number): Fr[] { + getPendingEntryKeysByFee(limit: number): Fr[] { const entryKeys: Fr[] = []; for (const [[_, entryKey], count] of this.#pendingMessagesByFee.entries({ diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.test.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.test.ts index 8335eb0fca8..e21a76d1b49 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.test.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.test.ts @@ -60,12 +60,12 @@ describe('pending_l1_to_l2_message_store', () => { }); it('get messages for an empty store', () => { - expect(store.getentryKeys(10)).toEqual([]); + expect(store.getEntryKeys(10)).toEqual([]); }); - it('getentryKeys returns an empty array if limit is 0', () => { + it('getEntryKeys returns an empty array if limit is 0', () => { store.addMessage(entryKey, msg); - expect(store.getentryKeys(0)).toEqual([]); + expect(store.getEntryKeys(0)).toEqual([]); }); it('get messages for a non-empty store when limit > number of messages in store', () => { @@ -73,7 +73,7 @@ describe('pending_l1_to_l2_message_store', () => { entryKeys.forEach(entryKey => { store.addMessage(entryKey, L1ToL2Message.random()); }); - expect(store.getentryKeys(10).length).toEqual(5); + expect(store.getEntryKeys(10).length).toEqual(5); }); it('get messages returns messages sorted by fees and also includes multiple of the same message', () => { @@ -92,7 +92,7 @@ describe('pending_l1_to_l2_message_store', () => { store.addMessage(entryKey, msg); }); const expectedMessageFees = [4n, 3n, 3n, 3n]; // the top 4. - const receivedMessageFees = store.getentryKeys(4).map(key => key.value); + const receivedMessageFees = store.getEntryKeys(4).map(key => key.value); expect(receivedMessageFees).toEqual(expectedMessageFees); }); }); diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts index 1ac914256e3..e1b0435db8a 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts @@ -38,7 +38,7 @@ export class L1ToL2MessageStore { * for removing messages or fetching multiple messages. */ export class PendingL1ToL2MessageStore extends L1ToL2MessageStore { - getentryKeys(limit: number): Fr[] { + getEntryKeys(limit: number): Fr[] { if (limit < 1) { return []; } diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index dcf30bea698..9d27331589e 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -246,8 +246,8 @@ export class MemoryArchiverStore implements ArchiverDataStore { * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP). * @returns The requested L1 to L2 entry keys. */ - public getPendingL1ToL2entryKeys(limit: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP): Promise { - return Promise.resolve(this.pendingL1ToL2Messages.getentryKeys(limit)); + public getPendingL1ToL2EntryKeys(limit: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP): Promise { + return Promise.resolve(this.pendingL1ToL2Messages.getEntryKeys(limit)); } /** diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 63ed1193d9f..22eaf2f2938 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -161,7 +161,7 @@ export abstract class TypedOracle { throw new Error('Not available.'); } - getL1ToL2MembershipWitness(_msgKey: Fr): Promise> { + getL1ToL2MembershipWitness(_entryKey: Fr): Promise> { throw new Error('Not available.'); } From 8dc56878017d8ecfe75f335d73401786eb8fb6f8 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Fri, 1 Mar 2024 10:46:02 +0000 Subject: [PATCH 7/7] chore: address comments --- .../aztec-nr/aztec/src/oracle/get_membership_witness.nr | 1 - .../end-to-end/src/e2e_public_cross_chain_messaging.test.ts | 4 ++-- yarn-project/simulator/src/client/private_execution.test.ts | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr index 9efcdd6cd8e..1e82b12c91e 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr @@ -2,7 +2,6 @@ use dep::protocol_types::{constants::{ARCHIVE_HEIGHT, CONTRACT_TREE_HEIGHT, NOTE global CONTRACT_TREE_ID = 0; global NOTE_HASH_TREE_ID = 2; -global L1_TO_L2_MESSAGE_TREE = 4; global ARCHIVE_TREE_ID = 5; // Note: We have M here because we need to somehow set it when calling get_membership_witness function and one way to diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 22b30fe4038..b6da1029eb0 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -52,7 +52,7 @@ describe('e2e_public_cross_chain_messaging', () => { user1Wallet = wallets[0]; user2Wallet = wallets[1]; await publicDeployAccounts(wallets[0], accounts.slice(0, 2)); - }, 300_00); + }, 30_000); beforeEach(async () => { crossChainTestHarness = await CrossChainTestHarness.new( @@ -324,7 +324,7 @@ describe('e2e_public_cross_chain_messaging', () => { { value: fee } as any, ); - // We check that the message was correctly injected by checking the emitted even + // We check that the message was correctly injected by checking the emitted event { const txReceipt = await crossChainTestHarness.publicClient.waitForTransactionReceipt({ hash: txHash, diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 36a82c3aa60..6ad0271bf49 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -618,7 +618,6 @@ describe('Private Execution test suite', () => { }); it('Invalid membership proof', async () => { - // Where is this one failing? Because we are not updating the header? preimage = computePreimage(); args = computeArgs();