@aztec/sequencer-client 0.27.2 → 0.28.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 (55) hide show
  1. package/dest/block_builder/index.d.ts +3 -1
  2. package/dest/block_builder/index.d.ts.map +1 -1
  3. package/dest/block_builder/solo_block_builder.d.ts +10 -5
  4. package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
  5. package/dest/block_builder/solo_block_builder.js +119 -52
  6. package/dest/prover/empty.d.ts +13 -1
  7. package/dest/prover/empty.d.ts.map +1 -1
  8. package/dest/prover/empty.js +19 -1
  9. package/dest/prover/index.d.ts +14 -2
  10. package/dest/prover/index.d.ts.map +1 -1
  11. package/dest/sequencer/abstract_phase_manager.d.ts +0 -2
  12. package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
  13. package/dest/sequencer/abstract_phase_manager.js +30 -7
  14. package/dest/sequencer/app_logic_phase_manager.d.ts +0 -2
  15. package/dest/sequencer/app_logic_phase_manager.d.ts.map +1 -1
  16. package/dest/sequencer/app_logic_phase_manager.js +10 -15
  17. package/dest/sequencer/sequencer.d.ts +4 -1
  18. package/dest/sequencer/sequencer.d.ts.map +1 -1
  19. package/dest/sequencer/sequencer.js +8 -4
  20. package/dest/sequencer/setup_phase_manager.d.ts +0 -2
  21. package/dest/sequencer/setup_phase_manager.d.ts.map +1 -1
  22. package/dest/sequencer/setup_phase_manager.js +8 -12
  23. package/dest/sequencer/tail_phase_manager.d.ts +0 -2
  24. package/dest/sequencer/tail_phase_manager.d.ts.map +1 -1
  25. package/dest/sequencer/tail_phase_manager.js +7 -11
  26. package/dest/sequencer/teardown_phase_manager.d.ts +0 -2
  27. package/dest/sequencer/teardown_phase_manager.d.ts.map +1 -1
  28. package/dest/sequencer/teardown_phase_manager.js +8 -12
  29. package/dest/sequencer/utils.d.ts +8 -0
  30. package/dest/sequencer/utils.d.ts.map +1 -0
  31. package/dest/sequencer/utils.js +28 -0
  32. package/dest/simulator/index.d.ts +13 -1
  33. package/dest/simulator/index.d.ts.map +1 -1
  34. package/dest/simulator/index.js +1 -1
  35. package/dest/simulator/public_executor.d.ts +6 -3
  36. package/dest/simulator/public_executor.d.ts.map +1 -1
  37. package/dest/simulator/public_executor.js +36 -15
  38. package/dest/simulator/rollup.d.ts +13 -1
  39. package/dest/simulator/rollup.d.ts.map +1 -1
  40. package/dest/simulator/rollup.js +24 -2
  41. package/package.json +13 -13
  42. package/src/block_builder/index.ts +3 -1
  43. package/src/block_builder/solo_block_builder.ts +150 -52
  44. package/src/prover/empty.ts +23 -0
  45. package/src/prover/index.ts +18 -1
  46. package/src/sequencer/abstract_phase_manager.ts +37 -8
  47. package/src/sequencer/app_logic_phase_manager.ts +10 -16
  48. package/src/sequencer/sequencer.ts +12 -3
  49. package/src/sequencer/setup_phase_manager.ts +8 -15
  50. package/src/sequencer/tail_phase_manager.ts +6 -11
  51. package/src/sequencer/teardown_phase_manager.ts +8 -15
  52. package/src/sequencer/utils.ts +30 -0
  53. package/src/simulator/index.ts +15 -0
  54. package/src/simulator/public_executor.ts +37 -14
  55. package/src/simulator/rollup.ts +39 -0
@@ -7,7 +7,6 @@ import { PublicProver } from '../prover/index.js';
7
7
  import { PublicKernelCircuitSimulator } from '../simulator/index.js';
8
8
  import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
9
9
  import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
10
- import { FailedTx } from './processed_tx.js';
11
10
 
