@aztec/ethereum 0.0.1-commit.e588bc7e5 → 0.0.1-commit.e5a3663dd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dest/client.d.ts +7 -1
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +14 -0
  4. package/dest/config.d.ts +6 -6
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +5 -9
  7. package/dest/contracts/chain_state_override.d.ts +38 -0
  8. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  9. package/dest/contracts/chain_state_override.js +100 -0
  10. package/dest/contracts/inbox.d.ts +3 -3
  11. package/dest/contracts/inbox.d.ts.map +1 -1
  12. package/dest/contracts/inbox.js +8 -2
  13. package/dest/contracts/index.d.ts +3 -3
  14. package/dest/contracts/index.d.ts.map +1 -1
  15. package/dest/contracts/index.js +2 -2
  16. package/dest/contracts/rollup.d.ts +4975 -22
  17. package/dest/contracts/rollup.d.ts.map +1 -1
  18. package/dest/contracts/rollup.js +107 -46
  19. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
  20. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  21. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +13 -15
  22. package/dest/deploy_aztec_l1_contracts.d.ts +3 -6
  23. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  24. package/dest/deploy_aztec_l1_contracts.js +2 -4
  25. package/dest/generated/l1-contracts-defaults.d.ts +1 -1
  26. package/dest/generated/l1-contracts-defaults.js +1 -1
  27. package/dest/l1_artifacts.d.ts +8675 -16072
  28. package/dest/l1_artifacts.d.ts.map +1 -1
  29. package/dest/l1_artifacts.js +9 -24
  30. package/dest/l1_contract_addresses.d.ts +1 -5
  31. package/dest/l1_contract_addresses.d.ts.map +1 -1
  32. package/dest/l1_contract_addresses.js +0 -6
  33. package/dest/l1_reader.js +1 -1
  34. package/dest/queries.d.ts +13 -2
  35. package/dest/queries.d.ts.map +1 -1
  36. package/dest/queries.js +62 -3
  37. package/dest/test/chain_monitor.d.ts +2 -1
  38. package/dest/test/chain_monitor.d.ts.map +1 -1
  39. package/dest/test/chain_monitor.js +5 -0
  40. package/dest/test/rollup_cheat_codes.d.ts +5 -1
  41. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  42. package/dest/test/rollup_cheat_codes.js +9 -1
  43. package/package.json +5 -5
  44. package/src/client.ts +18 -0
  45. package/src/config.ts +9 -13
  46. package/src/contracts/chain_state_override.ts +147 -0
  47. package/src/contracts/inbox.ts +11 -3
  48. package/src/contracts/index.ts +2 -2
  49. package/src/contracts/rollup.ts +114 -49
  50. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +14 -16
  51. package/src/deploy_aztec_l1_contracts.ts +1 -5
  52. package/src/generated/l1-contracts-defaults.ts +1 -1
  53. package/src/l1_artifacts.ts +12 -35
  54. package/src/l1_contract_addresses.ts +0 -7
  55. package/src/l1_reader.ts +1 -1
  56. package/src/queries.ts +70 -4
  57. package/src/test/chain_monitor.ts +5 -0
  58. package/src/test/rollup_cheat_codes.ts +11 -1
  59. package/dest/contracts/empire_slashing_proposer.d.ts +0 -69
  60. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  61. package/dest/contracts/empire_slashing_proposer.js +0 -216
  62. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  63. package/src/contracts/empire_slashing_proposer.ts +0 -265
