@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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.
- package/README.md +156 -22
- package/dest/archiver.d.ts +139 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +699 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +21 -5
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +62 -0
- package/dest/factory.d.ts +9 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +97 -13
- package/dest/index.d.ts +11 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +9 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/l1/bin/retrieve-calldata.js +148 -0
- package/dest/l1/calldata_retriever.d.ts +118 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +484 -0
- package/dest/l1/data_retrieval.d.ts +89 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver → l1}/data_retrieval.js +80 -153
- package/dest/l1/debug_tx.d.ts +19 -0
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/l1/debug_tx.js +73 -0
- package/dest/l1/spire_proposer.d.ts +70 -0
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/l1/spire_proposer.js +157 -0
- package/dest/l1/trace_tx.d.ts +97 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/trace_tx.js +91 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/l1/types.js +3 -0
- package/dest/l1/validate_trace.d.ts +32 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +154 -0
- package/dest/modules/data_source_base.d.ts +89 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +216 -0
- package/dest/modules/data_store_updater.d.ts +80 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +323 -0
- package/dest/modules/instrumentation.d.ts +39 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +39 -62
- package/dest/modules/l1_synchronizer.d.ts +76 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +196 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +773 -0
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +13 -9
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +354 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +464 -0
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +456 -0
- package/dest/store/message_store.d.ts +40 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/inbox_message.js +6 -5
- package/dest/structs/published.d.ts +2 -0
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +193 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +389 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +16 -8
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +19 -14
- package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +21 -11
- package/dest/test/mock_l2_block_source.d.ts +51 -18
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +245 -82
- package/dest/test/mock_structs.d.ts +80 -4
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +145 -11
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +20 -20
- package/src/archiver.ts +443 -0
- package/src/{archiver/config.ts → config.ts} +28 -12
- package/src/errors.ts +102 -0
- package/src/factory.ts +143 -13
- package/src/index.ts +11 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +98 -0
- package/src/l1/bin/retrieve-calldata.ts +181 -0
- package/src/l1/calldata_retriever.ts +663 -0
- package/src/{archiver → l1}/data_retrieval.ts +146 -224
- package/src/l1/debug_tx.ts +99 -0
- package/src/l1/spire_proposer.ts +160 -0
- package/src/l1/trace_tx.ts +128 -0
- package/src/l1/types.ts +13 -0
- package/src/l1/validate_trace.ts +229 -0
- package/src/modules/data_source_base.ts +328 -0
- package/src/modules/data_store_updater.ts +448 -0
- package/src/{archiver → modules}/instrumentation.ts +43 -66
- package/src/modules/l1_synchronizer.ts +932 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/store/block_store.ts +1015 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +13 -9
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
- package/src/store/kv_archiver_store.ts +671 -0
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +637 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
- package/src/{archiver/structs → structs}/inbox_message.ts +8 -8
- package/src/{archiver/structs → structs}/published.ts +0 -1
- package/src/test/fake_l1_state.ts +607 -0
- package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
- package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
- package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
- package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
- package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
- package/src/test/fixtures/trace_transaction-proxied.json +128 -0
- package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +23 -16
- package/src/test/mock_l1_to_l2_message_source.ts +18 -11
- package/src/test/mock_l2_block_source.ts +296 -90
- package/src/test/mock_structs.ts +275 -13
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -287
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1408
- package/dest/archiver/archiver_store.d.ts +0 -255
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -1289
- package/dest/archiver/config.d.ts +0 -21
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/data_retrieval.d.ts +0 -79
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -12
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -17
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -35
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -370
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -168
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -336
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts +0 -3
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -1858
- package/src/archiver/archiver_store.ts +0 -305
- package/src/archiver/archiver_store_test_suite.ts +0 -1264
- package/src/archiver/errors.ts +0 -26
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -481
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
- package/src/archiver/kv_archiver_store/log_store.ts +0 -406
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
|
+
import { type CheckpointBlobData } from '@aztec/blob-lib';
|
|
3
|
+
import type { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
5
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
7
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
9
|
+
import { CommitteeAttestation } from '@aztec/stdlib/block';
|
|
10
|
+
import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
11
|
+
import { Proof } from '@aztec/stdlib/proofs';
|
|
12
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
|
+
import { type Hex } from 'viem';
|
|
14
|
+
import type { ArchiverInstrumentation } from '../modules/instrumentation.js';
|
|
15
|
+
import type { DataRetrieval } from '../structs/data_retrieval.js';
|
|
16
|
+
import type { InboxMessage } from '../structs/inbox_message.js';
|
|
17
|
+
export type RetrievedCheckpoint = {
|
|
18
|
+
checkpointNumber: CheckpointNumber;
|
|
19
|
+
archiveRoot: Fr;
|
|
20
|
+
feeAssetPriceModifier: bigint;
|
|
21
|
+
header: CheckpointHeader;
|
|
22
|
+
checkpointBlobData: CheckpointBlobData;
|
|
23
|
+
l1: L1PublishedData;
|
|
24
|
+
chainId: Fr;
|
|
25
|
+
version: Fr;
|
|
26
|
+
attestations: CommitteeAttestation[];
|
|
27
|
+
};
|
|
28
|
+
export declare function retrievedToPublishedCheckpoint({ checkpointNumber, archiveRoot, feeAssetPriceModifier, header: checkpointHeader, checkpointBlobData, l1, chainId, version, attestations }: RetrievedCheckpoint): Promise<PublishedCheckpoint>;
|
|
29
|
+
/**
|
|
30
|
+
* Fetches new checkpoints.
|
|
31
|
+
* @param rollup - The rollup contract wrapper.
|
|
32
|
+
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
33
|
+
* @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
|
|
34
|
+
* @param blobClient - The blob client client for fetching blob data.
|
|
35
|
+
* @param searchStartBlock - The block number to use for starting the search.
|
|
36
|
+
* @param searchEndBlock - The highest block number that we should search up to.
|
|
37
|
+
* @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
|
|
38
|
+
* @param instrumentation - The archiver instrumentation instance.
|
|
39
|
+
* @param logger - The logger instance.
|
|
40
|
+
* @param isHistoricalSync - Whether this is a historical sync.
|
|
41
|
+
* @returns An array of retrieved checkpoints.
|
|
42
|
+
*/
|
|
43
|
+
export declare function retrieveCheckpointsFromRollup(rollup: RollupContract, publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, blobClient: BlobClientInterface, searchStartBlock: bigint, searchEndBlock: bigint, contractAddresses: {
|
|
44
|
+
governanceProposerAddress: EthAddress;
|
|
45
|
+
slashFactoryAddress?: EthAddress;
|
|
46
|
+
slashingProposerAddress: EthAddress;
|
|
47
|
+
}, instrumentation: ArchiverInstrumentation, logger?: Logger, isHistoricalSync?: boolean): Promise<RetrievedCheckpoint[]>;
|
|
48
|
+
export declare function getL1BlockTime(publicClient: ViemPublicClient, blockNumber: bigint): Promise<bigint>;
|
|
49
|
+
export declare function getCheckpointBlobDataFromBlobs(blobClient: BlobClientInterface, blockHash: string, blobHashes: Buffer<ArrayBufferLike>[], checkpointNumber: CheckpointNumber, logger: Logger, isHistoricalSync: boolean): Promise<CheckpointBlobData>;
|
|
50
|
+
/** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
|
|
51
|
+
export declare function retrieveL1ToL2Message(inbox: InboxContract, leaf: Fr, fromBlock: bigint, toBlock: bigint): Promise<InboxMessage | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Fetch L1 to L2 messages.
|
|
54
|
+
* @param inbox - The inbox contract wrapper.
|
|
55
|
+
* @param searchStartBlock - The block number to use for starting the search.
|
|
56
|
+
* @param searchEndBlock - The highest block number that we should search up to.
|
|
57
|
+
* @returns An array of InboxLeaf and next eth block to search from.
|
|
58
|
+
*/
|
|
59
|
+
export declare function retrieveL1ToL2Messages(inbox: InboxContract, searchStartBlock: bigint, searchEndBlock: bigint): Promise<InboxMessage[]>;
|
|
60
|
+
/** Retrieves L2ProofVerified events from the rollup contract. */
|
|
61
|
+
export declare function retrieveL2ProofVerifiedEvents(publicClient: ViemPublicClient, rollupAddress: EthAddress, searchStartBlock: bigint, searchEndBlock?: bigint): Promise<{
|
|
62
|
+
l1BlockNumber: bigint;
|
|
63
|
+
checkpointNumber: CheckpointNumber;
|
|
64
|
+
proverId: Fr;
|
|
65
|
+
txHash: Hex;
|
|
66
|
+
}[]>;
|
|
67
|
+
/** Retrieve submitted proofs from the rollup contract */
|
|
68
|
+
export declare function retrieveL2ProofsFromRollup(publicClient: ViemPublicClient, rollupAddress: EthAddress, searchStartBlock: bigint, searchEndBlock?: bigint): Promise<DataRetrieval<{
|
|
69
|
+
proof: Proof;
|
|
70
|
+
proverId: Fr;
|
|
71
|
+
checkpointNumber: number;
|
|
72
|
+
txHash: `0x${string}`;
|
|
73
|
+
}>>;
|
|
74
|
+
export type SubmitEpochProof = {
|
|
75
|
+
archiveRoot: Fr;
|
|
76
|
+
proverId: Fr;
|
|
77
|
+
proof: Proof;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Gets epoch proof metadata (archive root and proof) from the calldata of an L1 transaction.
|
|
81
|
+
* Assumes that the block was published from an EOA.
|
|
82
|
+
* TODO: Add retries and error management.
|
|
83
|
+
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
84
|
+
* @param txHash - Hash of the tx that published it.
|
|
85
|
+
* @param expectedProverId - Expected prover ID.
|
|
86
|
+
* @returns Epoch proof metadata from the calldata, deserialized.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getProofFromSubmitProofTx(publicClient: ViemPublicClient, txHash: `0x${string}`, expectedProverId: Fr): Promise<SubmitEpochProof>;
|
|
89
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YV9yZXRyaWV2YWwuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sMS9kYXRhX3JldHJpZXZhbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQ3JFLE9BQU8sRUFFTCxLQUFLLGtCQUFrQixFQUl4QixNQUFNLGlCQUFpQixDQUFDO0FBQ3pCLE9BQU8sS0FBSyxFQUdWLGFBQWEsRUFFYixjQUFjLEVBQ2YsTUFBTSwyQkFBMkIsQ0FBQztBQUNuQyxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxxQkFBcUIsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRXJGLE9BQU8sRUFBRSxnQkFBZ0IsRUFBeUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUMxRixPQUFPLEVBQUUsRUFBRSxFQUF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AAC,QAAQ,EAAE,EAAE,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,EAAE,CAAC,CAerG;AAED,yDAAyD;AACzD,wBAAsB,0BAA0B,CAC9C,YAAY,EAAE,gBAAgB,EAC9B,aAAa,EAAE,UAAU,EACzB,gBAAgB,EAAE,MAAM,EACxB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,aAAa,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,EAAE,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC,CAazG;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,EAAE,CAAC;IAChB,QAAQ,EAAE,EAAE,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,YAAY,EAAE,gBAAgB,EAC9B,MAAM,EAAE,KAAK,MAAM,EAAE,EACrB,gBAAgB,EAAE,EAAE,GACnB,OAAO,CAAC,gBAAgB,CAAC,CAmC3B"}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { BlobDeserializationError, SpongeBlob, decodeCheckpointBlobDataFromBlobs, encodeBlockBlobData } from '@aztec/blob-lib';
|
|
2
2
|
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
3
|
-
import {
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
7
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
7
|
-
import { Body,
|
|
8
|
-
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
8
|
+
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
9
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
9
10
|
import { Proof } from '@aztec/stdlib/proofs';
|
|
10
|
-
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
11
11
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
12
12
|
import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
13
|
-
import { decodeFunctionData, getAbiItem, hexToBytes
|
|
14
|
-
import { NoBlobBodiesFoundError } from '
|
|
15
|
-
|
|
13
|
+
import { decodeFunctionData, getAbiItem, hexToBytes } from 'viem';
|
|
14
|
+
import { NoBlobBodiesFoundError } from '../errors.js';
|
|
15
|
+
import { CalldataRetriever } from './calldata_retriever.js';
|
|
16
|
+
export async function retrievedToPublishedCheckpoint({ checkpointNumber, archiveRoot, feeAssetPriceModifier, header: checkpointHeader, checkpointBlobData, l1, chainId, version, attestations }) {
|
|
16
17
|
const { blocks: blocksBlobData } = checkpointBlobData;
|
|
17
18
|
// The lastArchiveRoot of a block is the new archive for the previous block.
|
|
18
19
|
const newArchiveRoots = blocksBlobData.map((b)=>b.lastArchiveRoot).slice(1).concat([
|
|
19
20
|
archiveRoot
|
|
20
21
|
]);
|
|
21
|
-
//
|
|
22
|
-
//
|
|
22
|
+
// An error will be thrown from `decodeCheckpointBlobDataFromBlobs` if it can't read a field for the
|
|
23
|
+
// `l1ToL2MessageRoot` of the first block. So below we can safely assume it exists:
|
|
23
24
|
const l1toL2MessageTreeRoot = blocksBlobData[0].l1ToL2MessageRoot;
|
|
24
25
|
const spongeBlob = SpongeBlob.init();
|
|
25
26
|
const l2Blocks = [];
|
|
@@ -45,7 +46,7 @@ export async function retrievedToPublishedCheckpoint({ checkpointNumber, archive
|
|
|
45
46
|
publicDataTree: new AppendOnlyTreeSnapshot(publicDataRoot, blockEndStateField.publicDataNextAvailableLeafIndex)
|
|
46
47
|
})
|
|
47
48
|
});
|
|
48
|
-
const body = Body.fromTxBlobData(
|
|
49
|
+
const body = Body.fromTxBlobData(blockBlobData.txs);
|
|
49
50
|
const blobFields = encodeBlockBlobData(blockBlobData);
|
|
50
51
|
await spongeBlob.absorb(blobFields);
|
|
51
52
|
const clonedSpongeBlob = spongeBlob.clone();
|
|
@@ -59,14 +60,15 @@ export async function retrievedToPublishedCheckpoint({ checkpointNumber, archive
|
|
|
59
60
|
totalManaUsed: new Fr(blockEndStateField.totalManaUsed)
|
|
60
61
|
});
|
|
61
62
|
const newArchive = new AppendOnlyTreeSnapshot(newArchiveRoots[i], l2BlockNumber + 1);
|
|
62
|
-
l2Blocks.push(new
|
|
63
|
+
l2Blocks.push(new L2Block(newArchive, header, body, checkpointNumber, IndexWithinCheckpoint(i)));
|
|
63
64
|
}
|
|
64
65
|
const lastBlock = l2Blocks.at(-1);
|
|
65
66
|
const checkpoint = Checkpoint.from({
|
|
66
67
|
archive: new AppendOnlyTreeSnapshot(archiveRoot, lastBlock.number + 1),
|
|
67
68
|
header: checkpointHeader,
|
|
68
69
|
blocks: l2Blocks,
|
|
69
|
-
number: checkpointNumber
|
|
70
|
+
number: checkpointNumber,
|
|
71
|
+
feeAssetPriceModifier: feeAssetPriceModifier
|
|
70
72
|
});
|
|
71
73
|
return PublishedCheckpoint.from({
|
|
72
74
|
checkpoint,
|
|
@@ -76,86 +78,100 @@ export async function retrievedToPublishedCheckpoint({ checkpointNumber, archive
|
|
|
76
78
|
}
|
|
77
79
|
/**
|
|
78
80
|
* Fetches new checkpoints.
|
|
81
|
+
* @param rollup - The rollup contract wrapper.
|
|
79
82
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
80
|
-
* @param
|
|
83
|
+
* @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
|
|
84
|
+
* @param blobClient - The blob client client for fetching blob data.
|
|
81
85
|
* @param searchStartBlock - The block number to use for starting the search.
|
|
82
86
|
* @param searchEndBlock - The highest block number that we should search up to.
|
|
83
|
-
* @param
|
|
84
|
-
* @
|
|
85
|
-
|
|
87
|
+
* @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
|
|
88
|
+
* @param instrumentation - The archiver instrumentation instance.
|
|
89
|
+
* @param logger - The logger instance.
|
|
90
|
+
* @param isHistoricalSync - Whether this is a historical sync.
|
|
91
|
+
* @returns An array of retrieved checkpoints.
|
|
92
|
+
*/ export async function retrieveCheckpointsFromRollup(rollup, publicClient, debugClient, blobClient, searchStartBlock, searchEndBlock, contractAddresses, instrumentation, logger = createLogger('archiver'), isHistoricalSync = false) {
|
|
86
93
|
const retrievedCheckpoints = [];
|
|
87
94
|
let rollupConstants;
|
|
88
95
|
do {
|
|
89
96
|
if (searchStartBlock > searchEndBlock) {
|
|
90
97
|
break;
|
|
91
98
|
}
|
|
92
|
-
const checkpointProposedLogs =
|
|
93
|
-
fromBlock: searchStartBlock,
|
|
94
|
-
toBlock: searchEndBlock
|
|
95
|
-
})).filter((log)=>log.blockNumber >= searchStartBlock && log.blockNumber <= searchEndBlock);
|
|
99
|
+
const checkpointProposedLogs = await rollup.getCheckpointProposedEvents(searchStartBlock, searchEndBlock);
|
|
96
100
|
if (checkpointProposedLogs.length === 0) {
|
|
97
101
|
break;
|
|
98
102
|
}
|
|
99
103
|
const lastLog = checkpointProposedLogs.at(-1);
|
|
100
|
-
logger.debug(`Got ${checkpointProposedLogs.length} processed logs for checkpoints
|
|
104
|
+
logger.debug(`Got ${checkpointProposedLogs.length} processed logs for checkpoints ${checkpointProposedLogs[0].args.checkpointNumber}-${lastLog.args.checkpointNumber} between L1 blocks ${searchStartBlock}-${searchEndBlock}`);
|
|
101
105
|
if (rollupConstants === undefined) {
|
|
102
106
|
const [chainId, version, targetCommitteeSize] = await Promise.all([
|
|
103
107
|
publicClient.getChainId(),
|
|
104
|
-
rollup.
|
|
105
|
-
rollup.
|
|
108
|
+
rollup.getVersion(),
|
|
109
|
+
rollup.getTargetCommitteeSize()
|
|
106
110
|
]);
|
|
107
111
|
rollupConstants = {
|
|
108
112
|
chainId: new Fr(chainId),
|
|
109
113
|
version: new Fr(version),
|
|
110
|
-
targetCommitteeSize
|
|
114
|
+
targetCommitteeSize
|
|
111
115
|
};
|
|
112
116
|
}
|
|
113
|
-
const newCheckpoints = await processCheckpointProposedLogs(rollup, publicClient,
|
|
117
|
+
const newCheckpoints = await processCheckpointProposedLogs(rollup, publicClient, debugClient, blobClient, checkpointProposedLogs, rollupConstants, contractAddresses, instrumentation, logger, isHistoricalSync);
|
|
114
118
|
retrievedCheckpoints.push(...newCheckpoints);
|
|
115
|
-
searchStartBlock = lastLog.
|
|
119
|
+
searchStartBlock = lastLog.l1BlockNumber + 1n;
|
|
116
120
|
}while (searchStartBlock <= searchEndBlock)
|
|
117
121
|
// The asyncPool from processCheckpointProposedLogs will not necessarily return the checkpoints in order, so we sort them before returning.
|
|
118
122
|
return retrievedCheckpoints.sort((a, b)=>Number(a.l1.blockNumber - b.l1.blockNumber));
|
|
119
123
|
}
|
|
120
124
|
/**
|
|
121
125
|
* Processes newly received CheckpointProposed logs.
|
|
122
|
-
* @param rollup - The rollup contract
|
|
126
|
+
* @param rollup - The rollup contract wrapper.
|
|
123
127
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
128
|
+
* @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
|
|
129
|
+
* @param blobClient - The blob client client for fetching blob data.
|
|
124
130
|
* @param logs - CheckpointProposed logs.
|
|
125
|
-
* @
|
|
126
|
-
|
|
131
|
+
* @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
|
|
132
|
+
* @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
|
|
133
|
+
* @param instrumentation - The archiver instrumentation instance.
|
|
134
|
+
* @param logger - The logger instance.
|
|
135
|
+
* @param isHistoricalSync - Whether this is a historical sync.
|
|
136
|
+
* @returns An array of retrieved checkpoints.
|
|
137
|
+
*/ async function processCheckpointProposedLogs(rollup, publicClient, debugClient, blobClient, logs, { chainId, version, targetCommitteeSize }, contractAddresses, instrumentation, logger, isHistoricalSync) {
|
|
127
138
|
const retrievedCheckpoints = [];
|
|
139
|
+
const calldataRetriever = new CalldataRetriever(publicClient, debugClient, targetCommitteeSize, instrumentation, logger, {
|
|
140
|
+
...contractAddresses,
|
|
141
|
+
rollupAddress: EthAddress.fromString(rollup.address)
|
|
142
|
+
});
|
|
128
143
|
await asyncPool(10, logs, async (log)=>{
|
|
129
|
-
const checkpointNumber =
|
|
144
|
+
const checkpointNumber = log.args.checkpointNumber;
|
|
130
145
|
const archive = log.args.archive;
|
|
131
|
-
const archiveFromChain = await rollup.
|
|
132
|
-
|
|
133
|
-
]);
|
|
134
|
-
const blobHashes = log.args.versionedBlobHashes.map((blobHash)=>Buffer.from(blobHash.slice(2), 'hex'));
|
|
146
|
+
const archiveFromChain = await rollup.archiveAt(checkpointNumber);
|
|
147
|
+
const blobHashes = log.args.versionedBlobHashes;
|
|
135
148
|
// The value from the event and contract will match only if the checkpoint is in the chain.
|
|
136
|
-
if (archive
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
timestamp: await getL1BlockTime(publicClient, log.blockNumber)
|
|
149
|
+
if (archive.equals(archiveFromChain)) {
|
|
150
|
+
// Build expected hashes object (fields may be undefined for backwards compatibility with older events)
|
|
151
|
+
const expectedHashes = {
|
|
152
|
+
attestationsHash: log.args.attestationsHash?.toString(),
|
|
153
|
+
payloadDigest: log.args.payloadDigest?.toString()
|
|
142
154
|
};
|
|
155
|
+
const checkpoint = await calldataRetriever.getCheckpointFromRollupTx(log.l1TransactionHash, blobHashes, checkpointNumber, expectedHashes);
|
|
156
|
+
const checkpointBlobData = await getCheckpointBlobDataFromBlobs(blobClient, checkpoint.blockHash, blobHashes, checkpointNumber, logger, isHistoricalSync);
|
|
157
|
+
const l1 = new L1PublishedData(log.l1BlockNumber, await getL1BlockTime(publicClient, log.l1BlockNumber), log.l1BlockHash.toString());
|
|
143
158
|
retrievedCheckpoints.push({
|
|
144
159
|
...checkpoint,
|
|
160
|
+
checkpointBlobData,
|
|
145
161
|
l1,
|
|
146
162
|
chainId,
|
|
147
163
|
version
|
|
148
164
|
});
|
|
149
|
-
logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.
|
|
150
|
-
l1BlockNumber: log.
|
|
165
|
+
logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
|
|
166
|
+
l1BlockNumber: log.l1BlockNumber,
|
|
151
167
|
checkpointNumber,
|
|
152
168
|
archive: archive.toString(),
|
|
153
169
|
attestations: checkpoint.attestations
|
|
154
170
|
});
|
|
155
171
|
} else {
|
|
156
172
|
logger.warn(`Ignoring checkpoint ${checkpointNumber} due to archive root mismatch`, {
|
|
157
|
-
actual: archive,
|
|
158
|
-
expected: archiveFromChain
|
|
173
|
+
actual: archive.toString(),
|
|
174
|
+
expected: archiveFromChain.toString()
|
|
159
175
|
});
|
|
160
176
|
}
|
|
161
177
|
});
|
|
@@ -168,149 +184,60 @@ export async function getL1BlockTime(publicClient, blockNumber) {
|
|
|
168
184
|
});
|
|
169
185
|
return block.timestamp;
|
|
170
186
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
* @param rollupAddress - The address of the rollup contract
|
|
175
|
-
* @returns The calldata for the first 'propose' method call to the rollup contract
|
|
176
|
-
*/ function extractRollupProposeCalldata(multicall3Data, rollupAddress) {
|
|
177
|
-
const { functionName: multicall3FunctionName, args: multicall3Args } = decodeFunctionData({
|
|
178
|
-
abi: multicall3Abi,
|
|
179
|
-
data: multicall3Data
|
|
180
|
-
});
|
|
181
|
-
if (multicall3FunctionName !== 'aggregate3') {
|
|
182
|
-
throw new Error(`Unexpected multicall3 method called ${multicall3FunctionName}`);
|
|
183
|
-
}
|
|
184
|
-
if (multicall3Args.length !== 1) {
|
|
185
|
-
throw new Error(`Unexpected number of arguments for multicall3`);
|
|
186
|
-
}
|
|
187
|
-
const [calls] = multicall3Args;
|
|
188
|
-
// Find all rollup calls
|
|
189
|
-
const rollupAddressLower = rollupAddress.toLowerCase();
|
|
190
|
-
for(let i = 0; i < calls.length; i++){
|
|
191
|
-
const addr = calls[i].target;
|
|
192
|
-
if (addr.toLowerCase() !== rollupAddressLower) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
const callData = calls[i].callData;
|
|
196
|
-
try {
|
|
197
|
-
const { functionName: rollupFunctionName } = decodeFunctionData({
|
|
198
|
-
abi: RollupAbi,
|
|
199
|
-
data: callData
|
|
200
|
-
});
|
|
201
|
-
if (rollupFunctionName === 'propose') {
|
|
202
|
-
return callData;
|
|
203
|
-
}
|
|
204
|
-
} catch {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
throw new Error(`Rollup address not found in multicall3 args`);
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Gets checkpoint from the calldata of an L1 transaction.
|
|
212
|
-
* Assumes that the checkpoint was published from an EOA.
|
|
213
|
-
* TODO: Add retries and error management.
|
|
214
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
215
|
-
* @param txHash - Hash of the tx that published it.
|
|
216
|
-
* @param checkpointNumber - Checkpoint number.
|
|
217
|
-
* @returns Checkpoint from the calldata, deserialized
|
|
218
|
-
*/ async function getCheckpointFromRollupTx(publicClient, blobSinkClient, txHash, blobHashes, checkpointNumber, rollupAddress, targetCommitteeSize, logger) {
|
|
219
|
-
logger.trace(`Fetching checkpoint ${checkpointNumber} from rollup tx ${txHash}`);
|
|
220
|
-
const { input: forwarderData, blockHash } = await publicClient.getTransaction({
|
|
221
|
-
hash: txHash
|
|
187
|
+
export async function getCheckpointBlobDataFromBlobs(blobClient, blockHash, blobHashes, checkpointNumber, logger, isHistoricalSync) {
|
|
188
|
+
const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
|
|
189
|
+
isHistoricalSync
|
|
222
190
|
});
|
|
223
|
-
const rollupData = extractRollupProposeCalldata(forwarderData, rollupAddress);
|
|
224
|
-
const { functionName: rollupFunctionName, args: rollupArgs } = decodeFunctionData({
|
|
225
|
-
abi: RollupAbi,
|
|
226
|
-
data: rollupData
|
|
227
|
-
});
|
|
228
|
-
if (rollupFunctionName !== 'propose') {
|
|
229
|
-
throw new Error(`Unexpected rollup method called ${rollupFunctionName}`);
|
|
230
|
-
}
|
|
231
|
-
const [decodedArgs, packedAttestations, _signers, _blobInput] = rollupArgs;
|
|
232
|
-
const attestations = CommitteeAttestation.fromPacked(packedAttestations, targetCommitteeSize);
|
|
233
|
-
logger.trace(`Recovered propose calldata from tx ${txHash}`, {
|
|
234
|
-
checkpointNumber,
|
|
235
|
-
archive: decodedArgs.archive,
|
|
236
|
-
header: decodedArgs.header,
|
|
237
|
-
l1BlockHash: blockHash,
|
|
238
|
-
blobHashes,
|
|
239
|
-
attestations,
|
|
240
|
-
packedAttestations,
|
|
241
|
-
targetCommitteeSize
|
|
242
|
-
});
|
|
243
|
-
const header = CheckpointHeader.fromViem(decodedArgs.header);
|
|
244
|
-
const blobBodies = await blobSinkClient.getBlobSidecar(blockHash, blobHashes);
|
|
245
191
|
if (blobBodies.length === 0) {
|
|
246
192
|
throw new NoBlobBodiesFoundError(checkpointNumber);
|
|
247
193
|
}
|
|
248
194
|
let checkpointBlobData;
|
|
249
195
|
try {
|
|
250
196
|
// Attempt to decode the checkpoint blob data.
|
|
251
|
-
checkpointBlobData = decodeCheckpointBlobDataFromBlobs(blobBodies
|
|
197
|
+
checkpointBlobData = decodeCheckpointBlobDataFromBlobs(blobBodies);
|
|
252
198
|
} catch (err) {
|
|
253
199
|
if (err instanceof BlobDeserializationError) {
|
|
254
200
|
logger.fatal(err.message);
|
|
255
201
|
} else {
|
|
256
202
|
logger.fatal('Unable to sync: failed to decode fetched blob, this blob was likely not created by us');
|
|
257
203
|
}
|
|
204
|
+
// Throwing an error since this is most likely caused by a bug.
|
|
258
205
|
throw err;
|
|
259
206
|
}
|
|
260
|
-
|
|
261
|
-
return {
|
|
262
|
-
checkpointNumber,
|
|
263
|
-
archiveRoot,
|
|
264
|
-
header,
|
|
265
|
-
checkpointBlobData,
|
|
266
|
-
attestations
|
|
267
|
-
};
|
|
207
|
+
return checkpointBlobData;
|
|
268
208
|
}
|
|
269
209
|
/** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */ export async function retrieveL1ToL2Message(inbox, leaf, fromBlock, toBlock) {
|
|
270
|
-
const logs = await inbox.
|
|
271
|
-
hash: leaf.toString()
|
|
272
|
-
}, {
|
|
273
|
-
fromBlock,
|
|
274
|
-
toBlock
|
|
275
|
-
});
|
|
210
|
+
const logs = await inbox.getMessageSentEventByHash(leaf.toString(), fromBlock, toBlock);
|
|
276
211
|
const messages = mapLogsInboxMessage(logs);
|
|
277
212
|
return messages.length > 0 ? messages[0] : undefined;
|
|
278
213
|
}
|
|
279
214
|
/**
|
|
280
215
|
* Fetch L1 to L2 messages.
|
|
281
|
-
* @param
|
|
282
|
-
* @param inboxAddress - The address of the inbox contract to fetch messages from.
|
|
283
|
-
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
216
|
+
* @param inbox - The inbox contract wrapper.
|
|
284
217
|
* @param searchStartBlock - The block number to use for starting the search.
|
|
285
218
|
* @param searchEndBlock - The highest block number that we should search up to.
|
|
286
219
|
* @returns An array of InboxLeaf and next eth block to search from.
|
|
287
220
|
*/ export async function retrieveL1ToL2Messages(inbox, searchStartBlock, searchEndBlock) {
|
|
288
221
|
const retrievedL1ToL2Messages = [];
|
|
289
222
|
while(searchStartBlock <= searchEndBlock){
|
|
290
|
-
const messageSentLogs =
|
|
291
|
-
fromBlock: searchStartBlock,
|
|
292
|
-
toBlock: searchEndBlock
|
|
293
|
-
})).filter((log)=>log.blockNumber >= searchStartBlock && log.blockNumber <= searchEndBlock);
|
|
223
|
+
const messageSentLogs = await inbox.getMessageSentEvents(searchStartBlock, searchEndBlock);
|
|
294
224
|
if (messageSentLogs.length === 0) {
|
|
295
225
|
break;
|
|
296
226
|
}
|
|
297
227
|
retrievedL1ToL2Messages.push(...mapLogsInboxMessage(messageSentLogs));
|
|
298
|
-
searchStartBlock = messageSentLogs.at(-1).
|
|
228
|
+
searchStartBlock = messageSentLogs.at(-1).l1BlockNumber + 1n;
|
|
299
229
|
}
|
|
300
230
|
return retrievedL1ToL2Messages;
|
|
301
231
|
}
|
|
302
232
|
function mapLogsInboxMessage(logs) {
|
|
303
|
-
return logs.map((log)=>{
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
rollingHash: Buffer16.fromString(rollingHash)
|
|
312
|
-
};
|
|
313
|
-
});
|
|
233
|
+
return logs.map((log)=>({
|
|
234
|
+
index: log.args.index,
|
|
235
|
+
leaf: log.args.leaf,
|
|
236
|
+
l1BlockNumber: log.l1BlockNumber,
|
|
237
|
+
l1BlockHash: log.l1BlockHash,
|
|
238
|
+
checkpointNumber: log.args.checkpointNumber,
|
|
239
|
+
rollingHash: log.args.rollingHash
|
|
240
|
+
}));
|
|
314
241
|
}
|
|
315
242
|
/** Retrieves L2ProofVerified events from the rollup contract. */ export async function retrieveL2ProofVerifiedEvents(publicClient, rollupAddress, searchStartBlock, searchEndBlock) {
|
|
316
243
|
const logs = await publicClient.getLogs({
|
|
@@ -325,7 +252,7 @@ function mapLogsInboxMessage(logs) {
|
|
|
325
252
|
});
|
|
326
253
|
return logs.map((log)=>({
|
|
327
254
|
l1BlockNumber: log.blockNumber,
|
|
328
|
-
checkpointNumber:
|
|
255
|
+
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber),
|
|
329
256
|
proverId: Fr.fromHexString(log.args.proverId),
|
|
330
257
|
txHash: log.transactionHash
|
|
331
258
|
}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DebugCallTrace, 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 } from '@aztec/foundation/schemas';
|
|
5
|
+
import type { Hex } from 'viem';
|
|
6
|
+
import type { CallInfo } from './types.js';
|
|
7
|
+
/** Zod schema for validating call trace from debug_traceTransaction */
|
|
8
|
+
export declare const callTraceSchema: ZodFor<DebugCallTrace>;
|
|
9
|
+
/**
|
|
10
|
+
* Traces a transaction and extracts all CALL operations to a specific contract and function selector.
|
|
11
|
+
*
|
|
12
|
+
* @param client - The Viem public client
|
|
13
|
+
* @param txHash - The transaction hash to trace
|
|
14
|
+
* @param targetAddress - The contract address to filter for
|
|
15
|
+
* @param functionSelector - The 4-byte function selector to filter for (with or without 0x prefix)
|
|
16
|
+
* @returns Array of CallInfo objects containing from, gasUsed, input, and value for matching calls
|
|
17
|
+
*/
|
|
18
|
+
export declare function getSuccessfulCallsFromDebug(client: ViemPublicDebugClient, txHash: Hex, targetAddress: EthAddress, functionSelector: string, logger?: Logger): Promise<CallInfo[]>;
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVidWdfdHguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sMS9kZWJ1Z190eC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxjQUFjLEVBQUUscUJBQXFCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNuRixPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDcEQsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFXLE1B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B,gBAAgB,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,QAAQ,EAAE,CAAC,CAwDrB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { schemas } from '@aztec/foundation/schemas';
|
|
3
|
+
import { withHexPrefix } from '@aztec/foundation/string';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/** Zod schema for validating call trace from debug_traceTransaction */ export const callTraceSchema = z.lazy(()=>z.object({
|
|
6
|
+
from: schemas.HexStringWith0x,
|
|
7
|
+
to: schemas.HexStringWith0x.optional(),
|
|
8
|
+
type: z.string(),
|
|
9
|
+
input: schemas.HexStringWith0x.optional(),
|
|
10
|
+
output: schemas.HexStringWith0x.optional(),
|
|
11
|
+
gas: schemas.HexStringWith0x.optional(),
|
|
12
|
+
gasUsed: schemas.HexStringWith0x.optional(),
|
|
13
|
+
value: schemas.HexStringWith0x.optional(),
|
|
14
|
+
error: z.string().optional(),
|
|
15
|
+
calls: z.array(callTraceSchema).optional()
|
|
16
|
+
}));
|
|
17
|
+
/**
|
|
18
|
+
* Traces a transaction and extracts all CALL operations to a specific contract and function selector.
|
|
19
|
+
*
|
|
20
|
+
* @param client - The Viem public client
|
|
21
|
+
* @param txHash - The transaction hash to trace
|
|
22
|
+
* @param targetAddress - The contract address to filter for
|
|
23
|
+
* @param functionSelector - The 4-byte function selector to filter for (with or without 0x prefix)
|
|
24
|
+
* @returns Array of CallInfo objects containing from, gasUsed, input, and value for matching calls
|
|
25
|
+
*/ export async function getSuccessfulCallsFromDebug(client, txHash, targetAddress, functionSelector, logger) {
|
|
26
|
+
// Normalize inputs for comparison
|
|
27
|
+
const normalizedTarget = targetAddress.toString().toLowerCase();
|
|
28
|
+
const normalizedSelector = withHexPrefix(functionSelector.toLowerCase());
|
|
29
|
+
// Call debug_traceTransaction with callTracer
|
|
30
|
+
// Using 'any' here because debug_traceTransaction is not in viem's standard RPC types
|
|
31
|
+
const rawTrace = await client.request({
|
|
32
|
+
method: 'debug_traceTransaction',
|
|
33
|
+
params: [
|
|
34
|
+
txHash,
|
|
35
|
+
{
|
|
36
|
+
tracer: 'callTracer'
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
if (rawTrace === null || rawTrace === undefined) {
|
|
41
|
+
throw new Error(`Failed to retrieve debug_traceTransaction for ${txHash}`);
|
|
42
|
+
}
|
|
43
|
+
logger?.trace(`Retrieved debug_traceTransaction for ${txHash}`, {
|
|
44
|
+
trace: rawTrace
|
|
45
|
+
});
|
|
46
|
+
// Validate the response with zod
|
|
47
|
+
const trace = callTraceSchema.parse(rawTrace);
|
|
48
|
+
const results = [];
|
|
49
|
+
/**
|
|
50
|
+
* Recursively traverse the call trace tree
|
|
51
|
+
*/ function traverseCalls(callTrace) {
|
|
52
|
+
// Skip calls that have errors, and all its descendants
|
|
53
|
+
if (callTrace.error) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// Check if this is a CALL (not DELEGATECALL or STATICCALL) to the target address with matching selector
|
|
57
|
+
if (callTrace.type.toUpperCase() === 'CALL' && callTrace.to?.toLowerCase() === normalizedTarget && callTrace.input?.toLowerCase().startsWith(normalizedSelector)) {
|
|
58
|
+
results.push({
|
|
59
|
+
from: EthAddress.fromString(callTrace.from),
|
|
60
|
+
gasUsed: callTrace.gasUsed === undefined ? undefined : BigInt(callTrace.gasUsed),
|
|
61
|
+
input: callTrace.input,
|
|
62
|
+
value: callTrace.value ? BigInt(callTrace.value) : 0n
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Recursively process nested calls
|
|
66
|
+
for (const nestedCall of callTrace.calls ?? []){
|
|
67
|
+
traverseCalls(nestedCall);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Start traversal from the root trace
|
|
71
|
+
traverseCalls(trace);
|
|
72
|
+
return results;
|
|
73
|
+
}
|