@aztec/sequencer-client 0.16.4 → 0.16.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 (37) hide show
  1. package/dest/block_builder/solo_block_builder.d.ts +3 -3
  2. package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
  3. package/dest/block_builder/solo_block_builder.js +26 -26
  4. package/dest/block_builder/types.d.ts +11 -2
  5. package/dest/block_builder/types.d.ts.map +1 -1
  6. package/dest/sequencer/utils.js +2 -2
  7. package/package.json +11 -11
  8. package/src/block_builder/index.ts +0 -24
  9. package/src/block_builder/solo_block_builder.ts +0 -758
  10. package/src/block_builder/types.ts +0 -16
  11. package/src/client/index.ts +0 -1
  12. package/src/client/sequencer-client.ts +0 -87
  13. package/src/config.ts +0 -76
  14. package/src/global_variable_builder/config.ts +0 -20
  15. package/src/global_variable_builder/global_builder.ts +0 -87
  16. package/src/global_variable_builder/index.ts +0 -16
  17. package/src/global_variable_builder/viem-reader.ts +0 -61
  18. package/src/index.ts +0 -15
  19. package/src/mocks/verification_keys.ts +0 -36
  20. package/src/prover/empty.ts +0 -74
  21. package/src/prover/index.ts +0 -53
  22. package/src/publisher/config.ts +0 -41
  23. package/src/publisher/index.ts +0 -14
  24. package/src/publisher/l1-publisher.ts +0 -291
  25. package/src/publisher/viem-tx-sender.ts +0 -195
  26. package/src/receiver.ts +0 -13
  27. package/src/sequencer/config.ts +0 -1
  28. package/src/sequencer/index.ts +0 -3
  29. package/src/sequencer/processed_tx.ts +0 -107
  30. package/src/sequencer/public_processor.ts +0 -433
  31. package/src/sequencer/sequencer.ts +0 -434
  32. package/src/sequencer/utils.ts +0 -25
  33. package/src/simulator/index.ts +0 -51
  34. package/src/simulator/public_executor.ts +0 -153
  35. package/src/simulator/public_kernel.ts +0 -54
  36. package/src/simulator/rollup.ts +0 -76
  37. package/src/utils.ts +0 -16
