@aztec/sequencer-client 0.23.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 (88) 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/prover/empty.d.ts +2 -2
  6. package/dest/prover/empty.d.ts.map +1 -1
  7. package/dest/prover/empty.js +1 -1
  8. package/dest/prover/index.d.ts +2 -2
  9. package/dest/prover/index.d.ts.map +1 -1
  10. package/dest/publisher/l1-publisher.d.ts +0 -2
  11. package/dest/publisher/l1-publisher.d.ts.map +1 -1
  12. package/dest/publisher/l1-publisher.js +2 -3
  13. package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
  14. package/dest/publisher/viem-tx-sender.js +6 -10
  15. package/dest/sequencer/abstract_phase_manager.d.ts +23 -30
  16. package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
  17. package/dest/sequencer/abstract_phase_manager.js +151 -98
  18. package/dest/sequencer/{fee_distribution_phase_manager.d.ts → app_logic_phase_manager.d.ts} +9 -11
  19. package/dest/sequencer/app_logic_phase_manager.d.ts.map +1 -0
  20. package/dest/sequencer/app_logic_phase_manager.js +44 -0
  21. package/dest/sequencer/phase_manager_factory.d.ts +19 -0
  22. package/dest/sequencer/phase_manager_factory.d.ts.map +1 -0
  23. package/dest/sequencer/phase_manager_factory.js +51 -0
  24. package/dest/sequencer/processed_tx.d.ts +4 -4
  25. package/dest/sequencer/processed_tx.d.ts.map +1 -1
  26. package/dest/sequencer/processed_tx.js +8 -8
  27. package/dest/sequencer/public_processor.d.ts +1 -1
  28. package/dest/sequencer/public_processor.d.ts.map +1 -1
  29. package/dest/sequencer/public_processor.js +13 -11
  30. package/dest/sequencer/sequencer.d.ts +3 -3
  31. package/dest/sequencer/sequencer.d.ts.map +1 -1
  32. package/dest/sequencer/sequencer.js +23 -16
  33. package/dest/sequencer/{fee_preparation_phase_manager.d.ts → setup_phase_manager.d.ts} +9 -11
  34. package/dest/sequencer/setup_phase_manager.d.ts.map +1 -0
  35. package/dest/sequencer/setup_phase_manager.js +37 -0
  36. package/dest/sequencer/{application_logic_phase_manager.d.ts → teardown_phase_manager.d.ts} +9 -12
  37. package/dest/sequencer/teardown_phase_manager.d.ts.map +1 -0
  38. package/dest/sequencer/teardown_phase_manager.js +36 -0
  39. package/dest/simulator/index.d.ts +11 -5
  40. package/dest/simulator/index.d.ts.map +1 -1
  41. package/dest/simulator/public_executor.d.ts +8 -3
  42. package/dest/simulator/public_executor.d.ts.map +1 -1
  43. package/dest/simulator/public_executor.js +64 -11
  44. package/dest/simulator/public_kernel.d.ts +11 -5
  45. package/dest/simulator/public_kernel.d.ts.map +1 -1
  46. package/dest/simulator/public_kernel.js +35 -16
  47. package/dest/simulator/rollup.js +2 -2
  48. package/package.json +14 -24
  49. package/src/block_builder/index.ts +24 -0
  50. package/src/block_builder/solo_block_builder.ts +726 -0
  51. package/src/block_builder/types.ts +8 -0
  52. package/src/client/index.ts +1 -0
  53. package/src/client/sequencer-client.ts +97 -0
  54. package/src/config.ts +86 -0
  55. package/src/global_variable_builder/config.ts +20 -0
  56. package/src/global_variable_builder/global_builder.ts +95 -0
  57. package/src/global_variable_builder/index.ts +16 -0
  58. package/src/global_variable_builder/viem-reader.ts +61 -0
  59. package/src/index.ts +15 -0
  60. package/src/mocks/verification_keys.ts +36 -0
  61. package/src/prover/empty.ts +74 -0
  62. package/src/prover/index.ts +53 -0
  63. package/src/publisher/config.ts +41 -0
  64. package/src/publisher/index.ts +14 -0
  65. package/src/publisher/l1-publisher.ts +362 -0
  66. package/src/publisher/viem-tx-sender.ts +235 -0
  67. package/src/receiver.ts +13 -0
  68. package/src/sequencer/abstract_phase_manager.ts +489 -0
  69. package/src/sequencer/app_logic_phase_manager.ts +75 -0
  70. package/src/sequencer/config.ts +1 -0
  71. package/src/sequencer/index.ts +2 -0
  72. package/src/sequencer/phase_manager_factory.ts +122 -0
  73. package/src/sequencer/processed_tx.ts +94 -0
  74. package/src/sequencer/public_processor.ts +153 -0
  75. package/src/sequencer/sequencer.ts +469 -0
  76. package/src/sequencer/setup_phase_manager.ts +68 -0
  77. package/src/sequencer/teardown_phase_manager.ts +67 -0
  78. package/src/simulator/index.ts +57 -0
  79. package/src/simulator/public_executor.ts +267 -0
  80. package/src/simulator/public_kernel.ts +84 -0
  81. package/src/simulator/rollup.ts +76 -0
  82. package/src/utils.ts +16 -0
  83. package/dest/sequencer/application_logic_phase_manager.d.ts.map +0 -1
  84. package/dest/sequencer/application_logic_phase_manager.js +0 -64
  85. package/dest/sequencer/fee_distribution_phase_manager.d.ts.map +0 -1
  86. package/dest/sequencer/fee_distribution_phase_manager.js +0 -42
  87. package/dest/sequencer/fee_preparation_phase_manager.d.ts.map +0 -1
  88. package/dest/sequencer/fee_preparation_phase_manager.js +0 -43
