From 8a0fb4570a5993c120d60aabc6dd0eb87825c36d Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 12:35:13 +0000 Subject: [PATCH 01/15] chore: moved publisher test to e2e --- .../src/l2-block-publisher.test.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename yarn-project/{sequencer-client/src/test/l2-block-publisher.test.ts_disabled => end-to-end/src/l2-block-publisher.test.ts} (100%) diff --git a/yarn-project/sequencer-client/src/test/l2-block-publisher.test.ts_disabled b/yarn-project/end-to-end/src/l2-block-publisher.test.ts similarity index 100% rename from yarn-project/sequencer-client/src/test/l2-block-publisher.test.ts_disabled rename to yarn-project/end-to-end/src/l2-block-publisher.test.ts From 2868186499bb17737b256764b468260fb025d048 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 13:59:36 +0000 Subject: [PATCH 02/15] WIP --- build_manifest.json | 3 +- yarn-project/end-to-end/package.json | 1 + .../end-to-end/src/deploy_l1_contracts.ts | 24 ++- .../end-to-end/src/e2e_block_building.test.ts | 1 - .../end-to-end/src/l2-block-publisher.test.ts | 180 +++++++++++------- yarn-project/end-to-end/tsconfig.json | 3 + yarn-project/sequencer-client/src/index.ts | 7 + yarn-project/sequencer-client/src/utils.ts | 9 - yarn-project/yarn.lock | 1 + 9 files changed, 149 insertions(+), 80 deletions(-) diff --git a/build_manifest.json b/build_manifest.json index 26ed7de3c21..84d3bcc4d8d 100644 --- a/build_manifest.json +++ b/build_manifest.json @@ -188,7 +188,8 @@ "aztec.js", "foundation", "l1-artifacts", - "noir-contracts" + "noir-contracts", + "sequencer-client" ] }, "foundation": { diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 834c6f5a079..41211b370a0 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -29,6 +29,7 @@ "@aztec/foundation": "workspace:^", "@aztec/l1-artifacts": "workspace:^", "@aztec/noir-contracts": "workspace:^", + "@aztec/sequencer-client": "workspace:^", "@types/jest": "^29.5.0", "jest": "^29.5.0", "lodash.times": "^4.3.2", diff --git a/yarn-project/end-to-end/src/deploy_l1_contracts.ts b/yarn-project/end-to-end/src/deploy_l1_contracts.ts index 48d00b3d4f8..ae85fdcfa07 100644 --- a/yarn-project/end-to-end/src/deploy_l1_contracts.ts +++ b/yarn-project/end-to-end/src/deploy_l1_contracts.ts @@ -1,6 +1,8 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { DebugLogger } from '@aztec/foundation/log'; import { + DecoderHelperAbi, + DecoderHelperBytecode, RollupAbi, RollupBytecode, UnverifiedDataEmitterAbi, @@ -18,11 +20,16 @@ import { createWalletClient, http, } from 'viem'; -import { HDAccount } from 'viem/accounts'; +import { HDAccount, PrivateKeyAccount } from 'viem/accounts'; import { foundry } from 'viem/chains'; -export const deployL1Contracts = async (rpcUrl: string, account: HDAccount, logger: DebugLogger) => { - logger('Deploying contracts... (rpcURL: %s)', rpcUrl); +export const deployL1Contracts = async ( + rpcUrl: string, + account: HDAccount | PrivateKeyAccount, + logger: DebugLogger, + deployDecoderHelper = false, +) => { + logger('Deploying contracts...'); const walletClient = createWalletClient({ account, @@ -35,7 +42,7 @@ export const deployL1Contracts = async (rpcUrl: string, account: HDAccount, logg }); const rollupAddress = await deployL1Contract(walletClient, publicClient, RollupAbi, RollupBytecode); - logger(`Deployed rollup contract at ${rollupAddress}`); + logger(`Deployed Rollup at ${rollupAddress}`); const unverifiedDataEmitterAddress = await deployL1Contract( walletClient, @@ -45,9 +52,16 @@ export const deployL1Contracts = async (rpcUrl: string, account: HDAccount, logg ); logger(`Deployed unverified data emitter at ${unverifiedDataEmitterAddress}`); + let decoderHelperAddress: EthAddress | undefined; + if (deployDecoderHelper) { + decoderHelperAddress = await deployL1Contract(walletClient, publicClient, DecoderHelperAbi, DecoderHelperBytecode); + logger(`Deployed DecoderHelper at ${decoderHelperAddress}`); + } + return { rollupAddress, unverifiedDataEmitterAddress, + decoderHelperAddress, }; }; @@ -56,7 +70,7 @@ async function deployL1Contract( publicClient: PublicClient, abi: Narrow, bytecode: Hex, -) { +): Promise { const hash = await walletClient.deployContract({ abi, bytecode, diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 9997ec9612b..dc2fb842955 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -23,7 +23,6 @@ describe('e2e_block_building', () => { beforeEach(async () => { const account = mnemonicToAccount(MNEMONIC); const privKey = account.getHdKey().privateKey; - console.log(config); const { rollupAddress, unverifiedDataEmitterAddress } = await deployL1Contracts(config.rpcUrl, account, logger); config.publisherPrivateKey = Buffer.from(privKey!); diff --git a/yarn-project/end-to-end/src/l2-block-publisher.test.ts b/yarn-project/end-to-end/src/l2-block-publisher.test.ts index d6e333787ef..e43841b3190 100644 --- a/yarn-project/end-to-end/src/l2-block-publisher.test.ts +++ b/yarn-project/end-to-end/src/l2-block-publisher.test.ts @@ -1,3 +1,4 @@ +import { createMemDown } from '@aztec/aztec-node'; import { Fr, KERNEL_NEW_COMMITMENTS_LENGTH, @@ -9,25 +10,38 @@ import { range, } from '@aztec/circuits.js'; import { fr, makeNewContractData, makeProof } from '@aztec/circuits.js/factories'; -import { EthereumRpc } from '@aztec/ethereum.js/eth_rpc'; -import { WalletProvider } from '@aztec/ethereum.js/provider'; -import { DecoderHelper, Rollup, UnverifiedDataEmitter } from '@aztec/l1-contracts'; +import { createDebugLogger } from '@aztec/foundation/log'; +import { + EmptyRollupProver, + L1Publisher, + SoloBlockBuilder, + WasmRollupCircuitSimulator, + getCombinedHistoricTreeRoots, + getL1Publisher, + getVerificationKeys, + makeEmptyProcessedTx as makeEmptyProcessedTxFromHistoricTreeRoots, + makeProcessedTx, + makePublicTx, +} from '@aztec/sequencer-client'; import { MerkleTreeOperations, MerkleTrees } from '@aztec/world-state'; import { beforeAll, describe, expect, it } from '@jest/globals'; import { default as levelup } from 'levelup'; -import { SoloBlockBuilder } from '../block_builder/solo_block_builder.js'; -import { createMemDown } from '../block_builder/solo_block_builder.test.js'; -import { getVerificationKeys, makePublicTx } from '../index.js'; -import { EmptyRollupProver } from '../prover/empty.js'; -import { EthereumjsTxSender } from '../publisher/ethereumjs-tx-sender.js'; -import { L1Publisher } from '../publisher/l1-publisher.js'; +import { PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts'; +import { deployL1Contracts } from './deploy_l1_contracts.js'; import { - makeEmptyProcessedTx as makeEmptyProcessedTxFromHistoricTreeRoots, - makeProcessedTx, -} from '../sequencer/processed_tx.js'; -import { getCombinedHistoricTreeRoots } from '../sequencer/utils.js'; -import { WasmRollupCircuitSimulator } from '../simulator/rollup.js'; -import { hexStringToBuffer } from '../utils.js'; + Chain, + GetContractReturnType, + HttpTransport, + PublicClient, + WalletClient, + createPublicClient, + createWalletClient, + getAddress, + getContract, + http, +} from 'viem'; +import { DecoderHelperAbi, RollupAbi, UnverifiedDataEmitterAbi } from '@aztec/l1-artifacts'; +import { foundry } from 'viem/chains'; // 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'; @@ -35,11 +49,27 @@ const deployerPK = '0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092 const anvilHost = process.env.ANVIL_HOST ?? 'http://127.0.0.1:8545'; const chainId = 31337; -describe.skip('L1Publisher integration', () => { - let decoderHelper: DecoderHelper; - let rollup: Rollup; - let unverifiedDataEmitter: UnverifiedDataEmitter; - let ethRpc: EthereumRpc; +const logger = createDebugLogger('aztec:integration_l1_publisher'); + +describe('L1Publisher integration', () => { + let publicClient: PublicClient; + + let rollup: GetContractReturnType< + typeof RollupAbi, + PublicClient, + WalletClient + >; + let unverifiedDataEmitter: GetContractReturnType< + typeof UnverifiedDataEmitterAbi, + PublicClient, + WalletClient + >; + let decoderHelper: GetContractReturnType< + typeof DecoderHelperAbi, + PublicClient, + WalletClient + >; + let publisher: L1Publisher; let l2Proof: Buffer; @@ -47,7 +77,44 @@ describe.skip('L1Publisher integration', () => { let builderDb: MerkleTreeOperations; beforeAll(async () => { - ({ ethRpc, decoderHelper, rollup, unverifiedDataEmitter } = await deployRollup()); + const deployerAccount = privateKeyToAccount(deployerPK); + const { rollupAddress, unverifiedDataEmitterAddress, decoderHelperAddress } = await deployL1Contracts( + anvilHost, + deployerAccount, + logger, + true, + ); + + const walletClient = createWalletClient({ + account: deployerAccount, + chain: foundry, + transport: http(anvilHost), + }); + + publicClient = createPublicClient({ + chain: foundry, + transport: http(anvilHost), + }); + + // Set up contract instances + rollup = getContract({ + address: getAddress(rollupAddress.toString()), + abi: RollupAbi, + publicClient, + walletClient, + }); + unverifiedDataEmitter = getContract({ + address: getAddress(unverifiedDataEmitterAddress.toString()), + abi: UnverifiedDataEmitterAbi, + publicClient, + walletClient, + }); + decoderHelper = getContract({ + address: getAddress(decoderHelperAddress!.toString()), + abi: DecoderHelperAbi, + publicClient, + walletClient, + }); builderDb = await MerkleTrees.new(levelup(createMemDown())).then(t => t.asLatest()); const vks = getVerificationKeys(); @@ -57,19 +124,15 @@ describe.skip('L1Publisher integration', () => { l2Proof = Buffer.alloc(0); - publisher = new L1Publisher( - new EthereumjsTxSender({ - rpcUrl: anvilHost, - chainId, - requiredConfirmations: 1, - rollupContract: rollup.address, - unverifiedDataEmitterContract: unverifiedDataEmitter.address, - publisherPrivateKey: hexStringToBuffer(sequencerPK), - }), - { - retryIntervalMs: 100, - }, - ); + publisher = getL1Publisher({ + rpcUrl: anvilHost, + chainId, + requiredConfirmations: 1, + rollupContract: rollupAddress, + unverifiedDataEmitterContract: unverifiedDataEmitterAddress, + publisherPrivateKey: hexStringToBuffer(sequencerPK), + retryIntervalMs: 100, + }); }, 60_000); const makeEmptyProcessedTx = async () => { @@ -100,7 +163,7 @@ describe.skip('L1Publisher integration', () => { }; it('Build 2 blocks of 4 txs building on each other', async () => { - const stateInRollup_ = await rollup.methods.rollupStateHash().call(); + const stateInRollup_ = await rollup.read.rollupStateHash(); expect(hexStringToBuffer(stateInRollup_.toString())).toEqual(Buffer.alloc(32, 0)); for (let i = 0; i < 2; i++) { @@ -116,8 +179,15 @@ describe.skip('L1Publisher integration', () => { const [block] = await builder.buildL2Block(1 + i, txs, l1ToL2Messages); // Now we can use the block we built! - const blockNumber = await ethRpc.blockNumber(); + const blockNumber = await publicClient.getBlockNumber(); await publisher.processL2Block(block); + + const abiItem = getAbiItem({ + abi: RollupAbi, + name: 'L2BlockProcessed', + }); + const logs = rollup.getLogs(abiItem, { fromBlock: blockNumber + 1 }); + const logs = await rollup.getLogs('L2BlockProcessed', { fromBlock: blockNumber + 1 }); expect(logs).toHaveLength(1); expect(logs[0].args.blockNum).toEqual(BigInt(i + 1)); @@ -126,9 +196,9 @@ describe.skip('L1Publisher integration', () => { const expectedData = rollup.methods.process(l2Proof, block.encode()).encodeABI(); expect(ethTx.input).toEqual(expectedData); - const decodedHashes = await decoderHelper.methods.computeDiffRootAndMessagesHash(block.encode()).call(); - const decodedRes = await decoderHelper.methods.decode(block.encode()).call(); - const stateInRollup = await rollup.methods.rollupStateHash().call(); + const decodedHashes = await decoderHelper.read.computeDiffRootAndMessagesHash(block.encode()); + const decodedRes = await decoderHelper.read.decode(block.encode()); + const stateInRollup = await rollup.read.rollupStateHash(); // @note There seems to be something wrong here. The Bytes32 returned are actually strings :( expect(block.number).toEqual(Number(decodedRes[0])); @@ -145,29 +215,11 @@ describe.skip('L1Publisher integration', () => { }, 60_000); }); -async function deployRollup() { - // Set up client - const provider = WalletProvider.fromHost(anvilHost); - provider.addAccount(hexStringToBuffer(deployerPK)); - provider.addAccount(hexStringToBuffer(sequencerPK)); - const [sequencer, deployer] = provider.getAccounts(); - const ethRpc = new EthereumRpc(provider); - - // Deploy DecodeHelper, Rollup and unverifiedDataEmitter contracts - const decoderHelper = new DecoderHelper(ethRpc, undefined, { from: deployer, gas: 1e6 }); - await decoderHelper.deploy().send().getReceipt(); - - const deployedRollup = new Rollup(ethRpc, undefined, { from: deployer, gas: 1e6 }); - await deployedRollup.deploy().send().getReceipt(); - - const deployedUnverifiedDataEmitter = new UnverifiedDataEmitter(ethRpc, undefined, { from: deployer, gas: 1e6 }); - await deployedUnverifiedDataEmitter.deploy().send().getReceipt(); - - // Create new instance so we can attach the sequencer as sender - const rollup = new Rollup(ethRpc, deployedRollup.address, { from: sequencer }); - const unverifiedDataEmitter = new UnverifiedDataEmitter(ethRpc, deployedUnverifiedDataEmitter.address, { - from: sequencer, - }); - - return { decoderHelper, rollup, deployer, unverifiedDataEmitter, sequencer, ethRpc }; +/** + * Converts a hex string into a buffer. String may be 0x-prefixed or not. + */ +function hexStringToBuffer(hex: string): Buffer { + if (!/^(0x)?[a-fA-F0-9]+$/.test(hex)) throw new Error(`Invalid format for hex string: "${hex}"`); + if (hex.length % 2 === 1) throw new Error(`Invalid length for hex string: "${hex}"`); + return Buffer.from(hex.replace(/^0x/, ''), 'hex'); } diff --git a/yarn-project/end-to-end/tsconfig.json b/yarn-project/end-to-end/tsconfig.json index 0f18e17e67e..abe357524a3 100644 --- a/yarn-project/end-to-end/tsconfig.json +++ b/yarn-project/end-to-end/tsconfig.json @@ -20,6 +20,9 @@ }, { "path": "../noir-contracts" + }, + { + "path": "../sequencer-client" } ], "include": ["src"] diff --git a/yarn-project/sequencer-client/src/index.ts b/yarn-project/sequencer-client/src/index.ts index 85dd7b8f795..80694f1136e 100644 --- a/yarn-project/sequencer-client/src/index.ts +++ b/yarn-project/sequencer-client/src/index.ts @@ -4,3 +4,10 @@ export * from './publisher/index.js'; export * from './client/index.js'; export * from './mocks/tx.js'; export * from './mocks/verification_keys.js'; + +// Used by publisher test in e2e +export { WasmRollupCircuitSimulator } from './simulator/rollup.js'; +export { EmptyRollupProver } from './prover/empty.js'; +export { SoloBlockBuilder } from './block_builder/solo_block_builder.js'; +export { makeProcessedTx, makeEmptyProcessedTx } from './sequencer/processed_tx.js'; +export { makePublicTx } from './mocks/tx.js'; diff --git a/yarn-project/sequencer-client/src/utils.ts b/yarn-project/sequencer-client/src/utils.ts index 83d028c1501..21a9b792c10 100644 --- a/yarn-project/sequencer-client/src/utils.ts +++ b/yarn-project/sequencer-client/src/utils.ts @@ -1,12 +1,3 @@ -/** - * Converts a hex string into a buffer. String may be 0x-prefixed or not. - */ -export function hexStringToBuffer(hex: string): Buffer { - if (!/^(0x)?[a-fA-F0-9]+$/.test(hex)) throw new Error(`Invalid format for hex string: "${hex}"`); - if (hex.length % 2 === 1) throw new Error(`Invalid length for hex string: "${hex}"`); - return Buffer.from(hex.replace(/^0x/, ''), 'hex'); -} - /** * Returns a promise that resolves after ms milliseconds, returning retval. * @param ms - How many milliseconds to sleep. diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 674fd9df136..cf1a5da5704 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -252,6 +252,7 @@ __metadata: "@aztec/foundation": "workspace:^" "@aztec/l1-artifacts": "workspace:^" "@aztec/noir-contracts": "workspace:^" + "@aztec/sequencer-client": "workspace:^" "@jest/globals": ^29.5.0 "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.5.0 From c3610c917281b49a5c63a83aecbd149dea228819 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 14:00:40 +0000 Subject: [PATCH 03/15] test: better test name --- ...2-block-publisher.test.ts => integration_l1-publisher.test.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename yarn-project/end-to-end/src/{l2-block-publisher.test.ts => integration_l1-publisher.test.ts} (100%) diff --git a/yarn-project/end-to-end/src/l2-block-publisher.test.ts b/yarn-project/end-to-end/src/integration_l1-publisher.test.ts similarity index 100% rename from yarn-project/end-to-end/src/l2-block-publisher.test.ts rename to yarn-project/end-to-end/src/integration_l1-publisher.test.ts From 0a52287ecc8248764c2f0088af3aa8b3094346de Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 15:37:41 +0000 Subject: [PATCH 04/15] chore: enabled test in CI --- .circleci/config.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 958f13e5fbe..aee0983bbc2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -375,6 +375,17 @@ jobs: name: "Test" command: cond_spot_run_tests end-to-end e2e_nested_contract.test.ts + integration-l1-publisher: + docker: + - image: aztecprotocol/alpine-build-image + resource_class: small + steps: + - *checkout + - *setup_env + - run: + name: "Test" + command: cond_spot_run_tests end-to-end integration_l1-publisher.test.ts + e2e-join: docker: - image: cimg/base:current @@ -460,3 +471,4 @@ workflows: - e2e-zk-token-contract: *e2e_test - e2e-block-building: *e2e_test - e2e-nested-contract: *e2e_test + - integration-l1-publisher: *e2e_test From 27bf2b57d61d37c89255446b1470a4cf6d9edf23 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 15:46:40 +0000 Subject: [PATCH 05/15] test: functional publisher test --- .../src/integration_l1-publisher.test.ts | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/yarn-project/end-to-end/src/integration_l1-publisher.test.ts b/yarn-project/end-to-end/src/integration_l1-publisher.test.ts index e43841b3190..d357cf9d422 100644 --- a/yarn-project/end-to-end/src/integration_l1-publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1-publisher.test.ts @@ -1,5 +1,6 @@ import { createMemDown } from '@aztec/aztec-node'; import { + EthAddress, Fr, KERNEL_NEW_COMMITMENTS_LENGTH, KERNEL_NEW_NULLIFIERS_LENGTH, @@ -11,6 +12,7 @@ import { } from '@aztec/circuits.js'; import { fr, makeNewContractData, makeProof } from '@aztec/circuits.js/factories'; import { createDebugLogger } from '@aztec/foundation/log'; +import { DecoderHelperAbi, RollupAbi } from '@aztec/l1-artifacts'; import { EmptyRollupProver, L1Publisher, @@ -26,9 +28,8 @@ import { import { MerkleTreeOperations, MerkleTrees } from '@aztec/world-state'; import { beforeAll, describe, expect, it } from '@jest/globals'; import { default as levelup } from 'levelup'; -import { PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts'; -import { deployL1Contracts } from './deploy_l1_contracts.js'; import { + Address, Chain, GetContractReturnType, HttpTransport, @@ -36,12 +37,15 @@ import { WalletClient, createPublicClient, createWalletClient, + encodeFunctionData, + getAbiItem, getAddress, getContract, - http, + http } from 'viem'; -import { DecoderHelperAbi, RollupAbi, UnverifiedDataEmitterAbi } from '@aztec/l1-artifacts'; +import { PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts'; import { foundry } from 'viem/chains'; +import { deployL1Contracts } from './deploy_l1_contracts.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'; @@ -54,16 +58,15 @@ const logger = createDebugLogger('aztec:integration_l1_publisher'); describe('L1Publisher integration', () => { let publicClient: PublicClient; + let rollupAddress: Address; + let unverifiedDataEmitterAddress: Address; + let decoderHelperAddress: Address; + let rollup: GetContractReturnType< typeof RollupAbi, PublicClient, WalletClient >; - let unverifiedDataEmitter: GetContractReturnType< - typeof UnverifiedDataEmitterAbi, - PublicClient, - WalletClient - >; let decoderHelper: GetContractReturnType< typeof DecoderHelperAbi, PublicClient, @@ -78,12 +81,15 @@ describe('L1Publisher integration', () => { beforeAll(async () => { const deployerAccount = privateKeyToAccount(deployerPK); - const { rollupAddress, unverifiedDataEmitterAddress, decoderHelperAddress } = await deployL1Contracts( - anvilHost, - deployerAccount, - logger, - true, - ); + const { + rollupAddress: rollupAddress_, + unverifiedDataEmitterAddress: unverifiedDataEmitterAddress_, + decoderHelperAddress: decoderHelperAddress_, + } = await deployL1Contracts(anvilHost, deployerAccount, logger, true); + + rollupAddress = getAddress(rollupAddress_.toString()); + unverifiedDataEmitterAddress = getAddress(unverifiedDataEmitterAddress_.toString()); + decoderHelperAddress = getAddress(decoderHelperAddress_!.toString()); const walletClient = createWalletClient({ account: deployerAccount, @@ -98,19 +104,13 @@ describe('L1Publisher integration', () => { // Set up contract instances rollup = getContract({ - address: getAddress(rollupAddress.toString()), + address: rollupAddress, abi: RollupAbi, publicClient, walletClient, }); - unverifiedDataEmitter = getContract({ - address: getAddress(unverifiedDataEmitterAddress.toString()), - abi: UnverifiedDataEmitterAbi, - publicClient, - walletClient, - }); decoderHelper = getContract({ - address: getAddress(decoderHelperAddress!.toString()), + address: decoderHelperAddress!, abi: DecoderHelperAbi, publicClient, walletClient, @@ -128,8 +128,8 @@ describe('L1Publisher integration', () => { rpcUrl: anvilHost, chainId, requiredConfirmations: 1, - rollupContract: rollupAddress, - unverifiedDataEmitterContract: unverifiedDataEmitterAddress, + rollupContract: EthAddress.fromString(rollupAddress), + unverifiedDataEmitterContract: EthAddress.fromString(unverifiedDataEmitterAddress), publisherPrivateKey: hexStringToBuffer(sequencerPK), retryIntervalMs: 100, }); @@ -182,22 +182,31 @@ describe('L1Publisher integration', () => { const blockNumber = await publicClient.getBlockNumber(); await publisher.processL2Block(block); - const abiItem = getAbiItem({ - abi: RollupAbi, - name: 'L2BlockProcessed', + const logs = await publicClient.getLogs({ + address: rollupAddress, + event: getAbiItem({ + abi: RollupAbi, + name: 'L2BlockProcessed', + }), + fromBlock: blockNumber + 1n, }); - const logs = rollup.getLogs(abiItem, { fromBlock: blockNumber + 1 }); - - const logs = await rollup.getLogs('L2BlockProcessed', { fromBlock: blockNumber + 1 }); expect(logs).toHaveLength(1); expect(logs[0].args.blockNum).toEqual(BigInt(i + 1)); - const ethTx = await ethRpc.getTransactionByHash(logs[0].transactionHash!); - const expectedData = rollup.methods.process(l2Proof, block.encode()).encodeABI(); + const ethTx = await publicClient.getTransaction({ + hash: logs[0].transactionHash!, + }); + + const expectedData = encodeFunctionData({ + abi: RollupAbi, + functionName: 'process', + args: [`0x${l2Proof.toString('hex')}`, `0x${block.encode().toString('hex')}`], + }); expect(ethTx.input).toEqual(expectedData); - const decodedHashes = await decoderHelper.read.computeDiffRootAndMessagesHash(block.encode()); - const decodedRes = await decoderHelper.read.decode(block.encode()); + const decoderArgs = [`0x${block.encode().toString('hex')}`] as const; + const decodedHashes = await decoderHelper.read.computeDiffRootAndMessagesHash(decoderArgs); + const decodedRes = await decoderHelper.read.decode(decoderArgs); const stateInRollup = await rollup.read.rollupStateHash(); // @note There seems to be something wrong here. The Bytes32 returned are actually strings :( From bfed465e671114a42fdeec25342dde36341d6915 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 15:53:48 +0000 Subject: [PATCH 06/15] refactor: cleanup --- .../src/integration_l1-publisher.test.ts | 40 +++++-------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/yarn-project/end-to-end/src/integration_l1-publisher.test.ts b/yarn-project/end-to-end/src/integration_l1-publisher.test.ts index d357cf9d422..b8419763dfd 100644 --- a/yarn-project/end-to-end/src/integration_l1-publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1-publisher.test.ts @@ -1,4 +1,4 @@ -import { createMemDown } from '@aztec/aztec-node'; +import { createMemDown, getConfigEnvVars } from '@aztec/aztec-node'; import { EthAddress, Fr, @@ -34,27 +34,25 @@ import { GetContractReturnType, HttpTransport, PublicClient, - WalletClient, createPublicClient, - createWalletClient, encodeFunctionData, getAbiItem, getAddress, getContract, - http + http, } from 'viem'; -import { PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts'; +import { privateKeyToAccount } from 'viem/accounts'; import { foundry } from 'viem/chains'; import { deployL1Contracts } from './deploy_l1_contracts.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'; const deployerPK = '0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba'; -const anvilHost = process.env.ANVIL_HOST ?? 'http://127.0.0.1:8545'; -const chainId = 31337; const logger = createDebugLogger('aztec:integration_l1_publisher'); +const config = getConfigEnvVars(); + describe('L1Publisher integration', () => { let publicClient: PublicClient; @@ -62,16 +60,8 @@ describe('L1Publisher integration', () => { let unverifiedDataEmitterAddress: Address; let decoderHelperAddress: Address; - let rollup: GetContractReturnType< - typeof RollupAbi, - PublicClient, - WalletClient - >; - let decoderHelper: GetContractReturnType< - typeof DecoderHelperAbi, - PublicClient, - WalletClient - >; + let rollup: GetContractReturnType>; + let decoderHelper: GetContractReturnType>; let publisher: L1Publisher; let l2Proof: Buffer; @@ -85,21 +75,15 @@ describe('L1Publisher integration', () => { rollupAddress: rollupAddress_, unverifiedDataEmitterAddress: unverifiedDataEmitterAddress_, decoderHelperAddress: decoderHelperAddress_, - } = await deployL1Contracts(anvilHost, deployerAccount, logger, true); + } = await deployL1Contracts(config.rpcUrl, deployerAccount, logger, true); rollupAddress = getAddress(rollupAddress_.toString()); unverifiedDataEmitterAddress = getAddress(unverifiedDataEmitterAddress_.toString()); decoderHelperAddress = getAddress(decoderHelperAddress_!.toString()); - const walletClient = createWalletClient({ - account: deployerAccount, - chain: foundry, - transport: http(anvilHost), - }); - publicClient = createPublicClient({ chain: foundry, - transport: http(anvilHost), + transport: http(config.rpcUrl), }); // Set up contract instances @@ -107,13 +91,11 @@ describe('L1Publisher integration', () => { address: rollupAddress, abi: RollupAbi, publicClient, - walletClient, }); decoderHelper = getContract({ address: decoderHelperAddress!, abi: DecoderHelperAbi, publicClient, - walletClient, }); builderDb = await MerkleTrees.new(levelup(createMemDown())).then(t => t.asLatest()); @@ -125,8 +107,8 @@ describe('L1Publisher integration', () => { l2Proof = Buffer.alloc(0); publisher = getL1Publisher({ - rpcUrl: anvilHost, - chainId, + rpcUrl: config.rpcUrl, + chainId: config.chainId, requiredConfirmations: 1, rollupContract: EthAddress.fromString(rollupAddress), unverifiedDataEmitterContract: EthAddress.fromString(unverifiedDataEmitterAddress), From e271cd9b738f61f48818fc855cc2064b11b5a3ab Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 16:59:26 +0000 Subject: [PATCH 07/15] test: fixed deps --- yarn-project/end-to-end/package.json | 2 ++ yarn-project/yarn.lock | 2 ++ 2 files changed, 4 insertions(+) diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 41211b370a0..53c0b2ff961 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -32,6 +32,7 @@ "@aztec/sequencer-client": "workspace:^", "@types/jest": "^29.5.0", "jest": "^29.5.0", + "levelup": "^5.1.1", "lodash.times": "^4.3.2", "ts-jest": "^29.1.0", "tslib": "^2.4.0", @@ -42,6 +43,7 @@ "@jest/globals": "^29.5.0", "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.5.0", + "@types/levelup": "^5.1.2", "@types/lodash.times": "^4.3.7", "@types/node": "^18.7.23", "concurrently": "^7.6.0", diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index cf1a5da5704..964e09dd19b 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -256,10 +256,12 @@ __metadata: "@jest/globals": ^29.5.0 "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.5.0 + "@types/levelup": ^5.1.2 "@types/lodash.times": ^4.3.7 "@types/node": ^18.7.23 concurrently: ^7.6.0 jest: ^29.5.0 + levelup: ^5.1.1 lodash.times: ^4.3.2 ts-jest: ^29.1.0 ts-node: ^10.9.1 From 0397e97f2bb8d78dd8e21e92e76a8ea388357f2a Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 17:01:44 +0000 Subject: [PATCH 08/15] test: fixed deps 2 --- yarn-project/end-to-end/package.json | 2 ++ yarn-project/yarn.lock | 2 ++ 2 files changed, 4 insertions(+) diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 53c0b2ff961..91fc460bdf5 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -26,10 +26,12 @@ "dependencies": { "@aztec/aztec-node": "workspace:^", "@aztec/aztec.js": "workspace:^", + "@aztec/circuits.js": "workspace:^", "@aztec/foundation": "workspace:^", "@aztec/l1-artifacts": "workspace:^", "@aztec/noir-contracts": "workspace:^", "@aztec/sequencer-client": "workspace:^", + "@aztec/world-state": "workspace:^", "@types/jest": "^29.5.0", "jest": "^29.5.0", "levelup": "^5.1.1", diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 964e09dd19b..1379d092e45 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -249,10 +249,12 @@ __metadata: dependencies: "@aztec/aztec-node": "workspace:^" "@aztec/aztec.js": "workspace:^" + "@aztec/circuits.js": "workspace:^" "@aztec/foundation": "workspace:^" "@aztec/l1-artifacts": "workspace:^" "@aztec/noir-contracts": "workspace:^" "@aztec/sequencer-client": "workspace:^" + "@aztec/world-state": "workspace:^" "@jest/globals": ^29.5.0 "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.5.0 From 076adabd419188954e896f927b9f2699b9d4a320 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 17:20:16 +0000 Subject: [PATCH 09/15] yarn prepare --- build_manifest.json | 4 +++- yarn-project/end-to-end/tsconfig.json | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build_manifest.json b/build_manifest.json index 84d3bcc4d8d..4bbdb9d70fb 100644 --- a/build_manifest.json +++ b/build_manifest.json @@ -186,10 +186,12 @@ "dependencies": [ "aztec-node", "aztec.js", + "circuits.js", "foundation", "l1-artifacts", "noir-contracts", - "sequencer-client" + "sequencer-client", + "world-state" ] }, "foundation": { diff --git a/yarn-project/end-to-end/tsconfig.json b/yarn-project/end-to-end/tsconfig.json index abe357524a3..29cb3e803c3 100644 --- a/yarn-project/end-to-end/tsconfig.json +++ b/yarn-project/end-to-end/tsconfig.json @@ -12,6 +12,9 @@ { "path": "../aztec.js" }, + { + "path": "../circuits.js" + }, { "path": "../foundation" }, @@ -23,6 +26,9 @@ }, { "path": "../sequencer-client" + }, + { + "path": "../world-state" } ], "include": ["src"] From c38d22cb5e9e5350adcf13cb1458db6a6e3787b4 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 May 2023 17:51:55 +0000 Subject: [PATCH 10/15] test: CI fix attempt 4 --- yarn-project/end-to-end/package.json | 1 + yarn-project/end-to-end/src/integration_l1-publisher.test.ts | 4 ++-- yarn-project/yarn.lock | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 91fc460bdf5..127229ab531 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -36,6 +36,7 @@ "jest": "^29.5.0", "levelup": "^5.1.1", "lodash.times": "^4.3.2", + "memdown": "^6.1.1", "ts-jest": "^29.1.0", "tslib": "^2.4.0", "typescript": "^4.9.5", diff --git a/yarn-project/end-to-end/src/integration_l1-publisher.test.ts b/yarn-project/end-to-end/src/integration_l1-publisher.test.ts index b8419763dfd..0a4bf5747be 100644 --- a/yarn-project/end-to-end/src/integration_l1-publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1-publisher.test.ts @@ -1,7 +1,7 @@ import { createMemDown, getConfigEnvVars } from '@aztec/aztec-node'; +import { EthAddress } from '@aztec/foundation/eth-address'; +import { Fr } from '@aztec/foundation/fields'; import { - EthAddress, - Fr, KERNEL_NEW_COMMITMENTS_LENGTH, KERNEL_NEW_NULLIFIERS_LENGTH, KernelCircuitPublicInputs, diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 1379d092e45..cc2a1f5c507 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -265,6 +265,7 @@ __metadata: jest: ^29.5.0 levelup: ^5.1.1 lodash.times: ^4.3.2 + memdown: ^6.1.1 ts-jest: ^29.1.0 ts-node: ^10.9.1 tslib: ^2.4.0 From 9a6269f6dd244629b6aa1374d98259a9e8ad72e0 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 5 May 2023 06:55:15 +0000 Subject: [PATCH 11/15] chore: same TS version as in the rest --- yarn-project/end-to-end/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 127229ab531..ca25086855e 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -39,7 +39,7 @@ "memdown": "^6.1.1", "ts-jest": "^29.1.0", "tslib": "^2.4.0", - "typescript": "^4.9.5", + "typescript": "^5.0.4", "viem": "^0.3.13" }, "devDependencies": { From 62d4cd8142506c233febba13b563fe763ed36f20 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 5 May 2023 07:14:07 +0000 Subject: [PATCH 12/15] chore: better naming + CI fix attempt --- .circleci/config.yml | 7 +++++-- yarn-project/end-to-end/package.json | 2 -- ...-publisher.test.ts => integration_l1_publisher.test.ts} | 0 3 files changed, 5 insertions(+), 4 deletions(-) rename yarn-project/end-to-end/src/{integration_l1-publisher.test.ts => integration_l1_publisher.test.ts} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index aee0983bbc2..0668ebed7cb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -384,7 +384,7 @@ jobs: - *setup_env - run: name: "Test" - command: cond_spot_run_tests end-to-end integration_l1-publisher.test.ts + command: cond_spot_run_tests end-to-end integration_l1_publisher.test.ts e2e-join: docker: @@ -463,9 +463,12 @@ workflows: - e2e-join: requires: - aztec-js + - circuits-js - end-to-end - - noir-contracts - foundation + - noir-contracts + - sequencer-client + - world-state <<: *defaults - e2e-deploy-contract: *e2e_test - e2e-zk-token-contract: *e2e_test diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index ca25086855e..1f5e1bdfc79 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -32,8 +32,6 @@ "@aztec/noir-contracts": "workspace:^", "@aztec/sequencer-client": "workspace:^", "@aztec/world-state": "workspace:^", - "@types/jest": "^29.5.0", - "jest": "^29.5.0", "levelup": "^5.1.1", "lodash.times": "^4.3.2", "memdown": "^6.1.1", diff --git a/yarn-project/end-to-end/src/integration_l1-publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts similarity index 100% rename from yarn-project/end-to-end/src/integration_l1-publisher.test.ts rename to yarn-project/end-to-end/src/integration_l1_publisher.test.ts From c0a35c994a63acf46a7bbc9976de6fdad69f0c3c Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 5 May 2023 07:27:57 +0000 Subject: [PATCH 13/15] deps cleanup --- yarn-project/end-to-end/package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 1f5e1bdfc79..00c48db1d22 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -35,16 +35,13 @@ "levelup": "^5.1.1", "lodash.times": "^4.3.2", "memdown": "^6.1.1", - "ts-jest": "^29.1.0", "tslib": "^2.4.0", - "typescript": "^5.0.4", "viem": "^0.3.13" }, "devDependencies": { "@jest/globals": "^29.5.0", "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.5.0", - "@types/levelup": "^5.1.2", "@types/lodash.times": "^4.3.7", "@types/node": "^18.7.23", "concurrently": "^7.6.0", From 929ef384e027831e143bc3bd2223f165b3cc2cbb Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 5 May 2023 07:39:52 +0000 Subject: [PATCH 14/15] CI fix attempt 5 --- yarn-project/end-to-end/package.json | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 00c48db1d22..45024ccb72a 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -32,23 +32,22 @@ "@aztec/noir-contracts": "workspace:^", "@aztec/sequencer-client": "workspace:^", "@aztec/world-state": "workspace:^", - "levelup": "^5.1.1", - "lodash.times": "^4.3.2", - "memdown": "^6.1.1", - "tslib": "^2.4.0", - "viem": "^0.3.13" - }, - "devDependencies": { "@jest/globals": "^29.5.0", "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.5.0", + "@types/levelup": "^5.1.2", "@types/lodash.times": "^4.3.7", "@types/node": "^18.7.23", "concurrently": "^7.6.0", "jest": "^29.5.0", + "levelup": "^5.1.1", + "lodash.times": "^4.3.2", + "memdown": "^6.1.1", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", - "typescript": "^5.0.4" + "tslib": "^2.4.0", + "typescript": "^5.0.4", + "viem": "^0.3.13" }, "files": [ "dest", @@ -56,4 +55,4 @@ "!*.test.*" ], "types": "./dest/index.d.ts" -} \ No newline at end of file +} From 5ab62afbb52848bf0abfd86fb8fc191dbe2ca582 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 5 May 2023 07:51:31 +0000 Subject: [PATCH 15/15] chore: deps cleanup 2 --- yarn-project/end-to-end/package.json | 7 ++++--- yarn-project/yarn.lock | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 45024ccb72a..1b72718bdfc 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -33,22 +33,23 @@ "@aztec/sequencer-client": "workspace:^", "@aztec/world-state": "workspace:^", "@jest/globals": "^29.5.0", - "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.5.0", "@types/levelup": "^5.1.2", "@types/lodash.times": "^4.3.7", "@types/node": "^18.7.23", - "concurrently": "^7.6.0", "jest": "^29.5.0", "levelup": "^5.1.1", "lodash.times": "^4.3.2", - "memdown": "^6.1.1", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", "tslib": "^2.4.0", "typescript": "^5.0.4", "viem": "^0.3.13" }, + "devDependencies": { + "@rushstack/eslint-patch": "^1.1.4", + "concurrently": "^7.6.0" + }, "files": [ "dest", "src", diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index cc2a1f5c507..1379d092e45 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -265,7 +265,6 @@ __metadata: jest: ^29.5.0 levelup: ^5.1.1 lodash.times: ^4.3.2 - memdown: ^6.1.1 ts-jest: ^29.1.0 ts-node: ^10.9.1 tslib: ^2.4.0