@aztec/sequencer-client 0.26.5 → 0.27.0

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 (72) hide show
  1. package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
  2. package/dest/block_builder/solo_block_builder.js +12 -28
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +2 -5
  5. package/dest/index.d.ts +7 -7
  6. package/dest/index.d.ts.map +1 -1
  7. package/dest/index.js +8 -8
  8. package/dest/publisher/l1-publisher.d.ts +1 -21
  9. package/dest/publisher/l1-publisher.d.ts.map +1 -1
  10. package/dest/publisher/l1-publisher.js +1 -55
  11. package/dest/publisher/viem-tx-sender.d.ts +1 -10
  12. package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
  13. package/dest/publisher/viem-tx-sender.js +2 -41
  14. package/dest/sequencer/abstract_phase_manager.d.ts +12 -15
  15. package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
  16. package/dest/sequencer/abstract_phase_manager.js +32 -24
  17. package/dest/sequencer/app_logic_phase_manager.d.ts +1 -6
  18. package/dest/sequencer/app_logic_phase_manager.d.ts.map +1 -1
  19. package/dest/sequencer/app_logic_phase_manager.js +11 -8
  20. package/dest/sequencer/hints_builder.d.ts +13 -0
  21. package/dest/sequencer/hints_builder.d.ts.map +1 -0
  22. package/dest/sequencer/hints_builder.js +21 -0
  23. package/dest/sequencer/index.d.ts +1 -1
  24. package/dest/sequencer/index.d.ts.map +1 -1
  25. package/dest/sequencer/index.js +2 -2
  26. package/dest/sequencer/phase_manager_factory.d.ts.map +1 -1
  27. package/dest/sequencer/phase_manager_factory.js +5 -1
  28. package/dest/sequencer/processed_tx.d.ts +38 -3
  29. package/dest/sequencer/processed_tx.d.ts.map +1 -1
  30. package/dest/sequencer/processed_tx.js +66 -10
  31. package/dest/sequencer/public_processor.d.ts.map +1 -1
  32. package/dest/sequencer/public_processor.js +15 -9
  33. package/dest/sequencer/sequencer.d.ts +0 -6
  34. package/dest/sequencer/sequencer.d.ts.map +1 -1
  35. package/dest/sequencer/sequencer.js +1 -27
  36. package/dest/sequencer/setup_phase_manager.d.ts +1 -6
  37. package/dest/sequencer/setup_phase_manager.d.ts.map +1 -1
  38. package/dest/sequencer/setup_phase_manager.js +3 -5
  39. package/dest/sequencer/tail_phase_manager.d.ts +28 -0
  40. package/dest/sequencer/tail_phase_manager.d.ts.map +1 -0
  41. package/dest/sequencer/tail_phase_manager.js +32 -0
  42. package/dest/sequencer/teardown_phase_manager.d.ts +1 -6
  43. package/dest/sequencer/teardown_phase_manager.d.ts.map +1 -1
  44. package/dest/sequencer/teardown_phase_manager.js +3 -4
  45. package/dest/simulator/index.d.ts +7 -1
  46. package/dest/simulator/index.d.ts.map +1 -1
  47. package/dest/simulator/index.js +1 -1
  48. package/dest/simulator/public_executor.d.ts.map +1 -1
  49. package/dest/simulator/public_executor.js +1 -15
  50. package/dest/simulator/public_kernel.d.ts +7 -1
  51. package/dest/simulator/public_kernel.d.ts.map +1 -1
  52. package/dest/simulator/public_kernel.js +22 -4
  53. package/package.json +13 -13
  54. package/src/block_builder/solo_block_builder.ts +17 -77
  55. package/src/config.ts +0 -4
  56. package/src/index.ts +7 -7
  57. package/src/publisher/l1-publisher.ts +1 -85
  58. package/src/publisher/viem-tx-sender.ts +2 -52
  59. package/src/sequencer/abstract_phase_manager.ts +58 -48
  60. package/src/sequencer/app_logic_phase_manager.ts +12 -22
  61. package/src/sequencer/hints_builder.ts +56 -0
  62. package/src/sequencer/index.ts +1 -1
  63. package/src/sequencer/phase_manager_factory.ts +12 -0
  64. package/src/sequencer/processed_tx.ts +133 -19
  65. package/src/sequencer/public_processor.ts +25 -13
  66. package/src/sequencer/sequencer.ts +0 -36
  67. package/src/sequencer/setup_phase_manager.ts +5 -19
  68. package/src/sequencer/tail_phase_manager.ts +49 -0
  69. package/src/sequencer/teardown_phase_manager.ts +5 -18
  70. package/src/simulator/index.ts +7 -0
  71. package/src/simulator/public_executor.ts +0 -20
  72. package/src/simulator/public_kernel.ts +35 -5
