@aztec/txe 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 (100) hide show
  1. package/dest/bin/index.d.ts +1 -1
  2. package/dest/bin/index.js +1 -1
  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 +8 -4
  9. package/dest/oracle/interfaces.d.ts +57 -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 +12 -12
  13. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_public_context.js +30 -34
  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 +463 -0
  18. package/dest/rpc_translator.d.ts +246 -0
  19. package/dest/rpc_translator.d.ts.map +1 -0
  20. package/dest/{txe_service/txe_service.js → rpc_translator.js} +201 -124
  21. package/dest/state_machine/archiver.d.ts +34 -13
  22. package/dest/state_machine/archiver.d.ts.map +1 -1
  23. package/dest/state_machine/archiver.js +111 -16
  24. package/dest/state_machine/dummy_p2p_client.d.ts +5 -2
  25. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  26. package/dest/state_machine/dummy_p2p_client.js +9 -1
  27. package/dest/state_machine/global_variable_builder.d.ts +6 -17
  28. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  29. package/dest/state_machine/global_variable_builder.js +16 -23
  30. package/dest/state_machine/index.d.ts +5 -5
  31. package/dest/state_machine/index.d.ts.map +1 -1
  32. package/dest/state_machine/index.js +17 -21
  33. package/dest/state_machine/mock_epoch_cache.d.ts +6 -5
  34. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  35. package/dest/state_machine/mock_epoch_cache.js +8 -7
  36. package/dest/state_machine/synchronizer.d.ts +5 -4
  37. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  38. package/dest/state_machine/synchronizer.js +5 -4
  39. package/dest/txe_session.d.ts +42 -46
  40. package/dest/txe_session.d.ts.map +1 -1
  41. package/dest/txe_session.js +241 -93
  42. package/dest/util/encoding.d.ts +623 -24
  43. package/dest/util/encoding.d.ts.map +1 -1
  44. package/dest/util/encoding.js +1 -1
  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_contract_store.d.ts +12 -0
  51. package/dest/util/txe_contract_store.d.ts.map +1 -0
  52. package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +4 -4
  53. package/dest/util/txe_public_contract_data_source.d.ts +8 -6
  54. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  55. package/dest/util/txe_public_contract_data_source.js +14 -12
  56. package/dest/utils/block_creation.d.ts +28 -0
  57. package/dest/utils/block_creation.d.ts.map +1 -0
  58. package/dest/utils/block_creation.js +45 -0
  59. package/dest/utils/tx_effect_creation.d.ts +6 -0
  60. package/dest/utils/tx_effect_creation.d.ts.map +1 -0
  61. package/dest/utils/tx_effect_creation.js +16 -0
  62. package/package.json +18 -17
  63. package/src/bin/index.ts +1 -1
  64. package/src/constants.ts +3 -0
  65. package/src/index.ts +20 -20
  66. package/src/oracle/interfaces.ts +86 -0
  67. package/src/oracle/txe_oracle_public_context.ts +37 -75
  68. package/src/oracle/txe_oracle_top_level_context.ts +716 -0
  69. package/src/{txe_service/txe_service.ts → rpc_translator.ts} +261 -125
  70. package/src/state_machine/archiver.ts +147 -29
  71. package/src/state_machine/dummy_p2p_client.ts +13 -2
  72. package/src/state_machine/global_variable_builder.ts +25 -42
  73. package/src/state_machine/index.ts +24 -21
  74. package/src/state_machine/mock_epoch_cache.ts +12 -11
  75. package/src/state_machine/synchronizer.ts +8 -7
  76. package/src/txe_session.ts +416 -115
  77. package/src/util/encoding.ts +1 -1
  78. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  79. package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +5 -4
  80. package/src/util/txe_public_contract_data_source.ts +16 -13
  81. package/src/utils/block_creation.ts +94 -0
  82. package/src/utils/tx_effect_creation.ts +38 -0
  83. package/dest/oracle/txe_oracle.d.ts +0 -124
  84. package/dest/oracle/txe_oracle.d.ts.map +0 -1
  85. package/dest/oracle/txe_oracle.js +0 -770
  86. package/dest/oracle/txe_typed_oracle.d.ts +0 -42
  87. package/dest/oracle/txe_typed_oracle.d.ts.map +0 -1
  88. package/dest/oracle/txe_typed_oracle.js +0 -83
  89. package/dest/txe_constants.d.ts +0 -2
  90. package/dest/txe_constants.d.ts.map +0 -1
  91. package/dest/txe_constants.js +0 -7
  92. package/dest/txe_service/txe_service.d.ts +0 -231
  93. package/dest/txe_service/txe_service.d.ts.map +0 -1
  94. package/dest/util/txe_account_data_provider.d.ts +0 -10
  95. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  96. package/dest/util/txe_contract_data_provider.d.ts +0 -11
  97. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  98. package/src/oracle/txe_oracle.ts +0 -1287
  99. package/src/oracle/txe_typed_oracle.ts +0 -142
  100. package/src/txe_constants.ts +0 -9
