Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 8, 2024
1 parent 9b4bbed commit e5b74cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;

Expand All @@ -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)
Expand Down

0 comments on commit e5b74cb

Please sign in to comment.