@aztec/txe 0.0.1-commit.9b94fc1 → 0.0.1-commit.a072138

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 (80) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +3 -2
  7. package/dest/oracle/interfaces.d.ts +11 -8
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +10 -12
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -12
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +111 -72
  15. package/dest/rpc_translator.d.ts +25 -13
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +102 -47
  18. package/dest/state_machine/archiver.d.ts +21 -52
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +61 -94
  21. package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +16 -11
  24. package/dest/state_machine/global_variable_builder.d.ts +6 -5
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +13 -1
  27. package/dest/state_machine/index.d.ts +5 -5
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +31 -19
  30. package/dest/state_machine/mock_epoch_cache.d.ts +7 -6
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +10 -7
  33. package/dest/state_machine/synchronizer.d.ts +3 -2
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +5 -4
  36. package/dest/txe_session.d.ts +21 -13
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +94 -47
  39. package/dest/util/encoding.d.ts +618 -19
  40. package/dest/util/encoding.d.ts.map +1 -1
  41. package/dest/util/encoding.js +1 -1
  42. package/dest/util/txe_account_store.d.ts +10 -0
  43. package/dest/util/txe_account_store.d.ts.map +1 -0
  44. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  45. package/dest/util/txe_contract_store.d.ts +12 -0
  46. package/dest/util/txe_contract_store.d.ts.map +1 -0
  47. package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
  48. package/dest/util/txe_public_contract_data_source.d.ts +7 -6
  49. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  50. package/dest/util/txe_public_contract_data_source.js +11 -11
  51. package/dest/utils/block_creation.d.ts +21 -6
  52. package/dest/utils/block_creation.d.ts.map +1 -1
  53. package/dest/utils/block_creation.js +36 -4
  54. package/dest/utils/tx_effect_creation.d.ts +3 -3
  55. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  56. package/dest/utils/tx_effect_creation.js +4 -7
  57. package/package.json +18 -18
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +15 -12
  60. package/src/oracle/interfaces.ts +10 -7
  61. package/src/oracle/txe_oracle_public_context.ts +12 -19
  62. package/src/oracle/txe_oracle_top_level_context.ts +176 -99
  63. package/src/rpc_translator.ts +137 -52
  64. package/src/state_machine/archiver.ts +57 -114
  65. package/src/state_machine/dummy_p2p_client.ts +21 -14
  66. package/src/state_machine/global_variable_builder.ts +21 -4
  67. package/src/state_machine/index.ts +40 -17
  68. package/src/state_machine/mock_epoch_cache.ts +10 -11
  69. package/src/state_machine/synchronizer.ts +6 -5
  70. package/src/txe_session.ts +188 -83
  71. package/src/util/encoding.ts +1 -1
  72. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  73. package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
  74. package/src/util/txe_public_contract_data_source.ts +13 -12
  75. package/src/utils/block_creation.ts +47 -15
  76. package/src/utils/tx_effect_creation.ts +5 -12
  77. package/dest/util/txe_account_data_provider.d.ts +0 -10
  78. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  79. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  80. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
@@ -4,6 +4,7 @@ import type {
4
4
  ENR,
5
5
  P2P,
6
6
  P2PBlockReceivedCallback,
7
+ P2PCheckpointReceivedCallback,
7
8
  P2PConfig,
8
9
  P2PSyncState,
9
10
  PeerId,
@@ -14,14 +15,10 @@ import type {
14
15
  } from '@aztec/p2p';
15
16
  import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
16
17
  import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
17
- import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
18
+ import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
18
19
  import type { Tx, TxHash } from '@aztec/stdlib/tx';
19
20
 
20
21
  export class DummyP2P implements P2P {
21
- public broadcastAttestations(_attestations: BlockAttestation[]): Promise<void> {
22
- return Promise.resolve();
23
- }
24
-
25
22
  public validate(_txs: Tx[]): Promise<void> {
26
23
  return Promise.resolve();
27
24
  }
@@ -46,10 +43,22 @@ export class DummyP2P implements P2P {
46
43
  throw new Error('DummyP2P does not implement "broadcastProposal"');
47
44
  }
48
45
 
46
+ public broadcastCheckpointProposal(_proposal: CheckpointProposal): Promise<void> {
47
+ throw new Error('DummyP2P does not implement "broadcastCheckpointProposal"');
48
+ }
49
+
50
+ public broadcastCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
51
+ throw new Error('DummyP2P does not implement "broadcastCheckpointAttestations"');
52
+ }
53
+
49
54
  public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
50
55
  throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
51
56
  }
