@aztec/sequencer-client 0.7.9 → 0.8.6

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 (73) hide show
  1. package/README.md +1 -1
  2. package/dest/client/sequencer-client.d.ts +3 -3
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +6 -6
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +14 -7
  7. package/dest/global_variable_builder/config.d.ts +5 -5
  8. package/dest/global_variable_builder/config.d.ts.map +1 -1
  9. package/dest/global_variable_builder/viem-reader.js +3 -3
  10. package/dest/publisher/config.d.ts +6 -2
  11. package/dest/publisher/config.d.ts.map +1 -1
  12. package/dest/publisher/index.d.ts +27 -0
  13. package/dest/publisher/index.d.ts.map +1 -1
  14. package/dest/publisher/index.js +1 -1
  15. package/dest/publisher/l1-publisher.d.ts +26 -11
  16. package/dest/publisher/l1-publisher.d.ts.map +1 -1
  17. package/dest/publisher/l1-publisher.js +18 -4
  18. package/dest/publisher/viem-tx-sender.d.ts +2 -1
  19. package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
  20. package/dest/publisher/viem-tx-sender.js +27 -7
  21. package/dest/sequencer/public_processor.d.ts +4 -2
  22. package/dest/sequencer/public_processor.d.ts.map +1 -1
  23. package/dest/sequencer/public_processor.js +11 -5
  24. package/dest/sequencer/sequencer.d.ts +13 -9
  25. package/dest/sequencer/sequencer.d.ts.map +1 -1
  26. package/dest/sequencer/sequencer.js +53 -34
  27. package/dest/simulator/index.d.ts +0 -1
  28. package/dest/simulator/index.d.ts.map +1 -1
  29. package/dest/simulator/index.js +2 -2
  30. package/dest/simulator/public_executor.d.ts +28 -4
  31. package/dest/simulator/public_executor.d.ts.map +1 -1
  32. package/dest/simulator/public_executor.js +46 -7
  33. package/dest/simulator/public_kernel.d.ts +1 -0
  34. package/dest/simulator/public_kernel.d.ts.map +1 -1
  35. package/dest/simulator/public_kernel.js +26 -5
  36. package/dest/simulator/rollup.d.ts +2 -8
  37. package/dest/simulator/rollup.d.ts.map +1 -1
  38. package/dest/simulator/rollup.js +37 -18
  39. package/package.json +70 -11
  40. package/src/client/sequencer-client.ts +7 -6
  41. package/src/config.ts +14 -5
  42. package/src/global_variable_builder/config.ts +6 -5
  43. package/src/global_variable_builder/viem-reader.ts +2 -2
  44. package/src/publisher/config.ts +7 -2
  45. package/src/publisher/index.ts +28 -0
  46. package/src/publisher/l1-publisher.ts +46 -13
  47. package/src/publisher/viem-tx-sender.ts +33 -13
  48. package/src/sequencer/public_processor.ts +13 -4
  49. package/src/sequencer/sequencer.ts +59 -45
  50. package/src/simulator/index.ts +0 -2
  51. package/src/simulator/public_executor.ts +53 -7
  52. package/src/simulator/public_kernel.ts +24 -4
  53. package/src/simulator/rollup.ts +38 -21
  54. package/.eslintrc.cjs +0 -1
  55. package/.tsbuildinfo +0 -1
  56. package/dest/block_builder/solo_block_builder.test.d.ts +0 -3
  57. package/dest/block_builder/solo_block_builder.test.d.ts.map +0 -1
  58. package/dest/block_builder/solo_block_builder.test.js +0 -277
  59. package/dest/publisher/l1-publisher.test.d.ts +0 -2
  60. package/dest/publisher/l1-publisher.test.d.ts.map +0 -1
  61. package/dest/publisher/l1-publisher.test.js +0 -58
  62. package/dest/sequencer/public_processor.test.d.ts +0 -2
  63. package/dest/sequencer/public_processor.test.d.ts.map +0 -1
  64. package/dest/sequencer/public_processor.test.js +0 -164
  65. package/dest/sequencer/sequencer.test.d.ts +0 -2
  66. package/dest/sequencer/sequencer.test.d.ts.map +0 -1
  67. package/dest/sequencer/sequencer.test.js +0 -99
  68. package/jest.integration.config.json +0 -13
  69. package/src/block_builder/solo_block_builder.test.ts +0 -425
  70. package/src/publisher/l1-publisher.test.ts +0 -79
  71. package/src/sequencer/public_processor.test.ts +0 -265
  72. package/src/sequencer/sequencer.test.ts +0 -160
  73. package/tsconfig.json +0 -38
