Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder
COPY . .
RUN cd aztec-js && yarn build
RUN cd aztec.js && yarn build
WORKDIR /usr/src/yarn-project/aztec.js
RUN yarn build && yarn formatting && yarn test

Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"@aztec/aztec-rpc": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/sequencer-client": "workspace:^",
"@aztec/tx": "workspace:^",
"tslib": "^2.4.0"
},
Expand Down
228 changes: 114 additions & 114 deletions yarn-project/end-to-end/src/e2e_zk_token_contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
import { AztecNode } from '@aztec/aztec-node';
import { AztecAddress, AztecRPCServer, Contract, ContractDeployer, Fr } from '@aztec/aztec.js';
import { EthAddress } from '@aztec/ethereum.js/eth_address';
import { EthereumRpc } from '@aztec/ethereum.js/eth_rpc';
import { WalletProvider } from '@aztec/ethereum.js/provider';
import { createDebugLogger } from '@aztec/foundation';
import { ZkTokenContractAbi } from '@aztec/noir-contracts/examples';
import { createAztecNode } from './create_aztec_node.js';
import { createAztecRpcServer } from './create_aztec_rpc_client.js';
import { createProvider, deployRollupContract, deployYeeterContract } from './deploy_l1_contracts.js';

const ETHEREUM_HOST = 'http://localhost:8545';
const MNEMONIC = 'test test test test test test test test test test test junk';

const logger = createDebugLogger('aztec:e2e_zk_token_contract');

