@aztec/txe 0.0.0-test.1 → 0.0.1-commit.001888fc

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 (96) hide show
  1. package/dest/bin/index.d.ts +1 -1
  2. package/dest/bin/index.js +3 -2
  3. package/dest/constants.d.ts +3 -0
  4. package/dest/constants.d.ts.map +1 -0
  5. package/dest/constants.js +2 -0
  6. package/dest/index.d.ts +1 -1
  7. package/dest/index.d.ts.map +1 -1
  8. package/dest/index.js +146 -82
  9. package/dest/oracle/interfaces.d.ts +58 -0
  10. package/dest/oracle/interfaces.d.ts.map +1 -0
  11. package/dest/oracle/interfaces.js +3 -0
  12. package/dest/oracle/txe_oracle_public_context.d.ts +34 -0
  13. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -0
  14. package/dest/oracle/txe_oracle_public_context.js +122 -0
  15. package/dest/oracle/txe_oracle_top_level_context.d.ts +65 -0
  16. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
  17. package/dest/oracle/txe_oracle_top_level_context.js +542 -0
  18. package/dest/rpc_translator.d.ts +254 -0
  19. package/dest/rpc_translator.d.ts.map +1 -0
  20. package/dest/rpc_translator.js +791 -0
  21. package/dest/state_machine/archiver.d.ts +31 -0
  22. package/dest/state_machine/archiver.d.ts.map +1 -0
  23. package/dest/state_machine/archiver.js +85 -0
  24. package/dest/state_machine/dummy_p2p_client.d.ts +59 -0
  25. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -0
  26. package/dest/state_machine/dummy_p2p_client.js +153 -0
  27. package/dest/state_machine/global_variable_builder.d.ts +11 -0
  28. package/dest/state_machine/global_variable_builder.d.ts.map +1 -0
  29. package/dest/state_machine/global_variable_builder.js +22 -0
  30. package/dest/state_machine/index.d.ts +18 -0
  31. package/dest/state_machine/index.d.ts.map +1 -0
  32. package/dest/state_machine/index.js +72 -0
  33. package/dest/state_machine/mock_epoch_cache.d.ts +29 -0
  34. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -0
  35. package/dest/state_machine/mock_epoch_cache.js +58 -0
  36. package/dest/state_machine/synchronizer.d.ts +33 -0
  37. package/dest/state_machine/synchronizer.d.ts.map +1 -0
  38. package/dest/state_machine/synchronizer.js +59 -0
  39. package/dest/txe_session.d.ts +78 -0
  40. package/dest/txe_session.d.ts.map +1 -0
  41. package/dest/txe_session.js +364 -0
  42. package/dest/util/encoding.d.ts +641 -24
  43. package/dest/util/encoding.d.ts.map +1 -1
  44. package/dest/util/encoding.js +66 -11
  45. package/dest/util/expected_failure_error.d.ts +1 -1
  46. package/dest/util/expected_failure_error.d.ts.map +1 -1
  47. package/dest/util/txe_account_store.d.ts +10 -0
  48. package/dest/util/txe_account_store.d.ts.map +1 -0
  49. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  50. package/dest/util/txe_public_contract_data_source.d.ts +11 -11
  51. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  52. package/dest/util/txe_public_contract_data_source.js +21 -59
  53. package/dest/utils/block_creation.d.ts +28 -0
  54. package/dest/utils/block_creation.d.ts.map +1 -0
  55. package/dest/utils/block_creation.js +58 -0
  56. package/dest/utils/tx_effect_creation.d.ts +5 -0
  57. package/dest/utils/tx_effect_creation.d.ts.map +1 -0
  58. package/dest/utils/tx_effect_creation.js +13 -0
  59. package/package.json +30 -24
  60. package/src/bin/index.ts +3 -2
  61. package/src/constants.ts +3 -0
  62. package/src/index.ts +171 -103
  63. package/src/oracle/interfaces.ts +87 -0
  64. package/src/oracle/txe_oracle_public_context.ts +158 -0
  65. package/src/oracle/txe_oracle_top_level_context.ts +782 -0
  66. package/src/rpc_translator.ts +1218 -0
  67. package/src/state_machine/archiver.ts +97 -0
  68. package/src/state_machine/dummy_p2p_client.ts +227 -0
  69. package/src/state_machine/global_variable_builder.ts +38 -0
  70. package/src/state_machine/index.ts +120 -0
  71. package/src/state_machine/mock_epoch_cache.ts +72 -0
  72. package/src/state_machine/synchronizer.ts +88 -0
  73. package/src/txe_session.ts +556 -0
  74. package/src/util/encoding.ts +85 -11
  75. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  76. package/src/util/txe_public_contract_data_source.ts +28 -69
  77. package/src/utils/block_creation.ts +97 -0
  78. package/src/utils/tx_effect_creation.ts +30 -0
  79. package/dest/node/txe_node.d.ts +0 -358
  80. package/dest/node/txe_node.d.ts.map +0 -1
  81. package/dest/node/txe_node.js +0 -504
  82. package/dest/oracle/txe_oracle.d.ts +0 -152
  83. package/dest/oracle/txe_oracle.d.ts.map +0 -1
  84. package/dest/oracle/txe_oracle.js +0 -833
  85. package/dest/txe_service/txe_service.d.ts +0 -212
  86. package/dest/txe_service/txe_service.d.ts.map +0 -1
  87. package/dest/txe_service/txe_service.js +0 -572
  88. package/dest/util/txe_account_data_provider.d.ts +0 -10
  89. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  90. package/dest/util/txe_world_state_db.d.ts +0 -14
  91. package/dest/util/txe_world_state_db.d.ts.map +0 -1
  92. package/dest/util/txe_world_state_db.js +0 -27
  93. package/src/node/txe_node.ts +0 -725
  94. package/src/oracle/txe_oracle.ts +0 -1241
  95. package/src/txe_service/txe_service.ts +0 -749
  96. package/src/util/txe_world_state_db.ts +0 -38
