@aztec/sequencer-client 0.1.0-alpha47 → 0.1.0-alpha49

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 (39) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/dest/block_builder/solo_block_builder.test.d.ts.map +1 -1
  3. package/dest/block_builder/solo_block_builder.test.js +5 -5
  4. package/dest/global_variable_builder/index.d.ts +1 -0
  5. package/dest/global_variable_builder/index.d.ts.map +1 -1
  6. package/dest/global_variable_builder/index.js +1 -1
  7. package/dest/index.d.ts +2 -0
  8. package/dest/index.d.ts.map +1 -1
  9. package/dest/index.js +4 -1
  10. package/dest/publisher/l1-publisher.d.ts +12 -6
  11. package/dest/publisher/l1-publisher.d.ts.map +1 -1
  12. package/dest/publisher/l1-publisher.js +3 -3
  13. package/dest/publisher/viem-tx-sender.d.ts +3 -3
  14. package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
  15. package/dest/publisher/viem-tx-sender.js +10 -7
  16. package/dest/sequencer/processed_tx.d.ts +18 -1
  17. package/dest/sequencer/processed_tx.d.ts.map +1 -1
  18. package/dest/sequencer/processed_tx.js +4 -3
  19. package/dest/sequencer/public_processor.d.ts +2 -2
  20. package/dest/sequencer/public_processor.d.ts.map +1 -1
  21. package/dest/sequencer/public_processor.js +12 -7
  22. package/dest/sequencer/public_processor.test.js +21 -13
  23. package/dest/sequencer/sequencer.d.ts +2 -2
  24. package/dest/sequencer/sequencer.d.ts.map +1 -1
  25. package/dest/sequencer/sequencer.js +11 -10
  26. package/dest/simulator/index.d.ts +1 -0
  27. package/dest/simulator/index.d.ts.map +1 -1
  28. package/dest/simulator/index.js +2 -2
  29. package/package.json +10 -10
  30. package/src/block_builder/solo_block_builder.test.ts +4 -3
  31. package/src/global_variable_builder/index.ts +1 -0
  32. package/src/index.ts +4 -0
  33. package/src/publisher/l1-publisher.ts +15 -13
  34. package/src/publisher/viem-tx-sender.ts +10 -7
  35. package/src/sequencer/processed_tx.ts +34 -3
  36. package/src/sequencer/public_processor.test.ts +33 -12
  37. package/src/sequencer/public_processor.ts +17 -8
  38. package/src/sequencer/sequencer.ts +10 -20
  39. package/src/simulator/index.ts +2 -0