@@ -1,4 +1,4 @@
1
- import { ContractDataSource, L1ToL2MessageSource, Tx } from '@aztec/circuit-types';
1
+ import { ContractDataSource, L1ToL2MessageSource, SimulationError, Tx } from '@aztec/circuit-types';
2
2
  import { TxSequencerProcessingStats } from '@aztec/circuit-types/stats';
3
3
  import { GlobalVariables, Header } from '@aztec/circuits.js';
4
4
  import { createDebugLogger } from '@aztec/foundation/log';
@@ -14,7 +14,14 @@ import { RealPublicKernelCircuitSimulator } from '../simulator/public_kernel.js'
14
14
  import { SimulationProvider } from '../simulator/simulation_provider.js';
15
15
  import { AbstractPhaseManager } from './abstract_phase_manager.js';
16
16
  import { PhaseManagerFactory } from './phase_manager_factory.js';
17
- import { FailedTx, ProcessedTx, makeEmptyProcessedTx, makeProcessedTx } from './processed_tx.js';
17
+ import {
18
+ FailedTx,
19
+ ProcessedTx,
20
+ getPreviousOutputAndProof,
21
+ makeEmptyProcessedTx,
22
+ makeProcessedTx,
23
+ validateProcessedTx,
24
+ } from './processed_tx.js';
18
25
 
