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
30 changes: 11 additions & 19 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
import { type ViemPublicClient, createEthereumChain } from '@aztec/ethereum';
import { RollupContract, type ViemPublicClient, createEthereumChain } from '@aztec/ethereum';
import type { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
import { count } from '@aztec/foundation/string';
import { elapsed } from '@aztec/foundation/timer';
import { InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import { InboxAbi } from '@aztec/l1-artifacts';
import {
ContractClassRegisteredEvent,
PrivateFunctionBroadcastedEvent,
Expand Down Expand Up @@ -84,7 +84,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
*/
private runningPromise?: RunningPromise;

private rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
private rollup: RollupContract;
private inbox: GetContractReturnType<typeof InboxAbi, ViemPublicClient>;

private store: ArchiverStoreHelper;
Expand Down Expand Up @@ -119,11 +119,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
this.tracer = instrumentation.tracer;
this.store = new ArchiverStoreHelper(dataStore);

this.rollup = getContract({
address: l1Addresses.rollupAddress.toString(),
abi: RollupAbi,
client: publicClient,
});
this.rollup = new RollupContract(publicClient, l1Addresses.rollupAddress);

this.inbox = getContract({
address: l1Addresses.inboxAddress.toString(),
Expand Down Expand Up @@ -152,15 +148,11 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
pollingInterval: config.viemPollingIntervalMS,
});

const rollup = getContract({
address: config.l1Contracts.rollupAddress.toString(),
abi: RollupAbi,
client: publicClient,
});
const rollup = new RollupContract(publicClient, config.l1Contracts.rollupAddress);

const [l1StartBlock, l1GenesisTime] = await Promise.all([
rollup.read.L1_BLOCK_AT_GENESIS(),
rollup.read.getGenesisTime(),
rollup.getL1StartBlock(),
rollup.getL1GenesisTime(),
] as const);

const { aztecEpochDuration: epochDuration, aztecSlotDuration: slotDuration, ethereumSlotDuration } = config;
Expand Down Expand Up @@ -306,7 +298,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
/** Queries the rollup contract on whether a prune can be executed on the immediatenext L1 block. */
private async canPrune(currentL1BlockNumber: bigint, currentL1Timestamp: bigint) {
const time = (currentL1Timestamp ?? 0n) + BigInt(this.l1constants.ethereumSlotDuration);
return await this.rollup.read.canPruneAtTime([time], { blockNumber: currentL1BlockNumber });
return await this.rollup.canPruneAtTime(time, { blockNumber: currentL1BlockNumber });
}

/** Checks if there'd be a reorg for the next block submission and start pruning now. */
Expand Down Expand Up @@ -394,7 +386,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
): Promise<{ provenBlockNumber: bigint }> {
const localPendingBlockNumber = BigInt(await this.getBlockNumber());
const [provenBlockNumber, provenArchive, pendingBlockNumber, pendingArchive, archiveForLocalPendingBlockNumber] =
await this.rollup.read.status([localPendingBlockNumber], { blockNumber: currentL1BlockNumber });
await this.rollup.status(localPendingBlockNumber, { blockNumber: currentL1BlockNumber });

const updateProvenBlock = async () => {
const localBlockForDestinationProvenBlockNumber = await this.getBlock(Number(provenBlockNumber));
Expand Down Expand Up @@ -473,7 +465,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
break;
}

const archiveAtContract = await this.rollup.read.archiveAt([BigInt(candidateBlock.number)]);
const archiveAtContract = await this.rollup.archiveAt(BigInt(candidateBlock.number));

if (archiveAtContract === candidateBlock.archive.root.toString()) {
break;
Expand Down Expand Up @@ -504,7 +496,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {

// TODO(md): Retrieve from blob sink then from consensus client, then from peers
const retrievedBlocks = await retrieveBlocksFromRollup(
this.rollup,
this.rollup.getContract(),
this.publicClient,
this.blobSinkClient,
searchStartBlock, // TODO(palla/reorg): If the L2 reorg was due to an L1 reorg, we need to start search earlier
Expand Down
14 changes: 5 additions & 9 deletions yarn-project/cli/src/cmds/infrastructure/sequencers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createCompatibleClient } from '@aztec/aztec.js';
import { createEthereumChain, getL1ContractsConfigEnvVars } from '@aztec/ethereum';
import { RollupContract, createEthereumChain, getL1ContractsConfigEnvVars } from '@aztec/ethereum';
import type { LogFn, Logger } from '@aztec/foundation/log';
import { RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts';

Expand Down Expand Up @@ -35,11 +35,7 @@ export async function sequencers(opts: {
})
: undefined;

const rollup = getContract({
address: l1ContractAddresses.rollupAddress.toString(),
abi: RollupAbi,
client: publicClient,
});
const rollup = new RollupContract(publicClient, l1ContractAddresses.rollupAddress);

const writeableRollup = walletClient
? getContract({
Expand All @@ -52,7 +48,7 @@ export async function sequencers(opts: {
const who = (maybeWho as `0x{string}`) ?? walletClient?.account.address.toString();

if (command === 'list') {
const sequencers = await rollup.read.getAttesters();
const sequencers = await rollup.getAttesters();
if (sequencers.length === 0) {
log(`No sequencers registered on rollup`);
} else {
Expand All @@ -69,7 +65,7 @@ export async function sequencers(opts: {
log(`Adding ${who} as sequencer`);

const stakingAsset = getContract({
address: await rollup.read.getStakingAsset(),
address: await rollup.getStakingAsset(),
abi: TestERC20Abi,
client: walletClient,
});
Expand All @@ -95,7 +91,7 @@ export async function sequencers(opts: {
await publicClient.waitForTransactionReceipt({ hash });
log(`Removed in tx ${hash}`);
} else if (command === 'who-next') {
const next = await rollup.read.getCurrentProposer();
const next = await rollup.getCurrentProposer();
log(`Sequencer expected to build is ${next}`);
} else {
throw new Error(`Unknown command ${command}`);
Expand Down
25 changes: 11 additions & 14 deletions yarn-project/cli/src/cmds/l1/update_l1_validators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
EthCheatCodes,
RollupContract,
createEthereumChain,
getExpectedAddress,
getL1ContractsConfigEnvVars,
Expand Down Expand Up @@ -181,30 +182,26 @@ export async function fastForwardEpochs({
export async function debugRollup({ rpcUrls, chainId, rollupAddress, log }: RollupCommandArgs & LoggerArgs) {
const config = getL1ContractsConfigEnvVars();
const publicClient = getPublicClient(rpcUrls, chainId);
const rollup = getContract({
address: rollupAddress.toString(),
abi: RollupAbi,
client: publicClient,
});
const rollup = new RollupContract(publicClient, rollupAddress);

const pendingNum = await rollup.read.getPendingBlockNumber();
const pendingNum = await rollup.getBlockNumber();
log(`Pending block num: ${pendingNum}`);
const provenNum = await rollup.read.getProvenBlockNumber();
const provenNum = await rollup.getProvenBlockNumber();
log(`Proven block num: ${provenNum}`);
const validators = await rollup.read.getAttesters();
const validators = await rollup.getAttesters();
log(`Validators: ${validators.map(v => v.toString()).join(', ')}`);
const committee = await rollup.read.getCurrentEpochCommittee();
const committee = await rollup.getCurrentEpochCommittee();
log(`Committee: ${committee.map(v => v.toString()).join(', ')}`);
const archive = await rollup.read.archive();
const archive = await rollup.archive();
log(`Archive: ${archive}`);
const epochNum = await rollup.read.getCurrentEpoch();
const epochNum = await rollup.getEpochNumber();
log(`Current epoch: ${epochNum}`);
const slot = await rollup.read.getCurrentSlot();
const slot = await rollup.getSlotNumber();
log(`Current slot: ${slot}`);
const proposerDuringPrevL1Block = await rollup.read.getCurrentProposer();
const proposerDuringPrevL1Block = await rollup.getCurrentProposer();
log(`Proposer during previous L1 block: ${proposerDuringPrevL1Block}`);
const nextBlockTS = BigInt((await publicClient.getBlock()).timestamp + BigInt(config.ethereumSlotDuration));
const proposer = await rollup.read.getProposerAt([nextBlockTS]);
const proposer = await rollup.getProposerAt(nextBlockTS);
log(`Proposer NOW: ${proposer.toString()}`);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('L1Publisher integration', () => {
let rollupAddress: Address;
let outboxAddress: Address;

let rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
let rollup: RollupContract;
let outbox: GetContractReturnType<typeof OutboxAbi, ViemPublicClient>;

let publisher: SequencerPublisher;
Expand Down Expand Up @@ -111,8 +111,8 @@ describe('L1Publisher integration', () => {

const progressTimeBySlot = async (slotsToJump = 1n) => {
const currentTime = (await publicClient.getBlock()).timestamp;
const currentSlot = await rollup.read.getCurrentSlot();
const timestamp = await rollup.read.getTimestampForSlot([currentSlot + slotsToJump]);
const currentSlot = await rollup.getSlotNumber();
const timestamp = await rollup.getTimestampForSlot(currentSlot + slotsToJump);
if (timestamp > currentTime) {
await ethCheatCodes.warp(Number(timestamp));
}
Expand All @@ -133,11 +133,7 @@ describe('L1Publisher integration', () => {
outboxAddress = getAddress(l1ContractAddresses.outboxAddress.toString());

// Set up contract instances
rollup = getContract({
address: rollupAddress,
abi: RollupAbi,
client: publicClient,
});
rollup = new RollupContract(publicClient, l1ContractAddresses.rollupAddress);
outbox = getContract({
address: outboxAddress,
abi: OutboxAbi,
Expand Down Expand Up @@ -242,10 +238,10 @@ describe('L1Publisher integration', () => {
await fork.close();

const ts = (await publicClient.getBlock()).timestamp;
baseFee = new GasFees(0, await rollup.read.getManaBaseFeeAt([ts, true]));
baseFee = new GasFees(0, await rollup.getManaBaseFeeAt(ts, true));

// We jump to the next epoch such that the committee can be setup.
const timeToJump = await rollup.read.getEpochDuration();
const timeToJump = await rollup.getEpochDuration();
await progressTimeBySlot(timeToJump);
});

Expand Down Expand Up @@ -394,7 +390,7 @@ describe('L1Publisher integration', () => {
};

const buildAndPublishBlock = async (numTxs: number, jsonFileNamePrefix: string) => {
const archiveInRollup_ = await rollup.read.archive();
const archiveInRollup_ = await rollup.archive();
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(new Fr(GENESIS_ARCHIVE_ROOT).toBuffer());

const blockNumber = await publicClient.getBlockNumber();
Expand All @@ -421,8 +417,8 @@ describe('L1Publisher integration', () => {
);

const ts = (await publicClient.getBlock()).timestamp;
const slot = await rollup.read.getSlotAt([ts + BigInt(config.ethereumSlotDuration)]);
const timestamp = await rollup.read.getTimestampForSlot([slot]);
const slot = await rollup.getSlotAt(ts + BigInt(config.ethereumSlotDuration));
const timestamp = await rollup.getTimestampForSlot(slot);

const globalVariables = new GlobalVariables(
new Fr(chainId),
Expand All @@ -432,7 +428,7 @@ describe('L1Publisher integration', () => {
new Fr(timestamp),
coinbase,
feeRecipient,
new GasFees(Fr.ZERO, new Fr(await rollup.read.getManaBaseFeeAt([timestamp, true]))),
new GasFees(Fr.ZERO, new Fr(await rollup.getManaBaseFeeAt(timestamp, true))),
);

const block = await buildBlock(globalVariables, txs, currentL1ToL2Messages);
Expand Down Expand Up @@ -482,7 +478,7 @@ describe('L1Publisher integration', () => {
hash: logs[i].transactionHash!,
});

const blobPublicInputsHash = await rollup.read.getBlobPublicInputsHash([BigInt(i + 1)]);
const blobPublicInputsHash = await rollup.getBlobPublicInputsHash(BigInt(i + 1));
const expectedHash = sha256(Buffer.from(BlockBlobPublicInputs.fromBlobs(blobs).toString().substring(2), 'hex'));
expect(blobPublicInputsHash).toEqual(`0x${expectedHash.toString('hex')}`);

Expand Down Expand Up @@ -549,7 +545,7 @@ describe('L1Publisher integration', () => {

it(`shows propose custom errors if tx reverts`, async () => {
// REFACTOR: code below is duplicated from "builds blocks of 2 empty txs building on each other"
const archiveInRollup_ = await rollup.read.archive();
const archiveInRollup_ = await rollup.archive();
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(new Fr(GENESIS_ARCHIVE_ROOT).toBuffer());

// Set up different l1-to-l2 messages than the ones on the inbox, so this submission reverts
Expand All @@ -559,8 +555,8 @@ describe('L1Publisher integration', () => {

const txs = await Promise.all([makeProcessedTx(0x1000), makeProcessedTx(0x2000)]);
const ts = (await publicClient.getBlock()).timestamp;
const slot = await rollup.read.getSlotAt([ts + BigInt(config.ethereumSlotDuration)]);
const timestamp = await rollup.read.getTimestampForSlot([slot]);
const slot = await rollup.getSlotAt(ts + BigInt(config.ethereumSlotDuration));
const timestamp = await rollup.getTimestampForSlot(slot);
const globalVariables = new GlobalVariables(
new Fr(chainId),
new Fr(config.version),
Expand All @@ -569,7 +565,7 @@ describe('L1Publisher integration', () => {
new Fr(timestamp),
coinbase,
feeRecipient,
new GasFees(Fr.ZERO, new Fr(await rollup.read.getManaBaseFeeAt([timestamp, true]))),
new GasFees(Fr.ZERO, new Fr(await rollup.getManaBaseFeeAt(timestamp, true))),
);
const block = await buildBlock(globalVariables, txs, l1ToL2Messages);
prevHeader = block.header;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@aztec/aztec.js';
import { CheatCodes } from '@aztec/aztec.js/testing';
import { type ViemPublicClient, createL1Clients, deployL1Contract } from '@aztec/ethereum';
import { InboxAbi, OutboxAbi, RollupAbi, TestERC20Abi, TestERC20Bytecode } from '@aztec/l1-artifacts';
import { InboxAbi, OutboxAbi, TestERC20Abi, TestERC20Bytecode } from '@aztec/l1-artifacts';
import { TokenContract } from '@aztec/noir-contracts.js/Token';
import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';

Expand Down Expand Up @@ -49,7 +49,6 @@ export class CrossChainMessagingTest {
l2Token!: TokenContract;
l2Bridge!: TokenBridgeContract;

rollup!: any; // GetContractReturnType<typeof RollupAbi> | undefined;
inbox!: any; // GetContractReturnType<typeof InboxAbi> | undefined;
outbox!: any; // GetContractReturnType<typeof OutboxAbi> | undefined;
cheatcodes!: CheatCodes;
Expand All @@ -60,7 +59,7 @@ export class CrossChainMessagingTest {
}

async assumeProven() {
await this.cheatcodes.rollup.markAsProven(await this.rollup.read.getPendingBlockNumber());
await this.cheatcodes.rollup.markAsProven();
}

async setup() {
Expand Down Expand Up @@ -88,17 +87,11 @@ export class CrossChainMessagingTest {
await this.snapshotManager.snapshot(
'3_accounts',
deployAccounts(3, this.logger),
async ({ deployedAccounts }, { pxe, aztecNodeConfig, aztecNode, deployL1ContractsValues }) => {
async ({ deployedAccounts }, { pxe, aztecNodeConfig, aztecNode }) => {
this.wallets = await Promise.all(deployedAccounts.map(a => getSchnorrWallet(pxe, a.address, a.signingKey)));
this.accounts = this.wallets.map(w => w.getCompleteAddress());
this.wallets.forEach((w, i) => this.logger.verbose(`Wallet ${i} address: ${w.getAddress()}`));

this.rollup = getContract({
address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
abi: RollupAbi,
client: deployL1ContractsValues.walletClient,
});

this.user1Wallet = this.wallets[0];
this.user2Wallet = this.wallets[1];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Fr } from '@aztec/aztec.js';
import { CheatCodes } from '@aztec/aztec.js/testing';
import { RollupAbi } from '@aztec/l1-artifacts';

import { getContract } from 'viem';
import { RollupContract } from '@aztec/ethereum';

import { CrossChainMessagingTest } from './cross_chain_messaging_test.js';

Expand All @@ -19,8 +17,8 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => {
l2Token,
user1Wallet,
user2Wallet,
rollup,
} = t;
let rollup: RollupContract;
let cheatCodes: CheatCodes;

beforeEach(async () => {
Expand All @@ -35,11 +33,10 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => {
ownerAddress = crossChainTestHarness.ownerAddress;
l2Bridge = crossChainTestHarness.l2Bridge;
l2Token = crossChainTestHarness.l2Token;
rollup = getContract({
address: crossChainTestHarness.l1ContractAddresses.rollupAddress.toString(),
abi: RollupAbi,
client: crossChainTestHarness.walletClient,
});
rollup = new RollupContract(
crossChainTestHarness!.publicClient,
crossChainTestHarness!.l1ContractAddresses.rollupAddress,
);

cheatCodes = await CheatCodes.create(t.aztecNodeConfig.l1RpcUrls, t.pxe);
}, 300_000);
Expand Down Expand Up @@ -91,7 +88,7 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => {
);

// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());

// Check balance before and after exit.
expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount);
Expand Down
Loading