@@ -0,0 +1,97 @@
1
+ import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
2
+ import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
3
+ import { CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import type { EthAddress } from '@aztec/foundation/eth-address';
6
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
7
+ import type { CheckpointId, L2BlockId, L2TipId, L2Tips, ValidateCheckpointResult } from '@aztec/stdlib/block';
8
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
9
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
10
+
11
+ /**
12
+ * TXE Archiver implementation.
13
+ * Provides most of the endpoints needed by the node for reading from and writing to state,
14
+ * without needing any of the extra overhead that the Archiver itself requires (i.e. an L1 client).
15
+ */
16
+ export class TXEArchiver extends ArchiverDataSourceBase {
17
+ private readonly updater = new ArchiverDataStoreUpdater(this.store);
18
+
19
+ constructor(db: AztecAsyncKVStore) {
20
+ const store = new KVArchiverDataStore(db, 9999);
21
+ super(store);
22
+ }
23
+
24
+ public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
25
+ await this.updater.addCheckpoints(checkpoints, result);
26
+ }
27
+
28
+ public getRollupAddress(): Promise<EthAddress> {
29
+ throw new Error('TXE Archiver does not implement "getRollupAddress"');
30
+ }
31
+
32
+ public getRegistryAddress(): Promise<EthAddress> {
33
+ throw new Error('TXE Archiver does not implement "getRegistryAddress"');
34
+ }
35
+
36
+ public getL1Constants(): Promise<L1RollupConstants> {
37
+ throw new Error('TXE Archiver does not implement "getL1Constants"');
38
+ }
39
+
40
+ public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
41
+ return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
42
+ }
43
+
44
+ public getL1Timestamp(): Promise<bigint | undefined> {
45
+ throw new Error('TXE Archiver does not implement "getL1Timestamp"');
46
+ }
47
+
48
+ public async getL2Tips(): Promise<L2Tips> {
49
+ // In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
50
+ // and 'finalized' to the latest block.
51
+ const blockHeader = await this.getBlockHeader('latest');
52
+ if (!blockHeader) {
53
+ throw new Error('L2Tips requested from TXE Archiver but no block header found');
54
+ }
55
+
56
+ const number = blockHeader.globalVariables.blockNumber;
57
+ const hash = (await blockHeader.hash()).toString();
58
+ const checkpointedBlock = await this.getCheckpointedBlock(number);
59
+ if (!checkpointedBlock) {
60
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
61
+ }
62
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
63
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
64
+ const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
65
+ if (checkpoint.length === 0) {
66
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
67
+ }
68
+ const blockId: L2BlockId = { number, hash };
69
+ const checkpointId: CheckpointId = {
70
+ number: checkpoint[0].checkpointNumber,
71
+ hash: checkpoint[0].header.hash().toString(),
72
+ };
73
+ const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
74
+ return {
75
+ proposed: blockId,
76
+ proven: tipId,
77
+ finalized: tipId,
78
+ checkpointed: tipId,
79
+ };
80
+ }
81
+
82
+ public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
83
+ throw new Error('TXE Archiver does not implement "getSyncedL2SlotNumber"');
84
+ }
85
+
86
+ public getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
87
+ throw new Error('TXE Archiver does not implement "getSyncedL2EpochNumber"');
88
+ }
89
+
90
+ public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
91
+ throw new Error('TXE Archiver does not implement "isEpochComplete"');
92
+ }
93
+
94
+ public syncImmediate(): Promise<void> {
95
+ throw new Error('TXE Archiver does not implement "syncImmediate"');
96
+ }
97
+ }
@@ -0,0 +1,227 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type {
3
+ AuthRequest,
4
+ ENR,
5
+ P2P,
6
+ P2PBlockReceivedCallback,
7
+ P2PCheckpointReceivedCallback,
8
+ P2PConfig,
9
+ P2PDuplicateAttestationCallback,
10
+ P2PDuplicateProposalCallback,
11
+ P2PSyncState,
12
+ PeerId,
13
+ ReqRespSubProtocol,
14
+ ReqRespSubProtocolHandler,
15
+ ReqRespSubProtocolValidators,
16
+ StatusMessage,
17
+ } from '@aztec/p2p';
18
+ import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
19
+ import type { ITxProvider, PeerInfo } from '@aztec/stdlib/interfaces/server';
20
+ import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicType } from '@aztec/stdlib/p2p';
21
+ import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
22
+
23
+ export class DummyP2P implements P2P {
24
+ public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
25
+ return Promise.resolve();
26
+ }
27
+
28
+ public clear(): Promise<void> {
29
+ throw new Error('DummyP2P does not implement "clear".');
30
+ }
31
+
32
+ public getPendingTxs(): Promise<Tx[]> {
33
+ throw new Error('DummyP2P does not implement "getPendingTxs"');
34
+ }
35
+
36
+ public getEncodedEnr(): Promise<string | undefined> {
37
+ throw new Error('DummyP2P does not implement "getEncodedEnr"');
38
+ }
39
+
40
+ public getPeers(_includePending?: boolean): Promise<PeerInfo[]> {
41
+ throw new Error('DummyP2P does not implement "getPeers"');
42
+ }
43
+
44
+ public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
45
+ return Promise.resolve(0);
46
+ }
47
+
48
+ public broadcastProposal(_proposal: BlockProposal): Promise<void> {
49
+ throw new Error('DummyP2P does not implement "broadcastProposal"');
50
+ }
51
+
52
+ public broadcastCheckpointProposal(_proposal: CheckpointProposal): Promise<void> {
53
+ throw new Error('DummyP2P does not implement "broadcastCheckpointProposal"');
54
+ }
55
+
56
+ public broadcastCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
57
+ throw new Error('DummyP2P does not implement "broadcastCheckpointAttestations"');
58
+ }
59
+
60
+ public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
61
+ throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
62
+ }
63
+
64
+ public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
65
+ throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
66
+ }
67
+
68
+ public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
69
+ throw new Error('DummyP2P does not implement "requestTxs"');
70
+ }
71
+
72
+ public requestTxByHash(_txHash: TxHash): Promise<Tx | undefined> {
73
+ throw new Error('DummyP2P does not implement "requestTxByHash"');
74
+ }
75
+
76
+ public sendTx(_tx: Tx): Promise<void> {
77
+ throw new Error('DummyP2P does not implement "sendTx"');
78
+ }
79
+
80
+ public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
81
+ throw new Error('DummyP2P does not implement "handleFailedExecution"');
82
+ }
83
+
84
+ public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
85
+ throw new Error('DummyP2P does not implement "getTxByHashFromPool"');
86
+ }
87
+
88
+ public getTxByHash(_txHash: TxHash): Promise<Tx | undefined> {
89
+ throw new Error('DummyP2P does not implement "getTxByHash"');
90
+ }
91
+
92
+ public getArchivedTxByHash(_txHash: TxHash): Promise<Tx | undefined> {
93
+ throw new Error('DummyP2P does not implement "getArchivedTxByHash"');
94
+ }
95
+
96
+ public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
97
+ // In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
98
+ // tx status for any tx hash.
99
+ return Promise.resolve('mined');
100
+ }
101
+
102
+ public iteratePendingTxs(): AsyncIterableIterator<Tx> {
103
+ throw new Error('DummyP2P does not implement "iteratePendingTxs"');
104
+ }
105
+
106
+ public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
107
+ throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
108
+ }
109
+
110
+ public getPendingTxCount(): Promise<number> {
111
+ throw new Error('DummyP2P does not implement "getPendingTxCount"');
112
+ }
113
+
114
+ public start(): Promise<void> {
115
+ throw new Error('DummyP2P does not implement "start"');
116
+ }
117
+
118
+ public stop(): Promise<void> {
119
+ throw new Error('DummyP2P does not implement "stop"');
120
+ }
121
+
122
+ public isReady(): boolean {
123
+ throw new Error('DummyP2P does not implement "isReady"');
124
+ }
125
+
126
+ public getStatus(): Promise<P2PSyncState> {
127
+ throw new Error('DummyP2P does not implement "getStatus"');
128
+ }
129
+
130
+ public getEnr(): ENR | undefined {
131
+ throw new Error('DummyP2P does not implement "getEnr"');
132
+ }
133
+
134
+ public isP2PClient(): true {
135
+ throw new Error('DummyP2P does not implement "isP2PClient"');
136
+ }
137
+
138
+ public getTxProvider(): ITxProvider {
139
+ throw new Error('DummyP2P does not implement "getTxProvider"');
140
+ }
141
+
142
+ public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
143
+ throw new Error('DummyP2P does not implement "getTxsByHash"');
144
+ }
145
+
146
+ public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
147
+ throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
148
+ }
149
+
150
+ public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
151
+ throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
152
+ }
153
+
154
+ public getL2BlockHash(_number: number): Promise<string | undefined> {
155
+ throw new Error('DummyP2P does not implement "getL2BlockHash"');
156
+ }
157
+
158
+ public updateP2PConfig(_config: Partial<P2PConfig>): Promise<void> {
159
+ throw new Error('DummyP2P does not implement "updateP2PConfig"');
160
+ }
161
+
162
+ public getL2Tips(): Promise<L2Tips> {
163
+ throw new Error('DummyP2P does not implement "getL2Tips"');
164
+ }
165
+
166
+ public handleBlockStreamEvent(_event: L2BlockStreamEvent): Promise<void> {
167
+ throw new Error('DummyP2P does not implement "handleBlockStreamEvent"');
168
+ }
169
+
170
+ public sync() {
171
+ throw new Error('DummyP2P does not implement "sync"');
172
+ }
173
+
174
+ public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
175
+ throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
176
+ }
177
+
178
+ public hasTxsInPool(_txHashes: TxHash[]): Promise<boolean[]> {
179
+ throw new Error('DummyP2P does not implement "hasTxsInPool"');
180
+ }
181
+
182
+ public getSyncedLatestBlockNum(): Promise<number> {
183
+ throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
184
+ }
185
+
186
+ public getSyncedProvenBlockNum(): Promise<number> {
187
+ throw new Error('DummyP2P does not implement "getSyncedProvenBlockNum"');
188
+ }
189
+
190
+ public getSyncedLatestSlot(): Promise<bigint> {
191
+ throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
192
+ }
193
+
194
+ protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
195
+ throw new Error('DummyP2P does not implement "protectTxs".');
196
+ }
197
+
198
+ prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
199
+ return Promise.resolve();
200
+ }
201
+
202
+ addReqRespSubProtocol(
203
+ _subProtocol: ReqRespSubProtocol,
204
+ _handler: ReqRespSubProtocolHandler,
205
+ _validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
206
+ ): Promise<void> {
207
+ throw new Error('DummyP2P does not implement "addReqRespSubProtocol".');
208
+ }
209
+ handleAuthRequestFromPeer(_authRequest: AuthRequest, _peerId: PeerId): Promise<StatusMessage> {
210
+ throw new Error('DummyP2P does not implement "handleAuthRequestFromPeer".');
211
+ }
212
+
213
+ //This is no-op
214
+ public registerThisValidatorAddresses(_address: EthAddress[]): void {}
215
+
216
+ public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
217
+ throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
218
+ }
219
+
220
+ public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
221
+ throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
222
+ }
223
+
224
+ public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
225
+ throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
226
+ }
227
+ }
@@ -0,0 +1,38 @@
1
+ import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { GasFees } from '@aztec/stdlib/gas';
5
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
6
+ import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
7
+
8
+ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
9
+ public getCurrentMinFees(): Promise<GasFees> {
10
+ return Promise.resolve(new GasFees(0, 0));
11
+ }
12
+
13
+ public buildGlobalVariables(
14
+ _blockNumber: BlockNumber,
15
+ _coinbase: EthAddress,
16
+ _feeRecipient: AztecAddress,
17
+ _slotNumber?: SlotNumber,
18
+ ): Promise<GlobalVariables> {
19
+ return Promise.resolve(makeGlobalVariables());
20
+ }
21
+
22
+ public buildCheckpointGlobalVariables(
23
+ _coinbase: EthAddress,
24
+ _feeRecipient: AztecAddress,
25
+ _slotNumber: SlotNumber,
26
+ ): Promise<CheckpointGlobalVariables> {
27
+ const vars = makeGlobalVariables();
28
+ return Promise.resolve({
29
+ chainId: vars.chainId,
30
+ version: vars.version,
31
+ slotNumber: vars.slotNumber,
32
+ timestamp: vars.timestamp,
33
+ coinbase: vars.coinbase,
34
+ feeRecipient: vars.feeRecipient,
35
+ gasFees: vars.gasFees,
36
+ });
37
+ }
38
+ }
@@ -0,0 +1,120 @@
1
+ import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
+ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+ import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
7
+ import { MessageContextService } from '@aztec/pxe/simulator';
8
+ import { L2Block } from '@aztec/stdlib/block';
9
+ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
10
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
11
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
12
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
13
+
14
+ import { TXEArchiver } from './archiver.js';
15
+ import { DummyP2P } from './dummy_p2p_client.js';
16
+ import { TXEGlobalVariablesBuilder } from './global_variable_builder.js';
17
+ import { MockEpochCache } from './mock_epoch_cache.js';
18
+ import { TXESynchronizer } from './synchronizer.js';
19
+
20
+ const VERSION = 1;
21
+ const CHAIN_ID = 1;
22
+
23
+ export class TXEStateMachine {
24
+ constructor(
25
+ public node: AztecNode,
26
+ public synchronizer: TXESynchronizer,
27
+ public archiver: TXEArchiver,
28
+ public anchorBlockStore: AnchorBlockStore,
29
+ public contractSyncService: ContractSyncService,
30
+ public messageContextService: MessageContextService,
31
+ ) {}
32
+
33
+ public static async create(
34
+ archiver: TXEArchiver,
35
+ anchorBlockStore: AnchorBlockStore,
36
+ contractStore: ContractStore,
37
+ noteStore: NoteStore,
38
+ ) {
39
+ const synchronizer = await TXESynchronizer.create();
40
+ const aztecNodeConfig = {} as AztecNodeConfig;
41
+
42
+ const log = createLogger('txe_node');
43
+ const node = new AztecNodeService(
44
+ aztecNodeConfig,
45
+ new DummyP2P(),
46
+ archiver,
47
+ archiver,
48
+ archiver,
49
+ archiver,
50
+ synchronizer,
51
+ undefined,
52
+ undefined,
53
+ undefined,
54
+ undefined,
55
+ undefined,
56
+ VERSION,
57
+ CHAIN_ID,
58
+ new TXEGlobalVariablesBuilder(),
59
+ new MockEpochCache(),
60
+ getPackageVersion() ?? '',
61
+ new TestCircuitVerifier(),
62
+ undefined,
63
+ log,
64
+ );
65
+
66
+ const contractSyncService = new ContractSyncService(
67
+ node,
68
+ contractStore,
69
+ noteStore,
70
+ createLogger('txe:contract_sync'),
71
+ );
72
+
73
+ const messageContextService = new MessageContextService(node);
74
+
75
+ return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService, messageContextService);
76
+ }
77
+
78
+ public async handleL2Block(block: L2Block) {
79
+ // Create a checkpoint from the block manually.
80
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
81
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
82
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
83
+ const checkpoint = new Checkpoint(
84
+ block.archive,
85
+ CheckpointHeader.from({
86
+ lastArchiveRoot: block.header.lastArchive.root,
87
+ inHash: Fr.ZERO,
88
+ blobsHash: Fr.ZERO,
89
+ blockHeadersHash: Fr.ZERO,
90
+ epochOutHash: Fr.ZERO,
91
+ slotNumber: block.header.globalVariables.slotNumber,
92
+ timestamp: block.header.globalVariables.timestamp,
93
+ coinbase: block.header.globalVariables.coinbase,
94
+ feeRecipient: block.header.globalVariables.feeRecipient,
95
+ gasFees: block.header.globalVariables.gasFees,
96
+ totalManaUsed: block.header.totalManaUsed,
97
+ }),
98
+ [block],
99
+ checkpointNumber,
100
+ );
101
+
102
+ const publishedCheckpoint = new PublishedCheckpoint(
103
+ checkpoint,
104
+ new L1PublishedData(
105
+ BigInt(block.header.globalVariables.blockNumber),
106
+ block.header.globalVariables.timestamp,
107
+ block.header.globalVariables.blockNumber.toString(),
108
+ ),
109
+ [],
110
+ );
111
+ // Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
112
+ this.contractSyncService.wipe();
113
+
114
+ await Promise.all([
115
+ this.synchronizer.handleL2Block(block),
116
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
117
+ this.anchorBlockStore.setHeader(block.header),
118
+ ]);
119
+ }
120
+ }
@@ -0,0 +1,72 @@
1
+ import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
2
+ import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
5
+
6
+ /**
7
+ * Mock implementation of the EpochCacheInterface used to satisfy dependencies of AztecNodeService.
8
+ * Since in TXE we don't validate transactions, mock suffices here.
9
+ */
10
+ export class MockEpochCache implements EpochCacheInterface {
11
+ getCommittee(): Promise<EpochCommitteeInfo> {
12
+ return Promise.resolve({
13
+ committee: undefined,
14
+ seed: 0n,
15
+ epoch: EpochNumber.ZERO,
16
+ isEscapeHatchOpen: false,
17
+ });
18
+ }
19
+
20
+ getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
21
+ return {
22
+ epoch: EpochNumber.ZERO,
23
+ slot: SlotNumber(0),
24
+ ts: 0n,
25
+ nowMs: 0n,
26
+ };
27
+ }
28
+
29
+ getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
30
+ return {
31
+ epoch: EpochNumber.ZERO,
32
+ slot: SlotNumber(0),
33
+ ts: 0n,
34
+ now: 0n,
35
+ };
36
+ }
37
+
38
+ getProposerIndexEncoding(_epoch: EpochNumber, _slot: SlotNumber, _seed: bigint): `0x${string}` {
39
+ return '0x00';
40
+ }
41
+
42
+ computeProposerIndex(_slot: SlotNumber, _epoch: EpochNumber, _seed: bigint, _size: bigint): bigint {
43
+ return 0n;
44
+ }
45
+
46
+ getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
47
+ return {
48
+ currentSlot: SlotNumber(0),
49
+ nextSlot: SlotNumber(0),
50
+ };
51
+ }
52
+
53
+ getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
54
+ return Promise.resolve(undefined);
55
+ }
56
+
57
+ isInCommittee(_slot: SlotTag, _validator: EthAddress): Promise<boolean> {
58
+ return Promise.resolve(false);
59
+ }
60
+
61
+ getRegisteredValidators(): Promise<EthAddress[]> {
62
+ return Promise.resolve([]);
63
+ }
64
+
65
+ filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
66
+ return Promise.resolve([]);
67
+ }
68
+
69
+ getL1Constants(): L1RollupConstants {
70
+ return EmptyL1RollupConstants;
71
+ }
72
+ }
@@ -0,0 +1,88 @@
1
+ import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import type { BlockHash, L2Block } from '@aztec/stdlib/block';
5
+ import type {
6
+ MerkleTreeReadOperations,
7
+ MerkleTreeWriteOperations,
8
+ SnapshotDataKeys,
9
+ WorldStateSynchronizer,
10
+ WorldStateSynchronizerStatus,
11
+ } from '@aztec/stdlib/interfaces/server';
12
+ import { NativeWorldStateService } from '@aztec/world-state/native';
13
+
14
+ export class TXESynchronizer implements WorldStateSynchronizer {
15
+ // This works when set to 1 as well.
16
+ private blockNumber = BlockNumber.ZERO;
17
+
18
+ constructor(public nativeWorldStateService: NativeWorldStateService) {}
19
+
20
+ static async create() {
21
+ const nativeWorldStateService = await NativeWorldStateService.tmp();
22
+
23
+ return new this(nativeWorldStateService);
24
+ }
25
+
26
+ public async handleL2Block(block: L2Block) {
27
+ await this.nativeWorldStateService.handleL2BlockAndMessages(
28
+ block,
29
+ Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
30
+ );
31
+
32
+ this.blockNumber = block.header.globalVariables.blockNumber;
33
+ }
34
+
35
+ /**
36
+ * Forces an immediate sync to an optionally provided minimum block number.
37
+ * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
38
+ * @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash.
39
+ * @returns A promise that resolves with the block number the world state was synced to
40
+ */
41
+ public syncImmediate(_minBlockNumber?: BlockNumber, _blockHash?: BlockHash): Promise<BlockNumber> {
42
+ return Promise.resolve(this.blockNumber);
43
+ }
44
+
45
+ /** Returns an instance of MerkleTreeAdminOperations that will not include uncommitted data. */
46
+ public getCommitted(): MerkleTreeReadOperations {
47
+ return this.nativeWorldStateService.getCommitted();
48
+ }
49
+
50
+ /** Forks the world state at the given block number, defaulting to the latest one. */
51
+ public fork(block?: number): Promise<MerkleTreeWriteOperations> {
52
+ return this.nativeWorldStateService.fork(block ? BlockNumber(block) : undefined);
53
+ }
54
+
55
+ /** Gets a handle that allows reading the state as it was at the given block number. */
56
+ public getSnapshot(blockNumber: number): MerkleTreeReadOperations {
57
+ return this.nativeWorldStateService.getSnapshot(BlockNumber(blockNumber));
58
+ }
59
+
60
+ /** Backups the db to the target path. */
61
+ public backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>> {
62
+ return this.nativeWorldStateService.backupTo(dstPath, compact);
63
+ }
64
+
65
+ public start(): Promise<void> {
66
+ throw new Error('TXE Synchronizer does not implement "start"');
67
+ }
68
+
69
+ public status(): Promise<WorldStateSynchronizerStatus> {
70
+ throw new Error('TXE Synchronizer does not implement "status"');
71
+ }
72
+
73
+ public stop(): Promise<void> {
74
+ throw new Error('TXE Synchronizer does not implement "stop"');
75
+ }
76
+
77
+ public stopSync(): Promise<void> {
78
+ throw new Error('TXE Synchronizer does not implement "stopSync"');
79
+ }
80
+
81
+ public resumeSync(): void {
82
+ throw new Error('TXE Synchronizer does not implement "resumeSync"');
83
+ }
84
+
85
+ public clear(): Promise<void> {
86
+ throw new Error('TXE Synchronizer does not implement "clear"');
87
+ }
88
+ }