19
26
  /**
20
27
  * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
@@ -99,17 +106,15 @@ export class PublicProcessor {
99
106
  this.publicStateDB,
100
107
  );
101
108
  this.log(`Beginning processing in phase ${phase?.phase} for tx ${tx.getTxHash()}`);
102
- let { publicKernelPublicInput, publicKernelProof } = AbstractPhaseManager.getKernelOutputAndProof(
103
- tx,
104
- undefined,
105
- undefined,
106
- );
109
+ let { publicKernelPublicInput, previousProof: proof } = getPreviousOutputAndProof(tx, undefined, undefined);
110
+ let revertReason: SimulationError | undefined;
107
111
  const timer = new Timer();
108
112
  try {
109
113
  while (phase) {
110
- const output = await phase.handle(tx, publicKernelPublicInput, publicKernelProof);
114
+ const output = await phase.handle(tx, publicKernelPublicInput, proof);
111
115
  publicKernelPublicInput = output.publicKernelOutput;
112
- publicKernelProof = output.publicKernelProof;
116
+ proof = output.publicKernelProof;
117
+ revertReason ??= output.revertReason;
113
118
  phase = PhaseManagerFactory.phaseFromOutput(
114
119
  publicKernelPublicInput,
115
120
  phase,
@@ -124,7 +129,9 @@ export class PublicProcessor {
124
129
  );
125
130
  }
126
131
 
127
- const processedTransaction = makeProcessedTx(tx, publicKernelPublicInput, publicKernelProof);
132
+ const processedTransaction = makeProcessedTx(tx, publicKernelPublicInput, proof, revertReason);
133
+ validateProcessedTx(processedTransaction);
134
+
128
135
  result.push(processedTransaction);
129
136
 
130
137
  this.log(`Processed public part of ${tx.data.endNonRevertibleData.newNullifiers[0].value}`, {
@@ -135,9 +142,14 @@ export class PublicProcessor {
135
142
  0,
136
143
  ...tx.getStats(),
137
144
  } satisfies TxSequencerProcessingStats);
138
- } catch (err) {
139
- const failedTx = await phase!.rollback(tx, err);
140
- failed.push(failedTx);
145
+ } catch (err: any) {
146
+ const errorMessage = err instanceof Error ? err.message : 'Unknown error';
147
+ this.log.warn(`Failed to process tx ${tx.getTxHash()}: ${errorMessage}`);
148
+
149
+ failed.push({
150
+ tx,
151
+ error: err instanceof Error ? err : new Error(errorMessage),
152
+ });
141
153
  }
142
154
  }
143
155
 
@@ -180,7 +180,6 @@ export class Sequencer {
180
180
  this.log.info(`Building block ${newBlockNumber} with ${validTxs.length} transactions`);
181
181
  this.state = SequencerState.CREATING_BLOCK;
182
182
 
183
- // Process txs and drop the ones that fail processing
184
183
  // We create a fresh processor each time to reset any cached state (eg storage writes)
185
184
  const processor = await this.publicProcessorFactory.create(historicalHeader, newGlobalVariables);
186
185
  const [publicProcessorDuration, [processedTxs, failedTxs]] = await elapsed(() => processor.process(validTxs));
@@ -228,10 +227,6 @@ export class Sequencer {
228
227
 
229
228
  await assertBlockHeight();
230
229
 
231
- await this.publishExtendedContractData(processedValidTxs, block);
232
-
233
- await assertBlockHeight();
234
-
235
230
  await this.publishL2Block(block);
236
231
  this.log.info(`Submitted rollup block ${block.number} with ${processedValidTxs.length} transactions`);
237
232
  } catch (err) {
@@ -240,37 +235,6 @@ export class Sequencer {
240
235
  }
241
236
  }
242
237
 
243
- /**
244
- * Gets new extended contract data from the txs and publishes it on chain.
245
- * @param validTxs - The set of real transactions being published as part of the block.
246
- * @param block - The L2Block to be published.
247
- */
248
- protected async publishExtendedContractData(validTxs: ProcessedTx[], block: L2Block) {
249
- // Publishes contract data for txs to the network and awaits the tx to be mined
250
- this.state = SequencerState.PUBLISHING_CONTRACT_DATA;
251
- const newContracts = validTxs.flatMap(tx => tx.newContracts).filter(cd => !cd.isEmpty());
252
-
253
- if (newContracts.length === 0) {
254
- this.log.debug(`No new contracts to publish in block ${block.number}`);
255
- return;
256
- }
257
-
258
- const txsEffectsHash = block.body.getTxsEffectsHash();
259
- this.log.info(`Publishing ${newContracts.length} contracts in block ${block.number}`);
260
-
261
- const publishedContractData = await this.publisher.processNewContractData(
262
- block.number,
263
- txsEffectsHash,
264
- newContracts,
265
- );
266
-
267
- if (publishedContractData) {
268
- this.log(`Successfully published new contract data for block ${block.number}`);
269
- } else if (!publishedContractData && newContracts.length) {
270
- this.log(`Failed to publish new contract data for block ${block.number}`);
271
- }
272
- }
273
-
274
238
  /**
275
239
  * Publishes the L2Block to the rollup contract.
276
240
  * @param block - The L2Block to be published.
@@ -27,34 +27,20 @@ export class SetupPhaseManager extends AbstractPhaseManager {
27
27
  super(db, publicExecutor, publicKernel, publicProver, globalVariables, historicalHeader, phase);
28
28
  }
29
29
 
30
- // this is a no-op for now
31
- async handle(
30
+ override async handle(
32
31
  tx: Tx,
33
32
  previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
34
33
  previousPublicKernelProof: Proof,
35
- ): Promise<{
36
- /**
37
- * the output of the public kernel circuit for this phase
38
- */
39
- publicKernelOutput: PublicKernelCircuitPublicInputs;
40
- /**
41
- * the proof of the public kernel circuit for this phase
42
- */
43
- publicKernelProof: Proof;
44
- }> {
34
+ ) {
45
35
  this.log(`Processing tx ${tx.getTxHash()}`);
46
- this.log(`Executing enqueued public calls for tx ${tx.getTxHash()}`);
47
- const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs] = await this.processEnqueuedPublicCalls(
48
- tx,
49
- previousPublicKernelOutput,
50
- previousPublicKernelProof,
51
- );
36
+ const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
37
+ await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof);
52
38
  tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
53
39
 
54
40
  // commit the state updates from this transaction
55
41
  await this.publicStateDB.commit();
56
42
 
57
- return { publicKernelOutput, publicKernelProof };
43
+ return { publicKernelOutput, publicKernelProof, revertReason };
58
44
  }
59
45
 
