Skip to content

Commit

Permalink
L2 block. (#88)
Browse files Browse the repository at this point in the history
* Add L2 Block package.

* Use l2-block in other packages.
  • Loading branch information
LeilaWang authored Mar 28, 2023
1 parent f837893 commit cccf9fe
Show file tree
Hide file tree
Showing 50 changed files with 359 additions and 265 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The Aztec 3 system consists of the following sub projects.
- `kernel-prover`
- `key-store`
- `l1-contracts`
- `l2-block`
- `p2p`
- `prover-client`
- `aztec-node`
Expand Down
1 change: 1 addition & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ PROJECTS=(
"yarn-project/foundation:yarn build"
"yarn-project/ethereum.js:yarn build"
"yarn-project/l1-contracts:yarn build"
"yarn-project/l2-block:yarn build"
"yarn-project/merkle-tree:yarn build"
"yarn-project/archiver:yarn build"
"yarn-project/world-state:yarn build"
Expand Down
38 changes: 20 additions & 18 deletions build_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"projectDir": "yarn-project/archiver",
"dockerfile": "archiver/Dockerfile",
"rebuildPatterns": ["^yarn-project/archiver/"],
"dependencies": ["yarn-project-base", "ethereum.js", "l1-contracts"]
"dependencies": ["foundation", "ethereum.js", "l1-contracts", "l2-block"]
},
"aztec-cli": {
"buildDir": "yarn-project",
Expand Down Expand Up @@ -85,49 +85,56 @@
"projectDir": "yarn-project/ethereum.js",
"dockerfile": "ethereum.js/Dockerfile",
"rebuildPatterns": ["^yarn-project/ethereum.js/"],
"dependencies": ["yarn-project-base", "foundation"]
"dependencies": ["foundation"]
},
"foundation": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/foundation",
"dockerfile": "foundation/Dockerfile",
"rebuildPatterns": ["^yarn-project/foundation/"],
"dependencies": []
"dependencies": ["yarn-project-base"]
},
"kernel-prover": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/kernel-prover",
"dockerfile": "kernel-prover/Dockerfile",
"rebuildPatterns": ["^yarn-project/kernel-prover/"],
"dependencies": ["yarn-project-base"]
"dependencies": ["acir-simulator"]
},
"key-store": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/key-store",
"dockerfile": "key-store/Dockerfile",
"rebuildPatterns": ["^yarn-project/key-store/"],
"dependencies": ["yarn-project-base"]
"dependencies": ["foundation"]
},
"l2-block": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/l2-block",
"dockerfile": "l2-block/Dockerfile",
"rebuildPatterns": ["^yarn-project/l2-block/"],
"dependencies": ["foundation"]
},
"merkle-tree": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/merkle-tree",
"dockerfile": "merkle-tree/Dockerfile",
"rebuildPatterns": ["^yarn-project/merkle-tree/"],
"dependencies": ["yarn-project-base", "foundation"]
"dependencies": ["foundation"]
},
"noir-contracts": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/noir-contracts",
"dockerfile": "noir-contracts/Dockerfile",
"rebuildPatterns": ["^yarn-project/noir-contracts/"],
"dependencies": ["yarn-project-base", "foundation"]
"dependencies": ["foundation"]
},
"p2p": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/p2p",
"dockerfile": "p2p/Dockerfile",
"rebuildPatterns": ["^yarn-project/p2p/"],
"dependencies": ["yarn-project-base", "archiver", "foundation"]
"dependencies": ["foundation", "l2-block"]
},
"prover-client": {
"buildDir": "yarn-project",
Expand All @@ -142,7 +149,7 @@
"dockerfile": "aztec-node/Dockerfile",
"rebuildPatterns": ["^yarn-project/aztec-node/"],
"dependencies": [
"yarn-project-base",
"foundation",
"archiver",
"world-state",
"p2p",
Expand All @@ -156,23 +163,18 @@
"dockerfile": "sequencer-client/Dockerfile",
"rebuildPatterns": ["^yarn-project/sequencer-client/"],
"dependencies": [
"yarn-project-base",
"world-state",
"foundation",
"world-state",
"ethereum.js",
"p2p",
"archiver"
"l2-block"
]
},
"world-state": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/world-state",
"dockerfile": "world-state/Dockerfile",
"rebuildPatterns": ["^yarn-project/world-state/"],
"dependencies": [
"yarn-project-base",
"merkle-tree",
"archiver",
"foundation"
]
"dependencies": ["foundation", "merkle-tree", "l2-block"]
}
}
29 changes: 0 additions & 29 deletions build_manifest.sh

This file was deleted.