@@ -1,8 +1,22 @@
1
- import { ArchiverStoreHelper, KVArchiverDataStore, type PublishedL2Block } from '@aztec/archiver';
1
+ import { ArchiverStoreHelper, KVArchiverDataStore } from '@aztec/archiver';
2
+ import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
3
+ import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
5
  import type { EthAddress } from '@aztec/foundation/eth-address';
6
+ import { isDefined } from '@aztec/foundation/types';
3
7
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
4
8
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import type { L2Block, L2BlockSource, L2Tips, ValidateBlockResult } from '@aztec/stdlib/block';
9
+ import {
10
+ CommitteeAttestation,
11
+ L2Block,
12
+ type L2BlockId,
13
+ type L2BlockNew,
14
+ type L2BlockSource,
15
+ type L2Tips,
16
+ PublishedL2Block,
17
+ type ValidateBlockResult,
18
+ } from '@aztec/stdlib/block';
19
+ import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
6
20
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
7
21
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
8
22
  import type { BlockHeader } from '@aztec/stdlib/tx';
@@ -16,11 +30,28 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
16
30
  super(new KVArchiverDataStore(db, 9999));
17
31
  }
18
32
 
19
- public override async addBlocks(blocks: PublishedL2Block[]): Promise<boolean> {
20
- const opResults = await Promise.all([
21
- this.store.addLogs(blocks.map(block => block.block)),
22
- this.store.addBlocks(blocks),
23
- ]);
33
+ public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
34
+ if (number === 0) {
35
+ return undefined;
36
+ }
37
+ const publishedBlocks = await this.getPublishedBlocks(number, 1);
38
+ if (publishedBlocks.length === 0) {
39
+ return undefined;
40
+ }
41
+ return publishedBlocks[0].block;
42
+ }
43
+
44
+ public async getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2Block[]> {
45
+ const publishedBlocks = await this.getPublishedBlocks(from, limit, proven);
46
+ return publishedBlocks.map(x => x.block);
47
+ }
48
+
49
+ public override async addCheckpoints(
50
+ checkpoints: PublishedCheckpoint[],
51
+ _result?: ValidateBlockResult,
52
+ ): Promise<boolean> {
53
+ const allBlocks = checkpoints.flatMap(ch => ch.checkpoint.blocks);
54
+ const opResults = await Promise.all([this.store.addLogs(allBlocks), this.store.addCheckpoints(checkpoints)]);
24
55
 
25
56
  return opResults.every(Boolean);
26
57
  }
@@ -29,16 +60,16 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
29
60
  * Gets the number of the latest L2 block processed by the block source implementation.
30
61
  * @returns The number of the latest L2 block processed by the block source implementation.
31
62
  */