60
46
  async rollback(tx: Tx, err: unknown): Promise<FailedTx> {
@@ -0,0 +1,49 @@
1
+ import { Tx } from '@aztec/circuit-types';
2
+ import { GlobalVariables, Header, Proof, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
3
+ import { PublicExecutor, PublicStateDB } from '@aztec/simulator';
4
+ import { MerkleTreeOperations } from '@aztec/world-state';
5
+
6
+ import { PublicProver } from '../prover/index.js';
7
+ import { PublicKernelCircuitSimulator } from '../simulator/index.js';
8
+ import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
9
+ import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
10
+ import { FailedTx } from './processed_tx.js';
11
+
12
+ export class TailPhaseManager extends AbstractPhaseManager {
13
+ constructor(
14
+ protected db: MerkleTreeOperations,
15
+ protected publicExecutor: PublicExecutor,
16
+ protected publicKernel: PublicKernelCircuitSimulator,
17
+ protected publicProver: PublicProver,
18
+ protected globalVariables: GlobalVariables,
19
+ protected historicalHeader: Header,
20
+ protected publicContractsDB: ContractsDataSourcePublicDB,
21
+ protected publicStateDB: PublicStateDB,
22
+ public readonly phase: PublicKernelPhase = PublicKernelPhase.TAIL,
23
+ ) {
24
+ super(db, publicExecutor, publicKernel, publicProver, globalVariables, historicalHeader, phase);
25
+ }
26
+
27
+ async handle(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs, previousPublicKernelProof: Proof) {
28
+ this.log(`Processing tx ${tx.getTxHash()}`);
29
+ this.log(`Executing tail circuit for tx ${tx.getTxHash()}`);
30
+ const [publicKernelOutput, publicKernelProof] = await this.runKernelCircuit(
31
+ previousPublicKernelOutput,
32
+ previousPublicKernelProof,
33
+ );
34
+
35
+ // commit the state updates from this transaction
36
+ await this.publicStateDB.commit();
37
+
38
+ return { publicKernelOutput, publicKernelProof, revertReason: undefined };
39
+ }
40
+
41
+ async rollback(tx: Tx, err: unknown): Promise<FailedTx> {
42
+ this.log.warn(`Error processing tx ${tx.getTxHash()}: ${err}`);
43
+ await this.publicStateDB.rollback();
44
+ return {
45
+ tx,
46
+ error: err instanceof Error ? err : new Error('Unknown error'),
47
+ };
48
+ }
49
+ }
@@ -27,33 +27,20 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
27
27
  super(db, publicExecutor, publicKernel, publicProver, globalVariables, historicalHeader, phase);
28
28
  }
29
29
 
30
- async handle(
30
+ override async handle(
31
31
  tx: Tx,
32
32
  previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
33
33
  previousPublicKernelProof: Proof,
34
- ): Promise<{
35
- /**
36
- * the output of the public kernel circuit for this phase
37
- */
38
- publicKernelOutput: PublicKernelCircuitPublicInputs;
39
- /**
40
- * the proof of the public kernel circuit for this phase
41
- */
42
- publicKernelProof: Proof;
43
- }> {
34
+ ) {
44
35
  this.log(`Processing tx ${tx.getTxHash()}`);
45
- this.log(`Executing enqueued public calls for tx ${tx.getTxHash()}`);
46
- const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs] = await this.processEnqueuedPublicCalls(
47
- tx,
48
- previousPublicKernelOutput,
49
- previousPublicKernelProof,
50
- );
36
+ const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
37
+ await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof);
51
38
  tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
52
39
 
53
40
  // commit the state updates from this transaction
54
41
  await this.publicStateDB.commit();
55
42
 
56
- return { publicKernelOutput, publicKernelProof };
43
+ return { publicKernelOutput, publicKernelProof, revertReason };
57
44
  }
58
45
 