12
11
  /**
13
12
  * The phase manager responsible for performing the fee preparation phase.
@@ -34,21 +33,15 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
34
33
  ) {
35
34
  this.log(`Processing tx ${tx.getTxHash()}`);
36
35
  const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
37
- await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof);
36
+ await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
37
+ // the abstract phase manager throws if simulation gives error in a non-revertible phase
38
+ async err => {
39
+ await this.publicStateDB.rollbackToCommit();
40
+ throw err;
41
+ },
42
+ );
38
43
  tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
39
-
40
- // commit the state updates from this transaction
41
- await this.publicStateDB.commit();
42
-
44
+ await this.publicStateDB.checkpoint();
43
45
  return { publicKernelOutput, publicKernelProof, revertReason };
44
46
  }
45
-
46
- async rollback(tx: Tx, err: unknown): Promise<FailedTx> {
47
- this.log.warn(`Error processing tx ${tx.getTxHash()}: ${err}`);
48
- await this.publicStateDB.rollback();
49
- return {
50
- tx,
51
- error: err instanceof Error ? err : new Error('Unknown error'),
52
- };
53
- }
54
47
  }
@@ -0,0 +1,30 @@
1
+ import { Tx } from '@aztec/circuit-types';
2
+ import { CallRequest } from '@aztec/circuits.js';
3
+
4
+ /**
5
+ * Looks at the side effects of a transaction and returns the highest counter
6
+ * @param tx - A transaction
7
+ * @returns The highest side effect counter in the transaction so far
8
+ */
9
+ export function lastSideEffectCounter(tx: Tx): number {
10
+ const sideEffectCounters = [
11
+ ...tx.data.endNonRevertibleData.newNoteHashes,
12
+ ...tx.data.endNonRevertibleData.newNullifiers,
13
+ ...tx.data.endNonRevertibleData.publicCallStack,
14
+ ...tx.data.end.newNoteHashes,
15
+ ...tx.data.end.newNullifiers,
16
+ ...tx.data.end.publicCallStack,
17
+ ];
18
+
19
+ let max = 0;
20
+ for (const sideEffect of sideEffectCounters) {
21
+ if (sideEffect instanceof CallRequest) {
22
+ // look at both start and end counters because for enqueued public calls start > 0 while end === 0
23
+ max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber());
24
+ } else {
25
+ max = Math.max(max, sideEffect.counter.toNumber());
26
+ }
27
+ }
28
+
29
+ return max;
30
+ }
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  BaseOrMergeRollupPublicInputs,
3
+ BaseParityInputs,
3
4
  BaseRollupInputs,
4
5
  MergeRollupInputs,
6
+ ParityPublicInputs,
5
7
  PublicKernelCircuitPrivateInputs,
6
8
  PublicKernelCircuitPublicInputs,
7
9
  PublicKernelTailCircuitPrivateInputs,
10
+ RootParityInputs,
8
11
  RootRollupInputs,
9
12
  RootRollupPublicInputs,
10
13
  } from '@aztec/circuits.js';
