From 4b9fe546e67a1a89170b68cb36e06583cc221e0d Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 29 Feb 2024 21:46:26 +0000 Subject: [PATCH] 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 1eaca0957ba9..b6a4f1cef7db 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 c3bddba93a5e..0e36e4522f72 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 421199522646..4551b27ce180 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 454985b248b9..25587cc5b893 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 958a5e863f46..32beec4e3909 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 d5244dddf809..88fb7c7fc4b6 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 5b77bb9fd312..1c1241e02ce8 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 bd19250a93cc..e87170844179 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 012c75766911..05ae69234444 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 636788133a3b..ad648de6ccfa 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 f7466dade14d..bcaf305488e8 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 0a2958a88e6e..6f9eea16528c 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 1ec3ec9b197f..4b0be6012e0b 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 3a60f3004092..8335eb0fca8e 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 fc0e57334b65..1ac914256e3e 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 4dcd8e60c8f7..dcf30bea6984 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 95566b3560f8..a1dd850558ab 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 fb55df3205c4..e3b287c8c431 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 95a7207ed7da..09bbbad70acc 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 3d08e4767009..22b30fe40380 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 c1edff0af937..edc904ebfc94 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 df1029d78cca..32525ffd5781 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 f4987d485b96..ffe8bf2b2eb1 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 24bb3375e4c8..c44f11a1c3cc 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 8a68d7441f65..4c953463ef52 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 6d9a19cb2dac..ba901a80854e 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 f3f3e570ca28..6f229971b5ef 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 c61a52d2070c..c973fc3cec47 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. |