@aztec/sequencer-client 0.14.2 → 0.15.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.
@@ -8,7 +8,6 @@ import {
8
8
  } from '@aztec/acir-simulator';
9
9
  import {
10
10
  AztecAddress,
11
- CircuitsWasm,
12
11
  CombinedAccumulatedData,
13
12
  ContractStorageRead,
14
13
  ContractStorageUpdateRequest,
@@ -38,7 +37,7 @@ import {
38
37
  VK_TREE_HEIGHT,
39
38
  } from '@aztec/circuits.js';
40
39
  import { computeCallStackItemHash, computeVarArgsHash } from '@aztec/circuits.js/abis';
41
- import { arrayNonEmptyLength, isArrayEmpty, padArrayEnd, padArrayStart } from '@aztec/foundation/collection';
40
+ import { arrayNonEmptyLength, isArrayEmpty, padArrayEnd } from '@aztec/foundation/collection';
42
41
  import { createDebugLogger } from '@aztec/foundation/log';
43
42
  import { Tuple, mapTuple, to2Fields } from '@aztec/foundation/serialize';
44
43
  import { ContractDataSource, FunctionL2Logs, L1ToL2MessageSource, MerkleTreeId, Tx } from '@aztec/types';
@@ -160,7 +159,9 @@ export class PublicProcessor {
160
159
 
161
160
  protected async processEnqueuedPublicCalls(tx: Tx): Promise<[PublicKernelPublicInputs, Proof, FunctionL2Logs[]]> {
162
161
  this.log(`Executing enqueued public calls for tx ${await tx.getTxHash()}`);
163
- if (!tx.enqueuedPublicFunctionCalls) throw new Error(`Missing preimages for enqueued public calls`);
162
+ if (!tx.enqueuedPublicFunctionCalls) {
163
+ throw new Error(`Missing preimages for enqueued public calls`);
164
+ }
164
165
 
165
166
  let kernelOutput = new KernelCircuitPublicInputs(
166
167
  CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end),
@@ -197,11 +198,13 @@ export class PublicProcessor {
197
198
 
198
199
  [kernelOutput, kernelProof] = await this.runKernelCircuit(callData, kernelOutput, kernelProof);
199
200
 
200
- if (!enqueuedExecutionResult) enqueuedExecutionResult = result;
201
+ if (!enqueuedExecutionResult) {
202
+ enqueuedExecutionResult = result;
203
+ }
201
204
  }
202
205
  // HACK(#1622): Manually patches the ordering of public state actions
203
206
  // TODO(#757): Enforce proper ordering of public state actions
204
- await this.patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!);
207
+ this.patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!);
205
208
  }
206
209
 
207
210
  return [kernelOutput, kernelProof, newUnencryptedFunctionLogs];
