@aztec/sequencer-client 0.22.0 → 0.24.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 (76) hide show
  1. package/dest/block_builder/solo_block_builder.d.ts +2 -2
  2. package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
  3. package/dest/block_builder/solo_block_builder.js +3 -3
  4. package/dest/client/sequencer-client.d.ts +2 -0
  5. package/dest/client/sequencer-client.d.ts.map +1 -1
  6. package/dest/client/sequencer-client.js +7 -1
  7. package/dest/config.d.ts.map +1 -1
  8. package/dest/config.js +6 -2
  9. package/dest/global_variable_builder/global_builder.d.ts +7 -3
  10. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  11. package/dest/global_variable_builder/global_builder.js +6 -4
  12. package/dest/prover/empty.d.ts +2 -2
  13. package/dest/prover/empty.d.ts.map +1 -1
  14. package/dest/prover/empty.js +1 -1
  15. package/dest/prover/index.d.ts +2 -2
  16. package/dest/prover/index.d.ts.map +1 -1
  17. package/dest/sequencer/abstract_phase_manager.d.ts +11 -11
  18. package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
  19. package/dest/sequencer/abstract_phase_manager.js +18 -15
  20. package/dest/sequencer/application_logic_phase_manager.d.ts +3 -3
  21. package/dest/sequencer/application_logic_phase_manager.d.ts.map +1 -1
  22. package/dest/sequencer/application_logic_phase_manager.js +2 -2
  23. package/dest/sequencer/fee_distribution_phase_manager.d.ts +4 -4
  24. package/dest/sequencer/fee_distribution_phase_manager.d.ts.map +1 -1
  25. package/dest/sequencer/fee_distribution_phase_manager.js +2 -2
  26. package/dest/sequencer/fee_preparation_phase_manager.d.ts +3 -3
  27. package/dest/sequencer/fee_preparation_phase_manager.d.ts.map +1 -1
  28. package/dest/sequencer/fee_preparation_phase_manager.js +1 -2
  29. package/dest/sequencer/processed_tx.d.ts +3 -3
  30. package/dest/sequencer/processed_tx.d.ts.map +1 -1
  31. package/dest/sequencer/processed_tx.js +4 -4
  32. package/dest/sequencer/public_processor.d.ts.map +1 -1
  33. package/dest/sequencer/public_processor.js +1 -1
  34. package/dest/sequencer/sequencer.d.ts +5 -1
  35. package/dest/sequencer/sequencer.d.ts.map +1 -1
  36. package/dest/sequencer/sequencer.js +18 -2
  37. package/dest/simulator/index.d.ts +3 -3
  38. package/dest/simulator/index.d.ts.map +1 -1
  39. package/dest/simulator/public_kernel.d.ts +3 -3
  40. package/dest/simulator/public_kernel.d.ts.map +1 -1
  41. package/dest/simulator/public_kernel.js +4 -4
  42. package/dest/simulator/rollup.js +2 -2
  43. package/package.json +12 -23
  44. package/src/block_builder/index.ts +24 -0
  45. package/src/block_builder/solo_block_builder.ts +715 -0
  46. package/src/block_builder/types.ts +8 -0
  47. package/src/client/index.ts +1 -0
  48. package/src/client/sequencer-client.ts +97 -0
  49. package/src/config.ts +86 -0
  50. package/src/global_variable_builder/config.ts +20 -0
  51. package/src/global_variable_builder/global_builder.ts +95 -0
  52. package/src/global_variable_builder/index.ts +16 -0
  53. package/src/global_variable_builder/viem-reader.ts +61 -0
  54. package/src/index.ts +15 -0
  55. package/src/mocks/verification_keys.ts +36 -0
  56. package/src/prover/empty.ts +74 -0
  57. package/src/prover/index.ts +53 -0
  58. package/src/publisher/config.ts +41 -0
  59. package/src/publisher/index.ts +14 -0
  60. package/src/publisher/l1-publisher.ts +365 -0
  61. package/src/publisher/viem-tx-sender.ts +241 -0
  62. package/src/receiver.ts +13 -0
  63. package/src/sequencer/abstract_phase_manager.ts +427 -0
  64. package/src/sequencer/application_logic_phase_manager.ts +107 -0
  65. package/src/sequencer/config.ts +1 -0
  66. package/src/sequencer/fee_distribution_phase_manager.ts +70 -0
  67. package/src/sequencer/fee_preparation_phase_manager.ts +79 -0
  68. package/src/sequencer/index.ts +2 -0
  69. package/src/sequencer/processed_tx.ts +95 -0
  70. package/src/sequencer/public_processor.ts +136 -0
  71. package/src/sequencer/sequencer.ts +462 -0
  72. package/src/simulator/index.ts +53 -0
  73. package/src/simulator/public_executor.ts +169 -0
  74. package/src/simulator/public_kernel.ts +58 -0
  75. package/src/simulator/rollup.ts +76 -0
  76. package/src/utils.ts +16 -0