52
57
 
58
+ public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
59
+ throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
60
+ }
61
+
53
62
  public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
54
63
  throw new Error('DummyP2P does not implement "requestTxs"');
55
64
  }
@@ -79,7 +88,9 @@ export class DummyP2P implements P2P {
79
88
  }
80
89
 
81
90
  public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
82
- throw new Error('DummyP2P does not implement "getTxStatus"');
91
+ // In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
92
+ // tx status for any tx hash.
93
+ return Promise.resolve('mined');
83
94
  }
84
95
 
85
96
  public iteratePendingTxs(): AsyncIterableIterator<Tx> {
@@ -118,16 +129,12 @@ export class DummyP2P implements P2P {
118
129
  throw new Error('DummyP2P does not implement "getTxsByHash"');
119
130
  }
120
131
 
121
- public getAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<BlockAttestation[]> {
122
- throw new Error('DummyP2P does not implement "getAttestationForSlot"');
123
- }
124
-
125
- public deleteAttestation(_attestation: BlockAttestation): Promise<void> {
126
- return Promise.resolve();
132
+ public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
133
+ throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
127
134
  }
128
135
 
129
- public addAttestations(_attestations: BlockAttestation[]): Promise<void> {
130
- throw new Error('DummyP2P does not implement "addAttestations"');
136
+ public addCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
137
+ throw new Error('DummyP2P does not implement "addCheckpointAttestations"');
131
138
  }
132
139
 
133
140
  public getL2BlockHash(_number: number): Promise<string | undefined> {
@@ -1,21 +1,38 @@
1
- import type { SlotNumber } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { GasFees } from '@aztec/stdlib/gas';
5
5
  import { makeGlobalVariables } from '@aztec/stdlib/testing';
6
- import { type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
6
+ import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
7
7
 
8
8
  export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
9
- public getCurrentBaseFees(): Promise<GasFees> {
9
+ public getCurrentMinFees(): Promise<GasFees> {
10
10
  return Promise.resolve(new GasFees(0, 0));
11
11
  }
12
12
 
13
13
  public buildGlobalVariables(
14
- _blockNumber: number,
14
+ _blockNumber: BlockNumber,
15
15
  _coinbase: EthAddress,
16
16
  _feeRecipient: AztecAddress,
17
17
  _slotNumber?: SlotNumber,
18
18
  ): Promise<GlobalVariables> {
19
19
  return Promise.resolve(makeGlobalVariables());
20
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
+ }
21
38
  }
@@ -1,10 +1,14 @@
1
1
  import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
2
  import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
5
  import { createLogger } from '@aztec/foundation/log';
4
6
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
- import { SyncDataProvider } from '@aztec/pxe/server';
6
- import { type L2Block, PublishedL2Block } from '@aztec/stdlib/block';
7
+ import { AnchorBlockStore } from '@aztec/pxe/server';
8
+ import { L2Block } from '@aztec/stdlib/block';
9
+ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
7
10
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
11
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
8
12
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
9
13
 
10
14
  import { TXEArchiver } from './archiver.js';
@@ -21,13 +25,13 @@ export class TXEStateMachine {
21
25
  public node: AztecNode,
22
26
  public synchronizer: TXESynchronizer,
23
27
  public archiver: TXEArchiver,
24
- public syncDataProvider: SyncDataProvider,
28
+ public anchorBlockStore: AnchorBlockStore,
25
29
  ) {}
26
30
 
27
31
  public static async create(db: AztecAsyncKVStore) {
28
32
  const archiver = new TXEArchiver(db);
29
33
  const synchronizer = await TXESynchronizer.create();
30
- const syncDataProvider = new SyncDataProvider(db);
34
+ const anchorBlockStore = new AnchorBlockStore(db);
31
35
 
32
36
  const aztecNodeConfig = {} as AztecNodeConfig;
33
37
 
@@ -54,24 +58,43 @@ export class TXEStateMachine {
54
58
  log,
55
59
  );
56
60
 
57
- return new this(node, synchronizer, archiver, syncDataProvider);
61
+ return new this(node, synchronizer, archiver, anchorBlockStore);
58
62
  }
59
63
 
60
64
  public async handleL2Block(block: L2Block) {
65
+ // Create a checkpoint from the block manually
66
+ const checkpoint = new Checkpoint(
67
+ block.archive,
68
+ CheckpointHeader.from({
69
+ lastArchiveRoot: block.header.lastArchive.root,
70
+ inHash: Fr.ZERO,
71
+ blobsHash: Fr.ZERO,
72
+ blockHeadersHash: Fr.ZERO,
73
+ epochOutHash: Fr.ZERO,
74
+ slotNumber: block.header.globalVariables.slotNumber,
75
+ timestamp: block.header.globalVariables.timestamp,
76
+ coinbase: block.header.globalVariables.coinbase,
77
+ feeRecipient: block.header.globalVariables.feeRecipient,
78
+ gasFees: block.header.globalVariables.gasFees,
79
+ totalManaUsed: block.header.totalManaUsed,
80
+ }),
81
+ [block],
82
+ CheckpointNumber.fromBlockNumber(block.number),
83
+ );
84
+
85
+ const publishedCheckpoint = new PublishedCheckpoint(
86
+ checkpoint,
87
+ new L1PublishedData(
88
+ BigInt(block.header.globalVariables.blockNumber),
89
+ block.header.globalVariables.timestamp,
90
+ block.header.globalVariables.blockNumber.toString(),
91
+ ),
92
+ [],
93
+ );
61
94
  await Promise.all([
62
95
  this.synchronizer.handleL2Block(block),
63
- this.archiver.addBlocks([
64
- PublishedL2Block.fromFields({
65
- block,
66
- l1: {
67
- blockHash: block.header.globalVariables.blockNumber.toString(),
68
- blockNumber: BigInt(block.header.globalVariables.blockNumber),
69
- timestamp: block.header.globalVariables.timestamp,
70
- },
71
- attestations: [],
72
- }),
73
- ]),
74
- this.syncDataProvider.setHeader(block.getBlockHeader()),
96
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
97
+ this.anchorBlockStore.setHeader(block.header),
75
98
  ]);
76
99
  }
77
100
  }
@@ -12,14 +12,16 @@ export class MockEpochCache implements EpochCacheInterface {
12
12
  committee: undefined,
13
13
  seed: 0n,
14
14
  epoch: EpochNumber.ZERO,
15
+ isEscapeHatchOpen: false,
15
16
  });
16
17
  }
