@aztec/archiver 3.0.0-nightly.20251210 → 3.0.0-nightly.20251211

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 (70) hide show
  1. package/dest/archiver/archiver.d.ts +9 -6
  2. package/dest/archiver/archiver.d.ts.map +1 -1
  3. package/dest/archiver/archiver.js +28 -10
  4. package/dest/archiver/archiver_store.d.ts +3 -3
  5. package/dest/archiver/archiver_store.d.ts.map +1 -1
  6. package/dest/archiver/config.d.ts +3 -2
  7. package/dest/archiver/config.d.ts.map +1 -1
  8. package/dest/archiver/config.js +8 -1
  9. package/dest/archiver/instrumentation.d.ts +3 -1
  10. package/dest/archiver/instrumentation.d.ts.map +1 -1
  11. package/dest/archiver/instrumentation.js +11 -0
  12. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +3 -3
  13. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  14. package/dest/archiver/kv_archiver_store/message_store.d.ts +2 -2
  15. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  16. package/dest/archiver/l1/bin/retrieve-calldata.d.ts +3 -0
  17. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +1 -0
  18. package/dest/archiver/l1/bin/retrieve-calldata.js +147 -0
  19. package/dest/archiver/l1/calldata_retriever.d.ts +98 -0
  20. package/dest/archiver/l1/calldata_retriever.d.ts.map +1 -0
  21. package/dest/archiver/l1/calldata_retriever.js +403 -0
  22. package/dest/archiver/l1/data_retrieval.d.ts +87 -0
  23. package/dest/archiver/l1/data_retrieval.d.ts.map +1 -0
  24. package/dest/archiver/{data_retrieval.js → l1/data_retrieval.js} +19 -89
  25. package/dest/archiver/l1/debug_tx.d.ts +19 -0
  26. package/dest/archiver/l1/debug_tx.d.ts.map +1 -0
  27. package/dest/archiver/l1/debug_tx.js +73 -0
  28. package/dest/archiver/l1/spire_proposer.d.ts +70 -0
  29. package/dest/archiver/l1/spire_proposer.d.ts.map +1 -0
  30. package/dest/archiver/l1/spire_proposer.js +157 -0
  31. package/dest/archiver/l1/trace_tx.d.ts +97 -0
  32. package/dest/archiver/l1/trace_tx.d.ts.map +1 -0
  33. package/dest/archiver/l1/trace_tx.js +91 -0
  34. package/dest/archiver/l1/types.d.ts +12 -0
  35. package/dest/archiver/l1/types.d.ts.map +1 -0
  36. package/dest/archiver/l1/types.js +3 -0
  37. package/dest/archiver/l1/validate_trace.d.ts +29 -0
  38. package/dest/archiver/l1/validate_trace.d.ts.map +1 -0
  39. package/dest/archiver/l1/validate_trace.js +150 -0
  40. package/dest/index.d.ts +2 -2
  41. package/dest/index.d.ts.map +1 -1
  42. package/dest/index.js +1 -1
  43. package/dest/test/mock_l2_block_source.js +1 -1
  44. package/package.json +15 -14
  45. package/src/archiver/archiver.ts +45 -20
  46. package/src/archiver/archiver_store.ts +2 -2
  47. package/src/archiver/config.ts +8 -7
  48. package/src/archiver/instrumentation.ts +14 -0
  49. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +2 -2
  50. package/src/archiver/kv_archiver_store/message_store.ts +1 -1
  51. package/src/archiver/l1/README.md +98 -0
  52. package/src/archiver/l1/bin/retrieve-calldata.ts +182 -0
  53. package/src/archiver/l1/calldata_retriever.ts +531 -0
  54. package/src/archiver/{data_retrieval.ts → l1/data_retrieval.ts} +50 -137
  55. package/src/archiver/l1/debug_tx.ts +99 -0
  56. package/src/archiver/l1/spire_proposer.ts +160 -0
  57. package/src/archiver/l1/trace_tx.ts +128 -0
  58. package/src/archiver/l1/types.ts +13 -0
  59. package/src/archiver/l1/validate_trace.ts +211 -0
  60. package/src/index.ts +1 -1
  61. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  62. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  63. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  64. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  65. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  66. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  67. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  68. package/src/test/mock_l2_block_source.ts +1 -1
  69. package/dest/archiver/data_retrieval.d.ts +0 -80
  70. package/dest/archiver/data_retrieval.d.ts.map +0 -1