1 change: 1 addition & 0 deletions yarn-project/archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@aztec/ethereum.js": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/l1-contracts": "workspace:^",
"@aztec/l2-block": "workspace:^",
"debug": "^4.3.4",
"tsc-watch": "^6.0.0",
"tslib": "^2.5.0",
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { EthAddress } from '@aztec/ethereum.js/eth_address';
import { RollupAbi, YeeterAbi } from '@aztec/l1-contracts/viem';
import { L2Block } from '@aztec/l2-block';
import { jest } from '@jest/globals';
import { mock, MockProxy } from 'jest-mock-extended';
import { encodeFunctionData, Log, PublicClient, toHex, Transaction } from 'viem';
import { Archiver, mockRandomL2Block } from './archiver.js';
import { Archiver } from './archiver.js';

describe('Archiver', () => {
const rollupAddress = '0x0000000000000000000000000000000000000000';
Expand Down Expand Up @@ -63,7 +64,7 @@ function makeRollupEvent(blockNum: number) {
*/
function makeRollupTx(blockNum: number) {
const proof = `0x`;
const block = toHex(mockRandomL2Block(blockNum).encode());
const block = toHex(L2Block.random(blockNum).encode());
const input = encodeFunctionData({ abi: RollupAbi, functionName: 'process', args: [proof, block] });
return { input } as Transaction<bigint, number>;
}
36 changes: 2 additions & 34 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { fr, makeAppendOnlyTreeSnapshot, makeEthAddress } from '@aztec/circuits.js/factories';
import { EthAddress } from '@aztec/ethereum.js/eth_address';
import { createDebugLogger } from '@aztec/foundation';
import { INITIAL_ROLLUP_ID } from '@aztec/l1-contracts';
import { RollupAbi, YeeterAbi } from '@aztec/l1-contracts/viem';
import { L2Block, L2BlockSource } from '@aztec/l2-block';
import { createPublicClient, decodeFunctionData, getAddress, Hex, hexToBytes, http, Log, PublicClient } from 'viem';
import { localhost } from 'viem/chains';
import { ArchiverConfig } from './config.js';
import { ContractData, L2Block } from '../l2_block/l2_block.js';
import { L2BlockSource } from '../l2_block/l2_block_source.js';
import { INITIAL_ROLLUP_ID } from '@aztec/l1-contracts';

/**
* Pulls L2 blocks in a non-blocking manner and provides interface for their retrieval.
Expand Down Expand Up @@ -240,33 +238,3 @@ export class Archiver implements L2BlockSource {
return Promise.resolve(this.l2Blocks[this.l2Blocks.length - 1].number);
}
}

/**
* Creates a random L2Block with the given block number.
* @param l2BlockNum - Block number.
* @returns Random L2Block.
*/
export function mockRandomL2Block(l2BlockNum: number): L2Block {
const newNullifiers = [fr(0x1), fr(0x2), fr(0x3), fr(0x4)];
const newCommitments = [fr(0x101), fr(0x102), fr(0x103), fr(0x104)];
const newContracts = [fr(0x201)];
const newContractsData: ContractData[] = [new ContractData(fr(0x301), makeEthAddress(0x302))];

return new L2Block(
l2BlockNum,
makeAppendOnlyTreeSnapshot(0),
makeAppendOnlyTreeSnapshot(0),
makeAppendOnlyTreeSnapshot(0),
makeAppendOnlyTreeSnapshot(0),
makeAppendOnlyTreeSnapshot(0),
makeAppendOnlyTreeSnapshot(newCommitments.length),
makeAppendOnlyTreeSnapshot(newNullifiers.length),
makeAppendOnlyTreeSnapshot(newContracts.length),
makeAppendOnlyTreeSnapshot(1),
makeAppendOnlyTreeSnapshot(1),
newCommitments,
newNullifiers,
newContracts,
newContractsData,
);
}
6 changes: 1 addition & 5 deletions yarn-project/archiver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { localhost } from 'viem/chains';
import { Archiver } from './archiver/index.js';

export * from './archiver/index.js';
export * from './block_downloader/index.js';
export * from './l2_block/index.js';
export * from '@aztec/l2-block';

const {
ETHEREUM_HOST = 'http://localhost:8545/',
Expand Down Expand Up @@ -49,6 +48,3 @@ if (process.argv[1] === fileURLToPath(import.meta.url).replace(/\/index\.js$/, '
process.exit(1);
});
}

export { Archiver, mockRandomL2Block } from './archiver/index.js';
export * from './l2_block/l2_block.js';
2 changes: 0 additions & 2 deletions yarn-project/archiver/src/l2_block/index.ts

This file was deleted.

11 changes: 6 additions & 5 deletions yarn-project/archiver/test/archiver-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { EthereumRpc } from '@aztec/ethereum.js/eth_rpc';
import { WalletProvider } from '@aztec/ethereum.js/provider';
import { Rollup, Yeeter } from '@aztec/l1-contracts';
import { L2Block } from '@aztec/l2-block';
import { beforeAll, describe, expect, it } from '@jest/globals';
import { createPublicClient, hexToBytes, http } from 'viem';
import { localhost } from 'viem/chains';
import { Archiver, INITIAL_BLOCK_NUM, L2Block, mockRandomL2Block } from '../src/index.js';
import { Archiver, INITIAL_BLOCK_NUM } from '../src/index.js';

// Accounts 4 and 5 of Anvil default startup with mnemonic: 'test test test test test test test test test test test junk'
const sequencerPK = '0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a';
Expand All @@ -21,7 +22,7 @@ describe('Archiver integration', () => {
beforeAll(async () => {
({ rollup, yeeter } = await deployContracts());

l2Block = mockRandomL2Block(INITIAL_BLOCK_NUM);
l2Block = L2Block.random(INITIAL_BLOCK_NUM);
l2Proof = Buffer.alloc(0);

const publicClient = createPublicClient({
Expand All @@ -34,8 +35,8 @@ describe('Archiver integration', () => {

it('reads l2block from archiver initial sync', async () => {
await rollup.methods.process(l2Proof, l2Block.encode()).send({ gas: 3e6 }).getReceipt(true, 0);
await archiver.start();

await archiver.start();
const blocks = await archiver.getL2Blocks(0, 1);
await archiver.stop();

Expand Down Expand Up @@ -64,4 +65,4 @@ async function deployContracts() {
const yeeter = new Yeeter(ethRpc, deployedYeeter.address, { from: sequencer });

return { rollup, yeeter, deployer, sequencer, ethRpc };
}
}
3 changes: 3 additions & 0 deletions yarn-project/archiver/tsconfig.dest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
},
{
"path": "../l1-contracts/tsconfig.dest.json"
},
{
"path": "../l2-block/tsconfig.dest.json"
}
]
}
3 changes: 3 additions & 0 deletions yarn-project/archiver/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
},
{
"path": "../l1-contracts/tsconfig.dest.json"
},
{
"path": "../l2-block/tsconfig.dest.json"
}
],
"include": ["src", "test"]
Expand Down
1 change: 1 addition & 0 deletions yarn-project/l2-block/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@aztec/foundation/eslint');
15 changes: 15 additions & 0 deletions yarn-project/l2-block/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder
COPY foundation foundation
COPY circuits.js circuits.js
COPY l2-block l2-block
WORKDIR /usr/src/yarn-project/l2-block
RUN yarn build && yarn formatting && yarn test

# Prune dev dependencies. See comment in base image.
RUN yarn cache clean
RUN yarn workspaces focus --production > /dev/null

FROM node:18-alpine
COPY --from=builder /usr/src/yarn-project/l2-block /usr/src/yarn-project/l2-block
WORKDIR /usr/src/yarn-project/l2-block
ENTRYPOINT ["yarn"]
1 change: 1 addition & 0 deletions yarn-project/l2-block/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# L2 Block
46 changes: 46 additions & 0 deletions yarn-project/l2-block/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@aztec/l2-block",
"version": "0.0.0",
"type": "module",
"exports": "./dest/index.js",
"typedoc": {
"entryPoint": "./src/index.ts",
"tsconfig": "./tsconfig.dest.json"
},
"scripts": {
"build": "yarn clean && tsc -b tsconfig.dest.json",
"build:dev": "tsc -b tsconfig.dest.json --watch",
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint --max-warnings 31 ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --passWithNoTests"
},
"jest": {
"preset": "ts-jest/presets/default-esm",
"globals": {
"ts-jest": {
"useESM": true
}
},
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"testRegex": "./src/.*\\.test\\.ts$",
"rootDir": "./src"
},
"dependencies": {
"@aztec/circuits.js": "workspace:^",
"@aztec/foundation": "workspace:^",
"tslib": "^2.5.0"
},
"devDependencies": {
"@jest/globals": "^29.4.3",
"@rushstack/eslint-patch": "^1.1.4",
"@types/jest": "^29.4.0",
"@types/node": "^18.7.23",
"jest": "^28.1.3",
"jest-mock-extended": "^3.0.3",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
}
}
Loading

0 comments on commit cccf9fe

Please sign in to comment.