Skip to content

Commit

Permalink
we live to try things out'
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed Sep 15, 2023
1 parent 78a3b96 commit 0b81b08
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,17 @@ jobs:
name: "Test"
command: cond_run_script end-to-end ./scripts/run_tests_local e2e_token_contract.test.ts

e2e-token-bridge-contract:
machine:
image: ubuntu-2004:202010-01
resource_class: large
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_run_script end-to-end ./scripts/run_tests_local e2e_token_bridge_contract.test.ts

e2e-private-token-contract:
machine:
image: ubuntu-2004:202010-01
Expand Down Expand Up @@ -1459,6 +1470,7 @@ workflows:
- e2e-deploy-contract: *e2e_test
- e2e-lending-contract: *e2e_test
- e2e-token-contract: *e2e_test
- e2e-token-bridge-contract: *e2e_test
- e2e-private-token-contract: *e2e_test
- e2e-sandbox-example: *e2e_test
- e2e-multi-transfer-contract: *e2e_test
Expand Down Expand Up @@ -1494,6 +1506,7 @@ workflows:
- e2e-deploy-contract
- e2e-lending-contract
- e2e-token-contract
- e2e-token-bridge-contract
- e2e-private-token-contract
- e2e-sandbox-example
- e2e-multi-transfer-contract
Expand Down
3 changes: 2 additions & 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 @@ -77,7 +77,7 @@ describe('CLI docs sandbox', () => {
logs.splice(0);
};

it('prints example contracts', async () => {
it.only('prints example contracts', async () => {
const docs = `
// docs:start:example-contracts
% aztec-cli example-contracts
Expand All @@ -104,6 +104,7 @@ SchnorrAuthWitnessAccountContractAbi
SchnorrHardcodedAccountContractAbi
SchnorrSingleKeyAccountContractAbi
TestContractAbi
TokenBridgeContractAbi
TokenContractAbi
UniswapContractAbi
// docs:end:example-contracts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('e2e_token_bridge_contract', () => {
tokenPortal = contracts.tokenPortal;
underlyingERC20 = contracts.underlyingERC20;
logger(`Deployed and initialized token, portal and its bridge.`);
}, 60_000);
}, 65_000);

afterEach(async () => {
await aztecNode?.stop();
Expand Down Expand Up @@ -139,7 +139,9 @@ describe('e2e_token_bridge_contract', () => {

// 3. Consume message on aztec and mint publicly
logger('Consuming messages on L2');
const tx = bridge.methods.mint_public(bridgeAmount, messageKey, secret, { address: ethAccount.toField() }).send();
const tx = bridge.methods
.deposit_public(bridgeAmount, messageKey, secret, { address: ethAccount.toField() })
.send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
const afterBalance = await token.methods.balance_of_public({ address: ownerAddress }).view();
Expand Down Expand Up @@ -188,7 +190,11 @@ describe('e2e_token_bridge_contract', () => {
const secretHash = await computeMessageSecretHash(secret);

// 1. Mint tokens on L1
await mintTokensOnL1(l1TokenBalance);
// TODO (#2291): Because same owner is used across two tests, l1 balance already exists. This is why we have two separate cross chain tests.
// Separate them like before
if ((await underlyingERC20.read.balanceOf([ethAccount.toString()])) === 0n) {
await mintTokensOnL1(l1TokenBalance);
}

// 2. Deposit tokens to the TokenPortal
const messageKey = await depositTokensToPortal(bridgeAmount, secretHash);
Expand All @@ -205,7 +211,7 @@ describe('e2e_token_bridge_contract', () => {

// 3. Consume message on aztec and mint publicly
logger('Consuming messages on L2');
const tx = bridge.methods.mint(bridgeAmount, messageKey, secret, { address: ethAccount.toField() }).send();
const tx = bridge.methods.deposit(bridgeAmount, messageKey, secret, { address: ethAccount.toField() }).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
const txClaim = token.methods.redeem_shield({ address: ownerAddress }, bridgeAmount, secret).send();
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export async function deployAndInitializeStandardizedTokenAndBridgeContracts(
throw new Error(`Bridge token is not ${l2Token.address}`);

// make the bridge a minter on the token:
const makeMinterTx = l2Token.methods.set_minter({ address: bridge.address }, 1).send();
const makeMinterTx = l2Token.methods.set_minter({ address: bridge.address }, true).send();
const makeMinterReceipt = await makeMinterTx.wait();
if (makeMinterReceipt.status !== TxStatus.MINED)
throw new Error(`Make bridge a minter tx status is ${makeMinterReceipt.status}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract TokenBridge {

// Consumes a L1->L2 message and calls the token contract to mint the appropriate amount publicly
#[aztec(public)]
fn mint_public(
fn deposit_public(
amount: Field,
msg_key: Field, // L1 to L2 message key as derived from the inbox contract
secret: Field,
Expand All @@ -60,14 +60,17 @@ contract TokenBridge {
context.consume_l1_to_l2_message(msg_key, content_hash, secret);

// Mint token on L2
Token::at(storage.token.read()).mint_public(context, context.msg_sender(), amount)
// If I call using the interface, for some reason, the kernel queues mint_public twice and mints double the tokens.
// So, for now, call the token contract directly
// Token::at(storage.token.read()).mint_public(context, context.msg_sender(), amount)
context.call_public_function(storage.token.read(), compute_selector("mint_public((Field),Field)"), [context.msg_sender(), amount])[0]
}

// Consumes a L1->L2 message and calls the token contract to mint the appropriate amount in private assets
// User needs to call token.redeem_shield() to get the private assets
// This method is public because it accesses public storage. For similar reasons, the corresponding call on the token is also public
#[aztec(public)]
fn mint(
fn deposit(
amount: Field,
msg_key: Field, // L1 to L2 message key as derived from the inbox contract
secret: Field,
Expand Down Expand Up @@ -111,24 +114,29 @@ contract TokenBridge {
// Requires `from` to give approval to the bridge to burn tokens on their behalf using witness signatures
#[aztec(private)]
fn withdraw(
token:AztecAddress, // can't read public storage in private, so pass the token and call an internal public fn to check if provided token is as expected.
token: AztecAddress, // can't read public storage in private, so pass the token and call an internal public fn to check if provided token is as expected.
recipient: EthereumAddress, // ethereum address to withdraw to
amount: Field,
callerOnL1: EthereumAddress, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call)
nonce: Field, // used in creating the approval message (to prevent replay attacks)
) -> Field {
// can't read public storage (`storage.token`) in private so let the user pass it in
// later assert that this token address is as expected
let return_value = Token::at(token.address).burn(&mut context, context.msg_sender(), amount, nonce);

// let return_value = Token::at(token.address).burn(&mut context, context.msg_sender(), amount, nonce);
let return_value = context.call_private_function(
token.address,
compute_selector("burn((Field),Field,Field)"),
[context.msg_sender(), amount, nonce]
);
let content = get_withdraw_content_hash(amount, recipient.address, callerOnL1.address);
// Emit the l2 to l1 message
context.message_portal(content);

// Assert that user provided token address is same as seen in storage.
context.call_public_function(token.address, compute_selector("_assert_token_is_same(Field)"), [token.address]);

return_value
return_value[0]

}

// /// Unconstrained ///
Expand Down

0 comments on commit 0b81b08

Please sign in to comment.