Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ describe('uniswap_trade_on_l1_from_l2', () => {
const [secretForRedeemingDai, secretHashForRedeemingDai] = await generateClaimSecret();

const withdrawReceipt = await uniswapL2Contract.methods
.swap(
.swap_private(
wethL2Contract.address,
wethL2Bridge.address,
wethAmountToBridge,
Expand All @@ -372,7 +372,7 @@ describe('uniswap_trade_on_l1_from_l2', () => {
// ensure that uniswap contract didn't eat the funds.
await expectPublicBalanceOnL2(uniswapL2Contract.address, 0n, wethL2Contract);

// 6. Consume L2 to L1 message by calling uniswapPortal.swap()
// 6. Consume L2 to L1 message by calling uniswapPortal.swap_private()
logger('Execute withdraw and swap on the uniswapPortal!');
const daiL1BalanceOfPortalBeforeSwap = await daiContract.read.balanceOf([daiTokenPortalAddress.toString()]);
const swapArgs = [
Expand Down
33 changes: 33 additions & 0 deletions yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,37 @@ describe('e2e_cross_chain_messaging', () => {
.simulate(),
).rejects.toThrowError(`Unknown auth witness for message hash 0x${expectedBurnMessageHash.toString('hex')}`);
});

it("Can't claim funds publicly if they were deposited privately", async () => {
// 1. Mint tokens on L1
const bridgeAmount = 100n;
await crossChainTestHarness.mintTokensOnL1(bridgeAmount);

// 2. Deposit tokens to the TokenPortal
Comment thread
LHerskind marked this conversation as resolved.
Outdated
const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] =
await crossChainTestHarness.generateClaimSecret();

const messageKey = await crossChainTestHarness.sendTokensToPortalPrivate(
bridgeAmount,
secretHashForL2MessageConsumption,
Fr.random(),
);
expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(0n);

// Wait for the archiver to process the message
await delay(5000); /// waiting 5 seconds.

// Perform an unrelated transaction on L2 to progress the rollup. Here we mint public tokens.
await crossChainTestHarness.performL2Transfer(0n);

// 3. Consume L1-> L2 message and mint private tokens on L2
Comment thread
LHerskind marked this conversation as resolved.
Outdated
await expect(
l2Bridge
.withWallet(user2Wallet)
.methods.claim_public(ownerAddress, bridgeAmount, ethAccount, messageKey, secretForL2MessageConsumption)
.simulate(),
).rejects.toThrowError(
"Failed to solve brillig function, reason: explicit trap hit in brillig 'l1_to_l2_message_data.message.content == content'",
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,26 @@ describe('e2e_public_cross_chain_messaging', () => {
.simulate(),
).rejects.toThrowError('Assertion failed: Message not authorized by account');
});

it("can't claim funds privately which were intended for public deposit from the token portal", async () => {
const bridgeAmount = 100n;
const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret();

await crossChainTestHarness.mintTokensOnL1(bridgeAmount);
const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash);
expect(await crossChainTestHarness.getL1BalanceOf(ownerEthAddress)).toBe(0n);

// Wait for the archiver to process the message
await delay(5000); /// waiting 5 seconds.

// Perform an unrelated transaction on L2 to progress the rollup. Here we mint public tokens.
await crossChainTestHarness.performL2Transfer(0n);

await expect(
l2Bridge
.withWallet(user2Wallet)
.methods.claim_private(bridgeAmount, secretHash, ownerEthAddress, messageKey, secret)
.simulate(),
).rejects.toThrowError("Cannot satisfy constraint 'l1_to_l2_message_data.message.content == content");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ export class CrossChainTestHarness {
expect(receipt.status).toBe(TxStatus.MINED);
}

async mintTokensPrivateOnL2(amount: bigint, secretHash: Fr) {
const tx = this.l2Token.methods.mint_private(amount, secretHash).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await this.addPendingShieldNoteToPXE(amount, secretHash, receipt.txHash);
}

async performL2Transfer(transferAmount: bigint) {
// send a transfer tx to force through rollup with the message included
const transferTx = this.l2Token.methods.transfer_public(this.ownerAddress, this.receiver, transferAmount, 0).send();
Expand Down
Loading