@aztec/archiver 2.1.8 → 2.1.9

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 (57) hide show
  1. package/dest/archiver/archiver.d.ts +6 -5
  2. package/dest/archiver/archiver.d.ts.map +1 -1
  3. package/dest/archiver/archiver.js +26 -9
  4. package/dest/archiver/config.d.ts.map +1 -1
  5. package/dest/archiver/config.js +5 -0
  6. package/dest/archiver/instrumentation.d.ts +2 -0
  7. package/dest/archiver/instrumentation.d.ts.map +1 -1
  8. package/dest/archiver/instrumentation.js +11 -0
  9. package/dest/archiver/l1/bin/retrieve-calldata.d.ts +3 -0
  10. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +1 -0
  11. package/dest/archiver/l1/bin/retrieve-calldata.js +149 -0
  12. package/dest/archiver/l1/calldata_retriever.d.ts +87 -0
  13. package/dest/archiver/l1/calldata_retriever.d.ts.map +1 -0
  14. package/dest/archiver/l1/calldata_retriever.js +406 -0
  15. package/dest/archiver/{data_retrieval.d.ts → l1/data_retrieval.d.ts} +13 -6
  16. package/dest/archiver/l1/data_retrieval.d.ts.map +1 -0
  17. package/dest/archiver/{data_retrieval.js → l1/data_retrieval.js} +22 -99
  18. package/dest/archiver/l1/debug_tx.d.ts +19 -0
  19. package/dest/archiver/l1/debug_tx.d.ts.map +1 -0
  20. package/dest/archiver/l1/debug_tx.js +73 -0
  21. package/dest/archiver/l1/spire_proposer.d.ts +70 -0
  22. package/dest/archiver/l1/spire_proposer.d.ts.map +1 -0
  23. package/dest/archiver/l1/spire_proposer.js +157 -0
  24. package/dest/archiver/l1/trace_tx.d.ts +97 -0
  25. package/dest/archiver/l1/trace_tx.d.ts.map +1 -0
  26. package/dest/archiver/l1/trace_tx.js +91 -0
  27. package/dest/archiver/l1/types.d.ts +12 -0
  28. package/dest/archiver/l1/types.d.ts.map +1 -0
  29. package/dest/archiver/l1/types.js +3 -0
  30. package/dest/archiver/l1/validate_trace.d.ts +29 -0
  31. package/dest/archiver/l1/validate_trace.d.ts.map +1 -0
  32. package/dest/archiver/l1/validate_trace.js +150 -0
  33. package/dest/index.d.ts +1 -1
  34. package/dest/index.d.ts.map +1 -1
  35. package/dest/index.js +1 -1
  36. package/package.json +15 -14
  37. package/src/archiver/archiver.ts +42 -12
  38. package/src/archiver/config.ts +5 -0
  39. package/src/archiver/instrumentation.ts +14 -0
  40. package/src/archiver/l1/README.md +98 -0
  41. package/src/archiver/l1/bin/retrieve-calldata.ts +186 -0
  42. package/src/archiver/l1/calldata_retriever.ts +528 -0
  43. package/src/archiver/{data_retrieval.ts → l1/data_retrieval.ts} +45 -155
  44. package/src/archiver/l1/debug_tx.ts +99 -0
  45. package/src/archiver/l1/spire_proposer.ts +160 -0
  46. package/src/archiver/l1/trace_tx.ts +128 -0
  47. package/src/archiver/l1/types.ts +13 -0
  48. package/src/archiver/l1/validate_trace.ts +211 -0
  49. package/src/index.ts +1 -1
  50. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  51. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  52. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  53. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  54. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  55. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  56. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  57. package/dest/archiver/data_retrieval.d.ts.map +0 -1
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+
6
+ import { type Hex, createPublicClient, http } from 'viem';
7
+ import { mainnet } from 'viem/chains';
8
+
9
+ import { CalldataRetriever } from '../calldata_retriever.js';
10
+
11
+ const logger = createLogger('archiver:calldata-test');
12
+
13
+ interface ScriptArgs {
14
+ rollupAddress: EthAddress;
15
+ txHash: Hex;
16
+ rpcUrl: string;
17
+ targetCommitteeSize: number;
18
+ }
19
+
20
+ function parseArgs(): ScriptArgs {
21
+ const args = process.argv.slice(2);
22
+
23
+ if (args.length < 2) {
24
+ // eslint-disable-next-line no-console
25
+ console.error('Usage: node index.js <rollup-address> <tx-hash> [target-committee-size]');
26
+ // eslint-disable-next-line no-console
27
+ console.error('');
28
+ // eslint-disable-next-line no-console
29
+ console.error('Environment variables:');
30
+ // eslint-disable-next-line no-console
31
+ console.error(' ETHEREUM_HOST or RPC_URL - Ethereum RPC endpoint');
32
+ // eslint-disable-next-line no-console
33
+ console.error('');
34
+ // eslint-disable-next-line no-console
35
+ console.error('Example:');
36
+ // eslint-disable-next-line no-console
37
+ console.error(' RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY \\');
38
+ // eslint-disable-next-line no-console
39
+ console.error(' node index.js 0x1234... 0xabcd... 32');
40
+ process.exit(1);
41
+ }
42
+
43
+ const rollupAddress = EthAddress.fromString(args[0]);
44
+ const txHash = args[1] as Hex;
45
+ const targetCommitteeSize = args[2] ? parseInt(args[2], 10) : 24;
46
+
47
+ const rpcUrl = process.env.ETHEREUM_HOST || process.env.RPC_URL;
48
+ if (!rpcUrl) {
49
+ // eslint-disable-next-line no-console
50
+ console.error('Error: ETHEREUM_HOST or RPC_URL environment variable must be set');
51
+ process.exit(1);
52
+ }
53
+
54
+ if (targetCommitteeSize <= 0 || targetCommitteeSize > 256) {
55
+ // eslint-disable-next-line no-console
56
+ console.error('Error: target-committee-size must be between 1 and 256');
57
+ process.exit(1);
58
+ }
59
+
60
+ return { rollupAddress, txHash, rpcUrl, targetCommitteeSize };
61
+ }
62
+
63
+ async function main() {
64
+ const { rollupAddress, txHash, rpcUrl, targetCommitteeSize } = parseArgs();
65
+
66
+ logger.info('Calldata Retriever Test Script');
67
+ logger.info('===============================');
68
+ logger.info(`Rollup Address: ${rollupAddress.toString()}`);
69
+ logger.info(`Transaction Hash: ${txHash}`);
70
+ logger.info(`RPC URL: ${rpcUrl}`);
71
+ logger.info(`Target Committee Size: ${targetCommitteeSize}`);
72
+ logger.info('');
73
+
74
+ try {
75
+ // Create viem public client
76
+ const publicClient = createPublicClient({
77
+ chain: mainnet,
78
+ transport: http(rpcUrl),
79
+ });
80
+
81
+ logger.info('Fetching transaction...');
82
+ const tx = await publicClient.getTransaction({ hash: txHash });
83
+
84
+ if (!tx) {
85
+ throw new Error(`Transaction ${txHash} not found`);
86
+ }
87
+
88
+ logger.info(`Transaction found in block ${tx.blockNumber}`);
89
+
90
+ // For simplicity, use zero addresses for optional contract addresses
91
+ // In production, these would be fetched from the rollup contract or configuration
92
+ const slashingProposerAddress = EthAddress.ZERO;
93
+ const governanceProposerAddress = EthAddress.ZERO;
94
+ const slashFactoryAddress = undefined;
95
+
96
+ logger.info('Using zero addresses for governance/slashing (can be configured if needed)');
97
+
98
+ // Create CalldataRetriever
99
+ const retriever = new CalldataRetriever(
100
+ publicClient as unknown as ViemPublicClient,
101
+ publicClient as unknown as ViemPublicDebugClient,
102
+ targetCommitteeSize,
103
+ undefined,
104
+ logger,
105
+ {
106
+ rollupAddress,
107
+ governanceProposerAddress,
108
+ slashingProposerAddress,
109
+ slashFactoryAddress,
110
+ },
111
+ );
112
+
113
+ // Extract L2 block number from transaction logs
114
+ logger.info('Decoding transaction to extract L2 block number...');
115
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
116
+ const l2BlockProposedEvent = receipt.logs.find(log => {
117
+ try {
118
+ // Try to match the L2BlockProposed event
119
+ return (
120
+ log.address.toLowerCase() === rollupAddress.toString().toLowerCase() &&
121
+ log.topics[0] === '0x2f1d0e696fa5186494a2f2f89a0e0bcbb15d607f6c5eac4637e07e1e5e7d3c00' // L2BlockProposed event signature
122
+ );
123
+ } catch {
124
+ return false;
125
+ }
126
+ });
127
+
128
+ let l2BlockNumber: number;
129
+ if (l2BlockProposedEvent && l2BlockProposedEvent.topics[1]) {
130
+ // L2 block number is typically the first indexed parameter
131
+ l2BlockNumber = Number(BigInt(l2BlockProposedEvent.topics[1]));
132
+ logger.info(`L2 Block Number (from event): ${l2BlockNumber}`);
133
+ } else {
134
+ // Fallback: try to extract from transaction data or use a default
135
+ logger.warn('Could not extract L2 block number from event, using block number as fallback');
136
+ l2BlockNumber = Number(tx.blockNumber);
137
+ }
138
+
139
+ logger.info('');
140
+ logger.info('Retrieving block header from rollup transaction...');
141
+ logger.info('');
142
+
143
+ const result = await retriever.getBlockHeaderFromRollupTx(txHash, l2BlockNumber);
144
+
145
+ logger.info(' Successfully retrieved block header!');
146
+ logger.info('');
147
+ logger.info('Block Header Details:');
148
+ logger.info('====================');
149
+ logger.info(`L2 Block Number: ${result.l2BlockNumber}`);
150
+ logger.info(`Block Hash: ${result.blockHash}`);
151
+ logger.info(`Archive Root: ${result.archiveRoot.toString()}`);
152
+ logger.info('');
153
+ logger.info('State Reference:');
154
+ logger.info(` L1 to L2 Message Tree Root: ${result.stateReference.l1ToL2MessageTree.root.toString()}`);
155
+ logger.info(
156
+ ` L1 to L2 Message Tree Next Index: ${result.stateReference.l1ToL2MessageTree.nextAvailableLeafIndex}`,
157
+ );
158
+ logger.info('');
159
+ logger.info('Header:');
160
+ logger.info(` Slot Number: ${result.header.slotNumber.toString()}`);
161
+ logger.info(` Timestamp: ${result.header.timestamp.toString()}`);
162
+ logger.info(` Coinbase: ${result.header.coinbase.toString()}`);
163
+ logger.info(` Fee Recipient: ${result.header.feeRecipient.toString()}`);
164
+ logger.info(` Total Mana Used: ${result.header.totalManaUsed.toString()}`);
165
+ logger.info('');
166
+ logger.info('Attestations:');
167
+ logger.info(` Count: ${result.attestations.length}`);
168
+ logger.info(` Non-empty attestations: ${result.attestations.filter(a => !a.signature.isEmpty()).length}`);
169
+
170
+ process.exit(0);
171
+ } catch (error) {
172
+ logger.error('Error retrieving block header:');
173
+ logger.error(error instanceof Error ? error.message : String(error));
174
+
175
+ if (error instanceof Error && error.stack) {
176
+ logger.debug(error.stack);
177
+ }
178
+
179
+ process.exit(1);
180
+ }
181
+ }
182
+
183
+ // Only run if this is the main module
184
+ if (import.meta.url === `file://${process.argv[1]}`) {
185
+ void main();
186
+ }