@@ -1,265 +0,0 @@
1
- import { PublicExecution, PublicExecutionResult, PublicExecutor } from '@aztec/acir-simulator';
2
- import {
3
- ARGS_LENGTH,
4
- AztecAddress,
5
- CallContext,
6
- CircuitsWasm,
7
- CombinedAccumulatedData,
8
- EthAddress,
9
- Fr,
10
- FunctionData,
11
- GlobalVariables,
12
- HistoricBlockData,
13
- MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,
14
- MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
15
- PUBLIC_DATA_TREE_HEIGHT,
16
- Proof,
17
- PublicCallRequest,
18
- PublicKernelPublicInputs,
19
- makeEmptyProof,
20
- makeTuple,
21
- } from '@aztec/circuits.js';
22
- import { computeCallStackItemHash } from '@aztec/circuits.js/abis';
23
- import {
24
- makeAztecAddress,
25
- makePrivateKernelPublicInputsFinal,
26
- makePublicCallRequest,
27
- makeSelector,
28
- } from '@aztec/circuits.js/factories';
29
- import { padArrayEnd } from '@aztec/foundation/collection';
30
- import {
31
- ContractDataSource,
32
- EncodedContractFunction,
33
- ExtendedContractData,
34
- FunctionCall,
35
- FunctionL2Logs,
36
- SiblingPath,
37
- Tx,
38
- TxL2Logs,
39
- mockTx,
40
- } from '@aztec/types';
41
- import { MerkleTreeOperations, TreeInfo } from '@aztec/world-state';
42
-
43
- import { MockProxy, mock } from 'jest-mock-extended';
44
- import times from 'lodash.times';
45
-
46
- import { PublicProver } from '../prover/index.js';
47
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
48
- import { WasmPublicKernelCircuitSimulator } from '../simulator/public_kernel.js';
49
- import { PublicProcessor } from './public_processor.js';
50
-
51
- describe('public_processor', () => {
52
- let db: MockProxy<MerkleTreeOperations>;
53
- let publicExecutor: MockProxy<PublicExecutor>;
54
- let publicProver: MockProxy<PublicProver>;
55
- let contractDataSource: MockProxy<ContractDataSource>;
56
-
57
- let publicFunction: EncodedContractFunction;
58
- let contractData: ExtendedContractData;
59
- let proof: Proof;
60
- let root: Buffer;
61
-
62
- let processor: PublicProcessor;
63
-
64
- beforeEach(() => {
65
- db = mock<MerkleTreeOperations>();
66
- publicExecutor = mock<PublicExecutor>();
67
- publicProver = mock<PublicProver>();
68
- contractDataSource = mock<ContractDataSource>();
69
-
70
- contractData = ExtendedContractData.random();
71
- publicFunction = EncodedContractFunction.random();
72
- proof = makeEmptyProof();
73
- root = Buffer.alloc(32, 5);
74
-
75
- publicProver.getPublicCircuitProof.mockResolvedValue(proof);
76
- publicProver.getPublicKernelCircuitProof.mockResolvedValue(proof);
77
- db.getTreeInfo.mockResolvedValue({ root } as TreeInfo);
78
- contractDataSource.getExtendedContractData.mockResolvedValue(contractData);
79
- contractDataSource.getPublicFunction.mockResolvedValue(publicFunction);
80
- });
81
-
82
- describe('with mock circuits', () => {
83
- let publicKernel: MockProxy<PublicKernelCircuitSimulator>;
84
-
85
- beforeEach(() => {
86
- publicKernel = mock<PublicKernelCircuitSimulator>();
87
- processor = new PublicProcessor(
88
- db,
89
- publicExecutor,
90
- publicKernel,
91
- publicProver,
92
- contractDataSource,
93
- GlobalVariables.empty(),
94
- HistoricBlockData.empty(),
95
- );
96
- });
97
-
98
- it('skips txs without public execution requests', async function () {
99
- const tx = mockTx();
100
- tx.data.end.publicCallStack = makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, Fr.zero);
101
- const hash = await tx.getTxHash();
102
- const [processed, failed] = await processor.process([tx]);
103
-
104
- expect(processed).toEqual([
105
- {
106
- isEmpty: false,
107
- hash,
108
- data: new PublicKernelPublicInputs(
109
- CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end),
110
- tx.data.constants,
111
- ),
112
- proof: tx.proof,
113
- encryptedLogs: tx.encryptedLogs,
114
- unencryptedLogs: tx.unencryptedLogs,
115
- },
116
- ]);
117
- expect(failed).toEqual([]);
118
- });
119
-
120
- it('returns failed txs without aborting entire operation', async function () {
121
- publicExecutor.simulate.mockRejectedValue(new Error(`Failed`));
122
-
123
- const tx = mockTx();
124
- const [processed, failed] = await processor.process([tx]);
125
-
126
- expect(processed).toEqual([]);
127
- expect(failed[0].tx).toEqual(tx);
128
- });
129
- });
130
-
131
- describe('with actual circuits', () => {
132
- let publicKernel: PublicKernelCircuitSimulator;
133
- let wasm: CircuitsWasm;
134
-
135
- beforeAll(async () => {
136
- wasm = await CircuitsWasm.get();
137
- });
138
-
139
- beforeEach(() => {
140
- const path = times(PUBLIC_DATA_TREE_HEIGHT, i => Buffer.alloc(32, i));
141
- db.getSiblingPath.mockResolvedValue(new SiblingPath<number>(PUBLIC_DATA_TREE_HEIGHT, path));
142
- publicKernel = new WasmPublicKernelCircuitSimulator();
143
- processor = new PublicProcessor(
144
- db,
145
- publicExecutor,
146
- publicKernel,
147
- publicProver,
148
- contractDataSource,
149
- GlobalVariables.empty(),
150
- HistoricBlockData.empty(),
151
- );
152
- });
153
-
154
- const expectedTxByHash = async (tx: Tx) =>
155
- expect.objectContaining({
156
- hash: await tx.getTxHash(),
157
- proof,
158
- });
159
-
160
- it('runs a tx with enqueued public calls', async function () {
161
- const callRequests: PublicCallRequest[] = [makePublicCallRequest(0x100), makePublicCallRequest(0x100)];
162
- const callStackItems = await Promise.all(callRequests.map(call => call.toPublicCallStackItem()));
163
- const callStackHashes = callStackItems.map(call => computeCallStackItemHash(wasm, call));
164
-
165
- const kernelOutput = makePrivateKernelPublicInputsFinal(0x10);
166
- kernelOutput.end.publicCallStack = padArrayEnd(callStackHashes, Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
167
- kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX);
168
-
169
- const tx = new Tx(kernelOutput, proof, TxL2Logs.random(2, 3), TxL2Logs.random(3, 2), callRequests, [
170
- ExtendedContractData.random(),
171
- ]);
172
-
173
- publicExecutor.simulate.mockImplementation(execution => {
174
- for (const request of callRequests) {
175
- if (execution.contractAddress.equals(request.contractAddress)) {
176
- return Promise.resolve(makePublicExecutionResultFromRequest(request));
177
- }
178
- }
179
- throw new Error(`Unexpected execution request: ${execution}`);
180
- });
181
-
182
- const [processed, failed] = await processor.process([tx]);
183
-
184
- expect(processed).toHaveLength(1);
185
- expect(processed).toEqual([await expectedTxByHash(tx)]);
186
- expect(failed).toHaveLength(0);
187
- expect(publicExecutor.simulate).toHaveBeenCalledTimes(2);
188
- });
189
-
190
- it('runs a tx with an enqueued public call with nested execution', async function () {
191
- const callRequest: PublicCallRequest = makePublicCallRequest(0x100);
192
- const callStackItem = await callRequest.toPublicCallStackItem();
193
- const callStackHash = computeCallStackItemHash(wasm, callStackItem);
194
-
195
- const kernelOutput = makePrivateKernelPublicInputsFinal(0x10);
196
- kernelOutput.end.publicCallStack = padArrayEnd([callStackHash], Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
197
- kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX);
198
-
199
- const tx = new Tx(
200
- kernelOutput,
201
- proof,
202
- TxL2Logs.random(2, 3),
203
- TxL2Logs.random(3, 2),
204
- [callRequest],
205
- [ExtendedContractData.random()],
206
- );
207
-
208
- const publicExecutionResult = makePublicExecutionResultFromRequest(callRequest);
209
- publicExecutionResult.nestedExecutions = [
210
- makePublicExecutionResult(publicExecutionResult.execution.contractAddress, {
211
- to: makeAztecAddress(30),
212
- functionData: new FunctionData(makeSelector(5), false, false, false),
213
- args: new Array(ARGS_LENGTH).fill(Fr.ZERO),
214
- }),
215
- ];
216
- publicExecutor.simulate.mockResolvedValue(publicExecutionResult);
217
-
218
- const [processed, failed] = await processor.process([tx]);
219
-
220
- expect(processed).toHaveLength(1);
221
- expect(processed).toEqual([await expectedTxByHash(tx)]);
222
- expect(failed).toHaveLength(0);
223
- expect(publicExecutor.simulate).toHaveBeenCalledTimes(1);
224
- });
225
- });
226
- });
227
-
228
- function makePublicExecutionResultFromRequest(item: PublicCallRequest): PublicExecutionResult {
229
- return {
230
- execution: item,
231
- nestedExecutions: [],
232
- returnValues: [new Fr(1n)],
233
- newCommitments: [],
234
- newL2ToL1Messages: [],
235
- newNullifiers: [],
236
- contractStorageReads: [],
237
- contractStorageUpdateRequests: [],
238
- unencryptedLogs: new FunctionL2Logs([]),
239
- };
240
- }
241
-
242
- function makePublicExecutionResult(
243
- from: AztecAddress,
244
- tx: FunctionCall,
245
- nestedExecutions: PublicExecutionResult[] = [],
246
- ): PublicExecutionResult {
247
- const callContext = new CallContext(from, tx.to, EthAddress.ZERO, false, false, false);
248
- const execution: PublicExecution = {
249
- callContext,
250
- contractAddress: tx.to,
251
- functionData: tx.functionData,
252
- args: tx.args,
253
- };
254
- return {
255
- execution,
256
- nestedExecutions,
257
- returnValues: [],
258
- newCommitments: [],
259
- newNullifiers: [],
260
- newL2ToL1Messages: [],
261
- contractStorageReads: [],
262
- contractStorageUpdateRequests: [],
263
- unencryptedLogs: new FunctionL2Logs([]),
264
- };
265
- }
@@ -1,160 +0,0 @@
1
- import {
2
- Fr,
3
- GlobalVariables,
4
- HistoricBlockData,
5
- NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
6
- makeEmptyProof,
7
- } from '@aztec/circuits.js';
8
- import { P2P, P2PClientState } from '@aztec/p2p';
9
- import { L1ToL2MessageSource, L2Block, L2BlockSource, MerkleTreeId, Tx, TxHash, mockTx } from '@aztec/types';
10
- import { MerkleTreeOperations, WorldStateRunningState, WorldStateSynchroniser } from '@aztec/world-state';
11
-
12
- import { MockProxy, mock } from 'jest-mock-extended';
13
- import times from 'lodash.times';
14
-
15
- import { BlockBuilder } from '../block_builder/index.js';
16
- import { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
17
- import { L1Publisher } from '../index.js';
18
- import { makeEmptyProcessedTx, makeProcessedTx } from './processed_tx.js';
19
- import { PublicProcessor, PublicProcessorFactory } from './public_processor.js';
20
- import { Sequencer } from './sequencer.js';
21
-
22
- describe('sequencer', () => {
23
- let publisher: MockProxy<L1Publisher>;
24
- let globalVariableBuilder: MockProxy<GlobalVariableBuilder>;
25
- let p2p: MockProxy<P2P>;
26
- let worldState: MockProxy<WorldStateSynchroniser>;
27
- let blockBuilder: MockProxy<BlockBuilder>;
28
- let merkleTreeOps: MockProxy<MerkleTreeOperations>;
29
- let publicProcessor: MockProxy<PublicProcessor>;
30
- let l2BlockSource: MockProxy<L2BlockSource>;
31
- let l1ToL2MessageSource: MockProxy<L1ToL2MessageSource>;
32
- let publicProcessorFactory: MockProxy<PublicProcessorFactory>;
33
-
34
- let lastBlockNumber: number;
35
-
36
- let sequencer: TestSubject;
37
-
38
- const chainId = Fr.ZERO;
39
- const version = Fr.ZERO;
40
-
41
- beforeEach(() => {
42
- lastBlockNumber = 0;
43
-
44
- publisher = mock<L1Publisher>();
45
- globalVariableBuilder = mock<GlobalVariableBuilder>();
46
- merkleTreeOps = mock<MerkleTreeOperations>();
47
- blockBuilder = mock<BlockBuilder>();
48
-
49
- p2p = mock<P2P>({
50
- getStatus: () => Promise.resolve({ state: P2PClientState.IDLE, syncedToL2Block: lastBlockNumber }),
51
- });
52
-
53
- worldState = mock<WorldStateSynchroniser>({
54
- getLatest: () => merkleTreeOps,
55
- status: () => Promise.resolve({ state: WorldStateRunningState.IDLE, syncedToL2Block: lastBlockNumber }),
56
- });
57
-
58
- publicProcessor = mock<PublicProcessor>({
59
- process: async txs => [await Promise.all(txs.map(tx => makeProcessedTx(tx))), []],
60
- makeEmptyProcessedTx: () => makeEmptyProcessedTx(HistoricBlockData.empty(), chainId, version),
61
- });
62
-
63
- publicProcessorFactory = mock<PublicProcessorFactory>({
64
- create: (_, __) => Promise.resolve(publicProcessor),
65
- });
66
-
67
- l2BlockSource = mock<L2BlockSource>({
68
- getBlockNumber: () => Promise.resolve(lastBlockNumber),
69
- });
70
-
71
- l1ToL2MessageSource = mock<L1ToL2MessageSource>({
72
- getPendingL1ToL2Messages: () => Promise.resolve(Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(Fr.ZERO)),
73
- });
74
-
75
- sequencer = new TestSubject(
76
- publisher,
77
- globalVariableBuilder,
78
- p2p,
79
- worldState,
80
- blockBuilder,
81
- l2BlockSource,
82
- l1ToL2MessageSource,
83
- publicProcessorFactory,
84
- {
85
- chainId: Number(chainId.value),
86
- version: Number(version.value),
87
- },
88
- );
89
- });
90
-
91
- it('builds a block out of a single tx', async () => {
92
- const tx = mockTx();
93
- const block = L2Block.random(lastBlockNumber + 1);
94
- const proof = makeEmptyProof();
95
-
96
- p2p.getTxs.mockResolvedValueOnce([tx]);
97
- blockBuilder.buildL2Block.mockResolvedValueOnce([block, proof]);
98
- publisher.processL2Block.mockResolvedValueOnce(true);
99
- globalVariableBuilder.buildGlobalVariables.mockResolvedValueOnce(
100
- new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO),
101
- );
102
-
103
- await sequencer.initialSync();
104
- await sequencer.work();
105
-
106
- const expectedTxHashes = [...(await Tx.getHashes([tx])), ...times(3, () => TxHash.ZERO)];
107
-
108
- expect(blockBuilder.buildL2Block).toHaveBeenCalledWith(
109
- new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO),
110
- expectedTxHashes.map(hash => expect.objectContaining({ hash })),
111
- Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)),
112
- );
113
- expect(publisher.processL2Block).toHaveBeenCalledWith(block);
114
- });
115
-
116
- it('builds a block out of several txs rejecting double spends', async () => {
117
- const txs = [mockTx(0x10000), mockTx(0x20000), mockTx(0x30000)];
118
- const doubleSpendTx = txs[1];
119
- const block = L2Block.random(lastBlockNumber + 1);
120
- const proof = makeEmptyProof();
121
-
122
- p2p.getTxs.mockResolvedValueOnce(txs);
123
- blockBuilder.buildL2Block.mockResolvedValueOnce([block, proof]);
124
- publisher.processL2Block.mockResolvedValueOnce(true);
125
- globalVariableBuilder.buildGlobalVariables.mockResolvedValueOnce(
126
- new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO),
127
- );
128
-
129
- // We make a nullifier from tx1 a part of the nullifier tree, so it gets rejected as double spend
130
- const doubleSpendNullifier = doubleSpendTx.data.end.newNullifiers[0].toBuffer();
131
- merkleTreeOps.findLeafIndex.mockImplementation((treeId: MerkleTreeId, value: Buffer) => {
132
- return Promise.resolve(
133
- treeId === MerkleTreeId.NULLIFIER_TREE && value.equals(doubleSpendNullifier) ? 1n : undefined,
134
- );
135
- });
136
-
137
- await sequencer.initialSync();
138
- await sequencer.work();
139
-
140
- const expectedTxHashes = [...(await Tx.getHashes([txs[0], txs[2]])), TxHash.ZERO, TxHash.ZERO];
141
-
142
- expect(blockBuilder.buildL2Block).toHaveBeenCalledWith(
143
- new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO),
144
- expectedTxHashes.map(hash => expect.objectContaining({ hash })),
145
- Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)),
146
- );
147
- expect(publisher.processL2Block).toHaveBeenCalledWith(block);
148
- expect(p2p.deleteTxs).toHaveBeenCalledWith([await doubleSpendTx.getTxHash()]);
149
- });
150
- });
151
-
152
- class TestSubject extends Sequencer {
153
- public work() {
154
- return super.work();
155
- }
156
-
157
- public initialSync(): Promise<void> {
158
- return super.initialSync();
159
- }
160
- }
package/tsconfig.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "extends": "..",
3
- "compilerOptions": {
4
- "outDir": "dest",
5
- "rootDir": "src",
6
- "tsBuildInfoFile": ".tsbuildinfo"
7
- },
8
- "references": [
9
- {
10
- "path": "../acir-simulator"
11
- },
12
- {
13
- "path": "../circuits.js"
14
- },
15
- {
16
- "path": "../ethereum"
17
- },
18
- {
19
- "path": "../foundation"
20
- },
21
- {
22
- "path": "../l1-artifacts"
23
- },
24
- {
25
- "path": "../merkle-tree"
26
- },
27
- {
28
- "path": "../p2p"
29
- },
30
- {
31
- "path": "../types"
32
- },
33
- {
34
- "path": "../world-state"
35
- }
36
- ],
37
- "include": ["src"]
38
- }