@aztec/archiver 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108

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 (133) hide show
  1. package/README.md +27 -6
  2. package/dest/archiver/archiver.d.ts +127 -84
  3. package/dest/archiver/archiver.d.ts.map +1 -1
  4. package/dest/archiver/archiver.js +1150 -382
  5. package/dest/archiver/archiver_store.d.ts +122 -45
  6. package/dest/archiver/archiver_store.d.ts.map +1 -1
  7. package/dest/archiver/archiver_store_test_suite.d.ts +1 -1
  8. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  9. package/dest/archiver/archiver_store_test_suite.js +2013 -343
  10. package/dest/archiver/config.d.ts +7 -20
  11. package/dest/archiver/config.d.ts.map +1 -1
  12. package/dest/archiver/config.js +21 -5
  13. package/dest/archiver/errors.d.ts +25 -1
  14. package/dest/archiver/errors.d.ts.map +1 -1
  15. package/dest/archiver/errors.js +37 -0
  16. package/dest/archiver/index.d.ts +2 -2
  17. package/dest/archiver/index.d.ts.map +1 -1
  18. package/dest/archiver/instrumentation.d.ts +5 -3
  19. package/dest/archiver/instrumentation.d.ts.map +1 -1
  20. package/dest/archiver/instrumentation.js +14 -0
  21. package/dest/archiver/kv_archiver_store/block_store.d.ts +83 -15
  22. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  23. package/dest/archiver/kv_archiver_store/block_store.js +396 -73
  24. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +2 -2
  25. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
  26. package/dest/archiver/kv_archiver_store/contract_class_store.js +1 -1
  27. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +2 -2
  28. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
  29. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +51 -55
  30. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  31. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +82 -46
  32. package/dest/archiver/kv_archiver_store/log_store.d.ts +12 -16
  33. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
  34. package/dest/archiver/kv_archiver_store/log_store.js +149 -84
  35. package/dest/archiver/kv_archiver_store/message_store.d.ts +6 -5
  36. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  37. package/dest/archiver/kv_archiver_store/message_store.js +15 -14
  38. package/dest/archiver/l1/bin/retrieve-calldata.d.ts +3 -0
  39. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +1 -0
  40. package/dest/archiver/l1/bin/retrieve-calldata.js +149 -0
  41. package/dest/archiver/l1/calldata_retriever.d.ts +112 -0
  42. package/dest/archiver/l1/calldata_retriever.d.ts.map +1 -0
  43. package/dest/archiver/l1/calldata_retriever.js +471 -0
  44. package/dest/archiver/l1/data_retrieval.d.ts +90 -0
  45. package/dest/archiver/l1/data_retrieval.d.ts.map +1 -0
  46. package/dest/archiver/l1/data_retrieval.js +331 -0
  47. package/dest/archiver/l1/debug_tx.d.ts +19 -0
  48. package/dest/archiver/l1/debug_tx.d.ts.map +1 -0
  49. package/dest/archiver/l1/debug_tx.js +73 -0
  50. package/dest/archiver/l1/spire_proposer.d.ts +70 -0
  51. package/dest/archiver/l1/spire_proposer.d.ts.map +1 -0
  52. package/dest/archiver/l1/spire_proposer.js +157 -0
  53. package/dest/archiver/l1/trace_tx.d.ts +97 -0
  54. package/dest/archiver/l1/trace_tx.d.ts.map +1 -0
  55. package/dest/archiver/l1/trace_tx.js +91 -0
  56. package/dest/archiver/l1/types.d.ts +12 -0
  57. package/dest/archiver/l1/types.d.ts.map +1 -0
  58. package/dest/archiver/l1/types.js +3 -0
  59. package/dest/archiver/l1/validate_trace.d.ts +29 -0
  60. package/dest/archiver/l1/validate_trace.d.ts.map +1 -0
  61. package/dest/archiver/l1/validate_trace.js +150 -0
  62. package/dest/archiver/structs/data_retrieval.d.ts +1 -1
  63. package/dest/archiver/structs/inbox_message.d.ts +4 -4
  64. package/dest/archiver/structs/inbox_message.d.ts.map +1 -1
  65. package/dest/archiver/structs/inbox_message.js +6 -5
  66. package/dest/archiver/structs/published.d.ts +2 -2
  67. package/dest/archiver/structs/published.d.ts.map +1 -1
  68. package/dest/archiver/validation.d.ts +10 -4
  69. package/dest/archiver/validation.d.ts.map +1 -1
  70. package/dest/archiver/validation.js +66 -44
  71. package/dest/factory.d.ts +4 -6
  72. package/dest/factory.d.ts.map +1 -1
  73. package/dest/factory.js +5 -4
  74. package/dest/index.d.ts +2 -2
  75. package/dest/index.d.ts.map +1 -1
  76. package/dest/index.js +1 -1
  77. package/dest/rpc/index.d.ts +2 -2
  78. package/dest/test/index.d.ts +1 -1
  79. package/dest/test/mock_archiver.d.ts +16 -8
  80. package/dest/test/mock_archiver.d.ts.map +1 -1
  81. package/dest/test/mock_archiver.js +19 -14
  82. package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
  83. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  84. package/dest/test/mock_l1_to_l2_message_source.js +10 -9
  85. package/dest/test/mock_l2_block_source.d.ts +31 -20
  86. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  87. package/dest/test/mock_l2_block_source.js +85 -18
  88. package/dest/test/mock_structs.d.ts +3 -2
  89. package/dest/test/mock_structs.d.ts.map +1 -1
  90. package/dest/test/mock_structs.js +9 -8
  91. package/package.json +18 -17
  92. package/src/archiver/archiver.ts +990 -481
  93. package/src/archiver/archiver_store.ts +141 -44
  94. package/src/archiver/archiver_store_test_suite.ts +2114 -331
  95. package/src/archiver/config.ts +30 -35
  96. package/src/archiver/errors.ts +64 -0
  97. package/src/archiver/index.ts +1 -1
  98. package/src/archiver/instrumentation.ts +19 -2
  99. package/src/archiver/kv_archiver_store/block_store.ts +541 -83
  100. package/src/archiver/kv_archiver_store/contract_class_store.ts +1 -1
  101. package/src/archiver/kv_archiver_store/contract_instance_store.ts +1 -1
  102. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +107 -67
  103. package/src/archiver/kv_archiver_store/log_store.ts +209 -99
  104. package/src/archiver/kv_archiver_store/message_store.ts +21 -18
  105. package/src/archiver/l1/README.md +98 -0
  106. package/src/archiver/l1/bin/retrieve-calldata.ts +182 -0
  107. package/src/archiver/l1/calldata_retriever.ts +641 -0
  108. package/src/archiver/l1/data_retrieval.ts +512 -0
  109. package/src/archiver/l1/debug_tx.ts +99 -0
  110. package/src/archiver/l1/spire_proposer.ts +160 -0
  111. package/src/archiver/l1/trace_tx.ts +128 -0
  112. package/src/archiver/l1/types.ts +13 -0
  113. package/src/archiver/l1/validate_trace.ts +211 -0
  114. package/src/archiver/structs/inbox_message.ts +8 -8
  115. package/src/archiver/structs/published.ts +1 -1
  116. package/src/archiver/validation.ts +86 -32
  117. package/src/factory.ts +6 -7
  118. package/src/index.ts +1 -1
  119. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  120. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  121. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  122. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  123. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  124. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  125. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  126. package/src/test/mock_archiver.ts +22 -16
  127. package/src/test/mock_l1_to_l2_message_source.ts +10 -9
  128. package/src/test/mock_l2_block_source.ts +114 -27
  129. package/src/test/mock_structs.ts +10 -9
  130. package/dest/archiver/data_retrieval.d.ts +0 -78
  131. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  132. package/dest/archiver/data_retrieval.js +0 -354
  133. package/src/archiver/data_retrieval.ts +0 -535
