@aztec/archiver 0.0.1-commit.0c875d939 → 0.0.1-commit.0dc957cde

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 (114) hide show
  1. package/README.md +12 -6
  2. package/dest/archiver.d.ts +13 -8
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +90 -114
  5. package/dest/config.d.ts +5 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +15 -3
  8. package/dest/errors.d.ts +50 -10
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +67 -16
  11. package/dest/factory.d.ts +4 -5
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +31 -27
  14. package/dest/index.d.ts +4 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +3 -1
  17. package/dest/l1/bin/retrieve-calldata.js +32 -28
  18. package/dest/l1/calldata_retriever.d.ts +73 -52
  19. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  20. package/dest/l1/calldata_retriever.js +191 -261
  21. package/dest/l1/data_retrieval.d.ts +24 -16
  22. package/dest/l1/data_retrieval.d.ts.map +1 -1
  23. package/dest/l1/data_retrieval.js +39 -45
  24. package/dest/l1/spire_proposer.d.ts +5 -5
  25. package/dest/l1/spire_proposer.d.ts.map +1 -1
  26. package/dest/l1/spire_proposer.js +9 -17
  27. package/dest/l1/validate_historical_logs.d.ts +23 -0
  28. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  29. package/dest/l1/validate_historical_logs.js +108 -0
  30. package/dest/modules/data_source_base.d.ts +14 -7
  31. package/dest/modules/data_source_base.d.ts.map +1 -1
  32. package/dest/modules/data_source_base.js +39 -77
  33. package/dest/modules/data_store_updater.d.ts +35 -15
  34. package/dest/modules/data_store_updater.d.ts.map +1 -1
  35. package/dest/modules/data_store_updater.js +137 -96
  36. package/dest/modules/instrumentation.d.ts +21 -3
  37. package/dest/modules/instrumentation.d.ts.map +1 -1
  38. package/dest/modules/instrumentation.js +41 -8
  39. package/dest/modules/l1_synchronizer.d.ts +10 -9
  40. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  41. package/dest/modules/l1_synchronizer.js +279 -150
  42. package/dest/modules/validation.d.ts +1 -1
  43. package/dest/modules/validation.d.ts.map +1 -1
  44. package/dest/modules/validation.js +2 -2
  45. package/dest/store/block_store.d.ts +73 -28
  46. package/dest/store/block_store.d.ts.map +1 -1
  47. package/dest/store/block_store.js +395 -136
  48. package/dest/store/contract_class_store.d.ts +2 -3
  49. package/dest/store/contract_class_store.d.ts.map +1 -1
  50. package/dest/store/contract_class_store.js +7 -67
  51. package/dest/store/contract_instance_store.d.ts +1 -1
  52. package/dest/store/contract_instance_store.d.ts.map +1 -1
  53. package/dest/store/contract_instance_store.js +6 -2
  54. package/dest/store/kv_archiver_store.d.ts +67 -24
  55. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  56. package/dest/store/kv_archiver_store.js +82 -27
  57. package/dest/store/l2_tips_cache.d.ts +20 -0
  58. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  59. package/dest/store/l2_tips_cache.js +109 -0
  60. package/dest/store/log_store.d.ts +6 -3
  61. package/dest/store/log_store.d.ts.map +1 -1
  62. package/dest/store/log_store.js +95 -20
  63. package/dest/store/message_store.d.ts +5 -1
  64. package/dest/store/message_store.d.ts.map +1 -1
  65. package/dest/store/message_store.js +21 -9
  66. package/dest/test/fake_l1_state.d.ts +24 -1
  67. package/dest/test/fake_l1_state.d.ts.map +1 -1
  68. package/dest/test/fake_l1_state.js +145 -28
  69. package/dest/test/mock_archiver.d.ts +1 -1
  70. package/dest/test/mock_archiver.d.ts.map +1 -1
  71. package/dest/test/mock_archiver.js +3 -2
  72. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  73. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  74. package/dest/test/mock_l1_to_l2_message_source.js +2 -1
  75. package/dest/test/mock_l2_block_source.d.ts +26 -5
  76. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  77. package/dest/test/mock_l2_block_source.js +160 -89
  78. package/dest/test/mock_structs.d.ts +4 -1
  79. package/dest/test/mock_structs.d.ts.map +1 -1
  80. package/dest/test/mock_structs.js +13 -1
  81. package/dest/test/noop_l1_archiver.d.ts +4 -1
  82. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  83. package/dest/test/noop_l1_archiver.js +9 -3
  84. package/package.json +13 -13
  85. package/src/archiver.ts +120 -137
  86. package/src/config.ts +22 -2
  87. package/src/errors.ts +104 -26
  88. package/src/factory.ts +31 -16
  89. package/src/index.ts +3 -1
  90. package/src/l1/README.md +25 -68
  91. package/src/l1/bin/retrieve-calldata.ts +40 -27
  92. package/src/l1/calldata_retriever.ts +250 -383
  93. package/src/l1/data_retrieval.ts +55 -69
  94. package/src/l1/spire_proposer.ts +7 -15
  95. package/src/l1/validate_historical_logs.ts +140 -0
  96. package/src/modules/data_source_base.ts +78 -98
  97. package/src/modules/data_store_updater.ts +164 -126
  98. package/src/modules/instrumentation.ts +56 -9
  99. package/src/modules/l1_synchronizer.ts +357 -188
  100. package/src/modules/validation.ts +2 -2
  101. package/src/store/block_store.ts +503 -172
  102. package/src/store/contract_class_store.ts +8 -106
  103. package/src/store/contract_instance_store.ts +8 -5
  104. package/src/store/kv_archiver_store.ts +130 -41
  105. package/src/store/l2_tips_cache.ts +134 -0
  106. package/src/store/log_store.ts +128 -32
  107. package/src/store/message_store.ts +27 -10
  108. package/src/structs/inbox_message.ts +1 -1
  109. package/src/test/fake_l1_state.ts +193 -32
  110. package/src/test/mock_archiver.ts +3 -2
  111. package/src/test/mock_l1_to_l2_message_source.ts +1 -0
  112. package/src/test/mock_l2_block_source.ts +209 -82
  113. package/src/test/mock_structs.ts +20 -6
  114. package/src/test/noop_l1_archiver.ts +10 -2
