From 978ce04864a073c685b3e9db3024d35d0403b0c7 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Sun, 17 Sep 2023 14:27:49 +0000 Subject: [PATCH] move address types to aztec-nr and minor ts updates --- yarn-project/aztec-nr/aztec/src/types.nr | 1 + .../aztec/src/types/address.nr} | 0 .../end-to-end/src/cli_docs_sandbox.test.ts | 2 +- .../src/e2e_cross_chain_messaging.test.ts | 7 ++- .../e2e_public_cross_chain_messaging.test.ts | 4 +- .../src/fixtures/cross_chain_test_harness.ts | 16 +++---- .../src/uniswap_trade_on_l1_from_l2.test.ts | 2 - .../token_bridge_contract/src/main.nr | 3 +- .../src/token_interface.nr | 1 - .../src/contracts/token_contract/src/main.nr | 3 +- .../src/contracts/token_contract/src/types.nr | 48 ------------------- 11 files changed, 21 insertions(+), 66 deletions(-) rename yarn-project/{noir-contracts/src/contracts/token_bridge_contract/src/types.nr => aztec-nr/aztec/src/types/address.nr} (100%) diff --git a/yarn-project/aztec-nr/aztec/src/types.nr b/yarn-project/aztec-nr/aztec/src/types.nr index 81b7155d4021..802ce648c491 100644 --- a/yarn-project/aztec-nr/aztec/src/types.nr +++ b/yarn-project/aztec-nr/aztec/src/types.nr @@ -1,3 +1,4 @@ +mod address; mod point; mod vec; // This can/should be moved out into an official noir library mod type_serialisation; \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/types.nr b/yarn-project/aztec-nr/aztec/src/types/address.nr similarity index 100% rename from yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/types.nr rename to yarn-project/aztec-nr/aztec/src/types/address.nr diff --git a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts index 3c046c9c8632..6a0010aae8bd 100644 --- a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts +++ b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts @@ -102,8 +102,8 @@ SchnorrAccountContractAbi SchnorrHardcodedAccountContractAbi SchnorrSingleKeyAccountContractAbi TestContractAbi -TokenContractAbi TokenBridgeContractAbi +TokenContractAbi UniswapContractAbi // docs:end:example-contracts `; diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index 88a8b250ab78..da263d7569d7 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -72,19 +72,22 @@ describe('e2e_cross_chain_messaging', () => { // 1. Mint tokens on L1 await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); + + // 2. Deposit tokens to the TokenPortal const messageKey = await crossChainTestHarness.sendTokensToPortal(bridgeAmount, secretHash); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount); // Wait for the archiver to process the message await delay(5000); /// waiting 5 seconds. - // Perform another unrelated transaction on L2 to progress the rollup. + // Perform an unrelated transaction on L2 to progress the rollup. Here we mint public tokens. const unrelatedMintAmount = 99n; await crossChainTestHarness.mintTokensPublicOnL2(unrelatedMintAmount); await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, unrelatedMintAmount); // 3. Consume L1-> L2 message and mint private tokens on L2 await crossChainTestHarness.consumeMessageOnAztecAndMintSecretly(bridgeAmount, messageKey, secret); + // tokens were minted privately in a TransparentNote which the owner (person who knows the secret) must redeem: await crossChainTestHarness.redeemShieldPrivatelyOnL2(bridgeAmount, secret); await crossChainTestHarness.expectPrivateBalanceOnL2(ownerAddress, bridgeAmount); @@ -116,4 +119,6 @@ describe('e2e_cross_chain_messaging', () => { expect(await outbox.read.contains([entryKey.toString(true)])).toBeFalsy(); }, 120_000); + + // TODO: Fialure cases! }); 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 bba6b576e19a..d51b4ab0aa0c 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 @@ -82,7 +82,7 @@ describe('e2e_public_cross_chain_messaging', () => { // 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 tokens to owner + // Perform an unrelated transaction on L2 to progress the rollup. Here we mint public tokens. const unrelatedMintAmount = 99n; await crossChainTestHarness.mintTokensPublicOnL2(unrelatedMintAmount); await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, unrelatedMintAmount); @@ -93,7 +93,7 @@ describe('e2e_public_cross_chain_messaging', () => { await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, balanceBefore + bridgeAmount); const afterBalance = balanceBefore + bridgeAmount; - // // time to withdraw the funds again! + // time to withdraw the funds again! logger('Withdrawing funds from L2'); // 4. Give approval to bridge to burn owner's funds: diff --git a/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts index 140666267815..7c60c1de3ed2 100644 --- a/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts @@ -42,7 +42,7 @@ export class CrossChainTestHarness { }); // Deploy and initialize all required contracts - logger(`Deploying and initializing token, portal and its bridge...`); + logger('Deploying and initializing token, portal and its bridge...'); const contracts = await deployAndInitializeStandardizedTokenAndBridgeContracts( wallet, walletClient, @@ -51,19 +51,19 @@ export class CrossChainTestHarness { owner.address, underlyingERC20Address, ); - const l2token = contracts.token; - const l2bridge = contracts.bridge; + const l2Token = contracts.token; + const l2Bridge = contracts.bridge; const underlyingERC20 = contracts.underlyingERC20; const tokenPortal = contracts.tokenPortal; const tokenPortalAddress = contracts.tokenPortalAddress; - logger(`Deployed and initialized token, portal and its bridge.`); + logger('Deployed and initialized token, portal and its bridge.'); if (initialBalance) { logger(`Minting ${initialBalance} tokens to ${owner.address}...`); - const mintTx = l2token.methods.mint_public({ address: owner.address }, initialBalance).send(); + const mintTx = l2Token.methods.mint_public({ address: owner.address }, initialBalance).send(); const mintReceipt = await mintTx.wait(); expect(mintReceipt.status).toBe(TxStatus.MINED); - expect(l2token.methods.balance_of_public({ address: owner.address }).view()).toBe(initialBalance); + expect(l2Token.methods.balance_of_public({ address: owner.address }).view()).toBe(initialBalance); logger(`Minted ${initialBalance} tokens to ${owner.address}.`); } @@ -73,8 +73,8 @@ export class CrossChainTestHarness { cheatCodes, accounts, logger, - l2token, - l2bridge, + l2Token, + l2Bridge, ethAccount, tokenPortalAddress, tokenPortal, diff --git a/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts b/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts index fa168996aa7d..0985f0b3ca86 100644 --- a/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts +++ b/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts @@ -41,7 +41,6 @@ describe.skip('uniswap_trade_on_l1_from_l2', () => { let ethAccount: EthAddress; let owner: AztecAddress; - let receiver: AztecAddress; const initialBalance = 10n; const wethAmountToBridge = parseEther('1'); @@ -68,7 +67,6 @@ describe.skip('uniswap_trade_on_l1_from_l2', () => { ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]); owner = accounts[0].address; - receiver = accounts[1].address; logger('Deploying DAI Portal, initializing and deploying l2 contract...'); daiCrossChainHarness = await CrossChainTestHarness.new( diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr index adb0cc274cc5..d28b84579798 100644 --- a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr @@ -1,4 +1,3 @@ -mod types; mod util; mod token_interface; @@ -14,10 +13,10 @@ contract TokenBridge { types::type_serialisation::field_serialisation::{ FieldSerialisationMethods, FIELD_SERIALISED_LEN, }, + types::address::{AztecAddress, EthereumAddress}, oracle::compute_selector::compute_selector, }; - use crate::types::{AztecAddress, EthereumAddress}; use crate::token_interface::Token; use crate::util::{get_mint_content_hash, get_withdraw_content_hash, compute_secret_hash}; diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/token_interface.nr b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/token_interface.nr index 45c11562d865..647fca790eac 100644 --- a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/token_interface.nr +++ b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/token_interface.nr @@ -28,7 +28,6 @@ impl Token { ); } - // Private fn mint_private(self: Self, context: PublicContext, amount: Field, secret_hash: Field) { let _return_values = context.call_public_function( self.address, diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr index adfae41aab76..187ecafef294 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr @@ -30,11 +30,12 @@ contract Token { types::type_serialisation::field_serialisation::{ FieldSerialisationMethods, FIELD_SERIALISED_LEN, }, + types::address::{AztecAddress}, oracle::compute_selector::compute_selector, auth::{assert_valid_message_for, assert_valid_public_message_for} }; - use crate::types::{AztecAddress, TransparentNote, TransparentNoteMethods, TRANSPARENT_NOTE_LEN}; + use crate::types::{TransparentNote, TransparentNoteMethods, TRANSPARENT_NOTE_LEN}; use crate::util::{compute_message_hash}; struct Storage { diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types.nr index 9161fba10180..d2deceb268f9 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types.nr @@ -10,54 +10,6 @@ use dep::aztec::constants_gen::GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET; global TRANSPARENT_NOTE_LEN: Field = 2; - -struct AztecAddress { - address: Field -} - -impl AztecAddress { - fn new(address: Field) -> Self { - Self { - address - } - } - - fn serialize(self: Self) -> [Field; 1] { - [self.address] - } - - fn deserialize(fields: [Field; 1]) -> Self { - Self { - address: fields[0] - } - } -} - -struct EthereumAddress { - address: Field -} - -impl EthereumAddress { - fn new(address: Field) -> Self { - Self { - address - } - } - - - fn serialize(self: Self) -> [Field; 1] { - [self.address] - } - - fn deserialize(fields: [Field; 1]) -> Self { - Self { - address: fields[0] - } - } -} - - - // Transparent note represents a note that is created in the clear (public execution), // but can only be spent by those that know the preimage of the "secret_hash" struct TransparentNote {