@@ -1,11 +1,7 @@
1
1
  import { type BlobSinkConfig, blobSinkConfigMapping } from '@aztec/blob-sink/client';
2
- import {
3
- type L1ContractsConfig,
4
- type L1ReaderConfig,
5
- l1ContractAddressesMapping,
6
- l1ContractsConfigMappings,
7
- l1ReaderConfigMappings,
8
- } from '@aztec/ethereum';
2
+ import { type L1ContractsConfig, l1ContractsConfigMappings } from '@aztec/ethereum/config';
3
+ import { l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
4
+ import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
9
5
  import {
10
6
  type ConfigMappingsType,
11
7
  booleanConfigHelper,
@@ -55,6 +51,11 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
55
51
  description: 'Maximum allowed drift in seconds between the Ethereum client and current time.',
56
52
  ...numberConfigHelper(300),
57
53
  },
54
+ ethereumAllowNoDebugHosts: {
55
+ env: 'ETHEREUM_ALLOW_NO_DEBUG_HOSTS',
56
+ description: 'Whether to allow starting the archiver without debug/trace method support on Ethereum hosts',
57
+ ...booleanConfigHelper(true),
58
+ },
58
59
  ...chainConfigMappings,
59
60
  ...l1ReaderConfigMappings,
60
61
  viemPollingIntervalMS: {
@@ -34,6 +34,8 @@ export class ArchiverInstrumentation {
34
34
  private syncDurationPerMessage: Histogram;
35
35
  private syncMessageCount: UpDownCounter;
36
36
 
37
+ private blockProposalTxTargetCount: UpDownCounter;
38
+
37
39
  private log = createLogger('archiver:instrumentation');
38
40
 
39
41
  private constructor(
@@ -114,6 +116,11 @@ export class ArchiverInstrumentation {
114
116
  valueType: ValueType.INT,
115
117
  });
116
118
 
119
+ this.blockProposalTxTargetCount = meter.createUpDownCounter(Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT, {
120
+ description: 'Number of block proposals by tx target',
121
+ valueType: ValueType.INT,
122
+ });
123
+
117
124
  this.dbMetrics = new LmdbMetrics(
118
125
  meter,
119
126
  {
@@ -184,4 +191,11 @@ export class ArchiverInstrumentation {
184
191
  public updateL1BlockHeight(blockNumber: bigint) {
185
192
  this.l1BlockHeight.record(Number(blockNumber));
186
193
  }
194
+
195
+ public recordBlockProposalTxTarget(target: string, usedTrace: boolean) {
196
+ this.blockProposalTxTargetCount.add(1, {
197
+ [Attributes.L1_BLOCK_PROPOSAL_TX_TARGET]: target.toLowerCase(),
198
+ [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace,
199
+ });
200
+ }
187
201
  }
@@ -1,5 +1,5 @@
1
- import type { L1BlockId } from '@aztec/ethereum';
2
- import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
1
+ import type { L1BlockId } from '@aztec/ethereum/l1-types';
2
+ import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
3
  import type { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { toArray } from '@aztec/foundation/iterable';
5
5
  import { createLogger } from '@aztec/foundation/log';
@@ -1,4 +1,4 @@
1
- import type { L1BlockId } from '@aztec/ethereum';
1
+ import type { L1BlockId } from '@aztec/ethereum/l1-types';
2
2
  import { CheckpointNumber } from '@aztec/foundation/branded-types';
3
3
  import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
@@ -0,0 +1,98 @@
1
+ # Archiver L1 Data Retrieval
2
+
3
+ Modules and classes to handle data retrieval from L1 for the archiver.
4
+
5
+ ## Calldata Retriever
6
+
7
+ The sequencer publisher bundles multiple operations into a single multicall3 transaction for gas
8
+ efficiency. A typical transaction includes:
9
+
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
13
+
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.
17
+
18
+ ### Multicall3 Validation and Decoding
19
+
20
+ First attempt to decode the transaction as a multicall3 `aggregate3` call with validation:
21
+
22
+ - Check if transaction is to multicall3 address (`0xcA11bde05977b3631167028862bE2a173976CA11`)
23
+ - 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
28
+
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.
31
+
32
+ ### Direct Propose Call
33
+
34
+ Second attempt to decode the transaction as a direct `propose` call to the rollup contract:
35
+
36
+ - Check if transaction is to the rollup address
37
+ - Decode as `propose` function call
38
+ - Verify the function is indeed `propose`
39
+ - Return the transaction input as the propose calldata
40
+
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
+ ### Spire Proposer Call
45
+
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.
89
+
90
+ However, modifying the rollup contract is out of scope for this change. But we can implement this approach in `v2`.
91
+
92
+ ### Debug and Trace Transaction Fallback
93
+
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.
96
+
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.
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env node
2
+ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
3
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { EthAddress } from '@aztec/foundation/eth-address';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+
7
+ import { type Hex, createPublicClient, http } from 'viem';
8
+ import { mainnet } from 'viem/chains';
9
+
10
+ import { CalldataRetriever } from '../calldata_retriever.js';
11
+
12
+ const logger = createLogger('archiver:calldata-test');
13
+
14
+ interface ScriptArgs {
15
+ rollupAddress: EthAddress;
16
+ txHash: Hex;
17
+ rpcUrl: string;
18
+ targetCommitteeSize: number;
19
+ }
20
+
21
+ function parseArgs(): ScriptArgs {
22
+ const args = process.argv.slice(2);
23
+
24
+ if (args.length < 2) {
25
+ // eslint-disable-next-line no-console
26
+ console.error('Usage: node index.js <rollup-address> <tx-hash> [target-committee-size]');
27
+ // eslint-disable-next-line no-console
28
+ console.error('');
29
+ // eslint-disable-next-line no-console
30
+ console.error('Environment variables:');
31
+ // eslint-disable-next-line no-console
32
+ console.error(' ETHEREUM_HOST or RPC_URL - Ethereum RPC endpoint');
33
+ // eslint-disable-next-line no-console
34
+ console.error('');
35
+ // eslint-disable-next-line no-console
36
+ console.error('Example:');
37
+ // eslint-disable-next-line no-console
38
+ console.error(' RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY \\');
39
+ // eslint-disable-next-line no-console
40
+ console.error(' node index.js 0x1234... 0xabcd... 32');
41
+ process.exit(1);
42
+ }
43
+
44
+ const rollupAddress = EthAddress.fromString(args[0]);
45
+ const txHash = args[1] as Hex;
46
+ const targetCommitteeSize = args[2] ? parseInt(args[2], 10) : 24;
47
+
48
+ const rpcUrl = process.env.ETHEREUM_HOST || process.env.RPC_URL;
49
+ if (!rpcUrl) {
50
+ // eslint-disable-next-line no-console
51
+ console.error('Error: ETHEREUM_HOST or RPC_URL environment variable must be set');
52
+ process.exit(1);
53
+ }
54
+
55
+ if (targetCommitteeSize <= 0 || targetCommitteeSize > 256) {
56
+ // eslint-disable-next-line no-console
57
+ console.error('Error: target-committee-size must be between 1 and 256');
58
+ process.exit(1);
59
+ }
60
+
61
+ return { rollupAddress, txHash, rpcUrl, targetCommitteeSize };
62
+ }
63
+
64
+ async function main() {
65
+ const { rollupAddress, txHash, rpcUrl, targetCommitteeSize } = parseArgs();
66
+
67
+ logger.info('Calldata Retriever Test Script');
68
+ logger.info('===============================');
69
+ logger.info(`Rollup Address: ${rollupAddress.toString()}`);
70
+ logger.info(`Transaction Hash: ${txHash}`);
71
+ logger.info(`RPC URL: ${rpcUrl}`);
72
+ logger.info(`Target Committee Size: ${targetCommitteeSize}`);
73
+ logger.info('');
74
+
75
+ try {
76
+ // Create viem public client
77
+ const publicClient = createPublicClient({
78
+ chain: mainnet,
79
+ transport: http(rpcUrl),
80
+ });
81
+
82
+ logger.info('Fetching transaction...');
83
+ const tx = await publicClient.getTransaction({ hash: txHash });
84
+
85
+ if (!tx) {
86
+ throw new Error(`Transaction ${txHash} not found`);
87
+ }
88
+
89
+ logger.info(`Transaction found in block ${tx.blockNumber}`);
90
+
91
+ // For simplicity, use zero addresses for optional contract addresses
92
+ // In production, these would be fetched from the rollup contract or configuration
93
+ const slashingProposerAddress = EthAddress.ZERO;
94
+ const governanceProposerAddress = EthAddress.ZERO;
95
+ const slashFactoryAddress = undefined;
96
+
97
+ logger.info('Using zero addresses for governance/slashing (can be configured if needed)');
98
+
99
+ // Create CalldataRetriever
100
+ const retriever = new CalldataRetriever(
101
+ publicClient as unknown as ViemPublicClient,
102
+ publicClient as unknown as ViemPublicDebugClient,
103
+ targetCommitteeSize,
104
+ undefined,
105
+ logger,
106
+ {
107
+ rollupAddress,
108
+ governanceProposerAddress,
109
+ slashingProposerAddress,
110
+ slashFactoryAddress,
111
+ },
112
+ );
113
+
114
+ // Extract L2 block number from transaction logs
115
+ logger.info('Decoding transaction to extract L2 block number...');
116
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
117
+ const l2BlockProposedEvent = receipt.logs.find(log => {
118
+ try {
119
+ // Try to match the L2BlockProposed event
120
+ return (
121
+ log.address.toLowerCase() === rollupAddress.toString().toLowerCase() &&
122
+ log.topics[0] === '0x2f1d0e696fa5186494a2f2f89a0e0bcbb15d607f6c5eac4637e07e1e5e7d3c00' // L2BlockProposed event signature
123
+ );
124
+ } catch {
125
+ return false;
126
+ }
127
+ });
128
+
129
+ let l2BlockNumber: number;
130
+ if (l2BlockProposedEvent && l2BlockProposedEvent.topics[1]) {
131
+ // L2 block number is typically the first indexed parameter
132
+ l2BlockNumber = Number(BigInt(l2BlockProposedEvent.topics[1]));
133
+ logger.info(`L2 Block Number (from event): ${l2BlockNumber}`);
134
+ } else {
135
+ // Fallback: try to extract from transaction data or use a default
136
+ logger.warn('Could not extract L2 block number from event, using block number as fallback');
137
+ l2BlockNumber = Number(tx.blockNumber);
138
+ }
139
+
140
+ logger.info('');
141
+ logger.info('Retrieving block header from rollup transaction...');
142
+ logger.info('');
143
+
144
+ // For this script, we don't have blob hashes, so pass empty array
145
+ const result = await retriever.getCheckpointFromRollupTx(txHash, [], CheckpointNumber(l2BlockNumber));
146
+
147
+ logger.info(' Successfully retrieved block header!');
148
+ logger.info('');
149
+ logger.info('Block Header Details:');
150
+ logger.info('====================');
151
+ logger.info(`Checkpoint Number: ${result.checkpointNumber}`);
152
+ logger.info(`Block Hash: ${result.blockHash}`);
153
+ logger.info(`Archive Root: ${result.archiveRoot.toString()}`);
154
+ logger.info('');
155
+ logger.info('Header:');
156
+ logger.info(` Slot Number: ${result.header.slotNumber.toString()}`);
157
+ logger.info(` Timestamp: ${result.header.timestamp.toString()}`);
158
+ logger.info(` Coinbase: ${result.header.coinbase.toString()}`);
159
+ logger.info(` Fee Recipient: ${result.header.feeRecipient.toString()}`);
160
+ logger.info(` Total Mana Used: ${result.header.totalManaUsed.toString()}`);
161
+ logger.info('');
162
+ logger.info('Attestations:');
163
+ logger.info(` Count: ${result.attestations.length}`);
164
+ logger.info(` Non-empty attestations: ${result.attestations.filter((a: any) => !a.signature.isEmpty()).length}`);
165
+
166
+ process.exit(0);
167
+ } catch (error) {
168
+ logger.error('Error retrieving block header:');
169
+ logger.error(error instanceof Error ? error.message : String(error));
170
+
171
+ if (error instanceof Error && error.stack) {
172
+ logger.debug(error.stack);
173
+ }
174
+
175
+ process.exit(1);
176
+ }
177
+ }
178
+
179
+ // Only run if this is the main module
180
+ if (import.meta.url === `file://${process.argv[1]}`) {
181
+ void main();
182
+ }