describe('e2e_zk_token_contract', () => {
let provider: WalletProvider;
let node: AztecNode;
let aztecRpcServer: AztecRPCServer;
let rollupAddress: EthAddress;
let yeeterAddress: EthAddress;
let accounts: AztecAddress[];
let contract: Contract;

beforeAll(async () => {
provider = createProvider(ETHEREUM_HOST, MNEMONIC, 1);
const ethRpc = new EthereumRpc(provider);
logger('Deploying contracts...');
rollupAddress = await deployRollupContract(provider, ethRpc);
yeeterAddress = await deployYeeterContract(provider, ethRpc);
logger('Deployed contracts...');
});

beforeEach(async () => {
node = await createAztecNode(rollupAddress, yeeterAddress, ETHEREUM_HOST, provider.getPrivateKey(0)!);
aztecRpcServer = await createAztecRpcServer(1, node);
accounts = await aztecRpcServer.getAccounts();
});

afterEach(async () => {
await node.stop();
await aztecRpcServer.stop();
});

const expectStorageSlot = async (accountIdx: number, expectedBalance: bigint) => {
// We only generate 1 note in each test. Balance is the first field of the only note.
// TBD - how to calculate storage slot?
const storageSlot = Fr.ZERO;
const [[balance]] = await aztecRpcServer.getStorageAt(contract.address, storageSlot);
logger(`Account ${accountIdx} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
};

const expectBalance = async (accountIdx: number, expectedBalance: bigint) => {
const balance = await contract.methods.getBalance().call({ from: accounts[accountIdx] });
logger(`Account ${accountIdx} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
};

const deployContract = async (initialBalance = 0n) => {
const deployer = new ContractDeployer(ZkTokenContractAbi, aztecRpcServer);
const receipt = await deployer.deploy(initialBalance).send().getReceipt();
return new Contract(receipt.contractAddress!, ZkTokenContractAbi, aztecRpcServer);
};

/**
* Milestone 1.3
* https://hackmd.io/AG5rb9DyTRu3y7mBptWauA
*/
it.skip('should deploy zk token contract with initial token minted to the account', async () => {
const initialBalance = 987n;
await deployContract(initialBalance);
await expectStorageSlot(0, initialBalance);
await expectStorageSlot(1, 0n);
});

/**
* Milestone 1.4
*/
it.skip('should call mint and increase balance', async () => {
const mintAmount = 65n;

await deployContract();

await expectStorageSlot(0, 0n);
await expectStorageSlot(1, 0n);

const receipt = await contract.methods.mint(mintAmount).send({ from: accounts[1] }).getReceipt();
expect(receipt.status).toBe(true);

await expectStorageSlot(0, 0n);
await expectStorageSlot(1, mintAmount);
});

/**
* Milestone 1.5
*/
it.skip('should call transfer and increase balance of another account', async () => {
const initialBalance = 987n;
const transferAmount = 654n;

await deployContract(initialBalance);

await expectBalance(0, initialBalance);
await expectBalance(1, 0n);

const receipt = await contract.methods.transfer(accounts[1]).send({ from: accounts[0] }).getReceipt();
expect(receipt.status).toBe(true);

await expectBalance(0, initialBalance - transferAmount);
await expectBalance(1, transferAmount);
});
});
// import { AztecNode } from '@aztec/aztec-node';
// import { AztecAddress, AztecRPCServer, Contract, ContractDeployer, Fr } from '@aztec/aztec.js';
// import { EthAddress } from '@aztec/ethereum.js/eth_address';
// import { EthereumRpc } from '@aztec/ethereum.js/eth_rpc';
// import { WalletProvider } from '@aztec/ethereum.js/provider';
// import { createDebugLogger } from '@aztec/foundation';
// import { ZkTokenContractAbi } from '@aztec/noir-contracts/examples';
// import { createAztecNode } from './create_aztec_node.js';
// import { createAztecRpcServer } from './create_aztec_rpc_client.js';
// import { createProvider, deployRollupContract, deployYeeterContract } from './deploy_l1_contracts.js';

// const ETHEREUM_HOST = 'http://localhost:8545';
// const MNEMONIC = 'test test test test test test test test test test test junk';

// const logger = createDebugLogger('aztec:e2e_zk_token_contract');

// describe('e2e_zk_token_contract', () => {
// let provider: WalletProvider;
// let node: AztecNode;
// let aztecRpcServer: AztecRPCServer;
// let rollupAddress: EthAddress;
// let yeeterAddress: EthAddress;
// let accounts: AztecAddress[];
// let contract: Contract;

// beforeAll(async () => {
// provider = createProvider(ETHEREUM_HOST, MNEMONIC, 1);
// const ethRpc = new EthereumRpc(provider);
// logger('Deploying contracts...');
// rollupAddress = await deployRollupContract(provider, ethRpc);
// yeeterAddress = await deployYeeterContract(provider, ethRpc);
// logger('Deployed contracts...');
// });

// beforeEach(async () => {
// node = await createAztecNode(rollupAddress, yeeterAddress, ETHEREUM_HOST, provider.getPrivateKey(0)!);
// aztecRpcServer = await createAztecRpcServer(1, node);
// accounts = await aztecRpcServer.getAccounts();
// });

// afterEach(async () => {
// await node.stop();
// await aztecRpcServer.stop();
// });

// const expectStorageSlot = async (accountIdx: number, expectedBalance: bigint) => {
// // We only generate 1 note in each test. Balance is the first field of the only note.
// // TBD - how to calculate storage slot?
// const storageSlot = Fr.ZERO;
// const [[balance]] = await aztecRpcServer.getStorageAt(contract.address, storageSlot);
// logger(`Account ${accountIdx} balance: ${balance}`);
// expect(balance).toBe(expectedBalance);
// };

// const expectBalance = async (accountIdx: number, expectedBalance: bigint) => {
// const balance = await contract.methods.getBalance().call({ from: accounts[accountIdx] });
// logger(`Account ${accountIdx} balance: ${balance}`);
// expect(balance).toBe(expectedBalance);
// };

// const deployContract = async (initialBalance = 0n) => {
// const deployer = new ContractDeployer(ZkTokenContractAbi, aztecRpcServer);
// const receipt = await deployer.deploy(initialBalance).send().getReceipt();
// return new Contract(receipt.contractAddress!, ZkTokenContractAbi, aztecRpcServer);
// };

// /**
// * Milestone 1.3
// * https://hackmd.io/AG5rb9DyTRu3y7mBptWauA
// */
// it.skip('should deploy zk token contract with initial token minted to the account', async () => {
// const initialBalance = 987n;
// await deployContract(initialBalance);
// await expectStorageSlot(0, initialBalance);
// await expectStorageSlot(1, 0n);
// });

// /**
// * Milestone 1.4
// */
// it.skip('should call mint and increase balance', async () => {
// const mintAmount = 65n;

// await deployContract();

// await expectStorageSlot(0, 0n);
// await expectStorageSlot(1, 0n);

// const receipt = await contract.methods.mint(mintAmount).send({ from: accounts[1] }).getReceipt();
// expect(receipt.status).toBe(true);

// await expectStorageSlot(0, 0n);
// await expectStorageSlot(1, mintAmount);
// });

// /**
// * Milestone 1.5
// */
// it.skip('should call transfer and increase balance of another account', async () => {
// const initialBalance = 987n;
// const transferAmount = 654n;

// await deployContract(initialBalance);

// await expectBalance(0, initialBalance);
// await expectBalance(1, 0n);

// const receipt = await contract.methods.transfer(accounts[1]).send({ from: accounts[0] }).getReceipt();
// expect(receipt.status).toBe(true);

// await expectBalance(0, initialBalance - transferAmount);
// await expectBalance(1, transferAmount);
// });
// });
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('sequencer/circuit_block_builder', () => {
let wasm: BarretenbergWasm;

const emptyProof = new UInt8Vector(Buffer.alloc(32, 0));
const emptyUnverifiedData = Buffer.alloc(0);

beforeAll(async () => {
wasm = new BarretenbergWasm();
Expand Down Expand Up @@ -83,9 +84,6 @@ describe('sequencer/circuit_block_builder', () => {
[MerkleTreeId.DATA_TREE, MerkleTreeId.DATA_TREE_ROOTS_TREE],
[MerkleTreeId.CONTRACT_TREE, MerkleTreeId.CONTRACT_TREE_ROOTS_TREE],
] as const) {
if (rootTree === MerkleTreeId.CONTRACT_TREE_ROOTS_TREE) {
await inspectTree(expectsDb, rootTree);
}
const newTreeInfo = await expectsDb.getTreeInfo(newTree);
await expectsDb.appendLeaves(rootTree, [newTreeInfo.root]);
}
Expand All @@ -109,7 +107,7 @@ describe('sequencer/circuit_block_builder', () => {

it('builds an L2 block', async () => {
// Assemble a fake transaction, we'll tweak some fields below
const tx = new Tx(makePrivateKernelPublicInputs(), emptyProof);
const tx = new Tx(makePrivateKernelPublicInputs(), emptyProof, emptyUnverifiedData);
const txsLeft = [tx, makeEmptyTx()];
const txsRight = [makeEmptyTx(), makeEmptyTx()];
const txs = [...txsLeft, ...txsRight];
Expand All @@ -129,8 +127,6 @@ describe('sequencer/circuit_block_builder', () => {
baseRollupOutputLeft.endNullifierTreeSnapshot = await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE);
baseRollupOutputLeft.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.DATA_TREE);

await inspectTree(expectsDb, MerkleTreeId.CONTRACT_TREE);

// Same for the two txs on the right
await updateExpectedTreesFromTxs(txsRight);
baseRollupOutputRight.endContractTreeSnapshot = await getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PreviousKernelData,
PreviousRollupData,
PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT,
ROLLUP_VK_TREE_HEIGHT,
RootRollupInputs,
RootRollupPublicInputs,
UInt8Vector,
Expand Down Expand Up @@ -274,7 +275,7 @@ export class CircuitPoweredBlockBuilder {

// MembershipWitness for a VK tree to be implemented in the future
FUTURE_NUM,
Array(VK_TREE_HEIGHT).fill(FUTURE_FR),
new MembershipWitness(ROLLUP_VK_TREE_HEIGHT, FUTURE_NUM, Array(ROLLUP_VK_TREE_HEIGHT).fill(FUTURE_FR)),
);
}

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/world-state/src/world-state-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface MerkleTreeDb extends MerkleTreeOperations {
*/
export async function inspectTree(db: MerkleTreeOperations, treeId: MerkleTreeId) {
const info = await db.getTreeInfo(treeId);
let output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`];
const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`];
for (let i = 0; i < info.size; i++) {
output.push(
` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex') ?? '[undefined]')}`,
Expand Down
1 change: 1 addition & 0 deletions yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ __metadata:
dependencies:
"@aztec/aztec-rpc": "workspace:^"
"@aztec/foundation": "workspace:^"
"@aztec/sequencer-client": "workspace:^"
"@aztec/tx": "workspace:^"
"@jest/globals": ^29.4.3
"@rushstack/eslint-patch": ^1.1.4
Expand Down