@@ -15,6 +15,7 @@ import {
15
15
  type Account,
16
16
  type GetContractReturnType,
17
17
  type Hex,
18
+ type Log,
18
19
  type StateOverride,
19
20
  type WatchContractEventReturnType,
20
21
  encodeAbiParameters,
@@ -31,11 +32,10 @@ import type { L1ReaderConfig } from '../l1_reader.js';
31
32
  import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
32
33
  import type { ViemClient } from '../types.js';
33
34
  import { formatViemError } from '../utils.js';
34
- import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
35
35
  import { GSEContract } from './gse.js';
36
36
  import type { L1EventLog } from './log.js';
37
37
  import { SlasherContract } from './slasher_contract.js';
38
- import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
38
+ import { SlashingProposerContract } from './slashing_proposer.js';
39
39
  import { checkBlockTag } from './utils.js';
40
40
 
41
41
  export type ViemCommitteeAttestation = {
@@ -57,7 +57,6 @@ export type L1RollupContractAddresses = Pick<
57
57
  | 'feeJuiceAddress'
58
58
  | 'stakingAssetAddress'
59
59
  | 'rewardDistributorAddress'
60
- | 'slashFactoryAddress'
61
60
  | 'gseAddress'
62
61
  >;
63
62
 
@@ -87,12 +86,6 @@ export type ViemGasFees = {
87
86
  feePerL2Gas: bigint;
88
87
  };
89
88
 
90
- export enum SlashingProposerType {
91
- None = 0,
92
- Tally = 1,
93
- Empire = 2,
94
- }
95
-
96
89
  /**
97
90
  * Status of a validator/attester in the staking system.
98
91
  * Matches the Status enum in StakingLib.sol
@@ -136,6 +129,17 @@ export type L1FeeData = {
136
129
  blobFee: bigint;
137
130
  };
138
131
 
132
+ /** Field offsets within the CompressedTempCheckpointLog struct in Solidity storage. */
133
+ export enum TempCheckpointLogField {
134
+ HeaderHash = 0,
135
+ BlobCommitmentsHash = 1,
136
+ OutHash = 2,
137
+ AttestationsHash = 3,
138
+ PayloadDigest = 4,
139
+ SlotNumber = 5,
140
+ FeeHeader = 6,
141
+ }
142
+
139
143
  /** Components of the minimum fee per mana, as returned by the L1 rollup contract. */
140
144
  export type ManaMinFeeComponents = {
141
145
  sequencerCost: bigint;
@@ -270,34 +274,18 @@ export class RollupContract {
270
274
  return this.rollup;
271
275
  }
272
276
 
273
- public async getSlashingProposer(): Promise<
274
- EmpireSlashingProposerContract | TallySlashingProposerContract | undefined
275
- > {
277
+ public async getSlashingProposer(): Promise<SlashingProposerContract | undefined> {
276
278
  const slasher = await this.getSlasherContract();
277
279
  if (!slasher) {
278
280
  return undefined;
279
281
  }
280
282
 
281
283
  const proposerAddress = await slasher.getProposer();
282
- const proposerAbi = [
283
- {
284
- type: 'function',
285
- name: 'SLASHING_PROPOSER_TYPE',
286
- inputs: [],
287
- outputs: [{ name: '', type: 'uint8', internalType: 'enum SlasherFlavor' }],
288
- stateMutability: 'view',
289
- },
290
- ] as const;
291
-
292
- const proposer = getContract({ address: proposerAddress.toString(), abi: proposerAbi, client: this.client });
293
- const proposerType = await proposer.read.SLASHING_PROPOSER_TYPE();
294
- if (proposerType === SlashingProposerType.Tally.valueOf()) {
295
- return new TallySlashingProposerContract(this.client, proposerAddress);
296
- } else if (proposerType === SlashingProposerType.Empire.valueOf()) {
297
- return new EmpireSlashingProposerContract(this.client, proposerAddress);
298
- } else {
299
- throw new Error(`Unknown slashing proposer type: ${proposerType}`);
284
+ if (proposerAddress.isZero()) {
285
+ return undefined;
300
286
  }
287
+
288
+ return new SlashingProposerContract(this.client, proposerAddress);
301
289
  }
302
290
 
303
291
  @memoize
@@ -538,8 +526,9 @@ export class RollupContract {
538
526
  return this.rollup.read.getCheckpointReward();
539
527
  }
540
528
 
541
- async getCheckpointNumber(): Promise<CheckpointNumber> {
542
- return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber());
529
+ async getCheckpointNumber(options?: { blockNumber?: bigint }): Promise<CheckpointNumber> {
530
+ await checkBlockTag(options?.blockNumber, this.client);
531
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber(options));
543
532
  }
544
533
 
545
534
  async getProvenCheckpointNumber(options?: { blockNumber?: bigint }): Promise<CheckpointNumber> {
@@ -547,18 +536,31 @@ export class RollupContract {
547
536
  return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber(options));
548
537
  }
549
538
 
550
- async getSlotNumber(): Promise<SlotNumber> {
551
- return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
539
+ async getSlotNumber(options?: { blockNumber?: bigint }): Promise<SlotNumber> {
540
+ await checkBlockTag(options?.blockNumber, this.client);
541
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot(options));
552
542
  }
553
543
 
554
- async getL1FeesAt(timestamp: bigint): Promise<L1FeeData> {
555
- const result = await this.rollup.read.getL1FeesAt([timestamp]);
544
+ async getL1FeesAt(timestamp: bigint, options?: { blockNumber?: bigint }): Promise<L1FeeData> {
545
+ await checkBlockTag(options?.blockNumber, this.client);
546
+ const result = await this.rollup.read.getL1FeesAt([timestamp], options);
556
547
  return {
557
548
  baseFee: result.baseFee,
558
549
  blobFee: result.blobFee,
559
550
  };
560
551
  }
561
552
 
553
+ async getFeeHeader(checkpointNumber: bigint): Promise<FeeHeader> {
554
+ const result = await this.rollup.read.getFeeHeader([checkpointNumber]);
555
+ return {
556
+ excessMana: result.excessMana,
557
+ manaUsed: result.manaUsed,
558
+ ethPerFeeAsset: result.ethPerFeeAsset,
559
+ congestionCost: result.congestionCost,
560
+ proverCost: result.proverCost,
561
+ };
562
+ }
563
+
562
564
  getEthPerFeeAsset(): Promise<bigint> {
563
565
  return this.rollup.read.getEthPerFeeAsset();
564
566
  }
@@ -633,8 +635,9 @@ export class RollupContract {
633
635
  return EthAddress.fromString(result);
634
636
  }
635
637
 
636
- async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
637
- const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
638
+ async getCheckpoint(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }): Promise<CheckpointLog> {
639
+ await checkBlockTag(options?.blockNumber, this.client);
640
+ const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)], options);
638
641
  return {
639
642
  archive: Fr.fromString(result.archive),
640
643
  headerHash: Buffer32.fromString(result.headerHash),
@@ -667,6 +670,30 @@ export class RollupContract {
667
670
  );
668
671
  }
669
672
 
673
+ /**
674
+ * Returns the effective pending checkpoint, accounting for potential prunes.
675
+ * When a prune can happen, the L1 contract uses the proven checkpoint instead of the pending one.
676
+ * This mirrors the behavior of getEffectivePendingCheckpointNumber in STFLib.sol.
677
+ * @param atTimestamp - The timestamp to evaluate pruneability at. Defaults to the current L1 block timestamp.
678
+ * @param options - Optional L1 block number to pin the queries to.
679
+ */
680
+ getEffectivePendingCheckpoint(atTimestamp?: bigint, options?: { blockNumber?: bigint }) {
681
+ return retry(
682
+ async () => {
683
+ const timestamp = atTimestamp ?? (await this.client.getBlock()).timestamp;
684
+ const canPrune = await this.canPruneAtTime(timestamp, options);
685
+ if (canPrune) {
686
+ const provenCheckpointNumber = await this.getProvenCheckpointNumber(options);
687
+ return await this.getCheckpoint(provenCheckpointNumber, options);
688
+ }
689
+ const pendingCheckpointNumber = await this.getCheckpointNumber(options);
690
+ return await this.getCheckpoint(pendingCheckpointNumber, options);
691
+ },
692
+ 'getting effective pending checkpoint',
693
+ makeBackoff([0.5, 0.5, 0.5]),
694
+ );
695
+ }
696
+
670
697
  async getTips(): Promise<{ pending: CheckpointNumber; proven: CheckpointNumber }> {
671
698
  const { pending, proven } = await this.rollup.read.getTips();
672
699
  return {
@@ -789,19 +816,11 @@ export class RollupContract {
789
816
  archive: Buffer,
790
817
  account: `0x${string}` | Account,
791
818
  timestamp: bigint,
792
- opts: {
793
- forcePendingCheckpointNumber?: CheckpointNumber;
794
- forceArchive?: { checkpointNumber: CheckpointNumber; archive: Fr };
795
- } = {},
819
+ stateOverride: StateOverride = [],
796
820
  ): Promise<{ slot: SlotNumber; checkpointNumber: CheckpointNumber; timeOfNextL1Slot: bigint }> {
797
821
  const timeOfNextL1Slot = timestamp;
798
822
  const who = typeof account === 'string' ? account : account.address;
799
823
 
800
- const stateOverride = RollupContract.mergeStateOverrides(
801
- await this.makePendingCheckpointNumberOverride(opts.forcePendingCheckpointNumber),
802
- opts.forceArchive ? this.makeArchiveOverride(opts.forceArchive.checkpointNumber, opts.forceArchive.archive) : [],
803
- );
804
-
805
824
  try {
806
825
  const {
807
826
  result: [slot, checkpointNumber],
@@ -1206,7 +1225,7 @@ export class RollupContract {
1206
1225
  }
1207
1226
 
1208
1227
  public listenToCheckpointInvalidated(
1209
- callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
1228
+ callback: (args: { checkpointNumber: CheckpointNumber; event: Log }) => unknown,
1210
1229
  ): WatchContractEventReturnType {
1211
1230
  return this.rollup.watchEvent.CheckpointInvalidated(
1212
1231
  {},
@@ -1215,7 +1234,7 @@ export class RollupContract {
1215
1234
  for (const log of logs) {
1216
1235
  const args = log.args;
1217
1236
  if (args.checkpointNumber !== undefined) {
1218
- callback({ checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber) });
1237
+ callback({ checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber), event: log });
1219
1238
  }
1220
1239
  }
1221
1240
  },
@@ -1248,6 +1267,17 @@ export class RollupContract {
1248
1267
  );
1249
1268
  }
1250
1269
 
1270
+ /**
1271
+ * Fetches OwnershipTransferred events emitted on the L1 block this rollup was deployed on.
1272
+ * The Rollup inherits from Ownable and emits this event in its constructor, so the event
1273
+ * is guaranteed to exist on `l1StartBlock` for any correctly deployed rollup. Used as a
1274
+ * probe to detect RPC nodes that prune historical logs.
1275
+ */
1276
+ async getOwnershipTransferredEventsAtDeploy() {
1277
+ const l1StartBlock = await this.getL1StartBlock();
1278
+ return await this.rollup.getEvents.OwnershipTransferred({}, { fromBlock: l1StartBlock, toBlock: l1StartBlock });
1279
+ }
1280
+
1251
1281
  /** Fetches CheckpointProposed events within the given block range. */
1252
1282
  async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
1253
1283
  const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
@@ -1280,4 +1310,39 @@ export class RollupContract {
1280
1310
  },
1281
1311
  }));
1282
1312
  }
1313
+
1314
+ /** Packs pending and proven checkpoint numbers into the chain tips storage format. */
1315
+ static packChainTips(pendingCheckpointNumber: bigint, provenCheckpointNumber: bigint): bigint {
1316
+ return (pendingCheckpointNumber << 128n) | (provenCheckpointNumber & ((1n << 128n) - 1n));
1317
+ }
1318
+
1319
+ /** Storage slot for the chain tips (offset 0 within the STF storage struct). */
1320
+ static get chainTipsStorageSlot(): bigint {
1321
+ return BigInt(RollupContract.stfStorageSlot);
1322
+ }
1323
+
1324
+ /**
1325
+ * Computes the storage slot for a field within a tempCheckpointLog entry.
1326
+ * @param checkpointNumber - The checkpoint number
1327
+ * @param field - The field within the CompressedTempCheckpointLog struct
1328
+ */
1329
+ async getTempCheckpointLogStorageSlot(
1330
+ checkpointNumber: CheckpointNumber,
1331
+ field: TempCheckpointLogField,
1332
+ ): Promise<bigint> {
1333
+ const fieldOffset = BigInt(field);
1334
+ const [epochDuration, proofSubmissionEpochs] = await Promise.all([
1335
+ this.getEpochDuration(),
1336
+ this.getProofSubmissionEpochs(),
1337
+ ]);
1338
+ const roundaboutSize = BigInt(epochDuration) * (BigInt(proofSubmissionEpochs) + 1n) + 1n;
1339
+ const tempCheckpointLogsBase = BigInt(RollupContract.stfStorageSlot) + 2n;
1340
+ const circularIndex = BigInt(checkpointNumber) % roundaboutSize;
1341
+ const entryBase = BigInt(
1342
+ keccak256(
1343
+ encodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], [circularIndex, tempCheckpointLogsBase]),
1344
+ ),
1345
+ );
1346
+ return entryBase + fieldOffset;
1347
+ }
1283
1348
  }
