@aztec/sequencer-client 0.24.0 → 0.26.1

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 (65) hide show
  1. package/dest/block_builder/solo_block_builder.d.ts +9 -9
  2. package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
  3. package/dest/block_builder/solo_block_builder.js +26 -48
  4. package/dest/global_variable_builder/viem-reader.js +2 -2
  5. package/dest/publisher/l1-publisher.d.ts +0 -2
  6. package/dest/publisher/l1-publisher.d.ts.map +1 -1
  7. package/dest/publisher/l1-publisher.js +2 -3
  8. package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
  9. package/dest/publisher/viem-tx-sender.js +6 -10
  10. package/dest/sequencer/abstract_phase_manager.d.ts +18 -25
  11. package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
  12. package/dest/sequencer/abstract_phase_manager.js +141 -91
  13. package/dest/sequencer/{fee_distribution_phase_manager.d.ts → app_logic_phase_manager.d.ts} +9 -11
  14. package/dest/sequencer/app_logic_phase_manager.d.ts.map +1 -0
  15. package/dest/sequencer/app_logic_phase_manager.js +44 -0
  16. package/dest/sequencer/phase_manager_factory.d.ts +19 -0
  17. package/dest/sequencer/phase_manager_factory.d.ts.map +1 -0
  18. package/dest/sequencer/phase_manager_factory.js +51 -0
  19. package/dest/sequencer/processed_tx.d.ts +2 -2
  20. package/dest/sequencer/processed_tx.d.ts.map +1 -1
  21. package/dest/sequencer/processed_tx.js +7 -7
  22. package/dest/sequencer/public_processor.d.ts +1 -1
  23. package/dest/sequencer/public_processor.d.ts.map +1 -1
  24. package/dest/sequencer/public_processor.js +13 -11
  25. package/dest/sequencer/sequencer.d.ts +3 -3
  26. package/dest/sequencer/sequencer.d.ts.map +1 -1
  27. package/dest/sequencer/sequencer.js +23 -16
  28. package/dest/sequencer/{fee_preparation_phase_manager.d.ts → setup_phase_manager.d.ts} +9 -11
  29. package/dest/sequencer/setup_phase_manager.d.ts.map +1 -0
  30. package/dest/sequencer/setup_phase_manager.js +37 -0
  31. package/dest/sequencer/{application_logic_phase_manager.d.ts → teardown_phase_manager.d.ts} +9 -12
  32. package/dest/sequencer/teardown_phase_manager.d.ts.map +1 -0
  33. package/dest/sequencer/teardown_phase_manager.js +36 -0
  34. package/dest/simulator/index.d.ts +10 -4
  35. package/dest/simulator/index.d.ts.map +1 -1
  36. package/dest/simulator/public_executor.d.ts +8 -3
  37. package/dest/simulator/public_executor.d.ts.map +1 -1
  38. package/dest/simulator/public_executor.js +64 -11
  39. package/dest/simulator/public_kernel.d.ts +10 -4
  40. package/dest/simulator/public_kernel.d.ts.map +1 -1
  41. package/dest/simulator/public_kernel.js +33 -14
  42. package/package.json +14 -13
  43. package/src/block_builder/solo_block_builder.ts +61 -50
  44. package/src/global_variable_builder/viem-reader.ts +1 -1
  45. package/src/publisher/l1-publisher.ts +1 -4
  46. package/src/publisher/viem-tx-sender.ts +6 -12
  47. package/src/sequencer/abstract_phase_manager.ts +207 -145
  48. package/src/sequencer/app_logic_phase_manager.ts +75 -0
  49. package/src/sequencer/phase_manager_factory.ts +122 -0
  50. package/src/sequencer/processed_tx.ts +12 -13
  51. package/src/sequencer/public_processor.ts +29 -12
  52. package/src/sequencer/sequencer.ts +22 -15
  53. package/src/sequencer/{fee_distribution_phase_manager.ts → setup_phase_manager.ts} +23 -25
  54. package/src/sequencer/teardown_phase_manager.ts +67 -0
  55. package/src/simulator/index.ts +10 -6
  56. package/src/simulator/public_executor.ts +108 -10
  57. package/src/simulator/public_kernel.ts +39 -13
  58. package/dest/sequencer/application_logic_phase_manager.d.ts.map +0 -1
  59. package/dest/sequencer/application_logic_phase_manager.js +0 -64
  60. package/dest/sequencer/fee_distribution_phase_manager.d.ts.map +0 -1
  61. package/dest/sequencer/fee_distribution_phase_manager.js +0 -42
  62. package/dest/sequencer/fee_preparation_phase_manager.d.ts.map +0 -1
  63. package/dest/sequencer/fee_preparation_phase_manager.js +0 -42
  64. package/src/sequencer/application_logic_phase_manager.ts +0 -107
  65. package/src/sequencer/fee_preparation_phase_manager.ts +0 -79