@@ -1,291 +0,0 @@
1
- import { createDebugLogger } from '@aztec/foundation/log';
2
- import { InterruptibleSleep } from '@aztec/foundation/sleep';
3
- import { ExtendedContractData, L2Block } from '@aztec/types';
4
- import { L1PublishStats } from '@aztec/types/stats';
5
-
6
- import pick from 'lodash.pick';
7
-
8
- import { L2BlockReceiver } from '../receiver.js';
9
- import { PublisherConfig } from './config.js';
10
-
11
- /**
12
- * Stats for a sent transaction.
13
- */
14
- export type TransactionStats = {
15
- /** Hash of the transaction. */
16
- transactionHash: string;
17
- /** Size in bytes of the tx calldata */
18
- calldataSize: number;
19
- /** Gas required to pay for the calldata inclusion (depends on size and number of zeros) */
20
- calldataGas: number;
21
- };
22
-
23
- /**
24
- * Minimal information from a tx receipt returned by an L1PublisherTxSender.
25
- */
26
- export type MinimalTransactionReceipt = {
27
- /** True if the tx was successful, false if reverted. */
28
- status: boolean;
29
- /** Hash of the transaction. */
30
- transactionHash: string;
31
- /** Effective gas used by the tx */
32
- gasUsed: bigint;
33
- /** Effective gas price paid by the tx */
34
- gasPrice: bigint;
35
- };
36
-
37
- /**
38
- * Pushes txs to the L1 chain and waits for their completion.
39
- */
40
- export interface L1PublisherTxSender {
41
- /**
42
- * Sends a tx to the L1 rollup contract with a new L2 block. Returns once the tx has been mined.
43
- * @param encodedData - Serialized data for processing the new L2 block.
44
- * @returns The hash of the mined tx.
45
- */
46
- sendProcessTx(encodedData: L1ProcessArgs): Promise<string | undefined>;
47
-
48
- /**
49
- * Sends a tx to the contract deployment emitter contract with contract deployment data such as bytecode. Returns once the tx has been mined.
50
- * @param l2BlockNum - Number of the L2 block that owns this encrypted logs.
51
- * @param l2BlockHash - The hash of the block corresponding to this data.
52
- * @param partialAddresses - The partial addresses of the deployed contract
53
- * @param publicKeys - The public keys of the deployed contract
54
- * @param newExtendedContractData - Data to publish.
55
- * @returns The hash of the mined tx.
56
- * @remarks Partial addresses, public keys and contract data has to be in the same order. Read more {@link https://docs.aztec.network/concepts/foundation/accounts/keys#addresses-partial-addresses-and-public-keys | here}.
57
- */
58
- sendEmitContractDeploymentTx(
59
- l2BlockNum: number,
60
- l2BlockHash: Buffer,
61
- newExtendedContractData: ExtendedContractData[],
62
- ): Promise<(string | undefined)[]>;
63
-
64
- /**
65
- * Returns a tx receipt if the tx has been mined.
66
- * @param txHash - Hash of the tx to look for.
67
- * @returns Undefined if the tx hasn't been mined yet, the receipt otherwise.
68
- */
69
- getTransactionReceipt(txHash: string): Promise<MinimalTransactionReceipt | undefined>;
70
-
71
- /**
72
- * Returns info on a tx by calling eth_getTransaction.
73
- * @param txHash - Hash of the tx to look for.
74
- */
75
- getTransactionStats(txHash: string): Promise<TransactionStats | undefined>;
76
- }
77
-
78
- /**
79
- * Encoded block data and proof ready to be pushed to the L1 contract.
80
- */
81
- export type L1ProcessArgs = {
82
- /**
83
- * Root rollup proof for an L1 block.
84
- */
85
- proof: Buffer;
86
- /**
87
- * Serialized L2Block data.
88
- */
89
- inputs: Buffer;
90
- };
91
-
92
- /**
93
- * Helper function to filter out undefined items from an array.
94
- * Also asserts the resulting array is of type <T>.
95
- * @param item - An item from an array to check if undefined or not.
96
- * @returns True if the item is not undefined.
97
- */
98
- function isNotUndefined<T>(item: T | undefined): item is T {
99
- return item !== undefined;
100
- }
101
-
102
- /**
103
- * Publishes L2 blocks to L1. This implementation does *not* retry a transaction in
104
- * the event of network congestion, but should work for local development.
105
- * - If sending (not mining) a tx fails, it retries indefinitely at 1-minute intervals.
106
- * - If the tx is not mined, keeps polling indefinitely at 1-second intervals.
107
- *
108
- * Adapted from https://github.com/AztecProtocol/aztec2-internal/blob/master/falafel/src/rollup_publisher.ts.
109
- */
110
- export class L1Publisher implements L2BlockReceiver {
111
- private interruptibleSleep = new InterruptibleSleep();
112
- private sleepTimeMs: number;
113
- private interrupted = false;
114
- private log = createDebugLogger('aztec:sequencer:publisher');
115
-
116
- constructor(private txSender: L1PublisherTxSender, config?: PublisherConfig) {
117
- this.sleepTimeMs = config?.l1BlockPublishRetryIntervalMS ?? 60_000;
118
- }
119
-
120
- /**
121
- * Processes incoming L2 block data by publishing it to the L1 rollup contract.
122
- * @param l2BlockData - L2 block data to publish.
123
- * @returns True once the tx has been confirmed and is successful, false on revert or interrupt, blocks otherwise.
124
- */
125
- public async processL2Block(l2BlockData: L2Block): Promise<boolean> {
126
- const proof = Buffer.alloc(0);
127
- const txData = { proof, inputs: l2BlockData.toBufferWithLogs() };
128
-
129
- while (!this.interrupted) {
130
- if (!(await this.checkFeeDistributorBalance())) {
131
- this.log(`Fee distributor ETH balance too low, awaiting top up...`);
132
- await this.sleepOrInterrupted();
133
- continue;
134
- }
135
-
136
- const txHash = await this.sendProcessTx(txData);
137
- if (!txHash) {
138
- break;
139
- }
140
-
141
- const receipt = await this.getTransactionReceipt(txHash);
142
- if (!receipt) {
143
- break;
144
- }
145
-
146
- // Tx was mined successfully
147
- if (receipt.status) {
148
- const tx = await this.txSender.getTransactionStats(txHash);
149
- const stats: L1PublishStats = {
150
- ...pick(receipt, 'gasPrice', 'gasUsed', 'transactionHash'),
151
- ...pick(tx!, 'calldataGas', 'calldataSize'),
152
- ...l2BlockData.getStats(),
153
- eventName: 'rollup-published-to-l1',
154
- };
155
- this.log.info(`Published L2 block to L1 rollup contract`, stats);
156
- return true;
157
- }
158
-
159
- // Check if someone else incremented the block number
160
- if (!(await this.checkNextL2BlockNum(l2BlockData.number))) {
161
- this.log('Publish failed. Contract changed underfoot.');
162
- break;
163
- }
164
-
165
- this.log(`Transaction status failed: ${receipt.transactionHash}`);
166
- await this.sleepOrInterrupted();
167
- }
168
-
169
- this.log('L2 block data syncing interrupted while processing blocks.');
170
- return false;
171
- }
172
-
173
- /**
174
- * Publishes new contract data to L1.
175
- * @param l2BlockNum - The L2 block number that the new contracts were deployed on.
176
- * @param l2BlockHash - The hash of the block corresponding to this data.
177
- * @param contractData - The new contract data to publish.
178
- * @returns True once the tx has been confirmed and is successful, false on revert or interrupt, blocks otherwise.
179
- */
180
- public async processNewContractData(l2BlockNum: number, l2BlockHash: Buffer, contractData: ExtendedContractData[]) {
181
- let _contractData: ExtendedContractData[] = [];
182
- while (!this.interrupted) {
183
- if (!(await this.checkFeeDistributorBalance())) {
184
- this.log(`Fee distributor ETH balance too low, awaiting top up...`);
185
- await this.sleepOrInterrupted();
186
- continue;
187
- }
188
-
189
- const arr = _contractData.length ? _contractData : contractData;
190
- const txHashes = await this.sendEmitNewContractDataTx(l2BlockNum, l2BlockHash, arr);
191
- if (!txHashes) {
192
- break;
193
- }
194
- // filter successful txs
195
- _contractData = arr.filter((_, i) => !!txHashes[i]);
196
-
197
- const receipts = await Promise.all(
198
- txHashes.filter(isNotUndefined).map(txHash => this.getTransactionReceipt(txHash)),
199
- );
200
- if (!receipts?.length) {
201
- break;
202
- }
203
-
204
- // ALL Txs were mined successfully
205
- if (receipts.length === contractData.length && receipts.every(r => r?.status)) {
206
- return true;
207
- }
208
-
209
- this.log(
210
- `Transaction status failed: ${receipts
211
- .filter(r => !r?.status)
212
- .map(r => r?.transactionHash)
213
- .join(',')}`,
214
- );
215
- await this.sleepOrInterrupted();
216
- }
217
-
218
- this.log('L2 block data syncing interrupted while processing contract data.');
219
- return false;
220
- }
221
-
222
- /**
223
- * Calling `interrupt` will cause any in progress call to `publishRollup` to return `false` asap.
224
- * Be warned, the call may return false even if the tx subsequently gets successfully mined.
225
- * In practice this shouldn't matter, as we'll only ever be calling `interrupt` when we know it's going to fail.
226
- * A call to `restart` is required before you can continue publishing.
227
- */
228
- public interrupt() {
229
- this.interrupted = true;
230
- this.interruptibleSleep.interrupt();
231
- }
232
-
233
- /** Restarts the publisher after calling `interrupt`. */
234
- public restart() {
235
- this.interrupted = false;
236
- }
237
-
238
- // TODO: Check fee distributor has at least 0.5 ETH.
239
- // Related to https://github.com/AztecProtocol/aztec-packages/issues/1588
240
- // eslint-disable-next-line require-await
241
- private async checkFeeDistributorBalance(): Promise<boolean> {
242
- return true;
243
- }
244
-
245
- // TODO: Fail if blockchainStatus.nextBlockNum > thisBlockNum.
246
- // Related to https://github.com/AztecProtocol/aztec-packages/issues/1588
247
- private checkNextL2BlockNum(_thisBlockNum: number): Promise<boolean> {
248
- return Promise.resolve(true);
249
- }
250
-
251
- private async sendProcessTx(encodedData: L1ProcessArgs): Promise<string | undefined> {
252
- while (!this.interrupted) {
253
- try {
254
- return await this.txSender.sendProcessTx(encodedData);
255
- } catch (err) {
256
- this.log.error(`Rollup publish failed`, err);
257
- return undefined;
258
- }
259
- }
260
- }
261
-
262
- private async sendEmitNewContractDataTx(
263
- l2BlockNum: number,
264
- l2BlockHash: Buffer,
265
- newExtendedContractData: ExtendedContractData[],
266
- ) {
267
- while (!this.interrupted) {
268
- try {
269
- return await this.txSender.sendEmitContractDeploymentTx(l2BlockNum, l2BlockHash, newExtendedContractData);
270
- } catch (err) {
271
- this.log.error(`Error sending contract data to L1`, err);
272
- await this.sleepOrInterrupted();
273
- }
274
- }
275
- }
276
-
277
- private async getTransactionReceipt(txHash: string): Promise<MinimalTransactionReceipt | undefined> {
278
- while (!this.interrupted) {
279
- try {
280
- return await this.txSender.getTransactionReceipt(txHash);
281
- } catch (err) {
282
- //this.log.error(`Error getting tx receipt`, err);
283
- await this.sleepOrInterrupted();
284
- }
285
- }
286
- }
287
-
288
- protected async sleepOrInterrupted() {
289
- await this.interruptibleSleep.sleep(this.sleepTimeMs);
290
- }
291
- }
@@ -1,195 +0,0 @@
1
- import { createEthereumChain } from '@aztec/ethereum';
2
- import { createDebugLogger } from '@aztec/foundation/log';
3
- import { ContractDeploymentEmitterAbi, RollupAbi } from '@aztec/l1-artifacts';
4
- import { BLOB_SIZE_IN_BYTES, ExtendedContractData } from '@aztec/types';
5
-
6
- import {
7
- GetContractReturnType,
8
- Hex,
9
- HttpTransport,
10
- PublicClient,
11
- WalletClient,
12
- createPublicClient,
13
- createWalletClient,
14
- getAddress,
15
- getContract,
16
- hexToBytes,
17
- http,
18
- } from 'viem';
19
- import { PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts';
20
- import * as chains from 'viem/chains';
21
-
22
- import { TxSenderConfig } from './config.js';
23
- import {
24
- L1PublisherTxSender,
25
- MinimalTransactionReceipt,
26
- L1ProcessArgs as ProcessTxArgs,
27
- TransactionStats,
28
- } from './l1-publisher.js';
29
-
30
- /**
31
- * Pushes transactions to the L1 rollup contract using viem.
32
- */
33
- export class ViemTxSender implements L1PublisherTxSender {
34
- private rollupContract: GetContractReturnType<
35
- typeof RollupAbi,
36
- PublicClient<HttpTransport, chains.Chain>,
37
- WalletClient<HttpTransport, chains.Chain, PrivateKeyAccount>
38
- >;
39
- private contractDeploymentEmitterContract: GetContractReturnType<
40
- typeof ContractDeploymentEmitterAbi,
41
- PublicClient<HttpTransport, chains.Chain>,
42
- WalletClient<HttpTransport, chains.Chain, PrivateKeyAccount>
43
- >;
44
-
45
- private log = createDebugLogger('aztec:sequencer:viem-tx-sender');
46
- private publicClient: PublicClient<HttpTransport, chains.Chain>;
47
- private account: PrivateKeyAccount;
48
-
49
- constructor(config: TxSenderConfig) {
50
- const { rpcUrl, apiKey, publisherPrivateKey, l1Contracts } = config;
51
- const chain = createEthereumChain(rpcUrl, apiKey);
52
- this.account = privateKeyToAccount(publisherPrivateKey);
53
- const walletClient = createWalletClient({
54
- account: this.account,
55
- chain: chain.chainInfo,
56
- transport: http(chain.rpcUrl),
57
- });
58
-
59
- this.publicClient = createPublicClient({
60
- chain: chain.chainInfo,
61
- transport: http(chain.rpcUrl),
62
- });
63
-
64
- this.rollupContract = getContract({
65
- address: getAddress(l1Contracts.rollupAddress.toString()),
66
- abi: RollupAbi,
67
- publicClient: this.publicClient,
68
- walletClient,
69
- });
70
- this.contractDeploymentEmitterContract = getContract({
71
- address: getAddress(l1Contracts.contractDeploymentEmitterAddress.toString()),
72
- abi: ContractDeploymentEmitterAbi,
73
- publicClient: this.publicClient,
74
- walletClient,
75
- });
76
- }
77
-
78
- async getTransactionStats(txHash: string): Promise<TransactionStats | undefined> {
79
- const tx = await this.publicClient.getTransaction({ hash: txHash as Hex });
80
- if (!tx) {
81
- return undefined;
82
- }
83
- const calldata = hexToBytes(tx.input);
84
- return {
85
- transactionHash: tx.hash,
86
- calldataSize: calldata.length,
87
- calldataGas: getCalldataGasUsage(calldata),
88
- };
89
- }
90
-
91
- /**
92
- * Returns a tx receipt if the tx has been mined.
93
- * @param txHash - Hash of the tx to look for.
94
- * @returns Undefined if the tx hasn't been mined yet, the receipt otherwise.
95
- */
96
- async getTransactionReceipt(txHash: string): Promise<MinimalTransactionReceipt | undefined> {
97
- const receipt = await this.publicClient.getTransactionReceipt({
98
- hash: txHash as Hex,
99
- });
100
-
101
- if (receipt) {
102
- return {
103
- status: receipt.status === 'success',
104
- transactionHash: txHash,
105
- gasUsed: receipt.gasUsed,
106
- gasPrice: receipt.effectiveGasPrice,
107
- };
108
- }
109
-
110
- this.log(`Receipt not found for tx hash ${txHash}`);
111
- return undefined;
112
- }
113
-
114
- /**
115
- * Sends a tx to the L1 rollup contract with a new L2 block. Returns once the tx has been mined.
116
- * @param encodedData - Serialized data for processing the new L2 block.
117
- * @returns The hash of the mined tx.
118
- */
119
- async sendProcessTx(encodedData: ProcessTxArgs): Promise<string | undefined> {
120
- const args = [`0x${encodedData.proof.toString('hex')}`, `0x${encodedData.inputs.toString('hex')}`] as const;
121
-
122
- const gas = await this.rollupContract.estimateGas.process(args, {
123
- account: this.account,
124
- });
125
- const hash = await this.rollupContract.write.process(args, {
126
- gas,
127
- account: this.account,
128
- });
129
- return hash;
130
- }
131
-
132
- /**
133
- * Sends a tx to the contract deployment emitter contract with contract deployment data such as bytecode. Returns once the tx has been mined.
134
- * @param l2BlockNum - Number of the L2 block that owns this encrypted logs.
135
- * @param l2BlockHash - The hash of the block corresponding to this data.
136
- * @param newExtendedContractData - Data to publish.
137
- * @returns The hash of the mined tx.
138
- */
139
- async sendEmitContractDeploymentTx(
140
- l2BlockNum: number,
141
- l2BlockHash: Buffer,
142
- newExtendedContractData: ExtendedContractData[],
143
- ): Promise<(string | undefined)[]> {
144
- const hashes: string[] = [];
145
- for (const extendedContractData of newExtendedContractData) {
146
- const args = [
147
- BigInt(l2BlockNum),
148
- extendedContractData.contractData.contractAddress.toString() as Hex,
149
- extendedContractData.contractData.portalContractAddress.toString() as Hex,
150
- `0x${l2BlockHash.toString('hex')}`,
151
- extendedContractData.partialAddress.toString(),
152
- extendedContractData.publicKey.x.toString(),
153
- extendedContractData.publicKey.y.toString(),
154
- `0x${extendedContractData.bytecode.toString('hex')}`,
155
- ] as const;
156
-
157
- const codeSize = extendedContractData.bytecode.length;
158
- this.log(`Bytecode is ${codeSize} bytes and require ${codeSize / BLOB_SIZE_IN_BYTES} blobs`);
159
-
160
- const gas = await this.contractDeploymentEmitterContract.estimateGas.emitContractDeployment(args, {
161
- account: this.account,
162
- });
163
- const hash = await this.contractDeploymentEmitterContract.write.emitContractDeployment(args, {
164
- gas,
165
- account: this.account,
166
- });
167
- hashes.push(hash);
168
- }
169
- return hashes;
170
- }
171
-
172
- /**
173
- * Gets the chain object for the given chain id.
174
- * @param chainId - Chain id of the target EVM chain.
175
- * @returns Viem's chain object.
176
- */
177
- private getChain(chainId: number) {
178
- for (const chain of Object.values(chains)) {
179
- if ('id' in chain && chain.id === chainId) {
180
- return chain;
181
- }
182
- }
183
-
184
- throw new Error(`Chain with id ${chainId} not found`);
185
- }
186
- }
187
-
188
- /**
189
- * Returns cost of calldata usage in Ethereum.
190
- * @param data - Calldata.
191
- * @returns 4 for each zero byte, 16 for each nonzero.
192
- */
193
- function getCalldataGasUsage(data: Uint8Array) {
194
- return data.filter(byte => byte === 0).length * 4 + data.filter(byte => byte !== 0).length * 16;
195
- }
package/src/receiver.ts DELETED
@@ -1,13 +0,0 @@
1
- import { L2Block } from '@aztec/types';
2
-
3
- /**
4
- * Given the necessary rollup data, verifies it, and updates the underlying state accordingly to advance the state of the system.
5
- * See https://hackmd.io/ouVCnacHQRq2o1oRc5ksNA#RollupReceiver.
6
- */
7
- export interface L2BlockReceiver {
8
- /**
9
- * Receive and L2 block and process it, returns true if successful.
10
- * @param l2BlockData - L2 block to process.
11
- */
12
- processL2Block(l2BlockData: L2Block): Promise<boolean>;
13
- }
@@ -1 +0,0 @@
1
- export { SequencerConfig } from '@aztec/types';
@@ -1,3 +0,0 @@
1
- export * from './sequencer.js';
2
- export * from './config.js';
3
- export * from './utils.js';
@@ -1,107 +0,0 @@
1
- import {
2
- BlockHeader,
3
- CombinedAccumulatedData,
4
- Fr,
5
- Proof,
6
- PublicKernelPublicInputs,
7
- makeEmptyProof,
8
- } from '@aztec/circuits.js';
9
- import { ExtendedContractData, Tx, TxHash, TxL2Logs } from '@aztec/types';
10
-
11
- /**
12
- * Represents a tx that has been processed by the sequencer public processor,
13
- * so its kernel circuit public inputs are filled in.
14
- */
15
- export type ProcessedTx = Pick<Tx, 'proof' | 'encryptedLogs' | 'unencryptedLogs' | 'newContracts'> & {
16
- /**
17
- * Output of the public kernel circuit for this tx.
18
- */
19
- data: PublicKernelPublicInputs;
20
- /**
21
- * Hash of the transaction.
22
- */
23
- hash: TxHash;
24
- /**
25
- * Flag indicating the tx is 'empty' meaning it's a padding tx to take us to a power of 2.
26
- */
27
- isEmpty: boolean;
28
- };
29
-
30
- /**
31
- * Represents a tx that failed to be processed by the sequencer public processor.
32
- */
33
- export type FailedTx = {
34
- /**
35
- * The failing transaction.
36
- */
37
- tx: Tx;
38
- /**
39
- * The error that caused the tx to fail.
40
- */
41
- error: Error;
42
- };
43
-
44
- /**
45
- * Makes a processed tx out of a private only tx that has its proof already set.
46
- * @param tx - Source tx that doesn't need further processing.
47
- */
48
- export async function makeProcessedTx(tx: Tx): Promise<ProcessedTx>;
49
-
50
- /**
51
- * Makes a processed tx out of a tx with a public component that needs processing.
52
- * @param tx - Source tx.
53
- * @param kernelOutput - Output of the public kernel circuit simulation for this tx.
54
- * @param proof - Proof of the public kernel circuit for this tx.
55
- */
56
- export async function makeProcessedTx(
57
- tx: Tx,
58
- kernelOutput: PublicKernelPublicInputs,
59
- proof: Proof,
60
- ): Promise<ProcessedTx>;
61
-
62
- /**
63
- * Makes a processed tx out of source tx.
64
- * @param tx - Source tx.
65
- * @param kernelOutput - Output of the kernel circuit simulation for this tx.
66
- * @param proof - Proof of the kernel circuit for this tx.
67
- */
68
- export async function makeProcessedTx(
69
- tx: Tx,
70
- kernelOutput?: PublicKernelPublicInputs,
71
- proof?: Proof,
72
- ): Promise<ProcessedTx> {
73
- return {
74
- hash: await tx.getTxHash(),
75
- data:
76
- kernelOutput ??
77
- new PublicKernelPublicInputs(CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end), tx.data.constants),
78
- proof: proof ?? tx.proof,
79
- encryptedLogs: tx.encryptedLogs,
80
- unencryptedLogs: tx.unencryptedLogs,
81
- newContracts: tx.newContracts,
82
- isEmpty: false,
83
- };
84
- }
85
-
86
- /**
87
- * Makes an empty tx from an empty kernel circuit public inputs.
88
- * @returns A processed empty tx.
89
- */
90
- export function makeEmptyProcessedTx(historicalTreeRoots: BlockHeader, chainId: Fr, version: Fr): Promise<ProcessedTx> {
91
- const emptyKernelOutput = PublicKernelPublicInputs.empty();
92
- emptyKernelOutput.constants.blockHeader = historicalTreeRoots;
93
- emptyKernelOutput.constants.txContext.chainId = chainId;
94
- emptyKernelOutput.constants.txContext.version = version;
95
- const emptyProof = makeEmptyProof();
96
-
97
- const hash = new TxHash(Fr.ZERO.toBuffer());
98
- return Promise.resolve({
99
- hash,
100
- encryptedLogs: new TxL2Logs([]),
101
- unencryptedLogs: new TxL2Logs([]),
102
- data: emptyKernelOutput,
103
- proof: emptyProof,
104
- newContracts: [ExtendedContractData.empty()],
105
- isEmpty: true,
106
- });
107
- }