@@ -249,10 +252,9 @@ export class PublicProcessor {
249
252
  this.blockData.publicDataTreeRoot = Fr.fromBuffer(publicDataTreeInfo.root);
250
253
 
251
254
  const callStackPreimages = await this.getPublicCallStackPreimages(result);
252
- const wasm = await CircuitsWasm.get();
253
255
 
254
256
  const publicCallStack = mapTuple(callStackPreimages, item =>
255
- item.isEmpty() ? Fr.zero() : computeCallStackItemHash(wasm, item),
257
+ item.isEmpty() ? Fr.ZERO : computeCallStackItemHash(item),
256
258
  );
257
259
 
258
260
  // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) --> set this in Noir
@@ -262,7 +264,7 @@ export class PublicProcessor {
262
264
  return PublicCircuitPublicInputs.from({
263
265
  callContext: result.execution.callContext,
264
266
  proverAddress: AztecAddress.ZERO,
265
- argsHash: await computeVarArgsHash(wasm, result.execution.args),
267
+ argsHash: computeVarArgsHash(result.execution.args),
266
268
  newCommitments: padArrayEnd(result.newCommitments, Fr.ZERO, MAX_NEW_COMMITMENTS_PER_CALL),
267
269
  newNullifiers: padArrayEnd(result.newNullifiers, Fr.ZERO, MAX_NEW_NULLIFIERS_PER_CALL),
268
270
  newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, Fr.ZERO, MAX_NEW_L2_TO_L1_MSGS_PER_CALL),
@@ -302,8 +304,8 @@ export class PublicProcessor {
302
304
  );
303
305
  }
304
306
 
305
- // Top of the stack is at the end of the array, so we padStart
306
- return padArrayStart(preimages, PublicCallStackItem.empty(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL);
307
+ // note this was previously padArrayStart in the cpp kernel, logic was updated in noir translation
308
+ return padArrayEnd(preimages, PublicCallStackItem.empty(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL);
307
309
  }
308
310
 
309
311
  protected getBytecodeHash(_result: PublicExecutionResult) {
@@ -345,14 +347,10 @@ export class PublicProcessor {
345
347
  * @param publicInputs - to be patched here: public inputs to the kernel iteration up to this point
346
348
  * @param execResult - result of the top/first execution for this enqueued public call
347
349
  */
348
- private async patchPublicStorageActionOrdering(
349
- publicInputs: KernelCircuitPublicInputs,
350
- execResult: PublicExecutionResult,
351
- ) {
350
+ private patchPublicStorageActionOrdering(publicInputs: KernelCircuitPublicInputs, execResult: PublicExecutionResult) {
352
351
  // Convert ContractStorage* objects to PublicData* objects and sort them in execution order
353
- const wasm = await CircuitsWasm.get();
354
- const simPublicDataReads = collectPublicDataReads(wasm, execResult);
355
- const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(wasm, execResult);
352
+ const simPublicDataReads = collectPublicDataReads(execResult);
353
+ const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(execResult);
356
354
 
357
355
  const { publicDataReads, publicDataUpdateRequests } = publicInputs.end; // from kernel
358
356
 
@@ -56,9 +56,15 @@ export class Sequencer {
56
56
  * @param config - New parameters.
57
57
  */
58
58
  public updateConfig(config: SequencerConfig) {
59
- if (config.transactionPollingIntervalMS) this.pollingIntervalMs = config.transactionPollingIntervalMS;
60
- if (config.maxTxsPerBlock) this.maxTxsPerBlock = config.maxTxsPerBlock;
61
- if (config.minTxsPerBlock) this.minTxsPerBLock = config.minTxsPerBlock;
59
+ if (config.transactionPollingIntervalMS) {
60
+ this.pollingIntervalMs = config.transactionPollingIntervalMS;
61
+ }
62
+ if (config.maxTxsPerBlock) {
63
+ this.maxTxsPerBlock = config.maxTxsPerBlock;
64
+ }
65
+ if (config.minTxsPerBlock) {
66
+ this.minTxsPerBLock = config.minTxsPerBlock;
67
+ }
62
68
  }
63
69
 
64
70
  /**
@@ -119,14 +125,18 @@ export class Sequencer {
119
125
  }
120
126
 
121
127
  // Do not go forward with new block if the previous one has not been mined and processed
122
- if (!prevBlockSynced) return;
128
+ if (!prevBlockSynced) {
129
+ return;
130
+ }
123
131
 
124
132
  const workTimer = new Timer();
125
133
  this.state = SequencerState.WAITING_FOR_TXS;
126
134
 
127
135
  // Get txs to build the new block
128
136
  const pendingTxs = await this.p2pClient.getTxs();
129
- if (pendingTxs.length < this.minTxsPerBLock) return;
137
+ if (pendingTxs.length < this.minTxsPerBLock) {
138
+ return;
139
+ }
130
140
  this.log.info(`Retrieved ${pendingTxs.length} txs from P2P pool`);
131
141
 
132
142
  const blockNumber = (await this.l2BlockSource.getBlockNumber()) + 1;
@@ -146,7 +156,9 @@ export class Sequencer {
146
156
  // Filter out invalid txs
147
157
  // TODO: It should be responsibility of the P2P layer to validate txs before passing them on here
148
158
  const validTxs = await this.takeValidTxs(pendingTxs, newGlobalVariables);
149
- if (validTxs.length < this.minTxsPerBLock) return;
159
+ if (validTxs.length < this.minTxsPerBLock) {
160
+ return;
161
+ }
150
162
 
151
163
  this.log.info(`Building block ${blockNumber} with ${validTxs.length} transactions`);
152
164
  this.state = SequencerState.CREATING_BLOCK;
@@ -284,7 +296,9 @@ export class Sequencer {
284
296
 
285
297
  tx.data.end.newNullifiers.forEach(n => thisBlockNullifiers.add(n.toBigInt()));
286
298
  validTxs.push(tx);
287
- if (validTxs.length >= this.maxTxsPerBlock) break;
299
+ if (validTxs.length >= this.maxTxsPerBlock) {
300
+ break;
301
+ }
288
302
  }
289
303
 
290
304
  // Make sure we remove these from the tx pool so we do not consider it again
@@ -373,13 +387,17 @@ export class Sequencer {
373
387
 
374
388
  // Ditch this tx if it has a repeated nullifiers
375
389
  const uniqNullifiers = new Set(newNullifiers.map(n => n.toBigInt()));
376
- if (uniqNullifiers.size !== newNullifiers.length) return true;
390
+ if (uniqNullifiers.size !== newNullifiers.length) {
391
+ return true;
392
+ }
377
393
 
378
394
  for (const nullifier of newNullifiers) {
379
395
  // TODO(AD): this is an exhaustive search currently
380
396
  const db = this.worldState.getLatest();
381
397
  const indexInDb = await db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
382
- if (indexInDb !== undefined) return true;
398
+ if (indexInDb !== undefined) {
399
+ return true;
400
+ }
383
401
  }
384
402
  return false;
385
403
  }
@@ -1,4 +1,4 @@
1
- import { CircuitsWasm, Fr, GlobalVariables, HistoricBlockData } from '@aztec/circuits.js';
1
+ import { Fr, GlobalVariables, HistoricBlockData } from '@aztec/circuits.js';
2
2
  import { computeGlobalsHash } from '@aztec/circuits.js/abis';
3
3
  import { MerkleTreeOperations } from '@aztec/world-state';
4
4
 
@@ -9,8 +9,7 @@ export async function getHistoricBlockData(
9
9
  db: MerkleTreeOperations,
10
10
  prevBlockGlobalVariables: GlobalVariables = GlobalVariables.empty(),
11
11
  ) {
12
- const wasm = await CircuitsWasm.get();
13
- const prevGlobalsHash = computeGlobalsHash(wasm, prevBlockGlobalVariables);
12
+ const prevGlobalsHash = computeGlobalsHash(prevBlockGlobalVariables);
14
13
  const roots = await db.getTreeRoots();
15
14
 
16
15
  return new HistoricBlockData(
@@ -5,7 +5,7 @@ import {
5
5
  PublicExecutor,
6
6
  PublicStateDB,
7
7
  } from '@aztec/acir-simulator';
8
- import { AztecAddress, CircuitsWasm, EthAddress, Fr, FunctionSelector, HistoricBlockData } from '@aztec/circuits.js';
8
+ import { AztecAddress, EthAddress, Fr, FunctionSelector, HistoricBlockData } from '@aztec/circuits.js';
9
9
  import { computePublicDataTreeIndex } from '@aztec/circuits.js/abis';
10
10
  import { ContractDataSource, ExtendedContractData, L1ToL2MessageSource, MerkleTreeId, Tx } from '@aztec/types';
11
11
  import { MerkleTreeOperations } from '@aztec/world-state';
@@ -107,9 +107,11 @@ class WorldStatePublicDB implements PublicStateDB {
107
107
  * @returns The current value in the storage slot.
108
108
  */
109
109
  public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
110
- const index = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, slot).value;
110
+ const index = computePublicDataTreeIndex(contract, slot).value;
111
111
  const cached = this.writeCache.get(index);
112
- if (cached !== undefined) return cached;
112
+ if (cached !== undefined) {
113
+ return cached;
114
+ }
113
115
  const value = await this.db.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, index);
114
116
  return value ? Fr.fromBuffer(value) : Fr.ZERO;
115
117
  }
@@ -120,9 +122,10 @@ class WorldStatePublicDB implements PublicStateDB {
120
122
  * @param slot - Slot to read in the contract storage.
121
123
  * @param newValue - The new value to store.
122
124
  */
123
- public async storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void> {
124
- const index = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, slot).value;
125
+ public storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void> {
126
+ const index = computePublicDataTreeIndex(contract, slot).value;
125
127
  this.writeCache.set(index, newValue);
128
+ return Promise.resolve();
126
129
  }
127
130
  }
128
131
 
@@ -1,6 +1,7 @@
1
- import { PublicKernelInputs, PublicKernelPublicInputs, simulatePublicKernelCircuit } from '@aztec/circuits.js';
1
+ import { PublicKernelInputs, PublicKernelPublicInputs } from '@aztec/circuits.js';
2
2
  import { createDebugLogger } from '@aztec/foundation/log';
3
3
  import { elapsed } from '@aztec/foundation/timer';
4
+ import { executePublicKernelPrivatePrevious, executePublicKernelPublicPrevious } from '@aztec/noir-protocol-circuits';
4
5
  import { CircuitSimulationStats } from '@aztec/types/stats';
5
6
 
6
7
  import { PublicKernelCircuitSimulator } from './index.js';
@@ -17,8 +18,10 @@ export class WasmPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
17
18
  * @returns The public inputs as outputs of the simulation.
18
19
  */
19
20
  public async publicKernelCircuitPrivateInput(input: PublicKernelInputs): Promise<PublicKernelPublicInputs> {
20
- if (!input.previousKernel.publicInputs.isPrivate) throw new Error(`Expected private kernel previous inputs`);
21
- const [duration, result] = await elapsed(() => simulatePublicKernelCircuit(input));
21
+ if (!input.previousKernel.publicInputs.isPrivate) {
22
+ throw new Error(`Expected private kernel previous inputs`);
23
+ }
24
+ const [duration, result] = await elapsed(() => executePublicKernelPrivatePrevious(input));
22
25
  this.log(`Simulated public kernel circuit with private input`, {
23
26
  eventName: 'circuit-simulation',
24
27
  circuitName: 'public-kernel-private-input',
@@ -35,8 +38,10 @@ export class WasmPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
35
38
  * @returns The public inputs as outputs of the simulation.
36
39
  */
37
40
  public async publicKernelCircuitNonFirstIteration(input: PublicKernelInputs): Promise<PublicKernelPublicInputs> {
38
- if (input.previousKernel.publicInputs.isPrivate) throw new Error(`Expected public kernel previous inputs`);
39
- const [duration, result] = await elapsed(() => simulatePublicKernelCircuit(input));
41
+ if (input.previousKernel.publicInputs.isPrivate) {
42
+ throw new Error(`Expected public kernel previous inputs`);
43
+ }
44
+ const [duration, result] = await elapsed(() => executePublicKernelPublicPrevious(input));
40
45
  this.log(`Simulated public kernel circuit non-first iteration`, {
41
46
  eventName: 'circuit-simulation',
42
47
  circuitName: 'public-kernel-non-first-iteration',
@@ -7,11 +7,10 @@ import {
7
7
  RootRollupInputs,
8
8
  RootRollupPublicInputs,
9
9
  baseRollupSim,
10
- mergeRollupSim,
11
- rootRollupSim,
12
10
  } from '@aztec/circuits.js';
13
11
  import { createDebugLogger } from '@aztec/foundation/log';
14
12
  import { elapsed } from '@aztec/foundation/timer';
13
+ import { executeMergeRollup, executeRootRollup } from '@aztec/noir-protocol-circuits';
15
14
  import { CircuitSimulationStats } from '@aztec/types/stats';
16
15
 
17
16
  import { RollupSimulator } from './index.js';
@@ -50,11 +49,7 @@ export class WasmRollupCircuitSimulator implements RollupSimulator {
50
49
  * @returns The public inputs as outputs of the simulation.
51
50
  */
52
51
  public async mergeRollupCircuit(input: MergeRollupInputs): Promise<BaseOrMergeRollupPublicInputs> {
53
- const wasm = await CircuitsWasm.get();
54
- const [duration, result] = await elapsed(() => mergeRollupSim(wasm, input));
55
- if (result instanceof CircuitError) {
56
- throw new CircuitError(result.code, result.message);
57
- }
52
+ const [duration, result] = await elapsed(() => executeMergeRollup(input));
58
53
 
59
54
  this.log(`Simulated merge rollup circuit`, {
60
55
  eventName: 'circuit-simulation',
@@ -73,11 +68,7 @@ export class WasmRollupCircuitSimulator implements RollupSimulator {
73
68
  * @returns The public inputs as outputs of the simulation.
74
69
  */
75
70
  public async rootRollupCircuit(input: RootRollupInputs): Promise<RootRollupPublicInputs> {
76
- const wasm = await CircuitsWasm.get();
77
- const [duration, result] = await elapsed(() => rootRollupSim(wasm, input));
78
- if (result instanceof CircuitError) {
79
- throw new CircuitError(result.code, result.message);
80
- }
71
+ const [duration, result] = await elapsed(() => executeRootRollup(input));
81
72
 
82
73
  this.log(`Simulated root rollup circuit`, {
83
74
  eventName: 'circuit-simulation',