@@ -4,11 +4,13 @@ import {
4
4
  AztecAddress,
5
5
  CallContext,
6
6
  CircuitsWasm,
7
+ CombinedAccumulatedData,
7
8
  EthAddress,
8
9
  Fr,
9
10
  FunctionData,
10
11
  GlobalVariables,
11
12
  HistoricBlockData,
13
+ KernelCircuitPublicInputs,
12
14
  MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,
13
15
  MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
14
16
  PUBLIC_DATA_TREE_HEIGHT,
@@ -20,15 +22,15 @@ import {
20
22
  import { computeCallStackItemHash } from '@aztec/circuits.js/abis';
21
23
  import {
22
24
  makeAztecAddress,
23
- makeKernelPublicInputs,
25
+ makeKernelPublicInputsFinal,
24
26
  makePublicCallRequest,
25
27
  makeSelector,
26
28
  } from '@aztec/circuits.js/factories';
27
29
  import { padArrayEnd } from '@aztec/foundation/collection';
28
30
  import {
29
- ContractDataAndBytecode,
30
31
  ContractDataSource,
31
32
  EncodedContractFunction,
33
+ ExtendedContractData,
32
34
  FunctionCall,
33
35
  FunctionL2Logs,
34
36
  SiblingPath,
@@ -39,7 +41,6 @@ import {
39
41
  import { MerkleTreeOperations, TreeInfo } from '@aztec/world-state';
40
42
 
41
43
  import { MockProxy, mock } from 'jest-mock-extended';
42
- import pick from 'lodash.pick';
43
44
  import times from 'lodash.times';
44
45
 
45
46
  import { PublicProver } from '../prover/index.js';
@@ -54,7 +55,7 @@ describe('public_processor', () => {
54
55
  let contractDataSource: MockProxy<ContractDataSource>;
55
56
 
56
57
  let publicFunction: EncodedContractFunction;
57
- let contractData: ContractDataAndBytecode;
58
+ let contractData: ExtendedContractData;
58
59
  let proof: Proof;
59
60
  let root: Buffer;
60
61
 
@@ -66,7 +67,7 @@ describe('public_processor', () => {
66
67
  publicProver = mock<PublicProver>();
67
68
  contractDataSource = mock<ContractDataSource>();
68
69
 
69
- contractData = ContractDataAndBytecode.random();
70
+ contractData = ExtendedContractData.random();
70
71
  publicFunction = EncodedContractFunction.random();
71
72
  proof = makeEmptyProof();
72
73
  root = Buffer.alloc(32, 5);
@@ -74,7 +75,7 @@ describe('public_processor', () => {
74
75
  publicProver.getPublicCircuitProof.mockResolvedValue(proof);
75
76
  publicProver.getPublicKernelCircuitProof.mockResolvedValue(proof);
76
77
  db.getTreeInfo.mockResolvedValue({ root } as TreeInfo);
77
- contractDataSource.getContractDataAndBytecode.mockResolvedValue(contractData);
78
+ contractDataSource.getExtendedContractData.mockResolvedValue(contractData);
78
79
  contractDataSource.getPublicFunction.mockResolvedValue(publicFunction);
79
80
  });
80
81
 
@@ -101,7 +102,18 @@ describe('public_processor', () => {
101
102
  const [processed, failed] = await processor.process([tx]);
102
103
 
103
104
  expect(processed).toEqual([
104
- { isEmpty: false, hash, ...pick(tx, 'data', 'proof', 'encryptedLogs', 'unencryptedLogs') },
105
+ {
106
+ isEmpty: false,
107
+ hash,
108
+ data: new KernelCircuitPublicInputs(
109
+ CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end),
110
+ tx.data.constants,
111
+ tx.data.isPrivate,
112
+ ),
113
+ proof: tx.proof,
114
+ encryptedLogs: tx.encryptedLogs,
115
+ unencryptedLogs: tx.unencryptedLogs,
116
+ },
105
117
  ]);
106
118
  expect(failed).toEqual([]);
107
119
  });
@@ -113,7 +125,7 @@ describe('public_processor', () => {
113
125
  const [processed, failed] = await processor.process([tx]);
114
126
 
115
127
  expect(processed).toEqual([]);
116
- expect(failed).toEqual([tx]);
128
+ expect(failed[0].tx).toEqual(tx);
117
129
  });
118
130
  });
119
131
 
@@ -151,11 +163,13 @@ describe('public_processor', () => {
151
163
  const callStackItems = await Promise.all(callRequests.map(call => call.toPublicCallStackItem()));
152
164
  const callStackHashes = callStackItems.map(call => computeCallStackItemHash(wasm, call));
153
165
 
154
- const kernelOutput = makeKernelPublicInputs(0x10);
166
+ const kernelOutput = makeKernelPublicInputsFinal(0x10);
155
167
  kernelOutput.end.publicCallStack = padArrayEnd(callStackHashes, Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
156
168
  kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX);
157
169
 
158
- const tx = new Tx(kernelOutput, proof, TxL2Logs.random(2, 3), TxL2Logs.random(3, 2), [], callRequests);
170
+ const tx = new Tx(kernelOutput, proof, TxL2Logs.random(2, 3), TxL2Logs.random(3, 2), callRequests, [
171
+ ExtendedContractData.random(),
172
+ ]);
159
173
 
160
174
  publicExecutor.execute.mockImplementation(execution => {
161
175
  for (const request of callRequests) {
@@ -179,11 +193,18 @@ describe('public_processor', () => {
179
193
  const callStackItem = await callRequest.toPublicCallStackItem();
180
194
  const callStackHash = computeCallStackItemHash(wasm, callStackItem);
181
195
 
182
- const kernelOutput = makeKernelPublicInputs(0x10);
196
+ const kernelOutput = makeKernelPublicInputsFinal(0x10);
183
197
  kernelOutput.end.publicCallStack = padArrayEnd([callStackHash], Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
184
198
  kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX);
185
199
 
186
- const tx = new Tx(kernelOutput, proof, TxL2Logs.random(2, 3), TxL2Logs.random(3, 2), [], [callRequest]);
200
+ const tx = new Tx(
201
+ kernelOutput,
202
+ proof,
203
+ TxL2Logs.random(2, 3),
204
+ TxL2Logs.random(3, 2),
205
+ [callRequest],
206
+ [ExtendedContractData.random()],
207
+ );
187
208
 
188
209
  const publicExecutionResult = makePublicExecutionResultFromRequest(callRequest);
189
210
  publicExecutionResult.nestedExecutions = [
@@ -9,6 +9,7 @@ import {
9
9
  import {
10
10
  AztecAddress,
11
11
  CircuitsWasm,
12
+ CombinedAccumulatedData,
12
13
  ContractStorageRead,
13
14
  ContractStorageUpdateRequest,
14
15
  Fr,
@@ -46,10 +47,9 @@ import { MerkleTreeOperations } from '@aztec/world-state';
46
47
  import { getVerificationKeys } from '../index.js';
47
48
  import { EmptyPublicProver } from '../prover/empty.js';
48
49
  import { PublicProver } from '../prover/index.js';
49
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
50
- import { getPublicExecutor } from '../simulator/public_executor.js';
50
+ import { PublicKernelCircuitSimulator, getPublicExecutor } from '../simulator/index.js';
51
51
  import { WasmPublicKernelCircuitSimulator } from '../simulator/public_kernel.js';
52
- import { ProcessedTx, makeEmptyProcessedTx, makeProcessedTx } from './processed_tx.js';
52
+ import { FailedTx, ProcessedTx, makeEmptyProcessedTx, makeProcessedTx } from './processed_tx.js';
53
53
  import { getHistoricBlockData } from './utils.js';
54
54
 
55
55
  /**
@@ -107,17 +107,22 @@ export class PublicProcessor {
107
107
  * @param txs - Txs to process.
108
108
  * @returns The list of processed txs with their circuit simulation outputs.
109
109
  */
110
- public async process(txs: Tx[]): Promise<[ProcessedTx[], Tx[]]> {
110
+ public async process(txs: Tx[]): Promise<[ProcessedTx[], FailedTx[]]> {
111
+ // The processor modifies the tx objects in place, so we need to clone them.
112
+ txs = txs.map(tx => Tx.fromJSON(tx.toJSON()));
111
113
  const result: ProcessedTx[] = [];
112
- const failed: Tx[] = [];
114
+ const failed: FailedTx[] = [];
113
115
 
114
116
  for (const tx of txs) {
115
117
  this.log(`Processing tx ${await tx.getTxHash()}`);
116
118
  try {
117
119
  result.push(await this.processTx(tx));
118
120
  } catch (err) {
119
- this.log.error(`Error processing tx ${await tx.getTxHash()}: ${err}`);
120
- failed.push(tx);
121
+ this.log.warn(`Error processing tx ${await tx.getTxHash()}: ${err}`);
122
+ failed.push({
123
+ tx,
124
+ error: err instanceof Error ? err : new Error('Unknown error'),
125
+ });
121
126
  }
122
127
  }
123
128
  return [result, failed];
@@ -149,7 +154,11 @@ export class PublicProcessor {
149
154
  this.log(`Executing enqueued public calls for tx ${await tx.getTxHash()}`);
150
155
  if (!tx.enqueuedPublicFunctionCalls) throw new Error(`Missing preimages for enqueued public calls`);
151
156
 
152
- let kernelOutput = tx.data;
157
+ let kernelOutput = new KernelCircuitPublicInputs(
158
+ CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end),
159
+ tx.data.constants,
160
+ tx.data.isPrivate,
161
+ );
153
162
  let kernelProof = tx.proof;
154
163
  const newUnencryptedFunctionLogs: FunctionL2Logs[] = [];
155
164
 
@@ -3,15 +3,7 @@ import { Fr } from '@aztec/foundation/fields';
3
3
  import { createDebugLogger } from '@aztec/foundation/log';
4
4
  import { RunningPromise } from '@aztec/foundation/running-promise';
5
5
  import { P2P } from '@aztec/p2p';
6
- import {
7
- ContractData,
8
- ContractDataAndBytecode,
9
- L1ToL2MessageSource,
10
- L2Block,
11
- L2BlockSource,
12
- MerkleTreeId,
13
- Tx,
14
- } from '@aztec/types';
6
+ import { L1ToL2MessageSource, L2Block, L2BlockSource, MerkleTreeId, Tx } from '@aztec/types';
15
7
  import { WorldStateStatus, WorldStateSynchroniser } from '@aztec/world-state';
16
8
 
17
9
  import times from 'lodash.times';
@@ -149,8 +141,9 @@ export class Sequencer {
149
141
  const processor = await this.publicProcessorFactory.create(prevGlobalVariables, newGlobalVariables);
150
142
  const [processedTxs, failedTxs] = await processor.process(validTxs);
151
143
  if (failedTxs.length > 0) {
152
- this.log(`Dropping failed txs ${(await Tx.getHashes(failedTxs)).join(', ')}`);
153
- await this.p2pClient.deleteTxs(await Tx.getHashes(failedTxs));
144
+ const failedTxData = failedTxs.map(fail => fail.tx);
145
+ this.log(`Dropping failed txs ${(await Tx.getHashes(failedTxData)).join(', ')}`);
146
+ await this.p2pClient.deleteTxs(await Tx.getHashes(failedTxData));
154
147
  }
155
148
 
156
149
  if (processedTxs.length === 0) {
@@ -170,7 +163,7 @@ export class Sequencer {
170
163
  const block = await this.buildBlock(processedTxs, l1ToL2Messages, emptyTx, newGlobalVariables);
171
164
  this.log(`Assembled block ${block.number}`);
172
165
 
173
- await this.publishContractDataAndBytecode(validTxs, block);
166
+ await this.publishExtendedContractData(validTxs, block);
174
167
 
175
168
  await this.publishL2Block(block);
176
169
  this.log.info(`Submitted rollup block ${block.number} with ${processedTxs.length} transactions`);
@@ -182,28 +175,25 @@ export class Sequencer {
182
175
  }
183
176
 
184
177
  /**
185
- * Gets new contract data and bytecode from the txs and publishes it on chain.
178
+ * Gets new extended contract data from the txs and publishes it on chain.
186
179
  * @param validTxs - The set of real transactions being published as part of the block.
187
180
  * @param block - The L2Block to be published.
188
181
  */
189
- protected async publishContractDataAndBytecode(validTxs: Tx[], block: L2Block) {
182
+ protected async publishExtendedContractData(validTxs: Tx[], block: L2Block) {
190
183
  // Publishes contract data for txs to the network and awaits the tx to be mined
191
184
  this.state = SequencerState.PUBLISHING_CONTRACT_DATA;
192
185
  const newContractData = validTxs
193
186
  .map(tx => {
194
187
  // Currently can only have 1 new contract per tx
195
188
  const newContract = tx.data?.end.newContracts[0];
196
- if (newContract && tx.newContractPublicFunctions?.length) {
197
- return new ContractDataAndBytecode(
198
- new ContractData(newContract.contractAddress, newContract.portalContractAddress),
199
- tx.newContractPublicFunctions,
200
- );
189
+ if (newContract) {
190
+ return tx.newContracts[0];
201
191
  }
202
192
  })
203
193
  .filter((cd): cd is Exclude<typeof cd, undefined> => cd !== undefined);
204
194
 
205
195
  const blockHash = block.getCalldataHash();
206
- this.log(`Publishing contract data and bytecode with block hash ${blockHash.toString('hex')}`);
196
+ this.log(`Publishing extended contract data with block hash ${blockHash.toString('hex')}`);
207
197
 
208
198
  const publishedContractData = await this.publisher.processNewContractData(block.number, blockHash, newContractData);
209
199
  if (publishedContractData) {
@@ -8,6 +8,8 @@ import {
8
8
  RootRollupPublicInputs,
9
9
  } from '@aztec/circuits.js';
10
10
 
11
+ export { getPublicExecutor } from './public_executor.js';
12
+
11
13
  /**
12
14
  * Circuit simulator for the rollup circuits.
13
15
  */