@aztec/stdlib 3.0.0-nightly.20251114 → 3.0.0-nightly.20251115
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/dest/avm/avm.d.ts +102 -8
- package/dest/avm/avm.d.ts.map +1 -1
- package/dest/avm/avm.js +43 -4
- package/dest/avm/public_data_write.d.ts +1 -1
- package/dest/avm/public_data_write.d.ts.map +1 -1
- package/dest/avm/revert_code.d.ts +2 -1
- package/dest/avm/revert_code.d.ts.map +1 -1
- package/dest/avm/revert_code.js +8 -8
- package/dest/block/body.d.ts +3 -6
- package/dest/block/body.d.ts.map +1 -1
- package/dest/block/body.js +6 -25
- package/dest/block/index.d.ts +1 -0
- package/dest/block/index.d.ts.map +1 -1
- package/dest/block/index.js +1 -0
- package/dest/block/l2_block.d.ts +5 -0
- package/dest/block/l2_block.d.ts.map +1 -1
- package/dest/block/l2_block.js +34 -4
- package/dest/block/l2_block_new.d.ts +97 -0
- package/dest/block/l2_block_new.d.ts.map +1 -0
- package/dest/block/l2_block_new.js +113 -0
- package/dest/checkpoint/checkpoint.d.ts +108 -0
- package/dest/checkpoint/checkpoint.d.ts.map +1 -0
- package/dest/checkpoint/checkpoint.js +39 -0
- package/dest/checkpoint/index.d.ts +1 -1
- package/dest/checkpoint/index.d.ts.map +1 -1
- package/dest/checkpoint/index.js +1 -1
- package/dest/logs/private_log.d.ts +1 -1
- package/dest/logs/private_log.d.ts.map +1 -1
- package/dest/logs/private_log.js +2 -5
- package/dest/messaging/in_hash.d.ts +4 -0
- package/dest/messaging/in_hash.d.ts.map +1 -0
- package/dest/messaging/in_hash.js +15 -0
- package/dest/messaging/index.d.ts +2 -0
- package/dest/messaging/index.d.ts.map +1 -1
- package/dest/messaging/index.js +2 -0
- package/dest/messaging/out_hash.d.ts +5 -0
- package/dest/messaging/out_hash.d.ts.map +1 -0
- package/dest/messaging/out_hash.js +28 -0
- package/dest/rollup/checkpoint_constant_data.d.ts +16 -0
- package/dest/rollup/checkpoint_constant_data.d.ts.map +1 -1
- package/dest/rollup/checkpoint_constant_data.js +17 -0
- package/dest/tests/factories.d.ts +17 -21
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +14 -111
- package/dest/tests/mocks.d.ts +17 -1
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +108 -4
- package/dest/tx/partial_state_reference.d.ts +3 -0
- package/dest/tx/partial_state_reference.d.ts.map +1 -1
- package/dest/tx/partial_state_reference.js +10 -0
- package/dest/tx/state_reference.d.ts +3 -0
- package/dest/tx/state_reference.d.ts.map +1 -1
- package/dest/tx/state_reference.js +9 -0
- package/dest/tx/tx_effect.d.ts +9 -6
- package/dest/tx/tx_effect.d.ts.map +1 -1
- package/dest/tx/tx_effect.js +53 -57
- package/package.json +8 -8
- package/src/avm/avm.ts +48 -10
- package/src/avm/public_data_write.ts +1 -1
- package/src/avm/revert_code.ts +9 -8
- package/src/block/body.ts +7 -32
- package/src/block/index.ts +1 -0
- package/src/block/l2_block.ts +33 -2
- package/src/block/l2_block_new.ts +143 -0
- package/src/checkpoint/checkpoint.ts +46 -0
- package/src/checkpoint/index.ts +1 -1
- package/src/logs/private_log.ts +2 -3
- package/src/messaging/in_hash.ts +15 -0
- package/src/messaging/index.ts +2 -0
- package/src/messaging/out_hash.ts +36 -0
- package/src/rollup/checkpoint_constant_data.ts +20 -0
- package/src/tests/factories.ts +91 -193
- package/src/tests/mocks.ts +196 -4
- package/src/tx/partial_state_reference.ts +9 -0
- package/src/tx/state_reference.ts +9 -0
- package/src/tx/tx_effect.ts +61 -67
- package/dest/checkpoint/checkpoint_body.d.ts +0 -4
- package/dest/checkpoint/checkpoint_body.d.ts.map +0 -1
- package/dest/checkpoint/checkpoint_body.js +0 -9
- package/src/checkpoint/checkpoint_body.ts +0 -10
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
+
import { sha256Trunc } from '@aztec/foundation/crypto';
|
|
4
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
+
import { MerkleTreeCalculator } from '@aztec/foundation/trees';
|
|
6
|
+
|
|
7
|
+
/** Computes the inHash for a block's ContentCommitment given its l1 to l2 messages. */
|
|
8
|
+
export async function computeInHashFromL1ToL2Messages(unpaddedL1ToL2Messages: Fr[]): Promise<Fr> {
|
|
9
|
+
const l1ToL2Messages = padArrayEnd<Fr, number>(unpaddedL1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
10
|
+
const hasher = (left: Buffer, right: Buffer) =>
|
|
11
|
+
Promise.resolve(sha256Trunc(Buffer.concat([left, right])) as Buffer<ArrayBuffer>);
|
|
12
|
+
const parityHeight = Math.ceil(Math.log2(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP));
|
|
13
|
+
const parityCalculator = await MerkleTreeCalculator.create(parityHeight, Fr.ZERO.toBuffer(), hasher);
|
|
14
|
+
return new Fr(await parityCalculator.computeTreeRoot(l1ToL2Messages.map(msg => msg.toBuffer())));
|
|
15
|
+
}
|
package/src/messaging/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './in_hash.js';
|
|
1
2
|
export * from './inbox_leaf.js';
|
|
2
3
|
export * from './l1_to_l2_message.js';
|
|
3
4
|
export * from './l1_to_l2_message_source.js';
|
|
@@ -5,3 +6,4 @@ export * from './l1_actor.js';
|
|
|
5
6
|
export * from './l2_actor.js';
|
|
6
7
|
export * from './l2_to_l1_message.js';
|
|
7
8
|
export * from './l2_to_l1_membership.js';
|
|
9
|
+
export * from './out_hash.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { UnbalancedMerkleTreeCalculator, computeUnbalancedMerkleTreeRoot } from '@aztec/foundation/trees';
|
|
3
|
+
|
|
4
|
+
export function computeTxOutHash(messages: Fr[]): Fr {
|
|
5
|
+
if (!messages.length) {
|
|
6
|
+
return Fr.ZERO;
|
|
7
|
+
}
|
|
8
|
+
// Tx out hash is the root of the unbalanced merkle tree of all the messages.
|
|
9
|
+
// Zero hashes (which should not happen) are not compressed.
|
|
10
|
+
return Fr.fromBuffer(computeUnbalancedMerkleTreeRoot(messages.map(msg => msg.toBuffer())));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function computeBlockOutHash(messagesPerBlock: Fr[][]): Fr {
|
|
14
|
+
const txOutHashes = messagesPerBlock.map(messages => computeTxOutHash(messages));
|
|
15
|
+
return aggregateOutHashes(txOutHashes);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function computeCheckpointOutHash(messagesForAllTxs: Fr[][][]): Fr {
|
|
19
|
+
const blockOutHashes = messagesForAllTxs.map(block => computeBlockOutHash(block));
|
|
20
|
+
return aggregateOutHashes(blockOutHashes);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The root of this tree should match the `out_hash` calculated in the circuits. Zero hashes are compressed to reduce
|
|
24
|
+
// cost if the non-zero leaves result in a shorter path.
|
|
25
|
+
function aggregateOutHashes(outHashes: Fr[]): Fr {
|
|
26
|
+
if (!outHashes.length) {
|
|
27
|
+
return Fr.ZERO;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const valueToCompress = Buffer.alloc(32);
|
|
31
|
+
const tree = UnbalancedMerkleTreeCalculator.create(
|
|
32
|
+
outHashes.map(hash => hash.toBuffer()),
|
|
33
|
+
valueToCompress,
|
|
34
|
+
);
|
|
35
|
+
return Fr.fromBuffer(tree.getRoot());
|
|
36
|
+
}
|
|
@@ -3,6 +3,8 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
3
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
4
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
5
5
|
|
|
6
|
+
import { inspect } from 'util';
|
|
7
|
+
|
|
6
8
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
7
9
|
import { GasFees } from '../gas/gas_fees.js';
|
|
8
10
|
|
|
@@ -81,4 +83,22 @@ export class CheckpointConstantData {
|
|
|
81
83
|
reader.readObject(GasFees),
|
|
82
84
|
);
|
|
83
85
|
}
|
|
86
|
+
|
|
87
|
+
toInspect() {
|
|
88
|
+
return {
|
|
89
|
+
chainId: this.chainId.toNumber(),
|
|
90
|
+
version: this.version.toNumber(),
|
|
91
|
+
vkTreeRoot: this.vkTreeRoot.toString(),
|
|
92
|
+
protocolContractsHash: this.protocolContractsHash.toString(),
|
|
93
|
+
proverId: this.proverId.toString(),
|
|
94
|
+
slotNumber: this.slotNumber.toNumber(),
|
|
95
|
+
coinbase: this.coinbase.toString(),
|
|
96
|
+
feeRecipient: this.feeRecipient.toString(),
|
|
97
|
+
gasFees: this.gasFees.toInspect(),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
[inspect.custom]() {
|
|
102
|
+
return `CheckpointConstantData ${inspect(this.toInspect())}`;
|
|
103
|
+
}
|
|
84
104
|
}
|
package/src/tests/factories.ts
CHANGED
|
@@ -5,8 +5,6 @@ import {
|
|
|
5
5
|
AZTEC_MAX_EPOCH_DURATION,
|
|
6
6
|
CHONK_PROOF_LENGTH,
|
|
7
7
|
CONTRACT_CLASS_LOG_SIZE_IN_FIELDS,
|
|
8
|
-
FIXED_DA_GAS,
|
|
9
|
-
FIXED_L2_GAS,
|
|
10
8
|
GeneratorIndex,
|
|
11
9
|
L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
12
10
|
MAX_CONTRACT_CLASS_LOGS_PER_TX,
|
|
@@ -39,8 +37,8 @@ import {
|
|
|
39
37
|
RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
40
38
|
VK_TREE_HEIGHT,
|
|
41
39
|
} from '@aztec/constants';
|
|
42
|
-
import { type FieldsOf,
|
|
43
|
-
import { compact
|
|
40
|
+
import { type FieldsOf, makeTuple } from '@aztec/foundation/array';
|
|
41
|
+
import { compact } from '@aztec/foundation/collection';
|
|
44
42
|
import { Grumpkin, SchnorrSignature, poseidon2HashWithSeparator, sha256 } from '@aztec/foundation/crypto';
|
|
45
43
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
46
44
|
import { Fq, Fr, GrumpkinScalar, Point } from '@aztec/foundation/fields';
|
|
@@ -75,7 +73,6 @@ import {
|
|
|
75
73
|
AvmSequentialInsertHintNullifierTree,
|
|
76
74
|
AvmSequentialInsertHintPublicDataTree,
|
|
77
75
|
AvmTxHint,
|
|
78
|
-
RevertCode,
|
|
79
76
|
} from '../avm/index.js';
|
|
80
77
|
import { PublicDataRead } from '../avm/public_data_read.js';
|
|
81
78
|
import { PublicDataWrite } from '../avm/public_data_write.js';
|
|
@@ -92,10 +89,8 @@ import {
|
|
|
92
89
|
computeContractClassId,
|
|
93
90
|
computePublicBytecodeCommitment,
|
|
94
91
|
} from '../contract/index.js';
|
|
95
|
-
import {
|
|
96
|
-
import { Gas, GasFees, GasSettings, type GasUsed } from '../gas/index.js';
|
|
92
|
+
import { Gas, GasFees, GasSettings } from '../gas/index.js';
|
|
97
93
|
import { computeCalldataHash } from '../hash/hash.js';
|
|
98
|
-
import type { MerkleTreeReadOperations } from '../interfaces/merkle_tree_operations.js';
|
|
99
94
|
import { KeyValidationRequest } from '../kernel/hints/key_validation_request.js';
|
|
100
95
|
import { KeyValidationRequestAndGenerator } from '../kernel/hints/key_validation_request_and_generator.js';
|
|
101
96
|
import { ReadRequest } from '../kernel/hints/read_request.js';
|
|
@@ -132,7 +127,6 @@ import { ParityPublicInputs } from '../parity/parity_public_inputs.js';
|
|
|
132
127
|
import { ParityRootPrivateInputs } from '../parity/parity_root_private_inputs.js';
|
|
133
128
|
import { ProofData } from '../proofs/index.js';
|
|
134
129
|
import { Proof } from '../proofs/proof.js';
|
|
135
|
-
import { ProvingRequestType } from '../proofs/proving_request_type.js';
|
|
136
130
|
import { makeRecursiveProof } from '../proofs/recursive_proof.js';
|
|
137
131
|
import { PrivateBaseRollupHints, PublicBaseRollupHints } from '../rollup/base_rollup_hints.js';
|
|
138
132
|
import { BlockConstantData } from '../rollup/block_constant_data.js';
|
|
@@ -163,7 +157,6 @@ import { ContentCommitment } from '../tx/content_commitment.js';
|
|
|
163
157
|
import { FunctionData } from '../tx/function_data.js';
|
|
164
158
|
import { GlobalVariables } from '../tx/global_variables.js';
|
|
165
159
|
import { PartialStateReference } from '../tx/partial_state_reference.js';
|
|
166
|
-
import { makeProcessedTxFromPrivateOnlyTx, makeProcessedTxFromTxWithPublicCalls } from '../tx/processed_tx.js';
|
|
167
160
|
import { ProtocolContracts } from '../tx/protocol_contracts.js';
|
|
168
161
|
import { PublicCallRequestWithCalldata } from '../tx/public_call_request_with_calldata.js';
|
|
169
162
|
import { StateReference } from '../tx/state_reference.js';
|
|
@@ -174,7 +167,6 @@ import { TxRequest } from '../tx/tx_request.js';
|
|
|
174
167
|
import { Vector } from '../types/index.js';
|
|
175
168
|
import { VkData } from '../vks/index.js';
|
|
176
169
|
import { VerificationKey, VerificationKeyAsFields, VerificationKeyData } from '../vks/verification_key.js';
|
|
177
|
-
import { mockTx } from './mocks.js';
|
|
178
170
|
|
|
179
171
|
/**
|
|
180
172
|
* Creates an arbitrary side effect object with the given seed.
|
|
@@ -264,7 +256,7 @@ function makeKeyValidationRequestAndGenerators(seed: number): KeyValidationReque
|
|
|
264
256
|
return new KeyValidationRequestAndGenerator(makeKeyValidationRequests(seed), fr(seed + 4));
|
|
265
257
|
}
|
|
266
258
|
|
|
267
|
-
function makePublicDataWrite(seed = 1) {
|
|
259
|
+
export function makePublicDataWrite(seed = 1) {
|
|
268
260
|
return new PublicDataWrite(fr(seed), fr(seed + 1));
|
|
269
261
|
}
|
|
270
262
|
|
|
@@ -307,31 +299,101 @@ function makeTxConstantData(seed = 1) {
|
|
|
307
299
|
return new TxConstantData(makeHeader(seed), makeTxContext(seed + 0x100), new Fr(seed + 0x200), new Fr(seed + 0x201));
|
|
308
300
|
}
|
|
309
301
|
|
|
302
|
+
function makePaddedTuple<T, N extends number>(
|
|
303
|
+
length: N,
|
|
304
|
+
fn: (i: number) => T,
|
|
305
|
+
nonPaddedLength = 0,
|
|
306
|
+
makePadding: () => T,
|
|
307
|
+
offset = 0,
|
|
308
|
+
) {
|
|
309
|
+
return makeTuple(length, i => (i < nonPaddedLength ? fn(i + offset) : makePadding()));
|
|
310
|
+
}
|
|
311
|
+
|
|
310
312
|
/**
|
|
311
313
|
* Creates arbitrary accumulated data.
|
|
312
314
|
* @param seed - The seed to use for generating the accumulated data.
|
|
313
315
|
* @returns An accumulated data.
|
|
314
316
|
*/
|
|
315
|
-
export function makePrivateToRollupAccumulatedData(
|
|
316
|
-
|
|
317
|
-
|
|
317
|
+
export function makePrivateToRollupAccumulatedData(
|
|
318
|
+
seed = 1,
|
|
319
|
+
{
|
|
320
|
+
numNoteHashes = MAX_NOTE_HASHES_PER_TX,
|
|
321
|
+
numNullifiers = MAX_NULLIFIERS_PER_TX,
|
|
322
|
+
numL2ToL1Messages = MAX_L2_TO_L1_MSGS_PER_TX,
|
|
323
|
+
numPrivateLogs = MAX_PRIVATE_LOGS_PER_TX,
|
|
324
|
+
numContractClassLogs = MAX_CONTRACT_CLASS_LOGS_PER_TX,
|
|
325
|
+
}: {
|
|
326
|
+
numNoteHashes?: number;
|
|
327
|
+
numNullifiers?: number;
|
|
328
|
+
numL2ToL1Messages?: number;
|
|
329
|
+
numPrivateLogs?: number;
|
|
330
|
+
numContractClassLogs?: number;
|
|
331
|
+
} = {},
|
|
332
|
+
): PrivateToRollupAccumulatedData {
|
|
318
333
|
return new PrivateToRollupAccumulatedData(
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
334
|
+
makePaddedTuple(MAX_NOTE_HASHES_PER_TX, fr, numNoteHashes, Fr.zero, seed + 0x100),
|
|
335
|
+
makePaddedTuple(MAX_NULLIFIERS_PER_TX, fr, numNullifiers, Fr.zero, seed + 0x200),
|
|
336
|
+
makePaddedTuple(
|
|
337
|
+
MAX_L2_TO_L1_MSGS_PER_TX,
|
|
338
|
+
makeScopedL2ToL1Message,
|
|
339
|
+
numL2ToL1Messages,
|
|
340
|
+
ScopedL2ToL1Message.empty,
|
|
341
|
+
seed + 0x300,
|
|
342
|
+
),
|
|
343
|
+
makePaddedTuple(MAX_PRIVATE_LOGS_PER_TX, makePrivateLog, numPrivateLogs, PrivateLog.empty, seed + 0x400),
|
|
344
|
+
makePaddedTuple(
|
|
345
|
+
MAX_CONTRACT_CLASS_LOGS_PER_TX,
|
|
346
|
+
makeScopedLogHash,
|
|
347
|
+
numContractClassLogs,
|
|
348
|
+
ScopedLogHash.empty,
|
|
349
|
+
seed + 0x500,
|
|
350
|
+
),
|
|
324
351
|
);
|
|
325
352
|
}
|
|
326
353
|
|
|
327
|
-
export function makePrivateToPublicAccumulatedData(
|
|
354
|
+
export function makePrivateToPublicAccumulatedData(
|
|
355
|
+
seed = 1,
|
|
356
|
+
{
|
|
357
|
+
numNoteHashes = MAX_NOTE_HASHES_PER_TX,
|
|
358
|
+
numNullifiers = MAX_NULLIFIERS_PER_TX,
|
|
359
|
+
numL2ToL1Messages = MAX_L2_TO_L1_MSGS_PER_TX,
|
|
360
|
+
numPrivateLogs = MAX_PRIVATE_LOGS_PER_TX,
|
|
361
|
+
numContractClassLogs = MAX_CONTRACT_CLASS_LOGS_PER_TX,
|
|
362
|
+
numEnqueuedCalls = MAX_ENQUEUED_CALLS_PER_TX,
|
|
363
|
+
}: {
|
|
364
|
+
numNoteHashes?: number;
|
|
365
|
+
numNullifiers?: number;
|
|
366
|
+
numL2ToL1Messages?: number;
|
|
367
|
+
numPrivateLogs?: number;
|
|
368
|
+
numContractClassLogs?: number;
|
|
369
|
+
numEnqueuedCalls?: number;
|
|
370
|
+
} = {},
|
|
371
|
+
) {
|
|
328
372
|
return new PrivateToPublicAccumulatedData(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
373
|
+
makePaddedTuple(MAX_NOTE_HASHES_PER_TX, fr, numNoteHashes, Fr.zero, seed),
|
|
374
|
+
makePaddedTuple(MAX_NULLIFIERS_PER_TX, fr, numNullifiers, Fr.zero, seed + 0x100),
|
|
375
|
+
makePaddedTuple(
|
|
376
|
+
MAX_L2_TO_L1_MSGS_PER_TX,
|
|
377
|
+
makeScopedL2ToL1Message,
|
|
378
|
+
numL2ToL1Messages,
|
|
379
|
+
ScopedL2ToL1Message.empty,
|
|
380
|
+
seed + 0x200,
|
|
381
|
+
),
|
|
382
|
+
makePaddedTuple(MAX_PRIVATE_LOGS_PER_TX, makePrivateLog, numPrivateLogs, PrivateLog.empty, seed + 0x300),
|
|
383
|
+
makePaddedTuple(
|
|
384
|
+
MAX_CONTRACT_CLASS_LOGS_PER_TX,
|
|
385
|
+
makeScopedLogHash,
|
|
386
|
+
numContractClassLogs,
|
|
387
|
+
ScopedLogHash.empty,
|
|
388
|
+
seed + 0x400,
|
|
389
|
+
),
|
|
390
|
+
makePaddedTuple(
|
|
391
|
+
MAX_ENQUEUED_CALLS_PER_TX,
|
|
392
|
+
makePublicCallRequest,
|
|
393
|
+
numEnqueuedCalls,
|
|
394
|
+
PublicCallRequest.empty,
|
|
395
|
+
seed + 0x500,
|
|
396
|
+
),
|
|
335
397
|
);
|
|
336
398
|
}
|
|
337
399
|
|
|
@@ -434,13 +496,10 @@ export function makeProtocolContracts(seed = 1) {
|
|
|
434
496
|
* @param seed - The seed to use for generating the kernel circuit public inputs.
|
|
435
497
|
* @returns Public kernel circuit public inputs.
|
|
436
498
|
*/
|
|
437
|
-
export function makePrivateToRollupKernelCircuitPublicInputs(
|
|
438
|
-
seed = 1,
|
|
439
|
-
fullAccumulatedData = true,
|
|
440
|
-
): PrivateToRollupKernelCircuitPublicInputs {
|
|
499
|
+
export function makePrivateToRollupKernelCircuitPublicInputs(seed = 1): PrivateToRollupKernelCircuitPublicInputs {
|
|
441
500
|
return new PrivateToRollupKernelCircuitPublicInputs(
|
|
442
501
|
makeTxConstantData(seed + 0x100),
|
|
443
|
-
makePrivateToRollupAccumulatedData(seed
|
|
502
|
+
makePrivateToRollupAccumulatedData(seed),
|
|
444
503
|
makeGas(seed + 0x600),
|
|
445
504
|
makeAztecAddress(seed + 0x700),
|
|
446
505
|
BigInt(seed + 0x800),
|
|
@@ -1601,164 +1660,3 @@ export async function makeAvmCircuitInputs(
|
|
|
1601
1660
|
export function fr(n: number): Fr {
|
|
1602
1661
|
return new Fr(BigInt(n));
|
|
1603
1662
|
}
|
|
1604
|
-
|
|
1605
|
-
/** Makes a bloated processed tx for testing purposes. */
|
|
1606
|
-
export async function makeBloatedProcessedTx({
|
|
1607
|
-
seed = 1,
|
|
1608
|
-
header,
|
|
1609
|
-
db,
|
|
1610
|
-
chainId = Fr.ZERO,
|
|
1611
|
-
version = Fr.ZERO,
|
|
1612
|
-
gasSettings = GasSettings.default({ maxFeesPerGas: new GasFees(10, 10) }),
|
|
1613
|
-
vkTreeRoot = Fr.ZERO,
|
|
1614
|
-
protocolContracts = makeProtocolContracts(seed + 0x100),
|
|
1615
|
-
globalVariables = GlobalVariables.empty(),
|
|
1616
|
-
newL1ToL2Snapshot = AppendOnlyTreeSnapshot.empty(),
|
|
1617
|
-
feePayer,
|
|
1618
|
-
feePaymentPublicDataWrite,
|
|
1619
|
-
// The default gasUsed is the tx overhead.
|
|
1620
|
-
gasUsed = Gas.from({ daGas: FIXED_DA_GAS, l2Gas: FIXED_L2_GAS }),
|
|
1621
|
-
privateOnly = false,
|
|
1622
|
-
}: {
|
|
1623
|
-
seed?: number;
|
|
1624
|
-
header?: BlockHeader;
|
|
1625
|
-
db?: MerkleTreeReadOperations;
|
|
1626
|
-
chainId?: Fr;
|
|
1627
|
-
version?: Fr;
|
|
1628
|
-
gasSettings?: GasSettings;
|
|
1629
|
-
vkTreeRoot?: Fr;
|
|
1630
|
-
globalVariables?: GlobalVariables;
|
|
1631
|
-
newL1ToL2Snapshot?: AppendOnlyTreeSnapshot;
|
|
1632
|
-
protocolContracts?: ProtocolContracts;
|
|
1633
|
-
feePayer?: AztecAddress;
|
|
1634
|
-
feePaymentPublicDataWrite?: PublicDataWrite;
|
|
1635
|
-
gasUsed?: Gas;
|
|
1636
|
-
privateOnly?: boolean;
|
|
1637
|
-
} = {}) {
|
|
1638
|
-
seed *= 0x1000; // Avoid clashing with the previous mock values if seed only increases by 1.
|
|
1639
|
-
header ??= db?.getInitialHeader() ?? makeHeader(seed);
|
|
1640
|
-
feePayer ??= await AztecAddress.random();
|
|
1641
|
-
|
|
1642
|
-
const txConstantData = TxConstantData.empty();
|
|
1643
|
-
txConstantData.anchorBlockHeader = header!;
|
|
1644
|
-
txConstantData.txContext.chainId = chainId;
|
|
1645
|
-
txConstantData.txContext.version = version;
|
|
1646
|
-
txConstantData.txContext.gasSettings = gasSettings;
|
|
1647
|
-
txConstantData.vkTreeRoot = vkTreeRoot;
|
|
1648
|
-
txConstantData.protocolContractsHash = await protocolContracts.hash();
|
|
1649
|
-
|
|
1650
|
-
const tx = !privateOnly
|
|
1651
|
-
? await mockTx(seed, { feePayer, gasUsed })
|
|
1652
|
-
: await mockTx(seed, {
|
|
1653
|
-
numberOfNonRevertiblePublicCallRequests: 0,
|
|
1654
|
-
numberOfRevertiblePublicCallRequests: 0,
|
|
1655
|
-
feePayer,
|
|
1656
|
-
gasUsed,
|
|
1657
|
-
});
|
|
1658
|
-
tx.data.constants = txConstantData;
|
|
1659
|
-
|
|
1660
|
-
const transactionFee = tx.data.gasUsed.computeFee(globalVariables.gasFees);
|
|
1661
|
-
|
|
1662
|
-
if (privateOnly) {
|
|
1663
|
-
const data = makePrivateToRollupAccumulatedData(seed + 0x1000);
|
|
1664
|
-
clearContractClassLogs(data);
|
|
1665
|
-
|
|
1666
|
-
feePaymentPublicDataWrite ??= new PublicDataWrite(Fr.random(), Fr.random());
|
|
1667
|
-
|
|
1668
|
-
tx.data.forRollup!.end = data;
|
|
1669
|
-
|
|
1670
|
-
await tx.recomputeHash();
|
|
1671
|
-
return makeProcessedTxFromPrivateOnlyTx(tx, transactionFee, feePaymentPublicDataWrite, globalVariables);
|
|
1672
|
-
} else {
|
|
1673
|
-
const dataFromPrivate = tx.data.forPublic!;
|
|
1674
|
-
|
|
1675
|
-
const nonRevertibleData = dataFromPrivate.nonRevertibleAccumulatedData;
|
|
1676
|
-
|
|
1677
|
-
// Create revertible data.
|
|
1678
|
-
const revertibleData = makePrivateToPublicAccumulatedData(seed + 0x1000);
|
|
1679
|
-
clearContractClassLogs(revertibleData);
|
|
1680
|
-
revertibleData.nullifiers[MAX_NULLIFIERS_PER_TX - 1] = Fr.ZERO; // Leave one space for the tx hash nullifier in nonRevertibleAccumulatedData.
|
|
1681
|
-
dataFromPrivate.revertibleAccumulatedData = revertibleData;
|
|
1682
|
-
|
|
1683
|
-
// Create avm output.
|
|
1684
|
-
const avmOutput = AvmCircuitPublicInputs.empty();
|
|
1685
|
-
// Assign data from hints.
|
|
1686
|
-
avmOutput.protocolContracts = protocolContracts;
|
|
1687
|
-
avmOutput.startTreeSnapshots.l1ToL2MessageTree = newL1ToL2Snapshot;
|
|
1688
|
-
avmOutput.endTreeSnapshots.l1ToL2MessageTree = newL1ToL2Snapshot;
|
|
1689
|
-
avmOutput.effectiveGasFees = computeEffectiveGasFees(globalVariables.gasFees, gasSettings);
|
|
1690
|
-
// Assign data from private.
|
|
1691
|
-
avmOutput.globalVariables = globalVariables;
|
|
1692
|
-
avmOutput.startGasUsed = tx.data.gasUsed;
|
|
1693
|
-
avmOutput.gasSettings = gasSettings;
|
|
1694
|
-
avmOutput.feePayer = feePayer;
|
|
1695
|
-
avmOutput.publicCallRequestArrayLengths = new PublicCallRequestArrayLengths(
|
|
1696
|
-
tx.data.numberOfNonRevertiblePublicCallRequests(),
|
|
1697
|
-
tx.data.numberOfRevertiblePublicCallRequests(),
|
|
1698
|
-
tx.data.hasTeardownPublicCallRequest(),
|
|
1699
|
-
);
|
|
1700
|
-
avmOutput.publicSetupCallRequests = dataFromPrivate.nonRevertibleAccumulatedData.publicCallRequests;
|
|
1701
|
-
avmOutput.publicAppLogicCallRequests = dataFromPrivate.revertibleAccumulatedData.publicCallRequests;
|
|
1702
|
-
avmOutput.publicTeardownCallRequest = dataFromPrivate.publicTeardownCallRequest;
|
|
1703
|
-
avmOutput.previousNonRevertibleAccumulatedData = new PrivateToAvmAccumulatedData(
|
|
1704
|
-
dataFromPrivate.nonRevertibleAccumulatedData.noteHashes,
|
|
1705
|
-
dataFromPrivate.nonRevertibleAccumulatedData.nullifiers,
|
|
1706
|
-
dataFromPrivate.nonRevertibleAccumulatedData.l2ToL1Msgs,
|
|
1707
|
-
);
|
|
1708
|
-
avmOutput.previousNonRevertibleAccumulatedDataArrayLengths =
|
|
1709
|
-
avmOutput.previousNonRevertibleAccumulatedData.getArrayLengths();
|
|
1710
|
-
avmOutput.previousRevertibleAccumulatedData = new PrivateToAvmAccumulatedData(
|
|
1711
|
-
dataFromPrivate.revertibleAccumulatedData.noteHashes,
|
|
1712
|
-
dataFromPrivate.revertibleAccumulatedData.nullifiers,
|
|
1713
|
-
dataFromPrivate.revertibleAccumulatedData.l2ToL1Msgs,
|
|
1714
|
-
);
|
|
1715
|
-
avmOutput.previousRevertibleAccumulatedDataArrayLengths =
|
|
1716
|
-
avmOutput.previousRevertibleAccumulatedData.getArrayLengths();
|
|
1717
|
-
// Assign final data emitted from avm.
|
|
1718
|
-
avmOutput.accumulatedData.noteHashes = revertibleData.noteHashes;
|
|
1719
|
-
avmOutput.accumulatedData.nullifiers = padArrayEnd(
|
|
1720
|
-
nonRevertibleData.nullifiers.concat(revertibleData.nullifiers).filter(n => !n.isEmpty()),
|
|
1721
|
-
Fr.ZERO,
|
|
1722
|
-
MAX_NULLIFIERS_PER_TX,
|
|
1723
|
-
);
|
|
1724
|
-
avmOutput.accumulatedData.l2ToL1Msgs = revertibleData.l2ToL1Msgs;
|
|
1725
|
-
avmOutput.accumulatedData.publicDataWrites = makeTuple(
|
|
1726
|
-
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
1727
|
-
i => new PublicDataWrite(new Fr(i), new Fr(i + 10)),
|
|
1728
|
-
seed + 0x2000,
|
|
1729
|
-
);
|
|
1730
|
-
avmOutput.accumulatedDataArrayLengths = avmOutput.accumulatedData.getArrayLengths();
|
|
1731
|
-
avmOutput.gasSettings = gasSettings;
|
|
1732
|
-
// Note: The fee is computed from the tx's gas used, which only includes the gas used in private. But this shouldn't
|
|
1733
|
-
// be a problem for the tests.
|
|
1734
|
-
avmOutput.transactionFee = transactionFee;
|
|
1735
|
-
|
|
1736
|
-
const avmCircuitInputs = await makeAvmCircuitInputs(seed + 0x3000, { publicInputs: avmOutput });
|
|
1737
|
-
avmCircuitInputs.hints.startingTreeRoots.l1ToL2MessageTree = newL1ToL2Snapshot;
|
|
1738
|
-
|
|
1739
|
-
const gasUsed = {
|
|
1740
|
-
totalGas: Gas.empty(),
|
|
1741
|
-
teardownGas: Gas.empty(),
|
|
1742
|
-
publicGas: Gas.empty(),
|
|
1743
|
-
billedGas: Gas.empty(),
|
|
1744
|
-
} satisfies GasUsed;
|
|
1745
|
-
|
|
1746
|
-
await tx.recomputeHash();
|
|
1747
|
-
return makeProcessedTxFromTxWithPublicCalls(
|
|
1748
|
-
tx,
|
|
1749
|
-
{
|
|
1750
|
-
type: ProvingRequestType.PUBLIC_VM,
|
|
1751
|
-
inputs: avmCircuitInputs,
|
|
1752
|
-
},
|
|
1753
|
-
gasUsed,
|
|
1754
|
-
RevertCode.OK,
|
|
1755
|
-
undefined /* revertReason */,
|
|
1756
|
-
);
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
// Remove all contract class log hashes from the data as they are not required for the current tests.
|
|
1761
|
-
// If they are needed one day, change this to create the random fields first and update the data with real hashes of those fields.
|
|
1762
|
-
function clearContractClassLogs(data: { contractClassLogsHashes: ScopedLogHash[] }) {
|
|
1763
|
-
data.contractClassLogsHashes.forEach((_, i) => (data.contractClassLogsHashes[i] = ScopedLogHash.empty()));
|
|
1764
|
-
}
|