@@ -0,0 +1,160 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+
4
+ import { type Hex, type Transaction, decodeFunctionData, getAddress, trim } from 'viem';
5
+
6
+ // Spire Proposer Multicall constants
7
+ export const SPIRE_PROPOSER_ADDRESS = '0x9ccc2f3ecde026230e11a5c8799ac7524f2bb294';
8
+ export const SPIRE_PROPOSER_EXPECTED_IMPLEMENTATION = '0x7d38d47e7c82195e6e607d3b0f1c20c615c7bf42';
9
+
10
+ // EIP-1967 storage slot for implementation address
11
+ // keccak256("eip1967.proxy.implementation") - 1 = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
12
+ export const EIP1967_IMPLEMENTATION_SLOT =
13
+ '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' as const;
14
+
15
+ // Spire Proposer Multicall ABI
16
+ export const SpireProposerAbi = [
17
+ {
18
+ inputs: [
19
+ {
20
+ components: [
21
+ { internalType: 'address', name: 'proposer', type: 'address' },
22
+ { internalType: 'address', name: 'target', type: 'address' },
23
+ { internalType: 'bytes', name: 'data', type: 'bytes' },
24
+ { internalType: 'uint256', name: 'value', type: 'uint256' },
25
+ { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },
26
+ ],
27
+ internalType: 'struct IProposerMulticall.Call[]',
28
+ name: '_calls',
29
+ type: 'tuple[]',
30
+ },
31
+ ],
32
+ name: 'multicall',
33
+ outputs: [],
34
+ stateMutability: 'nonpayable',
35
+ type: 'function',
36
+ },
37
+ ] as const;
38
+
39
+ /**
40
+ * Verifies that a proxy contract points to the expected implementation using EIP-1967.
41
+ * @param publicClient - The viem public client
42
+ * @param proxyAddress - The proxy contract address
43
+ * @param expectedImplementation - The expected implementation address
44
+ * @param logger - Logger instance
45
+ * @returns True if the proxy points to the expected implementation
46
+ */
47
+ export async function verifyProxyImplementation(
48
+ publicClient: { getStorageAt: (params: { address: Hex; slot: Hex }) => Promise<Hex | undefined> },
49
+ proxyAddress: Hex,
50
+ expectedImplementation: Hex,
51
+ logger: Logger,
52
+ ): Promise<boolean> {
53
+ try {
54
+ // Read the EIP-1967 implementation slot
55
+ const implementationData = await publicClient.getStorageAt({
56
+ address: proxyAddress,
57
+ slot: EIP1967_IMPLEMENTATION_SLOT,
58
+ });
59
+
60
+ if (!implementationData) {
61
+ logger.warn(`No implementation found in EIP-1967 slot for proxy ${proxyAddress}`);
62
+ return false;
63
+ }
64
+
65
+ // The implementation address is stored in the last 20 bytes of the slot
66
+ // We need to extract and normalize it for comparison
67
+ const implementationAddress = getAddress(trim(implementationData));
68
+ const expectedAddress = getAddress(expectedImplementation);
69
+
70
+ const matches = implementationAddress.toLowerCase() === expectedAddress.toLowerCase();
71
+
72
+ if (!matches) {
73
+ logger.warn(`Proxy implementation mismatch: expected ${expectedAddress}, got ${implementationAddress}`, {
74
+ proxyAddress,
75
+ expectedImplementation,
76
+ actualImplementation: implementationAddress,
77
+ });
78
+ }
79
+
80
+ return matches;
81
+ } catch (err) {
82
+ logger.warn(`Failed to verify proxy implementation for ${proxyAddress}: ${err}`);
83
+ return false;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Attempts to decode transaction as a Spire Proposer Multicall.
89
+ * Spire Proposer is a proxy contract that wraps multiple calls.
90
+ * Returns the target address and calldata of the wrapped call if validation succeeds and there is a single call.
91
+ * @param tx - The transaction to decode
92
+ * @param publicClient - The viem public client for proxy verification
93
+ * @param logger - Logger instance
94
+ * @returns Object with 'to' and 'data' of the wrapped call, or undefined if validation fails
95
+ */
96
+ export async function getCallFromSpireProposer(
97
+ tx: Transaction,
98
+ publicClient: { getStorageAt: (params: { address: Hex; slot: Hex }) => Promise<Hex | undefined> },
99
+ logger: Logger,
100
+ ): Promise<{ to: Hex; data: Hex } | undefined> {
101
+ const txHash = tx.hash;
102
+
103
+ try {
104
+ // Check if transaction is to the Spire Proposer address
105
+ if (!tx.to || !EthAddress.areEqual(tx.to, SPIRE_PROPOSER_ADDRESS)) {
106
+ logger.debug(`Transaction is not to Spire Proposer address (to: ${tx.to})`, { txHash });
107
+ return undefined;
108
+ }
109
+
110
+ // Verify the proxy points to the expected implementation
111
+ const isValidProxy = await verifyProxyImplementation(
112
+ publicClient,
113
+ tx.to as Hex,
114
+ SPIRE_PROPOSER_EXPECTED_IMPLEMENTATION as Hex,
115
+ logger,
116
+ );
117
+
118
+ if (!isValidProxy) {
119
+ logger.warn(`Spire Proposer proxy implementation verification failed`, { txHash, to: tx.to });
120
+ return undefined;
121
+ }
122
+
123
+ // Try to decode as Spire Proposer multicall
124
+ const { functionName: spireFunctionName, args: spireArgs } = decodeFunctionData({
125
+ abi: SpireProposerAbi,
126
+ data: tx.input,
127
+ });
128
+
129
+ // If not multicall, return undefined
130
+ if (spireFunctionName !== 'multicall') {
131
+ logger.warn(`Transaction to Spire Proposer is not multicall (got ${spireFunctionName})`, { txHash });
132
+ return undefined;
133
+ }
134
+
135
+ if (spireArgs.length !== 1) {
136
+ logger.warn(`Unexpected number of arguments for Spire Proposer multicall (got ${spireArgs.length})`, {
137
+ txHash,
138
+ });
139
+ return undefined;
140
+ }
141
+
142
+ const [calls] = spireArgs;
143
+
144
+ // Validate exactly ONE call (see ./README.md for rationale)
145
+ if (calls.length !== 1) {
146
+ logger.warn(`Spire Proposer multicall must contain exactly one call (got ${calls.length})`, { txHash });
147
+ return undefined;
148
+ }
149
+
150
+ const call = calls[0];
151
+
152
+ // Successfully extracted the single wrapped call
153
+ logger.trace(`Decoded Spire Proposer with single call to ${call.target}`, { txHash });
154
+ return { to: call.target, data: call.data };
155
+ } catch (err) {
156
+ // Any decoding error triggers fallback to trace
157
+ logger.warn(`Failed to decode Spire Proposer: ${err}`, { txHash });
158
+ return undefined;
159
+ }
160
+ }
@@ -0,0 +1,128 @@
1
+ import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { Logger } from '@aztec/foundation/log';
4
+ import { type ZodFor, schemas } from '@aztec/foundation/schemas';
5
+ import { withHexPrefix } from '@aztec/foundation/string';
6
+
7
+ import type { Hex } from 'viem';
8
+ import { z } from 'zod';
9
+
10
+ import type { CallInfo } from './types.js';
11
+
12
+ /** Zod schema for trace action from trace_transaction */
13
+ const traceActionSchema = z.object({
14
+ from: schemas.HexStringWith0x,
15
+ to: schemas.HexStringWith0x.optional(),
16
+ callType: z.string(),
17
+ gas: schemas.HexStringWith0x.optional(),
18
+ input: schemas.HexStringWith0x.optional(),
19
+ value: schemas.HexStringWith0x.optional(),
20
+ });
21
+
22
+ /** Zod schema for trace result from trace_transaction */
23
+ const traceResultSchema = z.object({
24
+ gasUsed: schemas.HexStringWith0x.optional(),
25
+ output: schemas.HexStringWith0x.optional(),
26
+ });
27
+
28
+ /** Zod schema for a single trace from trace_transaction */
29
+ export const traceSchema = z.object({
30
+ action: traceActionSchema,
31
+ result: traceResultSchema.optional(),
32
+ error: z.string().optional(),
33
+ subtraces: z.number(),
34
+ traceAddress: z.array(z.number()),
35
+ type: z.string(),
36
+ });
37
+
38
+ /** Type for trace_transaction response */
39
+ type TraceTransaction = z.infer<typeof traceSchema>;
40
+
41
+ /** Zod schema for the full trace_transaction response (array of traces) */
42
+ export const traceTransactionResponseSchema: ZodFor<TraceTransaction[]> = z.array(traceSchema);
43
+
44
+ /**
45
+ * Traces a transaction and extracts all CALL operations to a specific contract and function selector.
46
+ * Uses the trace_transaction RPC method which returns a flat array of traces.
47
+ *
48
+ * @param client - The Viem public debug client
49
+ * @param txHash - The transaction hash to trace
50
+ * @param targetAddress - The contract address to filter for
51
+ * @param functionSelector - The 4-byte function selector to filter for (with or without 0x prefix)
52
+ * @returns Array of CallInfo objects containing from, gasUsed, input, and value for matching calls
53
+ */
54
+ export async function getSuccessfulCallsFromTrace(
55
+ client: ViemPublicDebugClient,
56
+ txHash: Hex,
57
+ targetAddress: EthAddress,
58
+ functionSelector: string,
59
+ logger?: Logger,
60
+ ): Promise<CallInfo[]> {
61
+ // Normalize inputs for comparison
62
+ const normalizedTarget = targetAddress.toString().toLowerCase();
63
+ const normalizedSelector = withHexPrefix(functionSelector.toLowerCase());
64
+
65
+ // Call trace_transaction (no options needed)
66
+ const rawTrace = await client.request({
67
+ method: 'trace_transaction',
68
+ params: [txHash],
69
+ });
70
+
71
+ if (rawTrace === null || rawTrace === undefined) {
72
+ throw new Error(`Failed to retrieve trace_transaction for ${txHash}`);
73
+ }
74
+
75
+ logger?.trace(`Retrieved trace_transaction for ${txHash}`, { trace: rawTrace });
76
+
77
+ // Validate the response with zod
78
+ const traces = traceTransactionResponseSchema.parse(rawTrace);
79
+
80
+ const results: CallInfo[] = [];
81
+
82
+ // Build a set of trace addresses that errored - we should skip their descendants
83
+ // A trace address is the path in the trace tree, represented as an array of indices
84
+ const erroredTraceAddresses = new Set<string>();
85
+ for (const trace of traces) {
86
+ if (trace.error) {
87
+ erroredTraceAddresses.add(JSON.stringify(trace.traceAddress));
88
+ }
89
+ }
90
+
91
+ // Helper to check if a trace is a descendant of an errored trace
92
+ function isDescendantOfError(traceAddress: number[]): boolean {
93
+ // Check all possible ancestor paths
94
+ for (let i = 1; i < traceAddress.length; i++) {
95
+ const ancestorAddress = traceAddress.slice(0, i);
96
+ if (erroredTraceAddresses.has(JSON.stringify(ancestorAddress))) {
97
+ return true;
98
+ }
99
+ }
100
+ return false;
101
+ }
102
+
103
+ // Process each trace
104
+ for (const trace of traces) {
105
+ // Skip if this has an error or is a descendant of an errored trace
106
+ if (trace.error || isDescendantOfError(trace.traceAddress)) {
107
+ continue;
108
+ }
109
+
110
+ // Check if this is a CALL type trace to the target address with matching selector and result
111
+ if (
112
+ trace.type === 'call' &&
113
+ trace.action.callType.toLowerCase() === 'call' &&
114
+ trace.action.to?.toLowerCase() === normalizedTarget &&
115
+ trace.action.input?.toLowerCase().startsWith(normalizedSelector) &&
116
+ trace.result
117
+ ) {
118
+ results.push({
119
+ from: EthAddress.fromString(trace.action.from),
120
+ gasUsed: trace.result.gasUsed === undefined ? undefined : BigInt(trace.result.gasUsed),
121
+ input: trace.action.input,
122
+ value: trace.action.value ? BigInt(trace.action.value) : 0n,
123
+ });
124
+ }
125
+ }
126
+
127
+ return results;
128
+ }
@@ -0,0 +1,13 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+
3
+ import type { Hex } from 'viem';
4
+
5
+ /**
6
+ * Information about a matching CALL
7
+ */
8
+ export interface CallInfo {
9
+ from: EthAddress;
10
+ gasUsed?: bigint;
11
+ input: Hex;
12
+ value: bigint;
13
+ }
@@ -0,0 +1,211 @@
1
+ import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+
4
+ import type { Hex } from 'viem';
5
+ import type { ZodSchema } from 'zod';
6
+
7
+ import { callTraceSchema } from './debug_tx.js';
8
+ import { traceTransactionResponseSchema } from './trace_tx.js';
9
+
10
+ const logger = createLogger('aztec:archiver:validate_trace');
11
+
12
+ /**
13
+ * Helper function to test a trace method with validation
14
+ *
15
+ * @param client - The Viem public debug client
16
+ * @param txHash - Transaction hash to trace
17
+ * @param schema - Zod schema to validate the response
18
+ * @param method - Name of the RPC method ('debug_traceTransaction' or 'trace_transaction')
19
+ * @param blockType - Type of block being tested ('recent' or 'old')
20
+ * @returns true if the method works and validation passes, false otherwise
21
+ */
22
+ async function testTraceMethod(
23
+ client: ViemPublicDebugClient,
24
+ txHash: Hex,
25
+ schema: ZodSchema,
26
+ method: 'debug_traceTransaction' | 'trace_transaction',
27
+ blockType: string,
28
+ ): Promise<boolean> {
29
+ try {
30
+ // Make request with appropriate params based on method name
31
+ const result = await client.request(
32
+ method === 'debug_traceTransaction'
33
+ ? { method, params: [txHash, { tracer: 'callTracer' }] }
34
+ : { method, params: [txHash] },
35
+ );
36
+
37
+ schema.parse(result);
38
+ logger.debug(`${method} works for ${blockType} blocks`);
39
+ return true;
40
+ } catch (error) {
41
+ logger.warn(`${method} failed for ${blockType} blocks: ${error}`);
42
+ return false;
43
+ }
44
+ }
45
+
46
+ /** Result of trace availability checks */
47
+ export interface TraceAvailability {
48
+ /** Whether debug_traceTransaction works for recent blocks */
49
+ debugTraceRecent: boolean;
50
+ /** Whether trace_transaction works for recent blocks */
51
+ traceTransactionRecent: boolean;
52
+ /** Whether debug_traceTransaction works for old blocks (512 blocks ago) */
53
+ debugTraceOld: boolean;
54
+ /** Whether trace_transaction works for old blocks (512 blocks ago) */
55
+ traceTransactionOld: boolean;
56
+ }
57
+
58
+ /**
59
+ * Validates the availability of debug/trace methods on the Ethereum client.
60
+ *
61
+ * @param client - The Viem public debug client
62
+ * @returns Object indicating which trace methods are available for recent and old blocks
63
+ */
64
+ export async function validateTraceAvailability(client: ViemPublicDebugClient): Promise<TraceAvailability> {
65
+ const result: TraceAvailability = {
66
+ debugTraceRecent: false,
67
+ traceTransactionRecent: false,
68
+ debugTraceOld: false,
69
+ traceTransactionOld: false,
70
+ };
71
+
72
+ try {
73
+ // Get the latest block
74
+ let latestBlock = await client.getBlock({ blockTag: 'latest' });
75
+ let attempts = 10;
76
+
77
+ // Loop back to find a block with transactions (handles dev/test scenarios)
78
+ while (!hasTxs(latestBlock) && latestBlock.number && latestBlock.number > 0n && --attempts > 0) {
79
+ logger.debug(`Block ${latestBlock.number} has no transactions, checking previous block`);
80
+ latestBlock = await client.getBlock({ blockNumber: latestBlock.number - 1n });
81
+ }
82
+
83
+ if (!hasTxs(latestBlock)) {
84
+ logger.warn('No blocks with transactions found from latest back to genesis, cannot validate trace availability');
85
+ return result;
86
+ }
87
+
88
+ // Get a transaction from the found block
89
+ const recentTxHash = latestBlock.transactions[0] as Hex;
90
+
91
+ // Test debug_traceTransaction with recent block
92
+ result.debugTraceRecent = await testTraceMethod(
93
+ client,
94
+ recentTxHash,
95
+ callTraceSchema,
96
+ 'debug_traceTransaction',
97
+ 'recent',
98
+ );
99
+
100
+ // Test trace_transaction with recent block
101
+ result.traceTransactionRecent = await testTraceMethod(
102
+ client,
103
+ recentTxHash,
104
+ traceTransactionResponseSchema,
105
+ 'trace_transaction',
106
+ 'recent',
107
+ );
108
+
109
+ // Get a block from 512 blocks ago
110
+ const oldBlockNumber = latestBlock.number ? latestBlock.number - 512n : null;
111
+ if (!oldBlockNumber || oldBlockNumber < 0n) {
112
+ logger.debug('Cannot test old blocks, blockchain too short');
113
+ return result;
114
+ }
115
+
116
+ let oldBlock = await client.getBlock({ blockNumber: oldBlockNumber });
117
+ attempts = 10;
118
+
119
+ // Loop back to find a block with transactions (handles dev/test scenarios)
120
+ while (!hasTxs(oldBlock) && oldBlock.number && oldBlock.number > 0n && --attempts > 0) {
121
+ logger.debug(`Block ${oldBlock.number} has no transactions, checking previous block`);
122
+ oldBlock = await client.getBlock({ blockNumber: oldBlock.number - 1n });
123
+ }
124
+
125
+ if (!hasTxs(oldBlock)) {
126
+ logger.debug(
127
+ 'No blocks with transactions found from old block back to genesis, cannot validate trace availability for old blocks',
128
+ );
129
+ return result;
130
+ }
131
+
132
+ const oldTxHash = oldBlock.transactions[0] as Hex;
133
+
134
+ // Test debug_traceTransaction with old block
135
+ result.debugTraceOld = await testTraceMethod(client, oldTxHash, callTraceSchema, 'debug_traceTransaction', 'old');
136
+
137
+ // Test trace_transaction with old block
138
+ result.traceTransactionOld = await testTraceMethod(
139
+ client,
140
+ oldTxHash,
141
+ traceTransactionResponseSchema,
142
+ 'trace_transaction',
143
+ 'old',
144
+ );
145
+ } catch (error) {
146
+ logger.warn(`Error validating debug_traceTransaction and trace_transaction availability: ${error}`);
147
+ }
148
+
149
+ return result;
150
+ }
151
+
152
+ function hasTxs(block: { transactions?: Hex[] }): boolean {
153
+ return Array.isArray(block.transactions) && block.transactions.length > 0;
154
+ }
155
+
156
+ /**
157
+ * Validates trace availability and logs appropriate messages based on the results.
158
+ * Optionally throws an error if no trace methods are available and ethereumAllowNoDebugHosts is false.
159
+ *
160
+ * @param client - The Viem public debug client
161
+ * @param ethereumAllowNoDebugHosts - If false, throws an error when no trace methods are available
162
+ * @throws Error if ethereumAllowNoDebugHosts is false and no trace methods are available
163
+ */
164
+ export async function validateAndLogTraceAvailability(
165
+ client: ViemPublicDebugClient,
166
+ ethereumAllowNoDebugHosts: boolean,
167
+ ): Promise<void> {
168
+ logger.info('Validating trace/debug method availability...');
169
+
170
+ const availability = await validateTraceAvailability(client);
171
+
172
+ // Check if we have support for old blocks (either debug or trace)
173
+ const hasOldBlockSupport = availability.debugTraceOld || availability.traceTransactionOld;
174
+
175
+ if (hasOldBlockSupport) {
176
+ // Ideal case: we have trace support for old blocks
177
+ const methods: string[] = [];
178
+ if (availability.debugTraceOld) {
179
+ methods.push('debug_traceTransaction');
180
+ }
181
+ if (availability.traceTransactionOld) {
182
+ methods.push('trace_transaction');
183
+ }
184
+ logger.info(
185
+ `Ethereum client supports trace methods for old blocks (${methods.join(', ')}). Archiver can retrieve historical transaction traces.`,
186
+ );
187
+ } else if (availability.debugTraceRecent || availability.traceTransactionRecent) {
188
+ // Warning case: only recent block support
189
+ const methods: string[] = [];
190
+ if (availability.debugTraceRecent) {
191
+ methods.push('debug_traceTransaction');
192
+ }
193
+ if (availability.traceTransactionRecent) {
194
+ methods.push('trace_transaction');
195
+ }
196
+ logger.warn(
197
+ `Ethereum client only supports trace methods for recent blocks (${methods.join(', ')}). Historical transaction traces may not be available.`,
198
+ );
199
+ } else {
200
+ // Error case: no support at all
201
+ const errorMessage =
202
+ 'Ethereum debug client does not support debug_traceTransaction or trace_transaction methods. Transaction tracing will not be available. This may impact archiver syncing.';
203
+
204
+ if (ethereumAllowNoDebugHosts) {
205
+ logger.warn(`${errorMessage} Continuing because ETHEREUM_ALLOW_NO_DEBUG_HOSTS is set to true.`);
206
+ } else {
207
+ logger.error(errorMessage);
208
+ throw new Error(`${errorMessage} Set ETHEREUM_ALLOW_NO_DEBUG_HOSTS=true to bypass this check.`);
209
+ }
210
+ }
211
+ }
@@ -1,14 +1,14 @@
1
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
1
2
  import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
2
- import { keccak256 } from '@aztec/foundation/crypto';
3
- import { Fr } from '@aztec/foundation/fields';
3
+ import { keccak256 } from '@aztec/foundation/crypto/keccak';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
5
  import { BufferReader, bigintToUInt64BE, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
5
- import type { UInt32 } from '@aztec/stdlib/types';
6
6
 
7
7
  export type InboxMessage = {
8
8
  index: bigint;
9
9
  leaf: Fr;
10
- l2BlockNumber: UInt32;
11
- l1BlockNumber: bigint;
10
+ checkpointNumber: CheckpointNumber;
11
+ l1BlockNumber: bigint; // L1 block number - NOT Aztec L2
12
12
  l1BlockHash: Buffer32;
13
13
  rollingHash: Buffer16;
14
14
  };
@@ -24,7 +24,7 @@ export function serializeInboxMessage(message: InboxMessage): Buffer {
24
24
  message.leaf,
25
25
  message.l1BlockHash,
26
26
  numToUInt32BE(Number(message.l1BlockNumber)),
27
- numToUInt32BE(message.l2BlockNumber),
27
+ numToUInt32BE(message.checkpointNumber),
28
28
  message.rollingHash,
29
29
  ]);
30
30
  }
@@ -35,7 +35,7 @@ export function deserializeInboxMessage(buffer: Buffer): InboxMessage {
35
35
  const leaf = reader.readObject(Fr);
36
36
  const l1BlockHash = reader.readObject(Buffer32);
37
37
  const l1BlockNumber = BigInt(reader.readNumber());
38
- const l2BlockNumber = reader.readNumber();
38
+ const checkpointNumber = CheckpointNumber(reader.readNumber());
39
39
  const rollingHash = reader.readObject(Buffer16);
40
- return { index, leaf, l1BlockHash, l1BlockNumber, l2BlockNumber, rollingHash };
40
+ return { index, leaf, l1BlockHash, l1BlockNumber, checkpointNumber, rollingHash };
41
41
  }
@@ -1 +1 @@
1
- export type { PublishedL2Block, L1PublishedData } from '@aztec/stdlib/block';
1
+ export type { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';