@@ -7,7 +7,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
7
7
  import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import { hexToBuffer } from '@aztec/foundation/string';
9
9
  import { SlasherAbi } from '@aztec/l1-artifacts/SlasherAbi';
10
- import { TallySlashingProposerAbi } from '@aztec/l1-artifacts/TallySlashingProposerAbi';
10
+ import { SlashingProposerAbi } from '@aztec/l1-artifacts/SlashingProposerAbi';
11
11
 
12
12
  import {
13
13
  type GetContractReturnType,
@@ -19,13 +19,11 @@ import {
19
19
  } from 'viem';
20
20
 
21
21
  /**
22
- * Wrapper around the TallySlashingProposer contract that provides
22
+ * Wrapper around the SlashingProposer contract that provides
23
23
  * a TypeScript interface for interacting with the consensus-based slashing system.
24
24
  */
25
- export class TallySlashingProposerContract {
26
- private readonly contract: GetContractReturnType<typeof TallySlashingProposerAbi, ViemClient>;
27
-
28
- public readonly type = 'tally' as const;
25
+ export class SlashingProposerContract {
26
+ private readonly contract: GetContractReturnType<typeof SlashingProposerAbi, ViemClient>;
29
27
 
30
28
  constructor(
31
29
  public readonly client: ViemClient,
@@ -33,7 +31,7 @@ export class TallySlashingProposerContract {
33
31
  ) {
34
32
  this.contract = getContract({
35
33
  address: typeof address === 'string' ? address : address.toString(),
36
- abi: TallySlashingProposerAbi,
34
+ abi: SlashingProposerAbi,
37
35
  client,
38
36
  });
39
37
  }
@@ -136,12 +134,12 @@ export class TallySlashingProposerContract {
136
134
 
137
135
  /** Tries to extract a VoteCast event from the given logs. */
138
136
  public tryExtractVoteCastEvent(logs: Log[]) {
139
- return tryExtractEvent(logs, this.address.toString(), TallySlashingProposerAbi, 'VoteCast');
137
+ return tryExtractEvent(logs, this.address.toString(), SlashingProposerAbi, 'VoteCast');
140
138
  }
141
139
 
142
140
  /** Tries to extract a RoundExecuted event from the given logs. */
143
141
  public tryExtractRoundExecutedEvent(logs: Log[]) {
144
- return tryExtractEvent(logs, this.address.toString(), TallySlashingProposerAbi, 'RoundExecuted');
142
+ return tryExtractEvent(logs, this.address.toString(), SlashingProposerAbi, 'RoundExecuted');
145
143
  }
146
144
 
147
145
  /**
@@ -161,9 +159,9 @@ export class TallySlashingProposerContract {
161
159
 
162
160
  return {
163
161
  to: this.contract.address,
164
- abi: TallySlashingProposerAbi,
162
+ abi: SlashingProposerAbi,
165
163
  data: encodeFunctionData({
166
- abi: TallySlashingProposerAbi,
164
+ abi: SlashingProposerAbi,
167
165
  functionName: 'vote',
168
166
  args: [votes, signature.toViemSignature()],
169
167
  }),
@@ -173,7 +171,7 @@ export class TallySlashingProposerContract {
173
171
  /** Returns the typed data definition to EIP712-sign for voting */
174
172
  public buildVoteTypedData(votes: Hex, slot: SlotNumber): TypedDataDefinition {
175
173
  const domain = {
176
- name: 'TallySlashingProposer',
174
+ name: 'SlashingProposer',
177
175
  version: '1',
178
176
  chainId: this.client.chain.id,
179
177
  verifyingContract: this.contract.address,
@@ -209,9 +207,9 @@ export class TallySlashingProposerContract {
209
207
  public buildVoteRequestWithSignature(votes: Hex, signature: { v: number; r: Hex; s: Hex }): L1TxRequest {
210
208
  return {
211
209
  to: this.contract.address,
212
- abi: TallySlashingProposerAbi,
210
+ abi: SlashingProposerAbi,
213
211
  data: encodeFunctionData({
214
- abi: TallySlashingProposerAbi,
212
+ abi: SlashingProposerAbi,
215
213
  functionName: 'vote',
216
214
  args: [votes, signature],
217
215
  }),
@@ -227,9 +225,9 @@ export class TallySlashingProposerContract {
227
225
  public buildExecuteRoundRequest(round: bigint, committees: EthAddress[][]): L1TxRequest {
228
226
  return {
229
227
  to: this.contract.address,
230
- abi: mergeAbis([TallySlashingProposerAbi, SlasherAbi]),
228
+ abi: mergeAbis([SlashingProposerAbi, SlasherAbi]),
231
229
  data: encodeFunctionData({
232
- abi: TallySlashingProposerAbi,
230
+ abi: SlashingProposerAbi,
233
231
  functionName: 'executeRound',
234
232
  args: [round, committees.map(c => c.map(addr => addr.toString()))],
235
233
  }),
@@ -230,7 +230,6 @@ export function computeValidatorData(operator: Operator): ValidatorJson {
230
230
  export interface RollupUpgradeAddresses {
231
231
  rollupAddress: string;
232
232
  verifierAddress: string;
233
- slashFactoryAddress: string;
234
233
  inboxAddress: string;
235
234
  outboxAddress: string;
236
235
  feeJuicePortalAddress: string;
@@ -243,7 +242,6 @@ export interface RollupUpgradeAddresses {
243
242
  export interface ForgeRollupUpgradeResult {
244
243
  rollupAddress: Hex;
245
244
  verifierAddress: Hex;
246
- slashFactoryAddress: Hex;
247
245
  inboxAddress: Hex;
248
246
  outboxAddress: Hex;
249
247
  feeJuicePortalAddress: Hex;
@@ -403,7 +401,6 @@ export async function deployAztecL1Contracts(
403
401
  governanceProposerAddress: EthAddress.fromString(result.governanceProposerAddress),
404
402
  governanceAddress: EthAddress.fromString(result.governanceAddress),
405
403
  stakingAssetAddress: EthAddress.fromString(result.stakingAssetAddress),
406
- slashFactoryAddress: result.slashFactoryAddress ? EthAddress.fromString(result.slashFactoryAddress) : undefined,
407
404
  feeAssetHandlerAddress: result.feeAssetHandlerAddress
408
405
  ? EthAddress.fromString(result.feeAssetHandlerAddress)
409
406
  : undefined,
@@ -585,7 +582,7 @@ export function getDeployRollupForUpgradeEnvVars(
585
582
  AZTEC_EXIT_DELAY_SECONDS: args.exitDelaySeconds.toString(),
586
583
  AZTEC_PROVING_COST_PER_MANA: args.provingCostPerMana.toString(),
587
584
  AZTEC_INITIAL_ETH_PER_FEE_ASSET: args.initialEthPerFeeAsset.toString(),
588
- AZTEC_SLASHER_FLAVOR: args.slasherFlavor,
585
+ AZTEC_SLASHER_ENABLED: args.slasherEnabled ? 'true' : 'false',
589
586
  AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS: args.slashingRoundSizeInEpochs.toString(),
590
587
  AZTEC_SLASHING_QUORUM: args.slashingQuorum?.toString(),
591
588
  AZTEC_SLASHING_OFFSET_IN_ROUNDS: args.slashingOffsetInRounds.toString(),
@@ -645,6 +642,5 @@ export const deployRollupForUpgrade = async (
645
642
 
646
643
  return {
647
644
  rollup,
648
- slashFactoryAddress: result.slashFactoryAddress,
649
645
  };
650
646
  };
@@ -18,7 +18,7 @@ export const l1ContractsDefaultEnv = {
18
18
  AZTEC_MANA_TARGET: 100000000,
19
19
  AZTEC_PROVING_COST_PER_MANA: 100,
20
20
  AZTEC_INITIAL_ETH_PER_FEE_ASSET: 10000000,
21
- AZTEC_SLASHER_FLAVOR: 'tally',
21
+ AZTEC_SLASHER_ENABLED: true,
22
22
  AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS: 4,
23
23
  AZTEC_SLASHING_LIFETIME_IN_ROUNDS: 5,
24
24
  AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS: 0,
@@ -3,10 +3,6 @@ import {
3
3
  CoinIssuerBytecode,
4
4
  DateGatedRelayerAbi,
5
5
  DateGatedRelayerBytecode,
6
- EmpireSlasherDeploymentExtLibAbi,
7
- EmpireSlasherDeploymentExtLibBytecode,
8
- EmpireSlashingProposerAbi,
9
- EmpireSlashingProposerBytecode,
10
6
  FeeAssetHandlerAbi,
11
7
  FeeAssetHandlerBytecode,
12
8
  FeeJuicePortalAbi,
@@ -42,16 +38,14 @@ import {
42
38
  RollupLinkReferences,
43
39
  RollupOperationsExtLibAbi,
44
40
  RollupOperationsExtLibBytecode,
45
- SlashFactoryAbi,
46
- SlashFactoryBytecode,
47
41
  SlasherAbi,
48
42
  SlasherBytecode,
43
+ SlasherDeploymentExtLibAbi,
44
+ SlasherDeploymentExtLibBytecode,
45
+ SlashingProposerAbi,
46
+ SlashingProposerBytecode,
49
47
  StakingAssetHandlerAbi,
50
48
  StakingAssetHandlerBytecode,
51
- TallySlasherDeploymentExtLibAbi,
52
- TallySlasherDeploymentExtLibBytecode,
53
- TallySlashingProposerAbi,
54
- TallySlashingProposerBytecode,
55
49
  TestERC20Abi,
56
50
  TestERC20Bytecode,
57
51
  ValidatorOperationsExtLibAbi,
@@ -107,15 +101,10 @@ export const RollupArtifact = {
107
101
  contractAbi: RewardExtLibAbi,
108
102
  contractBytecode: RewardExtLibBytecode as Hex,
109
103
  },
110
- TallySlasherDeploymentExtLib: {
111
- name: 'TallySlasherDeploymentExtLib',
112
- contractAbi: TallySlasherDeploymentExtLibAbi,
113
- contractBytecode: TallySlasherDeploymentExtLibBytecode as Hex,
114
- },
115
- EmpireSlasherDeploymentExtLib: {
116
- name: 'EmpireSlasherDeploymentExtLib',
117
- contractAbi: EmpireSlasherDeploymentExtLibAbi,
118
- contractBytecode: EmpireSlasherDeploymentExtLibBytecode as Hex,
104
+ SlasherDeploymentExtLib: {
105
+ name: 'SlasherDeploymentExtLib',
106
+ contractAbi: SlasherDeploymentExtLibAbi,
107
+ contractBytecode: SlasherDeploymentExtLibBytecode as Hex,
119
108
  },
120
109
  },
121
110
  },
@@ -175,22 +164,10 @@ export const SlasherArtifact = {
175
164
  contractBytecode: SlasherBytecode as Hex,
176
165
  };
177
166
 
178
- export const EmpireSlashingProposerArtifact = {
179
- name: 'EmpireSlashingProposer',
180
- contractAbi: EmpireSlashingProposerAbi,
181
- contractBytecode: EmpireSlashingProposerBytecode as Hex,
182
- };
183
-
184
- export const TallySlashingProposerArtifact = {
185
- name: 'TallySlashingProposer',
186
- contractAbi: TallySlashingProposerAbi,
187
- contractBytecode: TallySlashingProposerBytecode as Hex,
188
- };
189
-
190
- export const SlashFactoryArtifact = {
191
- name: 'SlashFactory',
192
- contractAbi: SlashFactoryAbi,
193
- contractBytecode: SlashFactoryBytecode as Hex,
167
+ export const SlashingProposerArtifact = {
168
+ name: 'SlashingProposer',
169
+ contractAbi: SlashingProposerAbi,
170
+ contractBytecode: SlashingProposerBytecode as Hex,
194
171
  };
195
172
 
196
173
  export const RegisterNewRollupVersionPayloadArtifact = {
@@ -27,7 +27,6 @@ export const L1ContractsNames = [
27
27
  export type L1ContractAddresses = {
28
28
  [K in (typeof L1ContractsNames)[number]]: EthAddress;
29
29
  } & {
30
- slashFactoryAddress?: EthAddress | undefined;
31
30
  feeAssetHandlerAddress?: EthAddress | undefined;
32
31
  stakingAssetHandlerAddress?: EthAddress | undefined;
33
32
  zkPassportVerifierAddress?: EthAddress | undefined;
@@ -48,7 +47,6 @@ export const L1ContractAddressesSchema = zodFor<L1ContractAddresses>()(
48
47
  rewardDistributorAddress: schemas.EthAddress,
49
48
  governanceProposerAddress: schemas.EthAddress,
50
49
  governanceAddress: schemas.EthAddress,
51
- slashFactoryAddress: schemas.EthAddress.optional(),
52
50
  feeAssetHandlerAddress: schemas.EthAddress.optional(),
53
51
  stakingAssetHandlerAddress: schemas.EthAddress.optional(),
54
52
  zkPassportVerifierAddress: schemas.EthAddress.optional(),
@@ -67,11 +65,6 @@ export const l1ContractAddressesMapping: ConfigMappingsType<
67
65
  description: 'The deployed L1 registry contract address.',
68
66
  parseEnv,
69
67
  },
70
- slashFactoryAddress: {
71
- env: 'SLASH_FACTORY_CONTRACT_ADDRESS',
72
- description: 'The deployed L1 slashFactory contract address',
73
- parseEnv,
74
- },
75
68
  feeAssetHandlerAddress: {
76
69
  env: 'FEE_ASSET_HANDLER_CONTRACT_ADDRESS',
77
70
  description: 'The deployed L1 feeAssetHandler contract address',
package/src/l1_reader.ts CHANGED
@@ -30,7 +30,7 @@ export const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig> = {
30
30
  },
31
31
  l1ChainId: {
32
32
  env: 'L1_CHAIN_ID',
33
- parseEnv: (val: string) => +val,
33
+ ...optionalNumberConfigHelper(),
34
34
  description: 'The chain ID of the ethereum host.',
35
35
  },
36
36
  l1RpcUrls: {
package/src/queries.ts CHANGED
@@ -1,11 +1,77 @@
1
1
  import { EthAddress } from '@aztec/foundation/eth-address';
2
2
 
3
+ import { BaseError, type Block } from 'viem';
4
+
3
5
  import { DefaultL1ContractsConfig, type L1ContractsConfig } from './config.js';
4
6
  import { ReadOnlyGovernanceContract } from './contracts/governance.js';
5
7
  import { GovernanceProposerContract } from './contracts/governance_proposer.js';
6
8
  import { InboxContract } from './contracts/inbox.js';
7
9
  import { RollupContract } from './contracts/rollup.js';
8
- import type { ViemPublicClient } from './types.js';
10
+ import type { ViemClient, ViemPublicClient } from './types.js';
11
+
12
+ /**
13
+ * Returns the L1 finalized block, or `undefined` if the chain does not yet have one
14
+ * (common on freshly started devnets). Rethrows any other RPC error.
15
+ */
16
+ export async function getFinalizedL1Block(client: ViemClient): Promise<Block<bigint, false, 'finalized'> | undefined> {
17
+ try {
18
+ return await client.getBlock({ blockTag: 'finalized', includeTransactions: false });
19
+ } catch (err) {
20
+ if (isFinalizedBlockTagNotFoundError(err)) {
21
+ return undefined;
22
+ }
23
+ throw err;
24
+ }
25
+ }
26
+
27
+ // Error messages returned by popular Ethereum execution clients when
28
+ // eth_getBlockByNumber / eth_call is called with blockTag "finalized" or
29
+ // "safe" and no such block has been produced yet:
30
+ //
31
+ // geth "finalized block not found"
32
+ // "safe block not found"
33
+ // reth "block not found: finalized"
34
+ // "block not found: safe"
35
+ // nethermind "Unknown block error" (same for both tags)
36
+ // besu "Unknown block"
37
+ // erigon 'block "finalized" not available (head block: N)'
38
+ // 'block "safe" not available (head block: N)'
39
+ //
40
+ // A combined regex covers all five:
41
+ const FINALIZED_BLOCK_TAG_NOT_FOUND_MESSAGE_RE =
42
+ /(finalized|safe) block not found|block not found: (finalized|safe)|unknown block|block "(finalized|safe)" not available/i;
43
+
44
+ /**
45
+ * Returns true if the error originates from an RPC call that failed because
46
+ * the "finalized" (or "safe") block tag is not yet available on the chain.
47
+ */
48
+ export function isFinalizedBlockTagNotFoundError(err: unknown): boolean {
49
+ if (!err) {
50
+ return false;
51
+ }
52
+
53
+ if (err instanceof BaseError) {
54
+ const hit = err.walk((e: any) => matchesFinalizedBlockTagNotFound(e));
55
+ if (hit) {
56
+ return true;
57
+ }
58
+ }
59
+
60
+ for (let cur: any = err, i = 0; cur && i < 10; cur = cur.cause, i++) {
61
+ if (matchesFinalizedBlockTagNotFound(cur)) {
62
+ return true;
63
+ }
64
+ }
65
+ return false;
66
+ }
67
+
68
+ function matchesFinalizedBlockTagNotFound(e: any): boolean {
69
+ if (!e) {
70
+ return false;
71
+ }
72
+ const text = `${e.details ?? ''} ${e.message ?? ''} ${e.shortMessage ?? ''}`;
73
+ return FINALIZED_BLOCK_TAG_NOT_FOUND_MESSAGE_RE.test(text);
74
+ }
9
75
 
10
76
  /** Reads the L1ContractsConfig from L1 contracts. */
11
77
  export async function getL1ContractsConfig(
@@ -76,8 +142,8 @@ export async function getL1ContractsConfig(
76
142
  slasherProposer?.getRoundSize() ?? 0n,
77
143
  slasherProposer?.getLifetimeInRounds() ?? 0n,
78
144
  slasherProposer?.getExecutionDelayInRounds() ?? 0n,
79
- slasherProposer?.type === 'tally' ? slasherProposer.getSlashOffsetInRounds() : 0n,
80
- slasherProposer?.type === 'tally' ? slasherProposer.getSlashingAmounts() : [0n, 0n, 0n],
145
+ slasherProposer?.getSlashOffsetInRounds() ?? 0n,
146
+ slasherProposer?.getSlashingAmounts() ?? [0n, 0n, 0n],
81
147
  slasher?.getVetoer() ?? EthAddress.ZERO,
82
148
  slasher?.getSlashingDisableDuration() ?? 0,
83
149
  rollup.getManaTarget(),
@@ -114,7 +180,7 @@ export async function getL1ContractsConfig(
114
180
  rollupVersion: Number(rollupVersion),
115
181
  genesisArchiveTreeRoot: genesisArchiveTreeRoot.toString(),
116
182
  exitDelaySeconds: Number(exitDelay),
117
- slasherFlavor: slasherProposer?.type ?? 'tally',
183
+ slasherEnabled: !!slasherProposer,
118
184
  slashingOffsetInRounds: Number(slashingOffsetInRounds),
119
185
  slashAmountSmall: slashingAmounts[0],
120
186
  slashAmountMedium: slashingAmounts[1],
@@ -221,6 +221,11 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
221
221
  });
222
222
  }
223
223
 
224
+ public async waitUntilNextL2Slot(): Promise<void> {
225
+ const targetSlot = SlotNumber.add((await this.run()).l2SlotNumber, 1);
226
+ return this.waitUntilL2Slot(targetSlot);
227
+ }
228
+
224
229
  public waitUntilL1Block(block: number | bigint): Promise<void> {
225
230
  const targetBlock = typeof block === 'bigint' ? block.valueOf() : block;
226
231
  if (this.l1BlockNumber >= targetBlock) {
@@ -53,7 +53,17 @@ export class RollupCheatCodes {
53
53
  /** Returns the current slot */
54
54
  public async getSlot(): Promise<SlotNumber> {
55
55
  const ts = BigInt((await this.client.getBlock()).timestamp);
56
- return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([ts]));
56
+ return this.getSlotAt(ts);
57
+ }
58
+
59
+ /** Returns the slot number at a given timestamp. */
60
+ public async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
61
+ return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
62
+ }
63
+
64
+ /** Returns the timestamp for the start of a given slot. */
65
+ public async getTimestampForSlot(slot: SlotNumber): Promise<bigint> {
66
+ return await this.rollup.read.getTimestampForSlot([BigInt(slot)]);
57
67
  }
58
68
 
59
69
  /** Returns the number of seconds until the start of the given slot based on L1 block timestamp. */