Skip to content

Commit

Permalink
chore: remove unused log and fix find and replace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Feb 29, 2024
1 parent 4b9fe54 commit a8f42de
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 83 deletions.
64 changes: 32 additions & 32 deletions l1-contracts/test/portals/UniswapPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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)),
Expand All @@ -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));
Expand Down
14 changes: 0 additions & 14 deletions noir-projects/aztec-nr/aztec/src/messaging.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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];
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export class Archiver implements ArchiveSource {
* @returns The requested L1 to L2 messages' keys.
*/
getPendingL1ToL2EntryKeys(limit: number): Promise<Fr[]> {
return this.store.getPendingL1ToL2entryKeys(limit);
return this.store.getPendingL1ToL2EntryKeys(limit);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fr[]>;
getPendingL1ToL2EntryKeys(limit: number): Promise<Fr[]>;

/**
* Gets the confirmed L1 to L2 message corresponding to the given entry key.
Expand Down
34 changes: 17 additions & 17 deletions yarn-project/archiver/src/archiver/archiver_store_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,30 +185,30 @@ 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 () => {
const message = L1ToL2Message.random(Fr.random());
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!]);
});
});

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.getPendingL1ToL2entryKeys(1)).resolves.toEqual([message.entryKey!]);
await expect(store.getPendingL1ToL2EntryKeys(1)).resolves.toEqual([message.entryKey!]);
});

it('returns messages ordered by fee', async () => {
Expand All @@ -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([]);
});
});

Expand All @@ -240,22 +240,22 @@ 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 () => {
const message = L1ToL2Message.random(Fr.random());
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!]);
});
});

Expand All @@ -264,32 +264,32 @@ 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 () => {
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([]);

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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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!]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fr[]> {
return Promise.resolve(this.#messageStore.getPendingentryKeysByFee(limit));
getPendingL1ToL2EntryKeys(limit: number): Promise<Fr[]> {
return Promise.resolve(this.#messageStore.getPendingEntryKeysByFee(limit));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading

0 comments on commit a8f42de

Please sign in to comment.