@@ -0,0 +1,53 @@
1
+ import {
2
+ BaseOrMergeRollupPublicInputs,
3
+ BaseRollupInputs,
4
+ MergeRollupInputs,
5
+ PublicKernelCircuitPrivateInputs,
6
+ PublicKernelCircuitPublicInputs,
7
+ RootRollupInputs,
8
+ RootRollupPublicInputs,
9
+ } from '@aztec/circuits.js';
10
+
11
+ /**
12
+ * Circuit simulator for the rollup circuits.
13
+ */
14
+ export interface RollupSimulator {
15
+ /**
16
+ * Simulates the base rollup circuit from its inputs.
17
+ * @param input - Inputs to the circuit.
18
+ * @returns The public inputs as outputs of the simulation.
19
+ */
20
+ baseRollupCircuit(input: BaseRollupInputs): Promise<BaseOrMergeRollupPublicInputs>;
21
+ /**
22
+ * Simulates the merge rollup circuit from its inputs.
23
+ * @param input - Inputs to the circuit.
24
+ * @returns The public inputs as outputs of the simulation.
25
+ */
26
+ mergeRollupCircuit(input: MergeRollupInputs): Promise<BaseOrMergeRollupPublicInputs>;
27
+ /**
28
+ * Simulates the root rollup circuit from its inputs.
29
+ * @param input - Inputs to the circuit.
30
+ * @returns The public inputs as outputs of the simulation.
31
+ */
32
+ rootRollupCircuit(input: RootRollupInputs): Promise<RootRollupPublicInputs>;
33
+ }
34
+
35
+ /**
36
+ * Circuit simulator for the public kernel circuits.
37
+ */
38
+ export interface PublicKernelCircuitSimulator {
39
+ /**
40
+ * Simulates the public kernel circuit (with a previous private kernel circuit run) from its inputs.
41
+ * @param inputs - Inputs to the circuit.
42
+ * @returns The public inputs as outputs of the simulation.
43
+ */
44
+ publicKernelCircuitPrivateInput(inputs: PublicKernelCircuitPrivateInputs): Promise<PublicKernelCircuitPublicInputs>;
45
+ /**
46
+ * Simulates the public kernel circuit (with no previous public kernel circuit run) from its inputs.
47
+ * @param inputs - Inputs to the circuit.
48
+ * @returns The public inputs as outputs of the simulation.
49
+ */
50
+ publicKernelCircuitNonFirstIteration(
51
+ inputs: PublicKernelCircuitPrivateInputs,
52
+ ): Promise<PublicKernelCircuitPublicInputs>;
53
+ }
@@ -0,0 +1,169 @@
1
+ import { ContractDataSource, ExtendedContractData, L1ToL2MessageSource, MerkleTreeId, Tx } from '@aztec/circuit-types';
2
+ import {
3
+ AztecAddress,
4
+ EthAddress,
5
+ Fr,
6
+ FunctionSelector,
7
+ L1_TO_L2_MSG_TREE_HEIGHT,
8
+ PublicDataTreeLeafPreimage,
9
+ } from '@aztec/circuits.js';
10
+ import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/abis';
11
+ import { CommitmentsDB, MessageLoadOracleInputs, PublicContractsDB, PublicStateDB } from '@aztec/simulator';
12
+ import { MerkleTreeOperations } from '@aztec/world-state';
13
+
14
+ /**
15
+ * Implements the PublicContractsDB using a ContractDataSource.
16
+ * Progressively records contracts in transaction as they are processed in a block.
17
+ */
18
+ export class ContractsDataSourcePublicDB implements PublicContractsDB {
19
+ cache = new Map<string, ExtendedContractData>();
20
+
21
+ constructor(private db: ContractDataSource) {}
22
+
23
+ /**
24
+ * Add new contracts from a transaction
25
+ * @param tx - The transaction to add contracts from.
26
+ */
27
+ public addNewContracts(tx: Tx): Promise<void> {
28
+ for (const contract of tx.newContracts) {
29
+ const contractAddress = contract.contractData.contractAddress;
30
+
31
+ if (contractAddress.isZero()) {
32
+ continue;
33
+ }
34
+
35
+ this.cache.set(contractAddress.toString(), contract);
36
+ }
37
+
38
+ return Promise.resolve();
39
+ }
40
+
41
+ /**
42
+ * Removes new contracts added from transactions
43
+ * @param tx - The tx's contracts to be removed
44
+ */
45
+ public removeNewContracts(tx: Tx): Promise<void> {
46
+ for (const contract of tx.newContracts) {
47
+ const contractAddress = contract.contractData.contractAddress;
48
+
49
+ if (contractAddress.isZero()) {
50
+ continue;
51
+ }
52
+
53
+ this.cache.delete(contractAddress.toString());
54
+ }
55
+ return Promise.resolve();
56
+ }
57
+
58
+ async getBytecode(address: AztecAddress, selector: FunctionSelector): Promise<Buffer | undefined> {
59
+ const contract = await this.#getContract(address);
60
+ return contract?.getPublicFunction(selector)?.bytecode;
61
+ }
62
+ async getIsInternal(address: AztecAddress, selector: FunctionSelector): Promise<boolean | undefined> {
63
+ const contract = await this.#getContract(address);
64
+ return contract?.getPublicFunction(selector)?.isInternal;
65
+ }
66
+ async getPortalContractAddress(address: AztecAddress): Promise<EthAddress | undefined> {
67
+ const contract = await this.#getContract(address);
68
+ return contract?.contractData.portalContractAddress;
69
+ }
70
+
71
+ async #getContract(address: AztecAddress): Promise<ExtendedContractData | undefined> {
72
+ return this.cache.get(address.toString()) ?? (await this.db.getExtendedContractData(address));
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Implements the PublicStateDB using a world-state database.
78
+ */
79
+ export class WorldStatePublicDB implements PublicStateDB {
80
+ private commitedWriteCache: Map<bigint, Fr> = new Map();
81
+ private uncommitedWriteCache: Map<bigint, Fr> = new Map();
82
+
83
+ constructor(private db: MerkleTreeOperations) {}
84
+
85
+ /**
86
+ * Reads a value from public storage, returning zero if none.
87
+ * @param contract - Owner of the storage.
88
+ * @param slot - Slot to read in the contract storage.
89
+ * @returns The current value in the storage slot.
90
+ */
91
+ public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
92
+ const leafSlot = computePublicDataTreeLeafSlot(contract, slot).value;
93
+ const uncommited = this.uncommitedWriteCache.get(leafSlot);
94
+ if (uncommited !== undefined) {
95
+ return uncommited;
96
+ }
97
+ const commited = this.commitedWriteCache.get(leafSlot);
98
+ if (commited !== undefined) {
99
+ return commited;
100
+ }
101
+
102
+ const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
103
+ if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
104
+ return Fr.ZERO;
105
+ }
106
+
107
+ const preimage = (await this.db.getLeafPreimage(
108
+ MerkleTreeId.PUBLIC_DATA_TREE,
109
+ lowLeafResult.index,
110
+ )) as PublicDataTreeLeafPreimage;
111
+
112
+ return preimage.value;
113
+ }
114
+
115
+ /**
116
+ * Records a write to public storage.
117
+ * @param contract - Owner of the storage.
118
+ * @param slot - Slot to read in the contract storage.
119
+ * @param newValue - The new value to store.
120
+ */
121
+ public storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void> {
122
+ const index = computePublicDataTreeLeafSlot(contract, slot).value;
123
+ this.uncommitedWriteCache.set(index, newValue);
124
+ return Promise.resolve();
125
+ }
126
+
127
+ /**
128
+ * Commit the pending changes to the DB.
129
+ * @returns Nothing.
130
+ */
131
+ commit(): Promise<void> {
132
+ for (const [k, v] of this.uncommitedWriteCache) {
133
+ this.commitedWriteCache.set(k, v);
134
+ }
135
+ return this.rollback();
136
+ }
137
+
138
+ /**
139
+ * Rollback the pending changes.
140
+ * @returns Nothing.
141
+ */
142
+ rollback(): Promise<void> {
143
+ this.uncommitedWriteCache = new Map<bigint, Fr>();
144
+ return Promise.resolve();
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Implements WorldState db using a world state database.
150
+ */
151
+ export class WorldStateDB implements CommitmentsDB {
152
+ constructor(private db: MerkleTreeOperations, private l1ToL2MessageSource: L1ToL2MessageSource) {}
153
+
154
+ public async getL1ToL2Message(messageKey: Fr): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
155
+ // todo: #697 - make this one lookup.
156
+ const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey);
157
+ const index = (await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageKey.toBuffer()))!;
158
+ const siblingPath = await this.db.getSiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>(
159
+ MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
160
+ index,
161
+ );
162
+
163
+ return new MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>(message, index, siblingPath);
164
+ }
165
+
166
+ public async getCommitmentIndex(commitment: Fr): Promise<bigint | undefined> {
167
+ return await this.db.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, commitment.toBuffer());
168
+ }
169
+ }
@@ -0,0 +1,58 @@
1
+ import { CircuitSimulationStats } from '@aztec/circuit-types/stats';
2
+ import { PublicKernelCircuitPrivateInputs, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
3
+ import { createDebugLogger } from '@aztec/foundation/log';
4
+ import { elapsed } from '@aztec/foundation/timer';
5
+ import { executePublicKernelAppLogic, executePublicKernelSetup } from '@aztec/noir-protocol-circuits-types';
6
+
7
+ import { PublicKernelCircuitSimulator } from './index.js';
8
+
9
+ /**
10
+ * Implements the PublicKernelCircuitSimulator.
11
+ */
12
+ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimulator {
13
+ private log = createDebugLogger('aztec:public-kernel-simulator');
14
+
15
+ /**
16
+ * Simulates the public kernel circuit (with a previous private kernel circuit run) from its inputs.
17
+ * @param input - Inputs to the circuit.
18
+ * @returns The public inputs as outputs of the simulation.
19
+ */
20
+ public async publicKernelCircuitPrivateInput(
21
+ input: PublicKernelCircuitPrivateInputs,
22
+ ): Promise<PublicKernelCircuitPublicInputs> {
23
+ if (!input.previousKernel.publicInputs.isPrivate) {
24
+ throw new Error(`Expected private kernel previous inputs`);
25
+ }
26
+ const [duration, result] = await elapsed(() => executePublicKernelSetup(input));
27
+ this.log(`Simulated public kernel circuit with private input`, {
28
+ eventName: 'circuit-simulation',
29
+ circuitName: 'public-kernel-private-input',
30
+ duration,
31
+ inputSize: input.toBuffer().length,
32
+ outputSize: result.toBuffer().length,
33
+ } satisfies CircuitSimulationStats);
34
+ return result;
35
+ }
36
+
37
+ /**
38
+ * Simulates the public kernel circuit (with no previous public kernel circuit run) from its inputs.
39
+ * @param input - Inputs to the circuit.
40
+ * @returns The public inputs as outputs of the simulation.
41
+ */
42
+ public async publicKernelCircuitNonFirstIteration(
43
+ input: PublicKernelCircuitPrivateInputs,
44
+ ): Promise<PublicKernelCircuitPublicInputs> {
45
+ if (input.previousKernel.publicInputs.isPrivate) {
46
+ throw new Error(`Expected public kernel previous inputs`);
47
+ }
48
+ const [duration, result] = await elapsed(() => executePublicKernelAppLogic(input));
49
+ this.log(`Simulated public kernel circuit non-first iteration`, {
50
+ eventName: 'circuit-simulation',
51
+ circuitName: 'public-kernel-non-first-iteration',
52
+ duration,
53
+ inputSize: input.toBuffer().length,
54
+ outputSize: result.toBuffer().length,
55
+ } satisfies CircuitSimulationStats);
56
+ return result;
57
+ }
58
+ }
@@ -0,0 +1,76 @@
1
+ import { CircuitSimulationStats } from '@aztec/circuit-types/stats';
2
+ import {
3
+ BaseOrMergeRollupPublicInputs,
4
+ BaseRollupInputs,
5
+ MergeRollupInputs,
6
+ RootRollupInputs,
7
+ RootRollupPublicInputs,
8
+ } from '@aztec/circuits.js';
9
+ import { createDebugLogger } from '@aztec/foundation/log';
10
+ import { elapsed } from '@aztec/foundation/timer';
11
+ import { executeBaseRollup, executeMergeRollup, executeRootRollup } from '@aztec/noir-protocol-circuits-types';
12
+
13
+ import { RollupSimulator } from './index.js';
14
+
15
+ /**
16
+ * Implements the rollup circuit simulator.
17
+ */
18
+ export class RealRollupCircuitSimulator implements RollupSimulator {
19
+ private log = createDebugLogger('aztec:rollup-simulator');
20
+
21
+ /**
22
+ * Simulates the base rollup circuit from its inputs.
23
+ * @param input - Inputs to the circuit.
24
+ * @returns The public inputs as outputs of the simulation.
25
+ */
26
+ public async baseRollupCircuit(input: BaseRollupInputs): Promise<BaseOrMergeRollupPublicInputs> {
27
+ const [duration, result] = await elapsed(() => executeBaseRollup(input));
28
+
29
+ this.log(`Simulated base rollup circuit`, {
30
+ eventName: 'circuit-simulation',
31
+ circuitName: 'base-rollup',
32
+ duration,
33
+ inputSize: input.toBuffer().length,
34
+ outputSize: result.toBuffer().length,
35
+ } satisfies CircuitSimulationStats);
36
+
37
+ return Promise.resolve(result);
38
+ }
39
+ /**
40
+ * Simulates the merge rollup circuit from its inputs.
41
+ * @param input - Inputs to the circuit.
42
+ * @returns The public inputs as outputs of the simulation.
43
+ */
44
+ public async mergeRollupCircuit(input: MergeRollupInputs): Promise<BaseOrMergeRollupPublicInputs> {
45
+ const [duration, result] = await elapsed(() => executeMergeRollup(input));
46
+
47
+ this.log(`Simulated merge rollup circuit`, {
48
+ eventName: 'circuit-simulation',
49
+ circuitName: 'merge-rollup',
50
+ duration,
51
+ inputSize: input.toBuffer().length,
52
+ outputSize: result.toBuffer().length,
53
+ } satisfies CircuitSimulationStats);
54
+
55
+ return result;
56
+ }
57
+
58
+ /**
59
+ * Simulates the root rollup circuit from its inputs.
60
+ * @param input - Inputs to the circuit.
61
+ * @returns The public inputs as outputs of the simulation.
62
+ */
63
+ public async rootRollupCircuit(input: RootRollupInputs): Promise<RootRollupPublicInputs> {
64
+ const [duration, result] = await elapsed(() => executeRootRollup(input));
65
+
66
+ this.log(`Simulated root rollup circuit`, {
67
+ eventName: 'circuit-simulation',
68
+ circuitName: 'root-rollup',
69
+ duration,
70
+ inputSize: input.toBuffer().length,
71
+ outputSize: result.toBuffer().length,
72
+ } satisfies CircuitSimulationStats);
73
+
74
+ return result;
75
+ }
76
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns a promise that resolves after ms milliseconds, returning "returnValue".
3
+ * @param ms - How many milliseconds to sleep.
4
+ * @param returnValue - The return value of the promise.
5
+ */
6
+ export function sleep<T>(ms: number, returnValue: T): Promise<T> {
7
+ return new Promise(resolve => setTimeout(() => resolve(returnValue), ms));
8
+ }
9
+
10
+ /**
11
+ * Returns the lowest power of two that is greater of equal to the input.
12
+ * @param num - The input.
13
+ */
14
+ export function ceilPowerOfTwo(num: number): number {
15
+ return 2 ** Math.ceil(Math.log2(num));
16
+ }