@aztec/sequencer-client 0.6.7 → 0.7.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.
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@aztec/sequencer-client",
3
- "version": "0.6.7",
3
+ "version": "0.7.0",
4
4
  "exports": "./dest/index.js",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@aztec/acir-simulator": "0.6.7",
8
- "@aztec/circuits.js": "0.6.7",
9
- "@aztec/ethereum": "0.6.7",
10
- "@aztec/foundation": "0.6.7",
11
- "@aztec/l1-artifacts": "0.6.7",
12
- "@aztec/merkle-tree": "0.6.7",
13
- "@aztec/p2p": "0.6.7",
14
- "@aztec/types": "0.6.7",
15
- "@aztec/world-state": "0.6.7",
7
+ "@aztec/acir-simulator": "0.7.0",
8
+ "@aztec/circuits.js": "0.7.0",
9
+ "@aztec/ethereum": "0.7.0",
10
+ "@aztec/foundation": "0.7.0",
11
+ "@aztec/l1-artifacts": "0.7.0",
12
+ "@aztec/merkle-tree": "0.7.0",
13
+ "@aztec/p2p": "0.7.0",
14
+ "@aztec/types": "0.7.0",
15
+ "@aztec/world-state": "0.7.0",
16
16
  "lodash.chunk": "^4.2.0",
17
17
  "lodash.flatmap": "^4.5.0",
18
18
  "lodash.pick": "^4.4.0",
@@ -157,7 +157,7 @@ describe('sequencer/solo_block_builder', () => {
157
157
  rootRollupOutput.endPrivateDataTreeSnapshot.root,
158
158
  rootRollupOutput.endNullifierTreeSnapshot.root,
159
159
  rootRollupOutput.endContractTreeSnapshot.root,
160
- rootRollupOutput.endL1ToL2MessageTreeSnapshot.root,
160
+ rootRollupOutput.endL1ToL2MessagesTreeSnapshot.root,
161
161
  rootRollupOutput.endPublicDataTreeRoot,
162
162
  );
163
163
  await expectsDb.appendLeaves(MerkleTreeId.BLOCKS_TREE, [blockHash.toBuffer()]);
@@ -208,7 +208,7 @@ describe('sequencer/solo_block_builder', () => {
208
208
  rootRollupOutput.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);
209
209
  rootRollupOutput.endPublicDataTreeRoot = (await getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE)).root;
210
210
 
211
- rootRollupOutput.endL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE);
211
+ rootRollupOutput.endL1ToL2MessagesTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE);
212
212
 
213
213
  // Calculate block hash
214
214
  rootRollupOutput.globalVariables = globalVariables;
