Skip to content

Commit

Permalink
move address types to aztec-nr and minor ts updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed Sep 19, 2023
1 parent 55ca3e8 commit 1868a43
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 66 deletions.
1 change: 1 addition & 0 deletions yarn-project/aztec-nr/aztec/src/types.nr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod address;
mod point;
mod vec; // This can/should be moved out into an official noir library
mod type_serialisation;
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/cli_docs_sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ SchnorrHardcodedAccountContractAbi
SchnorrSingleKeyAccountContractAbi
StatefulTestContractAbi
TestContractAbi
TokenContractAbi
TokenBridgeContractAbi
TokenContractAbi
UniswapContractAbi
// docs:end:example-contracts
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -116,4 +119,6 @@ describe('e2e_cross_chain_messaging', () => {

expect(await outbox.read.contains([entryKey.toString(true)])).toBeFalsy();
}, 120_000);

// TODO: Fialure cases!
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}.`);
}

Expand All @@ -73,8 +73,8 @@ export class CrossChainTestHarness {
cheatCodes,
accounts,
logger,
l2token,
l2bridge,
l2Token,
l2Bridge,
ethAccount,
tokenPortalAddress,
tokenPortal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod types;
mod util;
mod token_interface;

Expand All @@ -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};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1868a43

Please sign in to comment.