@@ -1,4 +1,4 @@
1
- import { ContractData, L2Block, L2BlockL2Logs, MerkleTreeId, PublicDataWrite, TxL2Logs } from '@aztec/circuit-types';
1
+ import { Body, ContractData, L2Block, MerkleTreeId, PublicDataWrite, TxEffect, TxL2Logs } from '@aztec/circuit-types';
2
2
  import {
3
3
  ARCHIVE_HEIGHT,
4
4
  AppendOnlyTreeSnapshot,
@@ -6,10 +6,13 @@ import {
6
6
  BaseRollupInputs,
7
7
  CONTRACT_SUBTREE_HEIGHT,
8
8
  CONTRACT_SUBTREE_SIBLING_PATH_LENGTH,
9
+ CombinedAccumulatedData,
9
10
  ConstantRollupData,
10
11
  GlobalVariables,
11
12
  L1_TO_L2_MSG_SUBTREE_HEIGHT,
12
13
  L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
14
+ MAX_NEW_CONTRACTS_PER_TX,
15
+ MAX_NEW_NOTE_HASHES_PER_TX,
13
16
  MAX_NEW_NULLIFIERS_PER_TX,
14
17
  MAX_PUBLIC_DATA_READS_PER_TX,
15
18
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
@@ -30,8 +33,9 @@ import {
30
33
  Proof,
31
34
  PublicDataTreeLeaf,
32
35
  PublicDataTreeLeafPreimage,
33
- PublicKernelData,
34
36
  ROLLUP_VK_TREE_HEIGHT,
37
+ RollupKernelCircuitPublicInputs,
38
+ RollupKernelData,
35
39
  RollupTypes,
36
40
  RootRollupInputs,
37
41
  RootRollupPublicInputs,
@@ -42,8 +46,7 @@ import {
42
46
  VK_TREE_HEIGHT,
43
47
  VerificationKey,
44
48
  } from '@aztec/circuits.js';
45
- import { computeContractLeaf } from '@aztec/circuits.js/abis';
46
- import { makeTuple } from '@aztec/foundation/array';
49
+ import { assertPermutation, makeTuple } from '@aztec/foundation/array';
47
50
  import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
48
51
  import { padArrayEnd } from '@aztec/foundation/collection';
49
52
  import { Fr } from '@aztec/foundation/fields';
@@ -102,48 +105,44 @@ export class SoloBlockBuilder implements BlockBuilder {
102
105
  const [circuitsOutput, proof] = await this.runCircuits(globalVariables, txs, newL1ToL2Messages);
103
106
 
104
107
  // Collect all new nullifiers, commitments, and contracts from all txs in this block
105
- const newNullifiers = txs.flatMap(tx => tx.data.end.newNullifiers);
106
- const newCommitments = txs.flatMap(tx => tx.data.end.newCommitments);
107
- const newContracts = txs.flatMap(tx => tx.data.end.newContracts).map(cd => computeContractLeaf(cd));
108
- const newContractData = txs
109
- .flatMap(tx => tx.data.end.newContracts)
110
- .map(n => new ContractData(n.contractAddress, n.portalContractAddress));
111
- const newPublicDataWrites = txs.flatMap(tx =>
112
- tx.data.end.publicDataUpdateRequests.map(t => new PublicDataWrite(t.leafSlot, t.newValue)),
108
+ const txEffects: TxEffect[] = txs.map(
109
+ tx =>
110
+ new TxEffect(
111
+ tx.data.combinedData.newNoteHashes.map((c: SideEffect) => c.value) as Tuple<
112
+ Fr,
113
+ typeof MAX_NEW_NOTE_HASHES_PER_TX
114
+ >,
115
+ tx.data.combinedData.newNullifiers.map((n: SideEffectLinkedToNoteHash) => n.value) as Tuple<
116
+ Fr,
117
+ typeof MAX_NEW_NULLIFIERS_PER_TX
118
+ >,
119
+ tx.data.combinedData.newL2ToL1Msgs,
120
+ tx.data.combinedData.publicDataUpdateRequests.map(t => new PublicDataWrite(t.leafSlot, t.newValue)) as Tuple<
121
+ PublicDataWrite,
122
+ typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
123
+ >,
124
+ tx.data.combinedData.newContracts.map(cd => cd.hash()) as Tuple<Fr, typeof MAX_NEW_CONTRACTS_PER_TX>,
125
+ tx.data.combinedData.newContracts.map(
126
+ cd => new ContractData(cd.contractAddress, cd.portalContractAddress),
127
+ ) as Tuple<ContractData, typeof MAX_NEW_CONTRACTS_PER_TX>,
128
+ tx.encryptedLogs || new TxL2Logs([]),
129
+ tx.unencryptedLogs || new TxL2Logs([]),
130
+ ),
113
131
  );
114
- const newL2ToL1Msgs = txs.flatMap(tx => tx.data.end.newL2ToL1Msgs);
115
132
 
116
- // Consolidate logs data from all txs
117
- const encryptedLogsArr: TxL2Logs[] = [];
118
- const unencryptedLogsArr: TxL2Logs[] = [];
119
- for (const tx of txs) {
120
- const encryptedLogs = tx.encryptedLogs || new TxL2Logs([]);
121
- encryptedLogsArr.push(encryptedLogs);
122
- const unencryptedLogs = tx.unencryptedLogs || new TxL2Logs([]);
123
- unencryptedLogsArr.push(unencryptedLogs);
124
- }
125
- const newEncryptedLogs = new L2BlockL2Logs(encryptedLogsArr);
126
- const newUnencryptedLogs = new L2BlockL2Logs(unencryptedLogsArr);
133
+ const blockBody = new Body(padArrayEnd(newL1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP), txEffects);
127
134
 
128
135
  const l2Block = L2Block.fromFields({
129
136
  archive: circuitsOutput.archive,
130
137
  header: circuitsOutput.header,
131
- newCommitments: newCommitments.map((c: SideEffect) => c.value),
132
- newNullifiers: newNullifiers.map((n: SideEffectLinkedToNoteHash) => n.value),
133
- newL2ToL1Msgs,
134
- newContracts,
135
- newContractData,
136
- newPublicDataWrites,
137
- newL1ToL2Messages,
138
- newEncryptedLogs,
139
- newUnencryptedLogs,
138
+ body: blockBody,
140
139
  });
141
140
 
142
- if (!l2Block.getCalldataHash().equals(circuitsOutput.header.bodyHash)) {
141
+ if (!l2Block.body.getCalldataHash().equals(circuitsOutput.header.contentCommitment.txsHash)) {
143
142
  throw new Error(
144
- `Calldata hash mismatch, ${l2Block
143
+ `Calldata hash mismatch, ${l2Block.body
145
144
  .getCalldataHash()
146
- .toString('hex')} == ${circuitsOutput.header.bodyHash.toString('hex')} `,
145
+ .toString('hex')} == ${circuitsOutput.header.contentCommitment.txsHash.toString('hex')} `,
147
146
  );
148
147
  }
149
148
 
@@ -418,9 +417,14 @@ export class SoloBlockBuilder implements BlockBuilder {
418
417
  );
419
418
  }
420
419
 
421
- protected getKernelDataFor(tx: ProcessedTx) {
422
- return new PublicKernelData(
423
- tx.data,
420
+ protected getKernelDataFor(tx: ProcessedTx): RollupKernelData {
421
+ const inputs = new RollupKernelCircuitPublicInputs(
422
+ tx.data.aggregationObject,
423
+ CombinedAccumulatedData.recombine(tx.data.endNonRevertibleData, tx.data.end),
424
+ tx.data.constants,
425
+ );
426
+ return new RollupKernelData(
427
+ inputs,
424
428
  tx.proof,
425
429
 
426
430
  // VK for the kernel circuit
@@ -501,13 +505,14 @@ export class SoloBlockBuilder implements BlockBuilder {
501
505
  }
502
506
 
503
507
  protected async processPublicDataUpdateRequests(tx: ProcessedTx) {
508
+ const combinedPublicDataUpdateRequests = tx.data.combinedData.publicDataUpdateRequests.map(updateRequest => {
509
+ return new PublicDataTreeLeaf(updateRequest.leafSlot, updateRequest.newValue);
510
+ });
504
511
  const { lowLeavesWitnessData, newSubtreeSiblingPath, sortedNewLeaves, sortedNewLeavesIndexes } =
505
512
  await this.db.batchInsert(
506
513
  MerkleTreeId.PUBLIC_DATA_TREE,
514
+ combinedPublicDataUpdateRequests.map(x => x.toBuffer()),
507
515
  // TODO(#3675) remove oldValue from update requests
508
- tx.data.end.publicDataUpdateRequests.map(updateRequest => {
509
- return new PublicDataTreeLeaf(updateRequest.leafSlot, updateRequest.newValue).toBuffer();
510
- }),
511
516
  PUBLIC_DATA_SUBTREE_HEIGHT,
512
517
  );
513
518
 
@@ -546,6 +551,12 @@ export class SoloBlockBuilder implements BlockBuilder {
546
551
  return lowLeavesWitnessData[i].leafPreimage as PublicDataTreeLeafPreimage;
547
552
  });
548
553
 
554
+ // validate that the sortedPublicDataWrites and sortedPublicDataWritesIndexes are in the correct order
555
+ // otherwise it will just fail in the circuit
556
+ assertPermutation(combinedPublicDataUpdateRequests, sortedPublicDataWrites, sortedPublicDataWritesIndexes, (a, b) =>
557
+ a.equals(b),
558
+ );
559
+
549
560
  return {
550
561
  lowPublicDataWritesPreimages,
551
562
  lowPublicDataWritesMembershipWitnesses,
@@ -563,8 +574,9 @@ export class SoloBlockBuilder implements BlockBuilder {
563
574
 
564
575
  const newPublicDataReadsPreimages: Tuple<PublicDataTreeLeafPreimage, typeof MAX_PUBLIC_DATA_READS_PER_TX> =
565
576
  makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => PublicDataTreeLeafPreimage.empty());
566
- for (const i in tx.data.end.publicDataReads) {
567
- const leafSlot = tx.data.end.publicDataReads[i].leafSlot.value;
577
+
578
+ for (const i in tx.data.combinedData.publicDataReads) {
579
+ const leafSlot = tx.data.combinedData.publicDataReads[i].leafSlot.value;
568
580
  const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
569
581
  if (!lowLeafResult) {
570
582
  throw new Error(`Public data tree should have one initial leaf`);
@@ -616,14 +628,15 @@ export class SoloBlockBuilder implements BlockBuilder {
616
628
 
617
629
  // Update the contract and note hash trees with the new items being inserted to get the new roots
618
630
  // that will be used by the next iteration of the base rollup circuit, skipping the empty ones
619
- const newContracts = tx.data.end.newContracts.map(cd => computeContractLeaf(cd));
620
- const newCommitments = tx.data.end.newCommitments.map(x => x.value.toBuffer());
631
+ const newContracts = tx.data.combinedData.newContracts.map(cd => cd.hash());
632
+ const newNoteHashes = tx.data.combinedData.newNoteHashes.map(x => x.value.toBuffer());
633
+
621
634
  await this.db.appendLeaves(
622
635
  MerkleTreeId.CONTRACT_TREE,
623
636
  newContracts.map(x => x.toBuffer()),
624
637
  );
625
638
 
626
- await this.db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, newCommitments);
639
+ await this.db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, newNoteHashes);
627
640
 
628
641
  // The read witnesses for a given TX should be generated before the writes of the same TX are applied.
629
642
  // All reads that refer to writes in the same tx are transient and can be simplified out.
@@ -631,8 +644,6 @@ export class SoloBlockBuilder implements BlockBuilder {
631
644
  const txPublicDataUpdateRequestInfo = await this.processPublicDataUpdateRequests(tx);
632
645
 
633
646
  // Update the nullifier tree, capturing the low nullifier info for each individual operation
634
- const newNullifiers = tx.data.end.newNullifiers;
635
-
636
647
  const {
637
648
  lowLeavesWitnessData: nullifierWitnessLeaves,
638
649
  newSubtreeSiblingPath: newNullifiersSubtreeSiblingPath,
@@ -640,7 +651,7 @@ export class SoloBlockBuilder implements BlockBuilder {
640
651
  sortedNewLeavesIndexes,
641
652
  } = await this.db.batchInsert(
642
653
  MerkleTreeId.NULLIFIER_TREE,
643
- newNullifiers.map(sideEffectLinkedToNoteHash => sideEffectLinkedToNoteHash.value.toBuffer()),
654
+ tx.data.combinedData.newNullifiers.map(sideEffectLinkedToNoteHash => sideEffectLinkedToNoteHash.value.toBuffer()),
644
655
  NULLIFIER_SUBTREE_HEIGHT,
645
656
  );
646
657
  if (nullifierWitnessLeaves === undefined) {
@@ -35,7 +35,7 @@ export class ViemReader implements L1GlobalReader {
35
35
  this.rollupContract = getContract({
36
36
  address: getAddress(l1Contracts.rollupAddress.toString()),
37
37
  abi: RollupAbi,
38
- publicClient: this.publicClient,
38
+ client: this.publicClient,
39
39
  });
40
40
  }
41
41
 
@@ -105,8 +105,6 @@ export type L1ProcessArgs = {
105
105
  header: Buffer;
106
106
  /** A root of the archive tree after the L2 block is applied. */
107
107
  archive: Buffer;
108
- /** Transactions hash. */
109
- txsHash: Buffer;
110
108
  /** L2 block body. */
111
109
  body: Buffer;
112
110
  /** Root rollup proof of the L2 block. */
@@ -154,7 +152,7 @@ export class L1Publisher implements L2BlockReceiver {
154
152
  return false;
155
153
  }
156
154
 
157
- const encodedBody = block.bodyToBuffer();
155
+ const encodedBody = block.body.toBuffer();
158
156
 
159
157
  // Publish block transaction effects
160
158
  while (!this.interrupted) {
@@ -193,7 +191,6 @@ export class L1Publisher implements L2BlockReceiver {
193
191
  const processTxArgs = {
194
192
  header: block.header.toBuffer(),
195
193
  archive: block.archive.root.toBuffer(),
196
- txsHash: block.getCalldataHash(),
197
194
  body: encodedBody,
198
195
  proof: Buffer.alloc(0),
199
196
  };
@@ -1,4 +1,5 @@
1
- import { BLOB_SIZE_IN_BYTES, ExtendedContractData, L2Block } from '@aztec/circuit-types';
1
+ import { ExtendedContractData, L2Block } from '@aztec/circuit-types';
2
+ import { BLOB_SIZE_IN_BYTES } from '@aztec/circuits.js/constants';
2
3
  import { createEthereumChain } from '@aztec/ethereum';
3
4
  import { createDebugLogger } from '@aztec/foundation/log';
4
5
  import { AvailabilityOracleAbi, ContractDeploymentEmitterAbi, RollupAbi } from '@aztec/l1-artifacts';
@@ -33,17 +34,14 @@ import {
33
34
  export class ViemTxSender implements L1PublisherTxSender {
34
35
  private availabilityOracleContract: GetContractReturnType<
35
36
  typeof AvailabilityOracleAbi,
36
- PublicClient<HttpTransport, chains.Chain>,
37
37
  WalletClient<HttpTransport, chains.Chain, PrivateKeyAccount>
38
38
  >;
39
39
  private rollupContract: GetContractReturnType<
40
40
  typeof RollupAbi,
41
- PublicClient<HttpTransport, chains.Chain>,
42
41
  WalletClient<HttpTransport, chains.Chain, PrivateKeyAccount>
43
42
  >;
44
43
  private contractDeploymentEmitterContract: GetContractReturnType<
45
44
  typeof ContractDeploymentEmitterAbi,
46
- PublicClient<HttpTransport, chains.Chain>,
47
45
  WalletClient<HttpTransport, chains.Chain, PrivateKeyAccount>
48
46
  >;
49
47
 
@@ -69,20 +67,17 @@ export class ViemTxSender implements L1PublisherTxSender {
69
67
  this.availabilityOracleContract = getContract({
70
68
  address: getAddress(l1Contracts.availabilityOracleAddress.toString()),
71
69
  abi: AvailabilityOracleAbi,
72
- publicClient: this.publicClient,
73
- walletClient,
70
+ client: walletClient,
74
71
  });
75
72
  this.rollupContract = getContract({
76
73
  address: getAddress(l1Contracts.rollupAddress.toString()),
77
74
  abi: RollupAbi,
78
- publicClient: this.publicClient,
79
- walletClient,
75
+ client: walletClient,
80
76
  });
81
77
  this.contractDeploymentEmitterContract = getContract({
82
78
  address: getAddress(l1Contracts.contractDeploymentEmitterAddress.toString()),
83
79
  abi: ContractDeploymentEmitterAbi,
84
- publicClient: this.publicClient,
85
- walletClient,
80
+ client: walletClient,
86
81
  });
87
82
  }
88
83
 
@@ -92,7 +87,7 @@ export class ViemTxSender implements L1PublisherTxSender {
92
87
  }
93
88
 
94
89
  checkIfTxsAreAvailable(block: L2Block): Promise<boolean> {
95
- const args = [`0x${block.getCalldataHash().toString('hex')}`] as const;
90
+ const args = [`0x${block.body.getCalldataHash().toString('hex')}`] as const;
96
91
  return this.availabilityOracleContract.read.isAvailable(args);
97
92
  }
98
93
 
@@ -160,7 +155,6 @@ export class ViemTxSender implements L1PublisherTxSender {
160
155
  const args = [
161
156
  `0x${encodedData.header.toString('hex')}`,
162
157
  `0x${encodedData.archive.toString('hex')}`,
163
- `0x${encodedData.txsHash.toString('hex')}`,
164
158
  `0x${encodedData.body.toString('hex')}`,
165
159
  `0x${encodedData.proof.toString('hex')}`,
166
160
  ] as const;