package/src/errors.ts CHANGED
@@ -6,24 +6,9 @@ export class NoBlobBodiesFoundError extends Error {
6
6
  }
7
7
  }
8
8
 
9
- export class InitialBlockNumberNotSequentialError extends Error {
10
- constructor(
11
- public readonly newBlockNumber: number,
12
- public readonly previousBlockNumber: number | undefined,
13
- ) {
14
- super(
15
- `Cannot insert new block ${newBlockNumber} given previous block number in store is ${
16
- previousBlockNumber ?? 'undefined'
17
- }`,
18
- );
19
- }
20
- }
21
-
22
9
  export class BlockNumberNotSequentialError extends Error {
23
10
  constructor(newBlockNumber: number, previous: number | undefined) {
24
- super(
25
- `Cannot insert new block ${newBlockNumber} given previous block number in batch is ${previous ?? 'undefined'}`,
26
- );
11
+ super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
27
12
  }
28
13
  }
29
14
 
@@ -41,17 +26,13 @@ export class InitialCheckpointNumberNotSequentialError extends Error {
41
26
  }
42
27
 
43
28
  export class CheckpointNumberNotSequentialError extends Error {
44
- constructor(newCheckpointNumber: number, previous: number | undefined) {
45
- super(
46
- `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number in batch is ${previous ?? 'undefined'}`,
47
- );
48
- }
49
- }
50
-
51
- export class CheckpointNumberNotConsistentError extends Error {
52
- constructor(newCheckpointNumber: number, previous: number | undefined) {
29
+ constructor(
30
+ newCheckpointNumber: number,
31
+ previous: number | undefined,
32
+ source: 'confirmed' | 'proposed' = 'confirmed',
33
+ ) {
53
34
  super(
54
- `Cannot insert block for new checkpoint ${newCheckpointNumber} given previous block was checkpoint ${previous ?? 'undefined'}`,
35
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous ${source} checkpoint number is ${previous ?? 'undefined'}`,
55
36
  );
56
37
  }
57
38
  }
@@ -89,6 +70,103 @@ export class BlockNotFoundError extends Error {
89
70
  }
90
71
  }
91
72
 
73
+ /** Thrown when a proposed block matches a block that was already checkpointed. This is expected for late proposals. */
74
+ export class BlockAlreadyCheckpointedError extends Error {
75
+ constructor(public readonly blockNumber: number) {
76
+ super(`Block ${blockNumber} has already been checkpointed with the same content`);
77
+ this.name = 'BlockAlreadyCheckpointedError';
78
+ }
79
+ }
80
+
81
+ /** Thrown when logs are added for a tag whose last stored log has a higher block number than the new log. */
82
+ export class OutOfOrderLogInsertionError extends Error {
83
+ constructor(
84
+ public readonly logType: 'private' | 'public',
85
+ public readonly tag: string,
86
+ public readonly lastBlockNumber: number,
87
+ public readonly newBlockNumber: number,
88
+ ) {
89
+ super(
90
+ `Out-of-order ${logType} log insertion for tag ${tag}: ` +
91
+ `last existing log is from block ${lastBlockNumber} but new log is from block ${newBlockNumber}`,
92
+ );
93
+ this.name = 'OutOfOrderLogInsertionError';
94
+ }
95
+ }
96
+
97
+ /** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
98
+ export class L1ToL2MessagesNotReadyError extends Error {
99
+ constructor(
100
+ public readonly checkpointNumber: number,
101
+ public readonly inboxTreeInProgress: bigint,
102
+ ) {
103
+ super(
104
+ `Cannot get L1 to L2 messages for checkpoint ${checkpointNumber}: ` +
105
+ `inbox tree in progress is ${inboxTreeInProgress}, messages not yet sealed`,
106
+ );
107
+ this.name = 'L1ToL2MessagesNotReadyError';
108
+ }
109
+ }
110
+
111
+ /** Thrown when a proposed checkpoint number is stale (already processed). */
112
+ export class ProposedCheckpointStaleError extends Error {
113
+ constructor(
114
+ public readonly proposedCheckpointNumber: number,
115
+ public readonly currentProposedNumber: number,
116
+ ) {
117
+ super(`Stale proposed checkpoint ${proposedCheckpointNumber}: current proposed is ${currentProposedNumber}`);
118
+ this.name = 'ProposedCheckpointStaleError';
119
+ }
120
+ }
121
+
122
+ /** Thrown when a proposed checkpoint number is not the expected confirmed + 1. */
123
+ export class ProposedCheckpointNotSequentialError extends Error {
124
+ constructor(
125
+ public readonly proposedCheckpointNumber: number,
126
+ public readonly confirmedCheckpointNumber: number,
127
+ ) {
128
+ super(
129
+ `Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${confirmedCheckpointNumber + 1} (confirmed + 1)`,
130
+ );
131
+ this.name = 'ProposedCheckpointNotSequentialError';
132
+ }
133
+ }
134
+
135
+ /** Thrown when attempting to promote a proposed checkpoint but no proposed checkpoint exists in the store. */
136
+ export class NoProposedCheckpointToPromoteError extends Error {
137
+ constructor() {
138
+ super('Cannot promote proposed checkpoint: no proposed checkpoint exists');
139
+ this.name = 'NoProposedCheckpointToPromoteError';
140
+ }
141
+ }
142
+
143
+ /** Thrown when the archive root of the proposed checkpoint does not match the expected one. */
144
+ export class ProposedCheckpointArchiveRootMismatchError extends Error {
145
+ constructor(
146
+ public readonly expectedArchiveRoot: Fr,
147
+ public readonly actualArchiveRoot: Fr,
148
+ ) {
149
+ super(
150
+ `Cannot promote proposed checkpoint: archive root mismatch (expected ${expectedArchiveRoot}, got ${actualArchiveRoot})`,
151
+ );
152
+ this.name = 'ProposedCheckpointArchiveRootMismatchError';
153
+ }
154
+ }
155
+
156
+ /** Thrown when the proposed checkpoint does not directly follow the latest confirmed checkpoint. */
157
+ export class ProposedCheckpointPromotionNotSequentialError extends Error {
158
+ constructor(
159
+ public readonly proposedCheckpointNumber: number,
160
+ public readonly latestCheckpointNumber: number,
161
+ ) {
162
+ super(
163
+ `Cannot promote proposed checkpoint: not sequential (latest ${latestCheckpointNumber}, proposed ${proposedCheckpointNumber})`,
164
+ );
165
+ this.name = 'ProposedCheckpointPromotionNotSequentialError';
166
+ }
167
+ }
168
+
169
+ /** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
92
170
  export class CannotOverwriteCheckpointedBlockError extends Error {
93
171
  constructor(
94
172
  public readonly blockNumber: number,
package/src/factory.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { EpochCache } from '@aztec/epoch-cache';
2
2
  import { createEthereumChain } from '@aztec/ethereum/chain';
3
+ import { makeL1HttpTransport } from '@aztec/ethereum/client';
3
4
  import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
4
5
  import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
5
6
  import { BlockNumber } from '@aztec/foundation/branded-types';
@@ -7,38 +8,37 @@ import { Buffer32 } from '@aztec/foundation/buffer';
7
8
  import { merge } from '@aztec/foundation/collection';
8
9
  import { Fr } from '@aztec/foundation/curves/bn254';
9
10
  import { DateProvider } from '@aztec/foundation/timer';
10
- import type { DataStoreConfig } from '@aztec/kv-store/config';
11
11
  import { createStore } from '@aztec/kv-store/lmdb-v2';
12
12
  import { protocolContractNames } from '@aztec/protocol-contracts';
13
13
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
14
14
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
15
15
  import type { ArchiverEmitter } from '@aztec/stdlib/block';
16
- import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
17
- import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
16
+ import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
17
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
18
18
  import { getTelemetryClient } from '@aztec/telemetry-client';
19
19
 
20
20
  import { EventEmitter } from 'events';
21
- import { createPublicClient, fallback, http } from 'viem';
21
+ import { createPublicClient } from 'viem';
22
22
 
23
23
  import { Archiver, type ArchiverDeps } from './archiver.js';
24
24
  import { type ArchiverConfig, mapArchiverConfig } from './config.js';
25
25
  import { ArchiverInstrumentation } from './modules/instrumentation.js';
26
26
  import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
27
27
  import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './store/kv_archiver_store.js';
28
+ import { L2TipsCache } from './store/l2_tips_cache.js';
28
29
 
29
30
  export const ARCHIVER_STORE_NAME = 'archiver';
30
31
 
31
32
  /** Creates an archiver store. */
32
33
  export async function createArchiverStore(
33
34
  userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
34
- l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
35
35
  ) {
36
36
  const config = {
37
37
  ...userConfig,
38
38
  dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
39
39
  };
40
40
  const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
41
- return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
41
+ return new KVArchiverDataStore(store, config.maxLogs);
42
42
  }
43
43
 
44
44
  /**
@@ -53,14 +53,15 @@ export async function createArchiver(
53
53
  deps: ArchiverDeps,
54
54
  opts: { blockUntilSync: boolean } = { blockUntilSync: true },
55
55
  ): Promise<Archiver> {
56
- const archiverStore = await createArchiverStore(config, { epochDuration: config.aztecEpochDuration });
56
+ const archiverStore = await createArchiverStore(config);
57
57
  await registerProtocolContracts(archiverStore);
58
58
 
59
59
  // Create Ethereum clients
60
60
  const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
61
+ const httpTimeout = config.l1HttpTimeoutMS;
61
62
  const publicClient = createPublicClient({
62
63
  chain: chain.chainInfo,
63
- transport: fallback(config.l1RpcUrls.map(url => http(url, { batch: false }))),
64
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: httpTimeout }),
64
65
  pollingInterval: config.viemPollingIntervalMS,
65
66
  });
66
67
 
@@ -68,7 +69,7 @@ export async function createArchiver(
68
69
  const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
69
70
  const debugClient = createPublicClient({
70
71
  chain: chain.chainInfo,
71
- transport: fallback(debugRpcUrls.map(url => http(url, { batch: false }))),
72
+ transport: makeL1HttpTransport(debugRpcUrls, { timeout: httpTimeout }),
72
73
  pollingInterval: config.viemPollingIntervalMS,
73
74
  }) as ViemPublicDebugClient;
74
75
 
@@ -84,6 +85,7 @@ export async function createArchiver(
84
85
  genesisArchiveRoot,
85
86
  slashingProposerAddress,
86
87
  targetCommitteeSize,
88
+ rollupManaLimit,
87
89
  ] = await Promise.all([
88
90
  rollup.getL1StartBlock(),
89
91
  rollup.getL1GenesisTime(),
@@ -91,6 +93,7 @@ export async function createArchiver(
91
93
  rollup.getGenesisArchiveTreeRoot(),
92
94
  rollup.getSlashingProposerAddress(),
93
95
  rollup.getTargetCommitteeSize(),
96
+ rollup.getManaLimit(),
94
97
  ] as const);
95
98
 
96
99
  const l1StartBlockHash = await publicClient
@@ -109,6 +112,7 @@ export async function createArchiver(
109
112
  proofSubmissionEpochs: Number(proofSubmissionEpochs),
110
113
  targetCommitteeSize,
111
114
  genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
115
+ rollupManaLimit: Number(rollupManaLimit),
112
116
  };
113
117
 
114
118
  const archiverConfig = merge(
@@ -117,6 +121,7 @@ export async function createArchiver(
117
121
  batchSize: 100,
118
122
  maxAllowedEthClientDriftSeconds: 300,
119
123
  ethereumAllowNoDebugHosts: false,
124
+ skipHistoricalLogsCheck: false,
120
125
  },
121
126
  mapArchiverConfig(config),
122
127
  );
@@ -128,13 +133,15 @@ export async function createArchiver(
128
133
  // Create the event emitter that will be shared by archiver and synchronizer
129
134
  const events = new EventEmitter() as ArchiverEmitter;
130
135
 
136
+ // Create L2 tips cache shared by archiver and synchronizer
137
+ const l2TipsCache = new L2TipsCache(archiverStore.blockStore);
138
+
131
139
  // Create the L1 synchronizer
132
140
  const synchronizer = new ArchiverL1Synchronizer(
133
141
  publicClient,
134
142
  debugClient,
135
143
  rollup,
136
144
  inbox,
137
- { ...config.l1Contracts, slashingProposerAddress },
138
145
  archiverStore,
139
146
  archiverConfig,
140
147
  deps.blobClient,
@@ -144,6 +151,8 @@ export async function createArchiver(
144
151
  l1Constants,
145
152
  events,
146
153
  instrumentation.tracer,
154
+ l2TipsCache,
155
+ undefined, // log (use default)
147
156
  );
148
157
 
149
158
  const archiver = new Archiver(
@@ -158,22 +167,29 @@ export async function createArchiver(
158
167
  l1Constants,
159
168
  synchronizer,
160
169
  events,
170
+ l2TipsCache,
161
171
  );
162
172
 
163
173
  await archiver.start(opts.blockUntilSync);
164
174
  return archiver;
165
175
  }
166
176
 
167
- /** Registers protocol contracts in the archiver store. */
177
+ /** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
168
178
  export async function registerProtocolContracts(store: KVArchiverDataStore) {
169
179
  const blockNumber = 0;
170
180
  for (const name of protocolContractNames) {
171
181
  const provider = new BundledProtocolContractsProvider();
172
182
  const contract = await provider.getProtocolContractArtifact(name);
173
- const contractClassPublic: ContractClassPublic = {
183
+
184
+ // Skip if already registered (happens on node restart with a persisted store).
185
+ if (await store.getContractClass(contract.contractClass.id)) {
186
+ continue;
187
+ }
188
+
189
+ const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
190
+ const contractClassPublic: ContractClassPublicWithCommitment = {
174
191
  ...contract.contractClass,
175
- privateFunctions: [],
176
- utilityFunctions: [],
192
+ publicBytecodeCommitment,
177
193
  };
178
194
 
179
195
  const publicFunctionSignatures = contract.artifact.functions
@@ -181,8 +197,7 @@ export async function registerProtocolContracts(store: KVArchiverDataStore) {
181
197
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
182
198
 
183
199
  await store.registerContractFunctionSignatures(publicFunctionSignatures);
184
- const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
185
- await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
200
+ await store.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
186
201
  await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
187
202
  }
188
203
  }
package/src/index.ts CHANGED
@@ -8,5 +8,7 @@ export * from './config.js';
8
8
  export { type L1PublishedData } from './structs/published.js';
9
9
  export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './store/kv_archiver_store.js';
10
10
  export { ContractInstanceStore } from './store/contract_instance_store.js';
11
+ export { L2TipsCache } from './store/l2_tips_cache.js';
11
12
 
12
- export { retrieveCheckpointsFromRollup, retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
13
+ export { retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
14
+ export { CalldataRetriever } from './l1/calldata_retriever.js';
package/src/l1/README.md CHANGED
@@ -5,29 +5,27 @@ Modules and classes to handle data retrieval from L1 for the archiver.
5
5
  ## Calldata Retriever
6
6
 
7
7
  The sequencer publisher bundles multiple operations into a single multicall3 transaction for gas
8
- efficiency. A typical transaction includes:
8
+ efficiency. The archiver needs to extract the `propose` calldata from these bundled transactions
9
+ to reconstruct L2 blocks.
9
10
 
10
- 1. Attestation invalidations (if needed): `invalidateBadAttestation`, `invalidateInsufficientAttestations`
11
- 2. Block proposal: `propose` (exactly one per transaction to the rollup contract)
12
- 3. Governance and slashing (if needed): votes, payload creation/execution
11
+ The retriever uses hash matching against `attestationsHash` and `payloadDigest` from the
12
+ `CheckpointProposed` L1 event to verify it has found the correct propose calldata. These hashes
13
+ are always required.
13
14
 
14
- The archiver needs to extract the `propose` calldata from these bundled transactions to reconstruct
15
- L2 blocks. This class needs to handle scenarios where the transaction was submitted via multicall3,
16
- as well as alternative ways for submitting the `propose` call that other clients might use.
15
+ ### Multicall3 Decoding with Hash Matching
17
16
 
18
- ### Multicall3 Validation and Decoding
19
-
20
- First attempt to decode the transaction as a multicall3 `aggregate3` call with validation:
17
+ First attempt to decode the transaction as a multicall3 `aggregate3` call:
21
18
 
22
19
  - Check if transaction is to multicall3 address (`0xcA11bde05977b3631167028862bE2a173976CA11`)
23
20
  - Decode as `aggregate3(Call3[] calldata calls)`
24
- - Allow calls to known addresses and methods (rollup, governance, slashing contracts, etc.)
25
- - Find the single `propose` call to the rollup contract
26
- - Verify exactly one `propose` call exists
27
- - Extract and return the propose calldata
21
+ - Find all calls matching the rollup contract address and the `propose` function selector
22
+ - Verify each candidate by computing `attestationsHash` (keccak256 of ABI-encoded attestations)
23
+ and `payloadDigest` (keccak256 of the consensus payload signing hash) and comparing against
24
+ expected values from the `CheckpointProposed` event
25
+ - Return the verified candidate (if multiple verify, return the first with a warning)
28
26
 
29
- This step handles the common case efficiently without requiring expensive trace or debug RPC calls.
30
- Any validation failure triggers fallback to the next step.
27
+ This approach works regardless of what other calls are in the multicall3 bundle, because hash
28
+ matching identifies the correct propose call without needing an allowlist.
31
29
 
32
30
  ### Direct Propose Call
33
31
 
@@ -35,64 +33,23 @@ Second attempt to decode the transaction as a direct `propose` call to the rollu
35
33
 
36
34
  - Check if transaction is to the rollup address
37
35
  - Decode as `propose` function call
38
- - Verify the function is indeed `propose`
36
+ - Verify against expected hashes
39
37
  - Return the transaction input as the propose calldata
40
38
 
41
- This handles scenarios where clients submit transactions directly to the rollup contract without
42
- using multicall3 for bundling. Any validation failure triggers fallback to the next step.
43
-
44
39
  ### Spire Proposer Call
45
40
 
46
- Given existing attempts to route the call via the Spire proposer, we also check if the tx is `to` the
47
- proposer known address, and if so, we try decoding it as either a multicall3 or a direct call to the
48
- rollup contract.
49
-
50
- Similar as with the multicall3 check, we check that there are no other calls in the Spire proposer, so
51
- we are absolutely sure that the only call is the successful one to the rollup. Any extraneous call would
52
- imply an unexpected path to calling `propose` in the rollup contract, and since we cannot verify if the
53
- calldata arguments we extracted are the correct ones (see the section below), we cannot know for sure which
54
- one is the call that succeeded, so we don't know which calldata to process.
55
-
56
- Furthermore, since the Spire proposer is upgradeable, we check if the implementation has not changed in
57
- order to decode. As usual, any validation failure triggers fallback to the next step.
58
-
59
- ### Verifying Multicall3 Arguments
60
-
61
- **This is NOT implemented for simplicity's sake**
62
-
63
- If the checks above don't hold, such as when there are multiple calls to `propose`, then we cannot
64
- reliably extract the `propose` calldata from the multicall3 arguments alone. We can try a best-effort
65
- where we try all `propose` calls we see and validate them against on-chain data. Note that we can use these
66
- same strategies if we were to obtain the calldata from another source.
67
-
68
- #### TempBlockLog Verification
69
-
70
- Read the stored `TempBlockLog` for the L2 block number from L1 and verify it matches our decoded header hash,
71
- since the `TempBlockLog` stores the hash of the proposed block header, the payload commitment, and the attestations.
72
-
73
- However, `TempBlockLog` is only stored temporarily and deleted after proven, so this method only works for recent
74
- blocks, not for historical data syncing.
75
-
76
- #### Archive Verification
77
-
78
- Verify that the archive root in the decoded propose is correct with regard to the block header. This requires
79
- hashing the block header we have retrieved, inserting it into the archive tree, and checking the resulting root
80
- against the one we got from L1.
81
-
82
- However, this requires that the archive keeps a reference to world-state, which is not the case in the current
83
- system.
84
-
85
- #### Emit Commitments in Rollup Contract
86
-
87
- Modify rollup contract to emit commitments to the block header in the `L2BlockProposed` event, allowing us to easily
88
- verify the calldata we obtained vs the emitted event.
41
+ Given existing attempts to route the call via the Spire proposer, we also check if the tx is
42
+ `to` the proposer known address. If so, we extract all wrapped calls and try each as either
43
+ a multicall3 or direct propose call, using hash matching to find and verify the correct one.
89
44
 
90
- However, modifying the rollup contract is out of scope for this change. But we can implement this approach in `v2`.
45
+ Since the Spire proposer is upgradeable, we check that the implementation has not changed in
46
+ order to decode. Any validation failure triggers fallback to the next step.
91
47
 
92
48
  ### Debug and Trace Transaction Fallback
93
49
 
94
- Last, we use L1 node's trace/debug RPC methods to definitively identify the one successful `propose` call within the tx.
95
- We can then extract the exact calldata that hit the `propose` function in the rollup contract.
50
+ Last, we use L1 node's trace/debug RPC methods to definitively identify the one successful
51
+ `propose` call within the tx. We can then extract the exact calldata that hit the `propose`
52
+ function in the rollup contract.
96
53
 
97
- This approach requires access to a debug-enabled L1 node, which may be more resource-intensive, so we only
98
- use it as a fallback when the first step fails, which should be rare in practice.
54
+ This approach requires access to a debug-enabled L1 node, which may be more resource-intensive,
55
+ so we only use it as a fallback when earlier steps fail, which should be rare in practice.
@@ -5,7 +5,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
5
5
  import { createLogger } from '@aztec/foundation/log';
6
6
  import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
7
7
 
8
- import { type Hex, createPublicClient, getAbiItem, http, toEventSelector } from 'viem';
8
+ import { type Hex, createPublicClient, decodeEventLog, getAbiItem, http, toEventSelector } from 'viem';
9
9
  import { mainnet } from 'viem/chains';
10
10
 
11
11
  import { CalldataRetriever } from '../calldata_retriever.js';
@@ -89,14 +89,6 @@ async function main() {
89
89
 
90
90
  logger.info(`Transaction found in block ${tx.blockNumber}`);
91
91
 
92
- // For simplicity, use zero addresses for optional contract addresses
93
- // In production, these would be fetched from the rollup contract or configuration
94
- const slashingProposerAddress = EthAddress.ZERO;
95
- const governanceProposerAddress = EthAddress.ZERO;
96
- const slashFactoryAddress = undefined;
97
-
98
- logger.info('Using zero addresses for governance/slashing (can be configured if needed)');
99
-
100
92
  // Create CalldataRetriever
101
93
  const retriever = new CalldataRetriever(
102
94
  publicClient as unknown as ViemPublicClient,
@@ -104,46 +96,67 @@ async function main() {
104
96
  targetCommitteeSize,
105
97
  undefined,
106
98
  logger,
107
- {
108
- rollupAddress,
109
- governanceProposerAddress,
110
- slashingProposerAddress,
111
- slashFactoryAddress,
112
- },
99
+ rollupAddress,
113
100
  );
114
101
 
115
- // Extract checkpoint number from transaction logs
116
- logger.info('Decoding transaction to extract checkpoint number...');
102
+ // Extract checkpoint number and hashes from transaction logs
103
+ logger.info('Decoding transaction to extract checkpoint number and hashes...');
117
104
  const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
118
105
 
119
- // Look for CheckpointProposed event (emitted when a checkpoint is proposed to the rollup)
120
- // Event signature: CheckpointProposed(uint256 indexed checkpointNumber, bytes32 indexed archive, bytes32[], bytes32, bytes32)
121
- // Hash: keccak256("CheckpointProposed(uint256,bytes32,bytes32[],bytes32,bytes32)")
122
- const checkpointProposedEvent = receipt.logs.find(log => {
106
+ // Look for CheckpointProposed event
107
+ const checkpointProposedEventAbi = getAbiItem({ abi: RollupAbi, name: 'CheckpointProposed' });
108
+ const checkpointProposedLog = receipt.logs.find(log => {
123
109
  try {
124
110
  return (
125
111
  log.address.toLowerCase() === rollupAddress.toString().toLowerCase() &&
126
- log.topics[0] === toEventSelector(getAbiItem({ abi: RollupAbi, name: 'CheckpointProposed' }))
112
+ log.topics[0] === toEventSelector(checkpointProposedEventAbi)
127
113
  );
128
114
  } catch {
129
115
  return false;
130
116
  }
131
117
  });
132
118
 
133
- if (!checkpointProposedEvent || checkpointProposedEvent.topics[1] === undefined) {
119
+ if (!checkpointProposedLog || checkpointProposedLog.topics[1] === undefined) {
134
120
  throw new Error(`Checkpoint proposed event not found`);
135
121
  }
136
122
 
137
- const checkpointNumber = CheckpointNumber.fromBigInt(BigInt(checkpointProposedEvent.topics[1]));
123
+ const checkpointNumber = CheckpointNumber.fromBigInt(BigInt(checkpointProposedLog.topics[1]));
124
+
125
+ // Decode the full event to extract attestationsHash and payloadDigest
126
+ const decodedEvent = decodeEventLog({
127
+ abi: RollupAbi,
128
+ data: checkpointProposedLog.data,
129
+ topics: checkpointProposedLog.topics,
130
+ });
131
+
132
+ const eventArgs = decodedEvent.args as {
133
+ checkpointNumber: bigint;
134
+ archive: Hex;
135
+ versionedBlobHashes: Hex[];
136
+ attestationsHash: Hex;
137
+ payloadDigest: Hex;
138
+ };
139
+
140
+ if (!eventArgs.attestationsHash || !eventArgs.payloadDigest) {
141
+ throw new Error(`CheckpointProposed event missing attestationsHash or payloadDigest`);
142
+ }
143
+
144
+ const expectedHashes = {
145
+ attestationsHash: eventArgs.attestationsHash,
146
+ payloadDigest: eventArgs.payloadDigest,
147
+ };
148
+
149
+ logger.info(`Checkpoint Number: ${checkpointNumber}`);
150
+ logger.info(`Attestations Hash: ${expectedHashes.attestationsHash}`);
151
+ logger.info(`Payload Digest: ${expectedHashes.payloadDigest}`);
138
152
 
139
153
  logger.info('');
140
154
  logger.info('Retrieving checkpoint from rollup transaction...');
141
155
  logger.info('');
142
156
 
143
- // For this script, we don't have blob hashes or expected hashes, so pass empty arrays/objects
144
- const result = await retriever.getCheckpointFromRollupTx(txHash, [], checkpointNumber, {});
157
+ const result = await retriever.getCheckpointFromRollupTx(txHash, [], checkpointNumber, expectedHashes);
145
158
 
146
- logger.info(' Successfully retrieved block header!');
159
+ logger.info(' Successfully retrieved block header!');
147
160
  logger.info('');
148
161
  logger.info('Block Header Details:');
149
162
  logger.info('====================');