17
18
 
18
- getEpochAndSlotNow(): EpochAndSlot {
19
+ getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
19
20
  return {
20
21
  epoch: EpochNumber.ZERO,
21
22
  slot: SlotNumber(0),
22
23
  ts: 0n,
24
+ nowMs: 0n,
23
25
  };
24
26
  }
25
27
 
@@ -40,18 +42,15 @@ export class MockEpochCache implements EpochCacheInterface {
40
42
  return 0n;
41
43
  }
42
44
 
43
- getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
44
- currentProposer: EthAddress | undefined;
45
- nextProposer: EthAddress | undefined;
46
- currentSlot: SlotNumber;
47
- nextSlot: SlotNumber;
48
- }> {
49
- return Promise.resolve({
50
- currentProposer: undefined,
51
- nextProposer: undefined,
45
+ getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
46
+ return {
52
47
  currentSlot: SlotNumber(0),
53
48
  nextSlot: SlotNumber(0),
54
- });
49
+ };
50
+ }
51
+
52
+ getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
53
+ return Promise.resolve(undefined);
55
54
  }
56
55
 
57
56
  isInCommittee(_slot: SlotTag, _validator: EthAddress): Promise<boolean> {
@@ -1,5 +1,6 @@
1
1
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { L2Block } from '@aztec/stdlib/block';
4
5
  import type {
5
6
  MerkleTreeReadOperations,
@@ -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
 
@@ -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. */