59
46
  async rollback(tx: Tx, err: unknown): Promise<FailedTx> {
@@ -4,6 +4,7 @@ import {
4
4
  MergeRollupInputs,
5
5
  PublicKernelCircuitPrivateInputs,
6
6
  PublicKernelCircuitPublicInputs,
7
+ PublicKernelTailCircuitPrivateInputs,
7
8
  RootRollupInputs,
8
9
  RootRollupPublicInputs,
9
10
  } from '@aztec/circuits.js';
@@ -54,5 +55,11 @@ export interface PublicKernelCircuitSimulator {
54
55
  * @returns The public inputs as outputs of the simulation.
55
56
  */
56
57
  publicKernelCircuitTeardown(inputs: PublicKernelCircuitPrivateInputs): Promise<PublicKernelCircuitPublicInputs>;
58
+ /**
59
+ * Simulates the public kernel tail circuit from its inputs.
60
+ * @param inputs - Inputs to the circuit.
61
+ * @returns The public inputs as outputs of the simulation.
62
+ */
63
+ publicKernelCircuitTail(inputs: PublicKernelTailCircuitPrivateInputs): Promise<PublicKernelCircuitPublicInputs>;
57
64
  }
58
65
  export * from './acvm_wasm.js';
@@ -45,16 +45,6 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
45
45
  * @param tx - The transaction to add contracts from.
46
46
  */
47
47
  public addNewContracts(tx: Tx): Promise<void> {
48
- for (const contract of tx.newContracts) {
49
- const contractAddress = contract.contractData.contractAddress;
50
-
51
- if (contractAddress.isZero()) {
52
- continue;
53
- }
54
-
55
- this.cache.set(contractAddress.toString(), contract);
56
- }
57
-
58
48
  // Extract contract class and instance data from logs and add to cache for this block
59
49
  const logs = tx.unencryptedLogs.unrollLogs().map(UnencryptedL2Log.fromBuffer);
60
50
  ContractClassRegisteredEvent.fromLogs(logs, ClassRegistererAddress).forEach(e => {
@@ -76,16 +66,6 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
76
66
  * @param tx - The tx's contracts to be removed
77
67
  */
78
68
  public removeNewContracts(tx: Tx): Promise<void> {
79
- for (const contract of tx.newContracts) {
80
- const contractAddress = contract.contractData.contractAddress;
81
-
82
- if (contractAddress.isZero()) {
83
- continue;
84
- }
85
-
86
- this.cache.delete(contractAddress.toString());
87
- }
88
-
89
69
  // TODO(@spalladino): Can this inadvertently delete a valid contract added by another tx?
90
70
  // Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
91
71
  // wouldn't that accidentally remove the contract added on the first one?
@@ -1,17 +1,24 @@
1
1
  import { CircuitSimulationStats } from '@aztec/circuit-types/stats';
2
- import { PublicKernelCircuitPrivateInputs, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
2
+ import {
3
+ PublicKernelCircuitPrivateInputs,
4
+ PublicKernelCircuitPublicInputs,
5
+ PublicKernelTailCircuitPrivateInputs,
6
+ } from '@aztec/circuits.js';
3
7
  import { createDebugLogger } from '@aztec/foundation/log';
4
8
  import { elapsed } from '@aztec/foundation/timer';
5
9
  import {
6
10
  PublicKernelAppLogicArtifact,
7
11
  PublicKernelSetupArtifact,
12
+ PublicKernelTailArtifact,
8
13
  PublicKernelTeardownArtifact,
9
14
  convertPublicInnerRollupInputsToWitnessMap,
10
15
  convertPublicInnerRollupOutputFromWitnessMap,
11
16
  convertPublicSetupRollupInputsToWitnessMap,
12
17
  convertPublicSetupRollupOutputFromWitnessMap,
13
- convertPublicTailRollupInputsToWitnessMap,
14
- convertPublicTailRollupOutputFromWitnessMap,
18
+ convertPublicTailInputsToWitnessMap,
19
+ convertPublicTailOutputFromWitnessMap,
20
+ convertPublicTeardownRollupInputsToWitnessMap,
21
+ convertPublicTeardownRollupOutputFromWitnessMap,
15
22
  } from '@aztec/noir-protocol-circuits-types';
16
23
 
17
24
  import { PublicKernelCircuitSimulator, WASMSimulator } from './index.js';
@@ -91,11 +98,11 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
91
98
  if (!input.previousKernel.publicInputs.needsTeardown) {
92
99
  throw new Error(`Expected previous kernel inputs to need teardown`);
93
100
  }
94
- const inputWitness = convertPublicTailRollupInputsToWitnessMap(input);
101
+ const inputWitness = convertPublicTeardownRollupInputsToWitnessMap(input);
95
102
  const [duration, witness] = await elapsed(() =>
96
103
  this.wasmSimulator.simulateCircuit(inputWitness, PublicKernelTeardownArtifact),
97
104
  );
98
- const result = convertPublicTailRollupOutputFromWitnessMap(witness);
105
+ const result = convertPublicTeardownRollupOutputFromWitnessMap(witness);
99
106
  this.log(`Simulated public kernel teardown circuit`, {
100
107
  eventName: 'circuit-simulation',
101
108
  circuitName: 'public-kernel-teardown',
@@ -105,4 +112,27 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
105
112
  } satisfies CircuitSimulationStats);
106
113
  return result;
107
114
  }
115
+
116
+ /**
117
+ * Simulates the public kernel tail circuit from its inputs.
118
+ * @param input - Inputs to the circuit.
119
+ * @returns The public inputs as outputs of the simulation.
120
+ */
121
+ public async publicKernelCircuitTail(
122
+ input: PublicKernelTailCircuitPrivateInputs,
123
+ ): Promise<PublicKernelCircuitPublicInputs> {
124
+ const inputWitness = convertPublicTailInputsToWitnessMap(input);
125
+ const [duration, witness] = await elapsed(() =>
126
+ this.wasmSimulator.simulateCircuit(inputWitness, PublicKernelTailArtifact),
127
+ );
128
+ const result = convertPublicTailOutputFromWitnessMap(witness);
129
+ this.log(`Simulated public kernel tail circuit`, {
130
+ eventName: 'circuit-simulation',
131
+ circuitName: 'public-kernel-tail',
132
+ duration,
133
+ inputSize: input.toBuffer().length,
134
+ outputSize: result.toBuffer().length,
135
+ } satisfies CircuitSimulationStats);
136
+ return result;
137
+ }
108
138
  }