Skip to content
Draft
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
64 changes: 32 additions & 32 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class Archiver
slotDuration,
ethereumSlotDuration,
proofSubmissionEpochs: Number(proofSubmissionEpochs),
genesisArchiveRoot: Fr.fromHexString(genesisArchiveRoot),
genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
};

const opts = merge(
Expand Down Expand Up @@ -789,22 +789,17 @@ export class Archiver
private async handleCheckpoints(blocksSynchedTo: bigint, currentL1BlockNumber: bigint): Promise<RollupStatus> {
const localPendingCheckpointNumber = await this.getSynchedCheckpointNumber();
const initialValidationResult: ValidateBlockResult | undefined = await this.store.getPendingChainValidationStatus();
const [
rollupProvenCheckpointNumber,
provenArchive,
rollupPendingCheckpointNumber,
pendingArchive,
archiveForLocalPendingCheckpointNumber,
] = await this.rollup.status(localPendingCheckpointNumber, { blockNumber: currentL1BlockNumber });
const provenCheckpointNumber = CheckpointNumber.fromBigInt(rollupProvenCheckpointNumber);
const pendingCheckpointNumber = CheckpointNumber.fromBigInt(rollupPendingCheckpointNumber);
const rollupStatus = {
provenCheckpointNumber,
provenArchive,
pendingCheckpointNumber,
pendingArchive,
const checkpointStatus = await this.rollup.status(localPendingCheckpointNumber, {
blockNumber: currentL1BlockNumber,
});
const rollupStatus: RollupStatus = {
provenCheckpointNumber: checkpointStatus.provenCheckpointNumber,
provenArchive: checkpointStatus.provenArchive.toString(),
pendingCheckpointNumber: checkpointStatus.pendingCheckpointNumber,
pendingArchive: checkpointStatus.pendingArchive.toString(),
validationResult: initialValidationResult,
};
const archiveForLocalPendingCheckpointNumber = checkpointStatus.archiveOfMyCheckpoint;
this.log.trace(`Retrieved rollup status at current L1 block ${currentL1BlockNumber}.`, {
localPendingCheckpointNumber,
blocksSynchedTo,
Expand All @@ -817,16 +812,19 @@ export class Archiver
// Annoying edge case: if proven checkpoint is moved back to 0 due to a reorg at the beginning of the chain,
// we need to set it to zero. This is an edge case because we dont have a checkpoint zero (initial checkpoint is one),
// so localCheckpointForDestinationProvenCheckpointNumber would not be found below.
if (provenCheckpointNumber === 0) {
if (rollupStatus.provenCheckpointNumber === CheckpointNumber(0)) {
const localProvenCheckpointNumber = await this.getProvenCheckpointNumber();
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
await this.setProvenCheckpointNumber(provenCheckpointNumber);
this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, { provenCheckpointNumber });
if (localProvenCheckpointNumber !== rollupStatus.provenCheckpointNumber) {
await this.setProvenCheckpointNumber(rollupStatus.provenCheckpointNumber);
this.log.info(`Rolled back proven chain to checkpoint ${rollupStatus.provenCheckpointNumber}`, {
provenCheckpointNumber: rollupStatus.provenCheckpointNumber,
});
}
}

const localCheckpointForDestinationProvenCheckpointNumber =
await this.store.getCheckpointData(provenCheckpointNumber);
const localCheckpointForDestinationProvenCheckpointNumber = await this.store.getCheckpointData(
rollupStatus.provenCheckpointNumber,
);

// Sanity check. I've hit what seems to be a state where the proven checkpoint is set to a value greater than the latest
// synched checkpoint when requesting L2Tips from the archiver. This is the only place where the proven checkpoint is set.
Expand All @@ -841,20 +839,20 @@ export class Archiver
}

this.log.trace(
`Local checkpoint for remote proven checkpoint ${provenCheckpointNumber} is ${
`Local checkpoint for remote proven checkpoint ${rollupStatus.provenCheckpointNumber} is ${
localCheckpointForDestinationProvenCheckpointNumber?.archive.root.toString() ?? 'undefined'
}`,
);

if (
localCheckpointForDestinationProvenCheckpointNumber &&
provenArchive === localCheckpointForDestinationProvenCheckpointNumber.archive.root.toString()
rollupStatus.provenArchive === localCheckpointForDestinationProvenCheckpointNumber.archive.root.toString()
) {
const localProvenCheckpointNumber = await this.getProvenCheckpointNumber();
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
await this.setProvenCheckpointNumber(provenCheckpointNumber);
this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, {
provenCheckpointNumber,
if (localProvenCheckpointNumber !== rollupStatus.provenCheckpointNumber) {
await this.setProvenCheckpointNumber(rollupStatus.provenCheckpointNumber);
this.log.info(`Updated proven chain to checkpoint ${rollupStatus.provenCheckpointNumber}`, {
provenCheckpointNumber: rollupStatus.provenCheckpointNumber,
});
const provenSlotNumber = localCheckpointForDestinationProvenCheckpointNumber.header.slotNumber;
const provenEpochNumber: EpochNumber = getEpochAtSlot(provenSlotNumber, this.l1constants);
Expand All @@ -871,14 +869,15 @@ export class Archiver
});
this.instrumentation.updateLastProvenBlock(lastBlockNumberInCheckpoint);
} else {
this.log.trace(`Proven checkpoint ${provenCheckpointNumber} already stored.`);
this.log.trace(`Proven checkpoint ${rollupStatus.provenCheckpointNumber} already stored.`);
}
}
};

// This is an edge case that we only hit if there are no proposed checkpoints.
// If we have 0 checkpoints locally and there are no checkpoints onchain there is nothing to do.
const noCheckpoints = localPendingCheckpointNumber === 0 && pendingCheckpointNumber === 0;
const noCheckpoints =
localPendingCheckpointNumber === 0 && rollupStatus.pendingCheckpointNumber === CheckpointNumber(0);
if (noCheckpoints) {
await this.store.setCheckpointSynchedL1BlockNumber(currentL1BlockNumber);
this.log.debug(
Expand All @@ -898,7 +897,7 @@ export class Archiver
}

const localPendingArchiveRoot = localPendingCheckpoint.archive.root.toString();
const noCheckpointSinceLast = localPendingCheckpoint && pendingArchive === localPendingArchiveRoot;
const noCheckpointSinceLast = localPendingCheckpoint && rollupStatus.pendingArchive === localPendingArchiveRoot;
if (noCheckpointSinceLast) {
// We believe the following line causes a problem when we encounter L1 re-orgs.
// Basically, by setting the synched L1 block number here, we are saying that we have
Expand All @@ -912,7 +911,8 @@ export class Archiver
return rollupStatus;
}

const localPendingCheckpointInChain = archiveForLocalPendingCheckpointNumber === localPendingArchiveRoot;
const localPendingCheckpointInChain =
archiveForLocalPendingCheckpointNumber.toString() === localPendingArchiveRoot;
if (!localPendingCheckpointInChain) {
// If our local pending checkpoint tip is not in the chain on L1 a "prune" must have happened
// or the L1 have reorged.
Expand All @@ -938,7 +938,7 @@ export class Archiver
archiveLocal: candidateCheckpoint.archive.root.toString(),
},
);
if (archiveAtContract === candidateCheckpoint.archive.root.toString()) {
if (archiveAtContract.equals(candidateCheckpoint.archive.root)) {
break;
}
tipAfterUnwind--;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/archiver/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function validateCheckpointAttestations(
reason,
block: checkpoint.blocks[0].toBlockInfo(),
committee,
seed,
seed: seed.toBigInt(),
epoch,
attestors,
attestations,
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/aztec-node/src/sentinel/sentinel.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EpochCache } from '@aztec/epoch-cache';
import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
import { Buffer32 } from '@aztec/foundation/buffer';
import { compactArray, times } from '@aztec/foundation/collection';
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
import { EthAddress } from '@aztec/foundation/eth-address';
Expand Down Expand Up @@ -536,7 +537,7 @@ describe('sentinel', () => {

epochCache.getCommittee.mockResolvedValue({
committee: [validator1, validator2, validator3],
seed: 0n,
seed: Buffer32.fromBigInt(0n),
epoch: epochNumber,
});

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-node/src/sentinel/sentinel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
this.lastProcessedSlot = slot;
return;
}
const proposerIndex = this.epochCache.computeProposerIndex(slot, epoch, seed, BigInt(committee.length));
const proposerIndex = this.epochCache.computeProposerIndex(slot, epoch, seed.toBigInt(), BigInt(committee.length));
const proposer = committee[Number(proposerIndex)];
const stats = await this.getSlotActivity(slot, epoch, proposer, committee);
this.logger.verbose(`Updating L2 slot ${slot} observed activity`, stats);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli/src/cmds/infrastructure/sequencers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function sequencers(opts: {
log(`Adding ${who} as sequencer`);

const stakingAsset = getContract({
address: await rollup.getStakingAsset(),
address: (await rollup.getStakingAsset()).toString() as `0x${string}`,
abi: TestERC20Abi,
client: walletClient,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('e2e_epochs/epochs_proof_fails', () => {
const firstCheckpointNumber = (await test.monitor.run()).checkpointNumber;
expect(firstCheckpointNumber).toBeGreaterThanOrEqual(CheckpointNumber(1));
const firstCheckpoint = await rollup.getCheckpoint(CheckpointNumber(1));
const firstCheckpointEpoch = getEpochAtSlot(SlotNumber.fromBigInt(firstCheckpoint.slotNumber), test.constants);
const firstCheckpointEpoch = getEpochAtSlot(firstCheckpoint.slotNumber, test.constants);
expect(firstCheckpointEpoch).toEqual(EpochNumber(0));

// Create prover node after test setup to avoid early proving. We ensure the prover does not retry txs.
Expand Down
6 changes: 2 additions & 4 deletions yarn-project/end-to-end/src/e2e_fees/fees_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ export class FeesTest {
const blockReward = await this.rollupContract.getCheckpointReward();
const rewardConfig = await this.rollupContract.getRewardConfig();

const balance = await this.feeJuiceBridgeTestHarness.getL1FeeJuiceBalance(
EthAddress.fromString(rewardConfig.rewardDistributor),
);
const balance = await this.feeJuiceBridgeTestHarness.getL1FeeJuiceBalance(rewardConfig.rewardDistributor);

const toDistribute = balance > blockReward ? blockReward : balance;
const sequencerBlockRewards = (toDistribute * BigInt(rewardConfig.sequencerBps)) / 10000n;
Expand Down Expand Up @@ -325,7 +323,7 @@ export class FeesTest {
const { baseFee } = await this.rollupContract.getL1FeesAt(block!.header.globalVariables.timestamp);
const proverCost =
mulDiv(
mulDiv(L1_GAS_PER_EPOCH_VERIFIED, baseFee, await this.rollupContract.getEpochDuration()),
mulDiv(L1_GAS_PER_EPOCH_VERIFIED, baseFee, BigInt(await this.rollupContract.getEpochDuration())),
1n,
await this.rollupContract.getManaTarget(),
) + (await this.rollupContract.getProvingCostPerMana());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ describe('L1Publisher integration', () => {
sha256ToField(blockBlobs.map(b => b.getEthVersionedBlobHash())),
);

let prevBlobAccumulatorHash = hexToBuffer(await rollup.getCurrentBlobCommitmentsHash());
let prevBlobAccumulatorHash = (await rollup.getCurrentBlobCommitmentsHash()).toBuffer();

blocks.push(block);
blobFieldsPerCheckpoint.push(checkpointBlobFields);
Expand Down Expand Up @@ -481,7 +481,7 @@ describe('L1Publisher integration', () => {
(await rollup.getEpochNumberForCheckpoint(prevCheckpointNumber));
// If we are at the first blob of the epoch, we must initialize the hash:
prevBlobAccumulatorHash = isFirstCheckpointOfEpoch ? Buffer.alloc(0) : prevBlobAccumulatorHash;
const currentBlobAccumulatorHash = hexToBuffer(await rollup.getCurrentBlobCommitmentsHash());
const currentBlobAccumulatorHash = (await rollup.getCurrentBlobCommitmentsHash()).toBuffer();
let expectedBlobAccumulatorHash = prevBlobAccumulatorHash;
blockBlobs
.map(b => b.commitment)
Expand Down Expand Up @@ -980,7 +980,7 @@ describe('L1Publisher integration', () => {
expect(sendRequestsResult!.failedActions).toEqual([]);
expect(await rollup.getCheckpointNumber()).toEqual(CheckpointNumber.fromBlockNumber(block2.number));
const rollupBlock = await rollup.getCheckpoint(CheckpointNumber.fromBlockNumber(block2.number));
expect(SlotNumber.fromBigInt(rollupBlock.slotNumber)).toEqual(block2.slot);
expect(rollupBlock.slotNumber).toEqual(block2.slot);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Signature } from '@aztec/foundation/eth-signature';
import { sleep } from '@aztec/foundation/sleep';
import { MockZKPassportVerifierAbi } from '@aztec/l1-artifacts/MockZKPassportVerifierAbi';
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
import { StakingAssetHandlerAbi } from '@aztec/l1-artifacts/StakingAssetHandlerAbi';
import type { SequencerClient } from '@aztec/sequencer-client';
import { BlockAttestation, ConsensusPayload } from '@aztec/stdlib/p2p';
import { ZkPassportProofParams } from '@aztec/stdlib/zkpassport';
Expand Down Expand Up @@ -104,12 +103,6 @@ describe('e2e_p2p_network', () => {
client: t.ctx.deployL1ContractsValues.l1Client,
});

const stakingAssetHandler = getContract({
address: t.ctx.deployL1ContractsValues.l1ContractAddresses.stakingAssetHandlerAddress!.toString(),
abi: StakingAssetHandlerAbi,
client: t.ctx.deployL1ContractsValues.l1Client,
});

const zkPassportVerifier = getContract({
address: t.ctx.deployL1ContractsValues.l1ContractAddresses.zkPassportVerifierAddress!.toString(),
abi: MockZKPassportVerifierAbi,
Expand Down Expand Up @@ -151,10 +144,9 @@ describe('e2e_p2p_network', () => {
expect(attestersImmedatelyAfterAdding.length).toBe(validators.length);

// Check that the validators are added correctly
const withdrawer = await stakingAssetHandler.read.withdrawer();
for (const validator of validators) {
const info = await rollupWrapper.getAttesterView(validator.attester.toString());
expect(info.config.withdrawer).toBe(withdrawer);
expect(info.config.publicKey).toBeDefined();
}

// Wait for the validators to be added to the rollup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { AztecNodeService } from '@aztec/aztec-node';
import { RollupContract } from '@aztec/ethereum/contracts';
import { EthAddress } from '@aztec/foundation/eth-address';
import { retryUntil } from '@aztec/foundation/retry';
import { tryStop } from '@aztec/stdlib/interfaces/server';

Expand Down Expand Up @@ -155,7 +154,7 @@ describe('e2e_p2p_multiple_validators_sentinel', () => {
await Promise.all([
retryUntil(() => t.monitor.l2SlotNumber >= targetSlot, `reached slot ${targetSlot}`, timeout),
retryUntil(
() => rollup.getCurrentProposer().then(p => firstNodeValidators.some(v => v.equals(EthAddress.fromString(p)))),
() => rollup.getCurrentProposer().then(p => firstNodeValidators.some(v => v.equals(p))),
'proposer is first node',
timeout,
),
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export class P2PNetworkTest {
);

const slasherContract = getContract({
address: getAddress(await rollup.getSlasherAddress()),
address: getAddress((await rollup.getSlasherAddress()).toString()),
abi: SlasherAbi,
client: this.ctx.deployL1ContractsValues.l1Client,
});
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/end-to-end/src/e2e_p2p/reqresp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('e2e_p2p_reqresp_tx', () => {
t.ctx.deployL1ContractsValues.l1ContractAddresses.rollupAddress,
);

const attesters = await rollupContract.getAttesters();
const attesters = (await rollupContract.getAttesters()).map(a => a.toString() as `0x${string}`);

const currentTime = await t.ctx.cheatCodes.eth.timestamp();
const slotDuration = await rollupContract.getSlotDuration();
Expand All @@ -168,12 +168,12 @@ describe('e2e_p2p_reqresp_tx', () => {
proposers.push(proposer);
}
// Get the indexes of the nodes that are responsible for the next two slots
const proposerIndexes = proposers.map(proposer => attesters.indexOf(proposer as `0x${string}`));
const proposerIndexes = proposers.map(proposer => attesters.indexOf(proposer.toString() as `0x${string}`));

if (proposerIndexes.some(i => i === -1)) {
throw new Error(
`Proposer index not found for proposer ` +
`(proposers=${proposers.join(',')}, indices=${proposerIndexes.join(',')})`,
`(proposers=${proposers.map(p => p.toString()).join(',')}, indices=${proposerIndexes.join(',')})`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('e2e_p2p_reqresp_tx_no_handshake', () => {
t.ctx.deployL1ContractsValues.l1ContractAddresses.rollupAddress,
);

const attesters = await rollupContract.getAttesters();
const attesters = (await rollupContract.getAttesters()).map(a => a.toString() as `0x${string}`);

const currentTime = await t.ctx.cheatCodes.eth.timestamp();
const slotDuration = await rollupContract.getSlotDuration();
Expand All @@ -173,12 +173,12 @@ describe('e2e_p2p_reqresp_tx_no_handshake', () => {
proposers.push(proposer);
}
// Get the indexes of the nodes that are responsible for the next two slots
const proposerIndexes = proposers.map(proposer => attesters.indexOf(proposer as `0x${string}`));
const proposerIndexes = proposers.map(proposer => attesters.indexOf(proposer.toString() as `0x${string}`));

if (proposerIndexes.some(i => i === -1)) {
throw new Error(
`Proposer index not found for proposer ` +
`(proposers=${proposers.join(',')}, indices=${proposerIndexes.join(',')})`,
`(proposers=${proposers.map(p => p.toString()).join(',')}, indices=${proposerIndexes.join(',')})`,
);
}

Expand Down
Loading
Loading