32
- public getBlockNumber(): Promise<number> {
33
- return this.store.getSynchedL2BlockNumber();
63
+ public getBlockNumber(): Promise<BlockNumber> {
64
+ return this.store.getLatestBlockNumber();
34
65
  }
35
66
 
36
67
  /**
37
68
  * Gets the number of the latest L2 block proven seen by the block source implementation.
38
69
  * @returns The number of the latest L2 block proven seen by the block source implementation.
39
70
  */
40
- public getProvenBlockNumber(): Promise<number> {
41
- return this.store.getSynchedL2BlockNumber();
71
+ public override getProvenBlockNumber(): Promise<BlockNumber> {
72
+ return this.store.getProvenBlockNumber();
42
73
  }
43
74
 
44
75
  /**
@@ -46,16 +77,55 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
46
77
  * @param number - The block number to return (inclusive).
47
78
  * @returns The requested L2 block.
48
79
  */
49
- public override async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
80
+ public async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
50
81
  // If the number provided is -ve, then return the latest block.
51
82
  if (number < 0) {
52
- number = await this.store.getSynchedL2BlockNumber();
83
+ number = await this.store.getLatestBlockNumber();
53
84
  }
54
85
  if (number == 0) {
55
86
  return undefined;
56
87
  }
57
- const blocks = await this.store.getPublishedBlocks(number, 1);
58
- return blocks.length === 0 ? undefined : blocks[0];
88
+ const publishedBlocks = await this.retrievePublishedBlocks(BlockNumber(number), 1);
89
+ return publishedBlocks.length === 0 ? undefined : publishedBlocks[0];
90
+ }
91
+
92
+ getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<PublishedL2Block[]> {
93
+ return this.retrievePublishedBlocks(from, limit, proven);
94
+ }
95
+
96
+ private async retrievePublishedBlocks(
97
+ from: BlockNumber,
98
+ limit: number,
99
+ proven?: boolean,
100
+ ): Promise<PublishedL2Block[]> {
101
+ const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
102
+ const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
103
+ const blocks = (
104
+ await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
105
+ ).filter(isDefined);
106
+
107
+ const olbBlocks: PublishedL2Block[] = [];
108
+ for (let i = 0; i < checkpoints.length; i++) {
109
+ const blockForCheckpoint = blocks[i][0];
110
+ const checkpoint = checkpoints[i];
111
+ if (proven === true && checkpoint.checkpointNumber > provenCheckpointNumber) {
112
+ continue;
113
+ }
114
+ const oldCheckpoint = new Checkpoint(
115
+ blockForCheckpoint.archive,
116
+ checkpoint.header,
117
+ [blockForCheckpoint],
118
+ checkpoint.checkpointNumber,
119
+ );
120
+ const oldBlock = L2Block.fromCheckpoint(oldCheckpoint);
121
+ const publishedBlock = new PublishedL2Block(
122
+ oldBlock,
123
+ checkpoint.l1,
124
+ checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
125
+ );
126
+ olbBlocks.push(publishedBlock);
127
+ }
128
+ return olbBlocks;
59
129
  }
60
130
 
61
131
  /**
@@ -63,8 +133,20 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
63
133
  * @param number - The block number to return (inclusive).
64
134
  * @returns The requested L2 block.
65
135
  */
66
- public getBlock(number: number): Promise<L2Block | undefined> {
67
- return this.getPublishedBlock(number).then(block => block?.block);
136
+ public getL2Block(number: BlockNumber | 'latest'): Promise<L2Block | undefined> {
137
+ return this.getPublishedBlock(number != 'latest' ? number : -1).then(b => b?.block);
138
+ }
139
+
140
+ /**
141
+ * Gets an L2 block (new format).
142
+ * @param number - The block number to return.
143
+ * @returns The requested L2 block.
144
+ */
145
+ public getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
146
+ if (number === 0) {
147
+ return Promise.resolve(undefined);
148
+ }
149
+ return this.store.getBlock(number);
68
150
  }
69
151
 
70
152
  /**
@@ -74,47 +156,76 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
74
156
  */
75
157
  public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
76
158
  if (number === 'latest') {
77
- number = await this.store.getSynchedL2BlockNumber();
159
+ number = await this.store.getLatestBlockNumber();
78
160
  }
79
161
  if (number === 0) {
80
162
  return undefined;
81
163
  }
82
- const headers = await this.store.getBlockHeaders(number, 1);
164
+ const headers = await this.store.getBlockHeaders(BlockNumber(number), 1);
83
165
  return headers.length === 0 ? undefined : headers[0];
84
166
  }
85
167
 