@@ -0,0 +1,94 @@
1
+ import { ExtendedContractData, Tx, TxHash, TxL2Logs } from '@aztec/circuit-types';
2
+ import {
3
+ Fr,
4
+ Header,
5
+ Proof,
6
+ PublicAccumulatedNonRevertibleData,
7
+ PublicAccumulatedRevertibleData,
8
+ PublicKernelCircuitPublicInputs,
9
+ makeEmptyProof,
10
+ } from '@aztec/circuits.js';
11
+
12
+ /**
13
+ * Represents a tx that has been processed by the sequencer public processor,
14
+ * so its kernel circuit public inputs are filled in.
15
+ */
16
+ export type ProcessedTx = Pick<Tx, 'proof' | 'encryptedLogs' | 'unencryptedLogs' | 'newContracts'> & {
17
+ /**
18
+ * Output of the public kernel circuit for this tx.
19
+ */
20
+ data: PublicKernelCircuitPublicInputs;
21
+ /**
22
+ * Hash of the transaction.
23
+ */
24
+ hash: TxHash;
25
+ /**
26
+ * Flag indicating the tx is 'empty' meaning it's a padding tx to take us to a power of 2.
27
+ */
28
+ isEmpty: boolean;
29
+ };
30
+
31
+ /**
32
+ * Represents a tx that failed to be processed by the sequencer public processor.
33
+ */
34
+ export type FailedTx = {
35
+ /**
36
+ * The failing transaction.
37
+ */
38
+ tx: Tx;
39
+ /**
40
+ * The error that caused the tx to fail.
41
+ */
42
+ error: Error;
43
+ };
44
+
45
+ /**
46
+ * Makes a processed tx out of source tx.
47
+ * @param tx - Source tx.
48
+ * @param kernelOutput - Output of the kernel circuit simulation for this tx.
49
+ * @param proof - Proof of the kernel circuit for this tx.
50
+ */
51
+ export function makeProcessedTx(tx: Tx, kernelOutput?: PublicKernelCircuitPublicInputs, proof?: Proof): ProcessedTx {
52
+ return {
53
+ hash: tx.getTxHash(),
54
+ data:
55
+ kernelOutput ??
56
+ new PublicKernelCircuitPublicInputs(
57
+ tx.data.aggregationObject,
58
+ PublicAccumulatedNonRevertibleData.fromPrivateAccumulatedNonRevertibleData(tx.data.endNonRevertibleData),
59
+ PublicAccumulatedRevertibleData.fromPrivateAccumulatedRevertibleData(tx.data.end),
60
+ tx.data.constants,
61
+ tx.data.needsSetup,
62
+ tx.data.needsAppLogic,
63
+ tx.data.needsTeardown,
64
+ ),
65
+ proof: proof ?? tx.proof,
66
+ encryptedLogs: tx.encryptedLogs,
67
+ unencryptedLogs: tx.unencryptedLogs,
68
+ newContracts: tx.newContracts,
69
+ isEmpty: false,
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Makes an empty tx from an empty kernel circuit public inputs.
75
+ * @returns A processed empty tx.
76
+ */
77
+ export function makeEmptyProcessedTx(header: Header, chainId: Fr, version: Fr): ProcessedTx {
78
+ const emptyKernelOutput = PublicKernelCircuitPublicInputs.empty();
79
+ emptyKernelOutput.constants.historicalHeader = header;
80
+ emptyKernelOutput.constants.txContext.chainId = chainId;
81
+ emptyKernelOutput.constants.txContext.version = version;
82
+ const emptyProof = makeEmptyProof();
83
+
84
+ const hash = new TxHash(Fr.ZERO.toBuffer());
85
+ return {
86
+ hash,
87
+ encryptedLogs: new TxL2Logs([]),
88
+ unencryptedLogs: new TxL2Logs([]),
89
+ data: emptyKernelOutput,
90
+ proof: emptyProof,
91
+ newContracts: [ExtendedContractData.empty()],
92
+ isEmpty: true,
93
+ };
94
+ }
@@ -0,0 +1,153 @@
1
+ import { ContractDataSource, L1ToL2MessageSource, Tx } from '@aztec/circuit-types';
2
+ import { TxSequencerProcessingStats } from '@aztec/circuit-types/stats';
3
+ import { GlobalVariables, Header } from '@aztec/circuits.js';
4
+ import { createDebugLogger } from '@aztec/foundation/log';
5
+ import { Timer } from '@aztec/foundation/timer';
6
+ import { PublicExecutor, PublicStateDB } from '@aztec/simulator';
7
+ import { MerkleTreeOperations } from '@aztec/world-state';
8
+
9
+ import { EmptyPublicProver } from '../prover/empty.js';
10
+ import { PublicProver } from '../prover/index.js';
11
+ import { PublicKernelCircuitSimulator } from '../simulator/index.js';
12
+ import { ContractsDataSourcePublicDB, WorldStateDB, WorldStatePublicDB } from '../simulator/public_executor.js';
13
+ import { RealPublicKernelCircuitSimulator } from '../simulator/public_kernel.js';
14
+ import { AbstractPhaseManager } from './abstract_phase_manager.js';
15
+ import { PhaseManagerFactory } from './phase_manager_factory.js';
16
+ import { FailedTx, ProcessedTx, makeEmptyProcessedTx, makeProcessedTx } from './processed_tx.js';
17
+
18
+ /**
19
+ * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
20
+ */
21
+ export class PublicProcessorFactory {
22
+ constructor(
23
+ private merkleTree: MerkleTreeOperations,
24
+ private contractDataSource: ContractDataSource,
25
+ private l1Tol2MessagesDataSource: L1ToL2MessageSource,
26
+ ) {}
27
+
28
+ /**
29
+ * Creates a new instance of a PublicProcessor.
30
+ * @param historicalHeader - The header of a block previous to the one in which the tx is included.
31
+ * @param globalVariables - The global variables for the block being processed.
32
+ * @param newContracts - Provides access to contract bytecode for public executions.
33
+ * @returns A new instance of a PublicProcessor.
34
+ */
35
+ public async create(
36
+ historicalHeader: Header | undefined,
37
+ globalVariables: GlobalVariables,
38
+ ): Promise<PublicProcessor> {
39
+ historicalHeader = historicalHeader ?? (await this.merkleTree.buildInitialHeader());
40
+
41
+ const publicContractsDB = new ContractsDataSourcePublicDB(this.contractDataSource);
42
+ const worldStatePublicDB = new WorldStatePublicDB(this.merkleTree);
43
+ const worldStateDB = new WorldStateDB(this.merkleTree, this.l1Tol2MessagesDataSource);
44
+ const publicExecutor = new PublicExecutor(worldStatePublicDB, publicContractsDB, worldStateDB, historicalHeader);
45
+ return new PublicProcessor(
46
+ this.merkleTree,
47
+ publicExecutor,
48
+ new RealPublicKernelCircuitSimulator(),
49
+ new EmptyPublicProver(),
50
+ globalVariables,
51
+ historicalHeader,
52
+ publicContractsDB,
53
+ worldStatePublicDB,
54
+ );
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Converts Txs lifted from the P2P module into ProcessedTx objects by executing
60
+ * any public function calls in them. Txs with private calls only are unaffected.
61
+ */
62
+ export class PublicProcessor {
63
+ constructor(
64
+ protected db: MerkleTreeOperations,
65
+ protected publicExecutor: PublicExecutor,
66
+ protected publicKernel: PublicKernelCircuitSimulator,
67
+ protected publicProver: PublicProver,
68
+ protected globalVariables: GlobalVariables,
69
+ protected historicalHeader: Header,
70
+ protected publicContractsDB: ContractsDataSourcePublicDB,
71
+ protected publicStateDB: PublicStateDB,
72
+
73
+ private log = createDebugLogger('aztec:sequencer:public-processor'),
74
+ ) {}
75
+
76
+ /**
77
+ * Run each tx through the public circuit and the public kernel circuit if needed.
78
+ * @param txs - Txs to process.
79
+ * @returns The list of processed txs with their circuit simulation outputs.
80
+ */
81
+ public async process(txs: Tx[]): Promise<[ProcessedTx[], FailedTx[]]> {
82
+ // The processor modifies the tx objects in place, so we need to clone them.
83
+ txs = txs.map(tx => Tx.clone(tx));
84
+ const result: ProcessedTx[] = [];
85
+ const failed: FailedTx[] = [];
86
+
87
+ for (const tx of txs) {
88
+ let phase: AbstractPhaseManager | undefined = PhaseManagerFactory.phaseFromTx(
89
+ tx,
90
+ this.db,
91
+ this.publicExecutor,
92
+ this.publicKernel,
93
+ this.publicProver,
94
+ this.globalVariables,
95
+ this.historicalHeader,
96
+ this.publicContractsDB,
97
+ this.publicStateDB,
98
+ );
99
+ this.log(`Beginning processing in phase ${phase?.phase} for tx ${tx.getTxHash()}`);
100
+ let { publicKernelPublicInput, publicKernelProof } = AbstractPhaseManager.getKernelOutputAndProof(
101
+ tx,
102
+ undefined,
103
+ undefined,
104
+ );
105
+ const timer = new Timer();
106
+ try {
107
+ while (phase) {
108
+ const output = await phase.handle(tx, publicKernelPublicInput, publicKernelProof);
109
+ publicKernelPublicInput = output.publicKernelOutput;
110
+ publicKernelProof = output.publicKernelProof;
111
+ phase = PhaseManagerFactory.phaseFromOutput(
112
+ publicKernelPublicInput,
113
+ phase,
114
+ this.db,
115
+ this.publicExecutor,
116
+ this.publicKernel,
117
+ this.publicProver,
118
+ this.globalVariables,
119
+ this.historicalHeader,
120
+ this.publicContractsDB,
121
+ this.publicStateDB,
122
+ );
123
+ }
124
+
125
+ const processedTransaction = makeProcessedTx(tx, publicKernelPublicInput, publicKernelProof);
126
+ result.push(processedTransaction);
127
+
128
+ this.log(`Processed public part of ${tx.data.endNonRevertibleData.newNullifiers[0].value}`, {
129
+ eventName: 'tx-sequencer-processing',
130
+ duration: timer.ms(),
131
+ publicDataUpdateRequests:
132
+ processedTransaction.data.combinedData.publicDataUpdateRequests.filter(x => !x.leafSlot.isZero()).length ??
133
+ 0,
134
+ ...tx.getStats(),
135
+ } satisfies TxSequencerProcessingStats);
136
+ } catch (err) {
137
+ const failedTx = await phase!.rollback(tx, err);
138
+ failed.push(failedTx);
139
+ }
140
+ }
141
+
142
+ return [result, failed];
143
+ }
144
+
145
+ /**
146
+ * Makes an empty processed tx. Useful for padding a block to a power of two number of txs.
147
+ * @returns A processed tx with empty data.
148
+ */
149
+ public makeEmptyProcessedTx(): ProcessedTx {
150
+ const { chainId, version } = this.globalVariables;
151
+ return makeEmptyProcessedTx(this.historicalHeader, chainId, version);
152
+ }
153
+ }