From e5b74cbd4526df4e9aa23efc142cdcaf10422b0c Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 8 Nov 2024 19:00:37 +0000 Subject: [PATCH] WIP --- .../token_bridge_failure_cases.test.ts | 13 ++++---- .../token_bridge_private.test.ts | 30 ++----------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_failure_cases.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_failure_cases.test.ts index f0a0e64c90be..cac9f75b106c 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_failure_cases.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_failure_cases.test.ts @@ -50,24 +50,25 @@ describe('e2e_cross_chain_messaging token_bridge_failure_cases', () => { await crossChainTestHarness.makeMessageConsumable(claim.messageHash); // Wrong message hash - const content = sha256ToField([ - Buffer.from(toFunctionSelector('mint_private(bytes32,uint256)').substring(2), 'hex'), - claim.claimSecretHash, - new Fr(bridgeAmount), + const wrongBridgeAmount = bridgeAmount + 1n; + const wrongMessageContent = sha256ToField([ + Buffer.from(toFunctionSelector('mint_private(uint256)').substring(2), 'hex'), + new Fr(wrongBridgeAmount), ]); const wrongMessage = new L1ToL2Message( new L1Actor(crossChainTestHarness.tokenPortalAddress, crossChainTestHarness.publicClient.chain.id), new L2Actor(l2Bridge.address, 1), - content, + wrongMessageContent, claim.claimSecretHash, new Fr(claim.messageLeafIndex), ); + // Sending wrong secret hashes should fail: await expect( l2Bridge .withWallet(user2Wallet) - .methods.claim_private(claim.claimSecretHash, bridgeAmount, claim.claimSecret, claim.messageLeafIndex) + .methods.claim_private(ownerAddress, wrongBridgeAmount, claim.claimSecret, claim.messageLeafIndex) .prove(), ).rejects.toThrow(`No L1 to L2 message found for message hash ${wrongMessage.hash().toString()}`); }, 60_000); diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts index a87116a3d790..87af389c0e33 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts @@ -1,9 +1,7 @@ -import { Fr, L1Actor, L1ToL2Message, L2Actor } from '@aztec/aztec.js'; -import { sha256ToField } from '@aztec/foundation/crypto'; +import { Fr } from '@aztec/aztec.js'; import { RollupAbi } from '@aztec/l1-artifacts'; import { getContract } from 'viem'; -import { toFunctionSelector } from 'viem/utils'; import { CrossChainMessagingTest } from './cross_chain_messaging_test.js'; @@ -103,7 +101,8 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => { }); // docs:end:e2e_private_cross_chain - it('Someone else can mint funds to me on my behalf (privately)', async () => { + // This test checks that it's enough to have the claim secret to claim the funds to whoever we want. + it('Claim secret is enough to consume the message', async () => { const l1TokenBalance = 1000000n; const bridgeAmount = 100n; @@ -114,29 +113,6 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => { // Wait for the message to be available for consumption await crossChainTestHarness.makeMessageConsumable(claim.messageHash); - // 3. Consume L1 -> L2 message and mint private tokens on L2 - const wrongBridgeAmount = bridgeAmount + 1n; - const wrongMessageContent = sha256ToField([ - Buffer.from(toFunctionSelector('mint_private(uint256)').substring(2), 'hex'), - new Fr(wrongBridgeAmount), - ]); - - const wrongMessage = new L1ToL2Message( - new L1Actor(crossChainTestHarness.tokenPortalAddress, crossChainTestHarness.publicClient.chain.id), - new L2Actor(l2Bridge.address, 1), - wrongMessageContent, - claim.claimSecretHash, - new Fr(claim.messageLeafIndex), - ); - - // Sending wrong secret hashes should fail: - await expect( - l2Bridge - .withWallet(user2Wallet) - .methods.claim_private(ownerAddress, wrongBridgeAmount, claim.claimSecret, claim.messageLeafIndex) - .prove(), - ).rejects.toThrow(`No L1 to L2 message found for message hash ${wrongMessage.hash().toString()}`); - // send the right one - await l2Bridge .withWallet(user2Wallet)