86
- public getBlocks(from: number, limit: number, _proven?: boolean): Promise<L2Block[]> {
87
- return this.getPublishedBlocks(from, limit).then(blocks => blocks.map(b => b.block));
168
+ public getBlockRange(from: number, limit: number, _proven?: boolean): Promise<L2Block[]> {
169
+ return this.getPublishedBlocks(BlockNumber(from), limit).then(blocks => blocks.map(b => b.block));
88
170
  }
89
171
 
90
- public getL2SlotNumber(): Promise<bigint> {
172
+ public getPublishedCheckpoints(_from: CheckpointNumber, _limit: number): Promise<PublishedCheckpoint[]> {
173
+ throw new Error('TXE Archiver does not implement "getPublishedCheckpoints"');
174
+ }
175
+
176
+ public getCheckpointByArchive(_archive: Fr): Promise<Checkpoint | undefined> {
177
+ throw new Error('TXE Archiver does not implement "getCheckpointByArchive"');
178
+ }
179
+
180
+ public getL2SlotNumber(): Promise<SlotNumber | undefined> {
91
181
  throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
92
182
  }
93
183
 
94
- public getL2EpochNumber(): Promise<bigint> {
184
+ public getL2EpochNumber(): Promise<EpochNumber> {
95
185
  throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
96
186
  }
97
187
 
98
- public getBlocksForEpoch(_epochNumber: bigint): Promise<L2Block[]> {
188
+ public getCheckpointsForEpoch(_epochNumber: EpochNumber): Promise<Checkpoint[]> {
189
+ throw new Error('TXE Archiver does not implement "getCheckpointsForEpoch"');
190
+ }
191
+
192
+ public getBlocksForEpoch(_epochNumber: EpochNumber): Promise<L2Block[]> {
99
193
  throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
100
194
  }
101
195
 
102
- public getBlockHeadersForEpoch(_epochNumber: bigint): Promise<BlockHeader[]> {
196
+ public getBlockHeadersForEpoch(_epochNumber: EpochNumber): Promise<BlockHeader[]> {
103
197
  throw new Error('TXE Archiver does not implement "getBlockHeadersForEpoch"');
104
198
  }
105
199
 
106
- public isEpochComplete(_epochNumber: bigint): Promise<boolean> {
200
+ public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
107
201
  throw new Error('TXE Archiver does not implement "isEpochComplete"');
108
202
  }
109
203
 
110
- public getL2Tips(): Promise<L2Tips> {
111
- throw new Error('TXE Archiver does not implement "getL2Tips"');
204
+ public async getL2Tips(): Promise<L2Tips> {
205
+ // In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
206
+ // and 'finalized' to the latest block.
207
+ const blockHeader = await this.getBlockHeader('latest');
208
+ if (!blockHeader) {
209
+ throw new Error('L2Tips requested from TXE Archiver but no block header found');
210
+ }
211
+
212
+ const number = blockHeader.globalVariables.blockNumber;
213
+ const hash = (await blockHeader.hash()).toString();
214
+ return {
215
+ latest: { number, hash } as L2BlockId,
216
+ proven: { number, hash } as L2BlockId,
217
+ finalized: { number, hash } as L2BlockId,
218
+ };
112
219
  }
113
220
 
114
221
  public getL1Constants(): Promise<L1RollupConstants> {
115
222
  throw new Error('TXE Archiver does not implement "getL2Constants"');
116
223
  }
117
224
 
225
+ public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
226
+ return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
227
+ }
228
+
118
229
  public syncImmediate(): Promise<void> {
119
230
  throw new Error('TXE Archiver does not implement "syncImmediate"');
120
231
  }
@@ -139,7 +250,14 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
139
250
  return Promise.resolve(false);
140
251
  }
141
252
 
142
- public getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
253
+ public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
143
254
  return Promise.resolve({ valid: true });
144
255
  }
256
+
257
+ getPublishedBlockByHash(_blockHash: Fr): Promise<PublishedL2Block | undefined> {
258
+ throw new Error('Method not implemented.');
259
+ }
260
+ getPublishedBlockByArchive(_archive: Fr): Promise<PublishedL2Block | undefined> {
261
+ throw new Error('Method not implemented.');
262
+ }
145
263
  }
@@ -1,3 +1,4 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type {
2
3
  AuthRequest,
3
4
  ENR,
@@ -17,6 +18,10 @@ import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
17
18
  import type { Tx, TxHash } from '@aztec/stdlib/tx';
18
19
 
19
20
  export class DummyP2P implements P2P {
21
+ public broadcastAttestations(_attestations: BlockAttestation[]): Promise<void> {
22
+ return Promise.resolve();
23
+ }
24
+
20
25
  public validate(_txs: Tx[]): Promise<void> {
21
26
  return Promise.resolve();
22
27
  }
@@ -74,7 +79,9 @@ export class DummyP2P implements P2P {
74
79
  }
75
80
 
76
81
  public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
77
- throw new Error('DummyP2P does not implement "getTxStatus"');
82
+ // In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
83
+ // tx status for any tx hash.
84
+ return Promise.resolve('mined');
78
85
  }
79
86
 
80
87
  public iteratePendingTxs(): AsyncIterableIterator<Tx> {
@@ -113,10 +120,14 @@ export class DummyP2P implements P2P {
113
120
  throw new Error('DummyP2P does not implement "getTxsByHash"');
114
121
  }
115
122
 
116
- public getAttestationsForSlot(_slot: bigint, _proposalId?: string): Promise<BlockAttestation[]> {
123
+ public getAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<BlockAttestation[]> {
117
124
  throw new Error('DummyP2P does not implement "getAttestationForSlot"');
118
125
  }
119
126
 
127
+ public deleteAttestation(_attestation: BlockAttestation): Promise<void> {
128
+ return Promise.resolve();
129
+ }
130
+
120
131
  public addAttestations(_attestations: BlockAttestation[]): Promise<void> {
121
132
  throw new Error('DummyP2P does not implement "addAttestations"');
122
133
  }
@@ -1,55 +1,38 @@
1
+ import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Fr } from '@aztec/foundation/fields';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { GasFees } from '@aztec/stdlib/gas';
5
- import { type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
5
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
6
+ import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
6
7
 
7
8
  export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
8
- private timestamp = 1n;
9
- private slotNumber = 1n;
10
-
11
- // The version and chainId should match the one on txe_oracle
12
- private version = new Fr(1);
13
- private chainId = new Fr(1);
14
-
15
- constructor() {}
16
-
17
- public getCurrentBaseFees(): Promise<GasFees> {
9
+ public getCurrentMinFees(): Promise<GasFees> {
18
10
  return Promise.resolve(new GasFees(0, 0));
19
11
  }
20
12
 
21
- /**
22
- * Simple builder of global variables that use the minimum time possible.
23
- * @param blockNumber - The block number to build global variables for.
24
- * @param coinbase - The address to receive block reward.
25
- * @param feeRecipient - The address to receive fees.
26
- * @param slotNumber - The slot number to use for the global variables, if undefined it will be calculated.
27
- * @returns The global variables for the given block number.
28
- */
29
13
  public buildGlobalVariables(
30
- blockNumber: number,
31
- coinbase: EthAddress,
32
- feeRecipient: AztecAddress,
33
- slotNumber?: bigint,
14
+ _blockNumber: BlockNumber,
15
+ _coinbase: EthAddress,
16
+ _feeRecipient: AztecAddress,
17
+ _slotNumber?: SlotNumber,
34
18
  ): Promise<GlobalVariables> {
35
- const gasFees = new GasFees(0, 0);
36
-
37
- slotNumber ??= this.slotNumber;
38
-
39
- const globalVariables = new GlobalVariables(
40
- this.chainId,
41
- this.version,
42
- blockNumber,
43
- Fr.fromString(slotNumber.toString()),
44
- this.timestamp,
45
- coinbase,
46
- feeRecipient,
47
- gasFees,
48
- );
49
-
50
- this.slotNumber++;
51
- this.timestamp = this.timestamp + 1n;
19
+ return Promise.resolve(makeGlobalVariables());
20
+ }
52
21
 
53
- return Promise.resolve(globalVariables);
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
+ });
54
37
  }
55
38
  }
@@ -2,8 +2,9 @@ import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
2
  import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
- import { SyncDataProvider } from '@aztec/pxe/server';
6
- import type { L2Block } from '@aztec/stdlib/block';
5
+ import { AnchorBlockStore } from '@aztec/pxe/server';
6
+ import { L2Block } from '@aztec/stdlib/block';
7
+ import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
7
8
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
8
9
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
9
10
 
@@ -13,18 +14,21 @@ import { TXEGlobalVariablesBuilder } from './global_variable_builder.js';
13
14
  import { MockEpochCache } from './mock_epoch_cache.js';
14
15
  import { TXESynchronizer } from './synchronizer.js';
15
16
 
17
+ const VERSION = 1;
18
+ const CHAIN_ID = 1;
19
+
16
20
  export class TXEStateMachine {
17
21
  constructor(
18
22
  public node: AztecNode,
19
23
  public synchronizer: TXESynchronizer,
20
24
  public archiver: TXEArchiver,
21
- public syncDataProvider: SyncDataProvider,
25
+ public anchorBlockStore: AnchorBlockStore,
22
26
  ) {}
23
27
 
24
28
  public static async create(db: AztecAsyncKVStore) {
25
29
  const archiver = new TXEArchiver(db);
26
30
  const synchronizer = await TXESynchronizer.create();
27
- const syncDataProvider = new SyncDataProvider(db);
31
+ const anchorBlockStore = new AnchorBlockStore(db);
28
32
 
29
33
  const aztecNodeConfig = {} as AztecNodeConfig;
30
34
 
@@ -41,9 +45,8 @@ export class TXEStateMachine {
41
45
  undefined,
42
46
  undefined,
43
47
  undefined,
44
- // version and chainId should match the ones in txe oracle
45
- 1,
46
- 1,
48
+ VERSION,
49
+ CHAIN_ID,
47
50
  new TXEGlobalVariablesBuilder(),
48
51
  new MockEpochCache(),
49
52
  getPackageVersion() ?? '',
@@ -52,24 +55,24 @@ export class TXEStateMachine {
52
55
  log,
53
56
  );
54
57
 
55
- return new this(node, synchronizer, archiver, syncDataProvider);
58
+ return new this(node, synchronizer, archiver, anchorBlockStore);
56
59
  }
57
60
 
58
61
  public async handleL2Block(block: L2Block) {
62
+ const checkpoint = block.toCheckpoint();
63
+ const publishedCheckpoint = new PublishedCheckpoint(
64
+ checkpoint,
65
+ new L1PublishedData(
66
+ BigInt(block.header.globalVariables.blockNumber),
67
+ block.header.globalVariables.timestamp,
68
+ block.header.globalVariables.blockNumber.toString(),
69
+ ),
70
+ [],
71
+ );
59
72
  await Promise.all([
60
- this.synchronizer.handleL2Block(block),
61
- this.archiver.addBlocks([
62
- {
63
- block,
64
- l1: {
65
- blockHash: block.header.globalVariables.blockNumber.toString(),
66
- blockNumber: BigInt(block.header.globalVariables.blockNumber),
67
- timestamp: block.header.globalVariables.timestamp,
68
- },
69
- attestations: [],
70
- },
71
- ]),
72
- this.syncDataProvider.setHeader(block.header),
73
+ this.synchronizer.handleL2Block(block.toL2Block()),
74
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
75
+ this.anchorBlockStore.setHeader(block.getBlockHeader()),
73
76
  ]);
74
77
  }
75
78
  }
@@ -1,4 +1,5 @@
1
1
  import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
2
+ import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
3
  import { EthAddress } from '@aztec/foundation/eth-address';
3
4
 
4
5
  /**
@@ -10,46 +11,46 @@ export class MockEpochCache implements EpochCacheInterface {
10
11
  return Promise.resolve({
11
12
  committee: undefined,
12
13
  seed: 0n,
13
- epoch: 0n,
14
+ epoch: EpochNumber.ZERO,
14
15
  });
15
16
  }
16
17
 
17
18
  getEpochAndSlotNow(): EpochAndSlot {
18
19
  return {
19
- epoch: 0n,
20
- slot: 0n,
20
+ epoch: EpochNumber.ZERO,
21
+ slot: SlotNumber(0),
21
22
  ts: 0n,
22
23
  };
23
24
  }
24
25
 
25
26
  getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
26
27
  return {
27
- epoch: 0n,
28
- slot: 0n,
28
+ epoch: EpochNumber.ZERO,
29
+ slot: SlotNumber(0),
29
30
  ts: 0n,
30
31
  now: 0n,
31
32
  };
32
33
  }
33
34
 
34
- getProposerIndexEncoding(_epoch: bigint, _slot: bigint, _seed: bigint): `0x${string}` {
35
+ getProposerIndexEncoding(_epoch: EpochNumber, _slot: SlotNumber, _seed: bigint): `0x${string}` {
35
36
  return '0x00';
36
37
  }
37
38
 
38
- computeProposerIndex(_slot: bigint, _epoch: bigint, _seed: bigint, _size: bigint): bigint {
39
+ computeProposerIndex(_slot: SlotNumber, _epoch: EpochNumber, _seed: bigint, _size: bigint): bigint {
39
40
  return 0n;
40
41
  }
41
42
 
42
43
  getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
43
44
  currentProposer: EthAddress | undefined;
44
45
  nextProposer: EthAddress | undefined;
45
- currentSlot: bigint;
46
- nextSlot: bigint;
46
+ currentSlot: SlotNumber;
47
+ nextSlot: SlotNumber;
47
48
  }> {
48
49
  return Promise.resolve({
49
50
  currentProposer: undefined,
50
51
  nextProposer: undefined,
51
- currentSlot: 0n,
52
- nextSlot: 0n,
52
+ currentSlot: SlotNumber(0),
53
+ nextSlot: SlotNumber(0),
53
54
  });
54
55
  }
55
56
 
@@ -1,6 +1,7 @@
1
1
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import type { L2Block } from '@aztec/stdlib/block';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import type { L2BlockNew } from '@aztec/stdlib/block';
4
5
  import type {
5
6
  MerkleTreeReadOperations,
6
7
  MerkleTreeWriteOperations,
@@ -12,7 +13,7 @@ import { NativeWorldStateService } from '@aztec/world-state/native';
12
13
 
13
14
  export class TXESynchronizer implements WorldStateSynchronizer {
14
15
  // This works when set to 1 as well.
15
- private blockNumber = 0;
16
+ private blockNumber = BlockNumber.ZERO;
16
17
 
17
18
  constructor(public nativeWorldStateService: NativeWorldStateService) {}
18
19
 
@@ -22,7 +23,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
22
23
  return new this(nativeWorldStateService);
23
24
  }
24
25
 
25
- public async handleL2Block(block: L2Block) {
26
+ public async handleL2Block(block: L2BlockNew) {
26
27
  await this.nativeWorldStateService.handleL2BlockAndMessages(
27
28
  block,
28
29
  Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
@@ -37,7 +38,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
37
38
  * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
38
39
  * @returns A promise that resolves with the block number the world state was synced to
39
40
  */
40
- public syncImmediate(_minBlockNumber?: number, _skipThrowIfTargetNotReached?: boolean): Promise<number> {
41
+ public syncImmediate(_minBlockNumber?: BlockNumber, _skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber> {
41
42
  return Promise.resolve(this.blockNumber);
42
43
  }
43
44
 
@@ -48,12 +49,12 @@ export class TXESynchronizer implements WorldStateSynchronizer {
48
49
 
49
50
  /** Forks the world state at the given block number, defaulting to the latest one. */
50
51
  public fork(block?: number): Promise<MerkleTreeWriteOperations> {
51
- return this.nativeWorldStateService.fork(block);
52
+ return this.nativeWorldStateService.fork(block ? BlockNumber(block) : undefined);
52
53
  }
53
54
 
54
55
  /** Gets a handle that allows reading the state as it was at the given block number. */
55
56
  public getSnapshot(blockNumber: number): MerkleTreeReadOperations {
56
- return this.nativeWorldStateService.getSnapshot(blockNumber);
57
+ return this.nativeWorldStateService.getSnapshot(BlockNumber(blockNumber));
57
58
  }
58
59
 
59
60
  /** Backups the db to the target path. */