@@ -241,8 +241,8 @@ describe('sequencer/solo_block_builder', () => {
241
241
  endContractTreeSnapshot: rootRollupOutput.endContractTreeSnapshot,
242
242
  startPublicDataTreeRoot: rootRollupOutput.startPublicDataTreeRoot,
243
243
  endPublicDataTreeRoot: rootRollupOutput.endPublicDataTreeRoot,
244
- startL1ToL2MessageTreeSnapshot: rootRollupOutput.startL1ToL2MessageTreeSnapshot,
245
- endL1ToL2MessageTreeSnapshot: rootRollupOutput.endL1ToL2MessageTreeSnapshot,
244
+ startL1ToL2MessagesTreeSnapshot: rootRollupOutput.startL1ToL2MessagesTreeSnapshot,
245
+ endL1ToL2MessagesTreeSnapshot: rootRollupOutput.endL1ToL2MessagesTreeSnapshot,
246
246
  startHistoricBlocksTreeSnapshot: rootRollupOutput.startHistoricBlocksTreeSnapshot,
247
247
  endHistoricBlocksTreeSnapshot: rootRollupOutput.endHistoricBlocksTreeSnapshot,
248
248
  newCommitments,
@@ -3,10 +3,11 @@ import {
3
3
  BaseOrMergeRollupPublicInputs,
4
4
  BaseRollupInputs,
5
5
  CircuitsWasm,
6
- ConstantBaseRollupData,
6
+ ConstantRollupData,
7
7
  GlobalVariables,
8
8
  HISTORIC_BLOCKS_TREE_HEIGHT,
9
9
  L1_TO_L2_MSG_SUBTREE_HEIGHT,
10
+ L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
10
11
  MembershipWitness,
11
12
  MergeRollupInputs,
12
13
  NULLIFIER_TREE_HEIGHT,
@@ -29,7 +30,7 @@ import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
29
30
  import { padArrayEnd } from '@aztec/foundation/collection';
30
31
  import { Fr } from '@aztec/foundation/fields';
31
32
  import { createDebugLogger } from '@aztec/foundation/log';
32
- import { assertLength } from '@aztec/foundation/serialize';
33
+ import { Tuple, assertLength } from '@aztec/foundation/serialize';
33
34
  import { ContractData, L2Block, L2BlockL2Logs, MerkleTreeId, PublicDataWrite, TxL2Logs } from '@aztec/types';
34
35
  import { MerkleTreeOperations, computeGlobalVariablesHash } from '@aztec/world-state';
35
36
 
@@ -109,7 +110,7 @@ export class SoloBlockBuilder implements BlockBuilder {
109
110
  endNullifierTreeSnapshot,
110
111
  endContractTreeSnapshot,
111
112
  endPublicDataTreeRoot,
112
- endL1ToL2MessageTreeSnapshot,
113
+ endL1ToL2MessagesTreeSnapshot,
113
114
  endHistoricBlocksTreeSnapshot,
114
115
  } = circuitsOutput;
115
116
 
@@ -149,8 +150,8 @@ export class SoloBlockBuilder implements BlockBuilder {
149
150
  endContractTreeSnapshot,
150
151
  startPublicDataTreeRoot: startPublicDataTreeSnapshot.root,
151
152
  endPublicDataTreeRoot,
152
- startL1ToL2MessageTreeSnapshot,
153
- endL1ToL2MessageTreeSnapshot,
153
+ startL1ToL2MessagesTreeSnapshot: startL1ToL2MessageTreeSnapshot,
154
+ endL1ToL2MessagesTreeSnapshot,
154
155
  startHistoricBlocksTreeSnapshot,
155
156
  endHistoricBlocksTreeSnapshot,
156
157
  newCommitments,
@@ -207,7 +208,7 @@ export class SoloBlockBuilder implements BlockBuilder {
207
208
  }
208
209
 
209
210
  // padArrayEnd throws if the array is already full. Otherwise it pads till we reach the required size
210
- newL1ToL2Messages = padArrayEnd(newL1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
211
+ const newL1ToL2MessagesTuple = padArrayEnd(newL1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
211
212
 
212
213
  // Run the base rollup circuits for the txs
213
214
  const baseRollupOutputs: [BaseOrMergeRollupPublicInputs, Proof][] = [];
@@ -230,7 +231,7 @@ export class SoloBlockBuilder implements BlockBuilder {
230
231
 
231
232
  // Run the root rollup with the last two merge rollups (or base, if no merge layers)
232
233
  const [mergeOutputLeft, mergeOutputRight] = mergeRollupInputs;
233
- return this.rootRollupCircuit(mergeOutputLeft, mergeOutputRight, newL1ToL2Messages);
234
+ return this.rootRollupCircuit(mergeOutputLeft, mergeOutputRight, newL1ToL2MessagesTuple);
234
235
  }
235
236
 
236
237
  protected async baseRollupCircuit(
@@ -276,7 +277,7 @@ export class SoloBlockBuilder implements BlockBuilder {
276
277
  protected async rootRollupCircuit(
277
278
  left: [BaseOrMergeRollupPublicInputs, Proof],
278
279
  right: [BaseOrMergeRollupPublicInputs, Proof],
279
- newL1ToL2Messages: Fr[],
280
+ newL1ToL2Messages: Tuple<Fr, typeof NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP>,
280
281
  ): Promise<[RootRollupPublicInputs, Proof]> {
281
282
  this.debug(`Running root rollup circuit`);
282
283
  const rootInput = await this.getRootRollupInput(...left, ...right, newL1ToL2Messages);
@@ -351,7 +352,7 @@ export class SoloBlockBuilder implements BlockBuilder {
351
352
  await Promise.all([
352
353
  this.validateTrees(rootOutput),
353
354
  this.validateTree(rootOutput, MerkleTreeId.BLOCKS_TREE, 'HistoricBlocks'),
354
- this.validateTree(rootOutput, MerkleTreeId.L1_TO_L2_MESSAGES_TREE, 'L1ToL2Message'),
355
+ this.validateTree(rootOutput, MerkleTreeId.L1_TO_L2_MESSAGES_TREE, 'L1ToL2Messages'),
355
356
  ]);
356
357
  }
357
358
 
@@ -359,7 +360,7 @@ export class SoloBlockBuilder implements BlockBuilder {
359
360
  protected async validateRootTree(
360
361
  rootOutput: RootRollupPublicInputs,
361
362
  treeId: MerkleTreeId,
362
- name: 'Contract' | 'PrivateData' | 'L1ToL2Message',
363
+ name: 'Contract' | 'PrivateData' | 'L1ToL2Messages',
363
364
  ) {
364
365
  const localTree = await this.getTreeSnapshot(treeId);
365
366
  const simulatedTree = rootOutput[`endTreeOfHistoric${name}TreeRootsSnapshot`];
@@ -400,7 +401,7 @@ export class SoloBlockBuilder implements BlockBuilder {
400
401
  protected validateSimulatedTree(
401
402
  localTree: AppendOnlyTreeSnapshot,
402
403
  simulatedTree: AppendOnlyTreeSnapshot,
403
- name: 'PrivateData' | 'Contract' | 'Nullifier' | 'L1ToL2Message' | 'HistoricBlocks',
404
+ name: 'PrivateData' | 'Contract' | 'Nullifier' | 'L1ToL2Messages' | 'HistoricBlocks',
404
405
  label?: string,
405
406
  ) {
406
407
  if (!simulatedTree.root.toBuffer().equals(localTree.root.toBuffer())) {
@@ -421,7 +422,7 @@ export class SoloBlockBuilder implements BlockBuilder {
421
422
  rollupProofLeft: Proof,
422
423
  rollupOutputRight: BaseOrMergeRollupPublicInputs,
423
424
  rollupProofRight: Proof,
424
- newL1ToL2Messages: Fr[],
425
+ newL1ToL2Messages: Tuple<Fr, typeof NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP>,
425
426
  ) {
426
427
  const vk = this.getVerificationKey(rollupOutputLeft.rollupType);
427
428
  const previousRollupData: RootRollupInputs['previousRollupData'] = [
@@ -437,23 +438,36 @@ export class SoloBlockBuilder implements BlockBuilder {
437
438
  return path.toFieldArray();
438
439
  };
439
440
 
440
- const newL1ToL2MessageTreeRootSiblingPath = await this.getSubtreeSiblingPath(
441
+ const newL1ToL2MessagesTreeRootSiblingPathArray = await this.getSubtreeSiblingPath(
441
442
  MerkleTreeId.L1_TO_L2_MESSAGES_TREE,
442
443
  L1_TO_L2_MSG_SUBTREE_HEIGHT,
443
444
  );
444
445
 
446
+ const newL1ToL2MessagesTreeRootSiblingPath = makeTuple(
447
+ L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
448
+ i =>
449
+ i < newL1ToL2MessagesTreeRootSiblingPathArray.length ? newL1ToL2MessagesTreeRootSiblingPathArray[i] : Fr.ZERO,
450
+ 0,
451
+ );
452
+
445
453
  // Get tree snapshots
446
- const startL1ToL2MessageTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE);
454
+ const startL1ToL2MessagesTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE);
447
455
 
448
456
  // Get historic block tree roots
449
457
  const startHistoricBlocksTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.BLOCKS_TREE);
450
- const newHistoricBlocksTreeSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.BLOCKS_TREE);
458
+ const newHistoricBlocksTreeSiblingPathArray = await getRootTreeSiblingPath(MerkleTreeId.BLOCKS_TREE);
459
+
460
+ const newHistoricBlocksTreeSiblingPath = makeTuple(
461
+ HISTORIC_BLOCKS_TREE_HEIGHT,
462
+ i => (i < newHistoricBlocksTreeSiblingPathArray.length ? newHistoricBlocksTreeSiblingPathArray[i] : Fr.ZERO),
463
+ 0,
464
+ );
451
465
 
452
466
  return RootRollupInputs.from({
453
467
  previousRollupData,
454
468
  newL1ToL2Messages,
455
- newL1ToL2MessageTreeRootSiblingPath,
456
- startL1ToL2MessageTreeSnapshot,
469
+ newL1ToL2MessagesTreeRootSiblingPath,
470
+ startL1ToL2MessagesTreeSnapshot,
457
471
  startHistoricBlocksTreeSnapshot,
458
472
  newHistoricBlocksTreeSiblingPath,
459
473
  });
@@ -528,8 +542,8 @@ export class SoloBlockBuilder implements BlockBuilder {
528
542
  return this.getMembershipWitnessFor(blockHash, MerkleTreeId.BLOCKS_TREE, HISTORIC_BLOCKS_TREE_HEIGHT);
529
543
  }
530
544
 
531
- protected async getConstantBaseRollupData(globalVariables: GlobalVariables): Promise<ConstantBaseRollupData> {
532
- return ConstantBaseRollupData.from({
545
+ protected async getConstantRollupData(globalVariables: GlobalVariables): Promise<ConstantRollupData> {
546
+ return ConstantRollupData.from({
533
547
  baseRollupVkHash: DELETE_FR,
534
548
  mergeRollupVkHash: DELETE_FR,
535
549
  privateKernelVkTreeRoot: FUTURE_FR,
@@ -604,7 +618,7 @@ export class SoloBlockBuilder implements BlockBuilder {
604
618
  const wasm = await CircuitsWasm.get();
605
619
 
606
620
  // Get trees info before any changes hit
607
- const constants = await this.getConstantBaseRollupData(globalVariables);
621
+ const constants = await this.getConstantRollupData(globalVariables);
608
622
  const startNullifierTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE);
609
623
  const startContractTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
610
624
  const startPrivateDataTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);
@@ -5,7 +5,7 @@ import { AppendOnlyTreeSnapshot, BaseOrMergeRollupPublicInputs, RootRollupPublic
5
5
  */
6
6
  export type AllowedTreeNames<T extends BaseOrMergeRollupPublicInputs | RootRollupPublicInputs> =
7
7
  T extends RootRollupPublicInputs
8
- ? 'PrivateData' | 'Contract' | 'Nullifier' | 'L1ToL2Message' | 'HistoricBlocks'
8
+ ? 'PrivateData' | 'Contract' | 'Nullifier' | 'L1ToL2Messages' | 'HistoricBlocks'
9
9
  : 'PrivateData' | 'Contract' | 'Nullifier';
10
10
 
11
11
  /**
@@ -129,10 +129,11 @@ export class Sequencer {
129
129
  return;
130
130
  }
131
131
 
132
- this.log(`Processing ${validTxs.length} txs...`);
132
+ const blockNumber = (await this.l2BlockSource.getBlockNumber()) + 1;
133
+
134
+ this.log.info(`Building block ${blockNumber} with ${validTxs.length} transactions...`);
133
135
  this.state = SequencerState.CREATING_BLOCK;
134
136
 
135
- const blockNumber = (await this.l2BlockSource.getBlockNumber()) + 1;
136
137
  const newGlobalVariables = await this.globalsBuilder.buildGlobalVariables(new Fr(blockNumber));
137
138
  const prevGlobalVariables = (await this.l2BlockSource.getL2Block(-1))?.globalVariables ?? GlobalVariables.empty();
138
139
 
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  BaseOrMergeRollupPublicInputs,
3
3
  BaseRollupInputs,
4
+ CircuitError,
4
5
  CircuitsWasm,
5
6
  MergeRollupInputs,
6
7
  RollupWasmWrapper,
7
8
  RootRollupInputs,
8
9
  RootRollupPublicInputs,
10
+ mergeRollupSim,
11
+ rootRollupSim,
9
12
  } from '@aztec/circuits.js';
10
13
 
11
14
  import { RollupSimulator } from './index.js';
@@ -15,9 +18,11 @@ import { RollupSimulator } from './index.js';
15
18
  */
16
19
  export class WasmRollupCircuitSimulator implements RollupSimulator {
17
20
  private rollupWasmWrapper: RollupWasmWrapper;
21
+ private wasm: CircuitsWasm;
18
22
 
19
23
  constructor(wasm: CircuitsWasm) {
20
24
  this.rollupWasmWrapper = new RollupWasmWrapper(wasm);
25
+ this.wasm = wasm;
21
26
  }
22
27
 
23
28
  /**
@@ -42,14 +47,25 @@ export class WasmRollupCircuitSimulator implements RollupSimulator {
42
47
  * @returns The public inputs as outputs of the simulation.
43
48
  */
44
49
  mergeRollupCircuit(input: MergeRollupInputs): Promise<BaseOrMergeRollupPublicInputs> {
45
- return Promise.resolve(this.rollupWasmWrapper.simulateMergeRollup(input));
50
+ const result = mergeRollupSim(this.wasm, input);
51
+ if (result instanceof CircuitError) {
52
+ throw new CircuitError(result.code, result.message);
53
+ }
54
+
55
+ return Promise.resolve(result);
46
56
  }
57
+
47
58
  /**
48
59
  * Simulates the root rollup circuit from its inputs.
49
60
  * @param input - Inputs to the circuit.
50
61
  * @returns The public inputs as outputs of the simulation.
51
62
  */
52
63
  rootRollupCircuit(input: RootRollupInputs): Promise<RootRollupPublicInputs> {
53
- return Promise.resolve(this.rollupWasmWrapper.simulateRootRollup(input));
64
+ const result = rootRollupSim(this.wasm, input);
65
+ if (result instanceof CircuitError) {
66
+ throw new CircuitError(result.code, result.message);
67
+ }
68
+
69
+ return Promise.resolve(result);
54
70
  }
55
71
  }