@@ -13,6 +16,18 @@ import {
13
16
  * Circuit simulator for the rollup circuits.
14
17
  */
15
18
  export interface RollupSimulator {
19
+ /**
20
+ * Simulates the base parity circuit from its inputs.
21
+ * @param inputs - Inputs to the circuit.
22
+ * @returns The public inputs of the parity circuit.
23
+ */
24
+ baseParityCircuit(inputs: BaseParityInputs): Promise<ParityPublicInputs>;
25
+ /**
26
+ * Simulates the root parity circuit from its inputs.
27
+ * @param inputs - Inputs to the circuit.
28
+ * @returns The public inputs of the parity circuit.
29
+ */
30
+ rootParityCircuit(inputs: RootParityInputs): Promise<ParityPublicInputs>;
16
31
  /**
17
32
  * Simulates the base rollup circuit from its inputs.
18
33
  * @param input - Inputs to the circuit.
@@ -130,8 +130,9 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
130
130
  * Implements the PublicStateDB using a world-state database.
131
131
  */
132
132
  export class WorldStatePublicDB implements PublicStateDB {
133
- private commitedWriteCache: Map<bigint, Fr> = new Map();
134
- private uncommitedWriteCache: Map<bigint, Fr> = new Map();
133
+ private committedWriteCache: Map<bigint, Fr> = new Map();
134
+ private checkpointedWriteCache: Map<bigint, Fr> = new Map();
135
+ private uncommittedWriteCache: Map<bigint, Fr> = new Map();
135
136
 
136
137
  constructor(private db: MerkleTreeOperations) {}
137
138
 
@@ -143,13 +144,17 @@ export class WorldStatePublicDB implements PublicStateDB {
143
144
  */
144
145
  public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
145
146
  const leafSlot = computePublicDataTreeLeafSlot(contract, slot).value;
146
- const uncommited = this.uncommitedWriteCache.get(leafSlot);
147
- if (uncommited !== undefined) {
148
- return uncommited;
147
+ const uncommitted = this.uncommittedWriteCache.get(leafSlot);
148
+ if (uncommitted !== undefined) {
149
+ return uncommitted;
149
150
  }
150
- const commited = this.commitedWriteCache.get(leafSlot);
151
- if (commited !== undefined) {
152
- return commited;
151
+ const checkpointed = this.checkpointedWriteCache.get(leafSlot);
152
+ if (checkpointed !== undefined) {
153
+ return checkpointed;
154
+ }
155
+ const committed = this.committedWriteCache.get(leafSlot);
156
+ if (committed !== undefined) {
157
+ return committed;
153
158
  }
154
159
 
155
160
  const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
@@ -173,7 +178,7 @@ export class WorldStatePublicDB implements PublicStateDB {
173
178
  */
174
179
  public storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void> {
175
180
  const index = computePublicDataTreeLeafSlot(contract, slot).value;
176
- this.uncommitedWriteCache.set(index, newValue);
181
+ this.uncommittedWriteCache.set(index, newValue);
177
182
  return Promise.resolve();
178
183
  }
179
184
 
@@ -182,18 +187,36 @@ export class WorldStatePublicDB implements PublicStateDB {
182
187
  * @returns Nothing.
183
188
  */
184
189
  commit(): Promise<void> {
185
- for (const [k, v] of this.uncommitedWriteCache) {
186
- this.commitedWriteCache.set(k, v);
190
+ for (const [k, v] of this.checkpointedWriteCache) {
191
+ this.committedWriteCache.set(k, v);
192
+ }
193
+ // uncommitted writes take precedence over checkpointed writes
194
+ // since they are the most recent
195
+ for (const [k, v] of this.uncommittedWriteCache) {
196
+ this.committedWriteCache.set(k, v);
187
197
  }
188
- return this.rollback();
198
+ return this.rollbackToCommit();
189
199
  }
190
200
 
191
201
  /**
192
202
  * Rollback the pending changes.
193
203
  * @returns Nothing.
194
204
  */
195
- rollback(): Promise<void> {
196
- this.uncommitedWriteCache = new Map<bigint, Fr>();
205
+ async rollbackToCommit(): Promise<void> {
206
+ await this.rollbackToCheckpoint();
207
+ this.checkpointedWriteCache = new Map<bigint, Fr>();
208
+ return Promise.resolve();
209
+ }
210
+
211
+ checkpoint(): Promise<void> {
212
+ for (const [k, v] of this.uncommittedWriteCache) {
213
+ this.checkpointedWriteCache.set(k, v);
214
+ }
215
+ return this.rollbackToCheckpoint();
216
+ }
217
+
218
+ rollbackToCheckpoint(): Promise<void> {
219
+ this.uncommittedWriteCache = new Map<bigint, Fr>();
197
220
  return Promise.resolve();
198
221
  }
199
222
  }
@@ -1,21 +1,30 @@
1
1
  import { CircuitSimulationStats } from '@aztec/circuit-types/stats';
2
2
  import {
3
3
  BaseOrMergeRollupPublicInputs,
4
+ BaseParityInputs,
4
5
  BaseRollupInputs,
5
6
  MergeRollupInputs,
7
+ ParityPublicInputs,
8
+ RootParityInputs,
6
9
  RootRollupInputs,
7
10
  RootRollupPublicInputs,
8
11
  } from '@aztec/circuits.js';
9
12
  import { createDebugLogger } from '@aztec/foundation/log';
10
13
  import { elapsed } from '@aztec/foundation/timer';
11
14
  import {
15
+ BaseParityArtifact,
12
16
  BaseRollupArtifact,
13
17
  MergeRollupArtifact,
18
+ RootParityArtifact,
14
19
  RootRollupArtifact,
20
+ convertBaseParityInputsToWitnessMap,
21
+ convertBaseParityOutputsFromWitnessMap,
15
22
  convertBaseRollupInputsToWitnessMap,
16
23
  convertBaseRollupOutputsFromWitnessMap,
17
24
  convertMergeRollupInputsToWitnessMap,
18
25
  convertMergeRollupOutputsFromWitnessMap,
26
+ convertRootParityInputsToWitnessMap,
27
+ convertRootParityOutputsFromWitnessMap,
19
28
  convertRootRollupInputsToWitnessMap,
20
29
  convertRootRollupOutputsFromWitnessMap,
21
30
  } from '@aztec/noir-protocol-circuits-types';
@@ -34,6 +43,36 @@ export class RealRollupCircuitSimulator implements RollupSimulator {
34
43
 
35
44
  constructor(private simulationProvider: SimulationProvider) {}
36
45
 
46
+ /**
47
+ * Simulates the base parity circuit from its inputs.
48
+ * @param inputs - Inputs to the circuit.
49
+ * @returns The public inputs of the parity circuit.
50
+ */
51
+ public async baseParityCircuit(inputs: BaseParityInputs): Promise<ParityPublicInputs> {
52
+ const witnessMap = convertBaseParityInputsToWitnessMap(inputs);
53
+
54
+ const witness = await this.simulationProvider.simulateCircuit(witnessMap, BaseParityArtifact);
55
+
56
+ const result = convertBaseParityOutputsFromWitnessMap(witness);
57
+
58
+ return Promise.resolve(result);
59
+ }
60
+
61
+ /**
62
+ * Simulates the root parity circuit from its inputs.
63
+ * @param inputs - Inputs to the circuit.
64
+ * @returns The public inputs of the parity circuit.
65
+ */
66
+ public async rootParityCircuit(inputs: RootParityInputs): Promise<ParityPublicInputs> {
67
+ const witnessMap = convertRootParityInputsToWitnessMap(inputs);
68
+
69
+ const witness = await this.simulationProvider.simulateCircuit(witnessMap, RootParityArtifact);
70
+
71
+ const result = convertRootParityOutputsFromWitnessMap(witness);
72
+
73
+ return Promise.resolve(result);
74
+ }
75
+
37
76
  /**
38
77
  * Simulates the base rollup circuit from its inputs.
39
78
  * @param input - Inputs to the circuit.