@aztec/pxe 0.0.1-commit.64b6bbb → 0.0.1-commit.684755437

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 (155) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/config/index.d.ts +2 -2
  5. package/dest/config/index.d.ts.map +1 -1
  6. package/dest/config/index.js +1 -1
  7. package/dest/config/package_info.js +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts +8 -6
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +114 -44
  11. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  12. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
  14. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  15. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -2
  16. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  18. package/dest/contract_function_simulator/oracle/interfaces.d.ts +49 -45
  19. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -44
  21. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/oracle.js +132 -89
  23. package/dest/contract_function_simulator/oracle/private_execution.js +1 -1
  24. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +22 -21
  25. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +37 -37
  27. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +39 -36
  28. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +56 -53
  30. package/dest/contract_logging.d.ts +22 -0
  31. package/dest/contract_logging.d.ts.map +1 -0
  32. package/dest/contract_logging.js +23 -0
  33. package/dest/contract_sync/contract_sync_service.d.ts +4 -2
  34. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  35. package/dest/contract_sync/contract_sync_service.js +34 -19
  36. package/dest/contract_sync/helpers.d.ts +3 -2
  37. package/dest/contract_sync/helpers.d.ts.map +1 -1
  38. package/dest/contract_sync/helpers.js +3 -3
  39. package/dest/debug/pxe_debug_utils.d.ts +5 -4
  40. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  41. package/dest/debug/pxe_debug_utils.js +4 -4
  42. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  43. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  44. package/dest/entrypoints/client/bundle/index.js +3 -0
  45. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  46. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  47. package/dest/entrypoints/client/lazy/index.js +3 -0
  48. package/dest/entrypoints/server/index.d.ts +3 -1
  49. package/dest/entrypoints/server/index.d.ts.map +1 -1
  50. package/dest/entrypoints/server/index.js +2 -0
  51. package/dest/logs/log_service.d.ts +3 -2
  52. package/dest/logs/log_service.d.ts.map +1 -1
  53. package/dest/logs/log_service.js +9 -14
  54. package/dest/notes/note_service.d.ts +4 -3
  55. package/dest/notes/note_service.d.ts.map +1 -1
  56. package/dest/notes/note_service.js +3 -2
  57. package/dest/notes_filter.d.ts +25 -0
  58. package/dest/notes_filter.d.ts.map +1 -0
  59. package/dest/notes_filter.js +4 -0
  60. package/dest/oracle_version.d.ts +2 -2
  61. package/dest/oracle_version.js +3 -3
  62. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  63. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  64. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  65. package/dest/private_kernel/hints/index.d.ts +1 -1
  66. package/dest/private_kernel/hints/index.js +1 -1
  67. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  68. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  69. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  70. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  71. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  72. package/dest/private_kernel/hints/test_utils.js +203 -0
  73. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  74. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  75. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  76. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  77. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  78. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  79. package/dest/pxe.d.ts +18 -13
  80. package/dest/pxe.d.ts.map +1 -1
  81. package/dest/pxe.js +48 -37
  82. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  83. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  84. package/dest/storage/contract_store/contract_store.js +140 -64
  85. package/dest/storage/note_store/note_store.d.ts +3 -3
  86. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  87. package/dest/storage/note_store/note_store.js +3 -4
  88. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  89. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  90. package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
  91. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  92. package/dest/storage/tagging_store/sender_tagging_store.js +4 -4
  93. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  94. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  95. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  96. package/dest/tagging/index.d.ts +2 -2
  97. package/dest/tagging/index.d.ts.map +1 -1
  98. package/dest/tagging/index.js +1 -1
  99. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  100. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  101. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  102. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  103. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  104. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  105. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  106. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  107. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  108. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +3 -6
  109. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -7
  110. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  111. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +14 -15
  112. package/package.json +16 -16
  113. package/src/access_scopes.ts +9 -0
  114. package/src/config/index.ts +1 -1
  115. package/src/config/package_info.ts +1 -1
  116. package/src/contract_function_simulator/contract_function_simulator.ts +220 -63
  117. package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
  118. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  119. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  120. package/src/contract_function_simulator/oracle/interfaces.ts +47 -44
  121. package/src/contract_function_simulator/oracle/oracle.ts +135 -107
  122. package/src/contract_function_simulator/oracle/private_execution.ts +1 -1
  123. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +44 -39
  124. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +64 -64
  125. package/src/contract_logging.ts +39 -0
  126. package/src/contract_sync/contract_sync_service.ts +49 -26
  127. package/src/contract_sync/helpers.ts +7 -2
  128. package/src/debug/pxe_debug_utils.ts +11 -9
  129. package/src/entrypoints/client/bundle/index.ts +3 -0
  130. package/src/entrypoints/client/lazy/index.ts +3 -0
  131. package/src/entrypoints/server/index.ts +2 -0
  132. package/src/logs/log_service.ts +17 -24
  133. package/src/notes/note_service.ts +4 -3
  134. package/src/notes_filter.ts +26 -0
  135. package/src/oracle_version.ts +3 -3
  136. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  137. package/src/private_kernel/hints/index.ts +1 -1
  138. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  139. package/src/private_kernel/hints/test_utils.ts +325 -0
  140. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  141. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  142. package/src/pxe.ts +67 -54
  143. package/src/storage/contract_store/contract_store.ts +170 -71
  144. package/src/storage/note_store/note_store.ts +8 -5
  145. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  146. package/src/storage/tagging_store/sender_tagging_store.ts +8 -8
  147. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  148. package/src/tagging/index.ts +1 -1
  149. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  150. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  151. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  152. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +4 -9
  153. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +11 -20
  154. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  155. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
@@ -2,23 +2,26 @@ import {
2
2
  AVM_EMITNOTEHASH_BASE_L2_GAS,
3
3
  AVM_EMITNULLIFIER_BASE_L2_GAS,
4
4
  AVM_SENDL2TOL1MSG_BASE_L2_GAS,
5
- DA_BYTES_PER_FIELD,
6
- DA_GAS_PER_BYTE,
5
+ DA_GAS_PER_FIELD,
7
6
  FIXED_AVM_STARTUP_L2_GAS,
8
- FIXED_DA_GAS,
9
- FIXED_L2_GAS,
10
- GeneratorIndex,
11
7
  L2_GAS_PER_CONTRACT_CLASS_LOG,
8
+ L2_GAS_PER_L2_TO_L1_MSG,
9
+ L2_GAS_PER_NOTE_HASH,
10
+ L2_GAS_PER_NULLIFIER,
12
11
  L2_GAS_PER_PRIVATE_LOG,
13
12
  MAX_CONTRACT_CLASS_LOGS_PER_TX,
14
13
  MAX_ENQUEUED_CALLS_PER_TX,
15
14
  MAX_L2_TO_L1_MSGS_PER_TX,
16
15
  MAX_NOTE_HASHES_PER_TX,
16
+ MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
17
17
  MAX_NULLIFIERS_PER_TX,
18
+ MAX_NULLIFIER_READ_REQUESTS_PER_TX,
18
19
  MAX_PRIVATE_LOGS_PER_TX,
20
+ PRIVATE_TX_L2_GAS_OVERHEAD,
21
+ PUBLIC_TX_L2_GAS_OVERHEAD,
22
+ TX_DA_GAS_OVERHEAD,
19
23
  } from '@aztec/constants';
20
24
  import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
21
- import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
22
25
  import { Fr } from '@aztec/foundation/curves/bn254';
23
26
  import { type Logger, createLogger } from '@aztec/foundation/log';
24
27
  import { Timer } from '@aztec/foundation/timer';
@@ -38,25 +41,36 @@ import type { FunctionCall } from '@aztec/stdlib/abi';
38
41
  import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
39
42
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
40
43
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
44
+ import type { BlockParameter } from '@aztec/stdlib/block';
41
45
  import { Gas } from '@aztec/stdlib/gas';
42
46
  import {
43
47
  computeNoteHashNonce,
44
48
  computeProtocolNullifier,
49
+ computeSiloedPrivateLogFirstField,
45
50
  computeUniqueNoteHash,
46
51
  siloNoteHash,
47
52
  siloNullifier,
48
53
  } from '@aztec/stdlib/hash';
49
54
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
50
55
  import {
56
+ ClaimedLengthArray,
51
57
  PartialPrivateTailPublicInputsForPublic,
52
58
  PartialPrivateTailPublicInputsForRollup,
53
59
  type PrivateExecutionStep,
54
60
  type PrivateKernelExecutionProofOutput,
55
61
  PrivateKernelTailCircuitPublicInputs,
62
+ PrivateLogData,
56
63
  PrivateToPublicAccumulatedData,
57
64
  PrivateToRollupAccumulatedData,
58
65
  PublicCallRequest,
66
+ ReadRequestActionEnum,
59
67
  ScopedLogHash,
68
+ ScopedNoteHash,
69
+ ScopedNullifier,
70
+ ScopedReadRequest,
71
+ buildTransientDataHints,
72
+ getNoteHashReadRequestResetActions,
73
+ getNullifierReadRequestResetActions,
60
74
  } from '@aztec/stdlib/kernel';
61
75
  import { PrivateLog } from '@aztec/stdlib/logs';
62
76
  import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
@@ -69,9 +83,11 @@ import {
69
83
  TxConstantData,
70
84
  TxExecutionRequest,
71
85
  collectNested,
86
+ collectNoteHashNullifierCounterMap,
72
87
  getFinalMinRevertibleSideEffectCounter,
73
88
  } from '@aztec/stdlib/tx';
74
89
 
90
+ import type { AccessScopes } from '../access_scopes.js';
75
91
  import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
76
92
  import type { AddressStore } from '../storage/address_store/address_store.js';
77
93
  import type { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
@@ -102,8 +118,8 @@ export type ContractSimulatorRunOpts = {
102
118
  anchorBlockHeader: BlockHeader;
103
119
  /** The address used as a tagging sender when emitting private logs. */
104
120
  senderForTags?: AztecAddress;
105
- /** The accounts whose notes we can access in this call. Defaults to all. */
106
- scopes?: AztecAddress[];
121
+ /** The accounts whose notes we can access in this call. */
122
+ scopes: AccessScopes;
107
123
  /** The job ID for staged writes. */
108
124
  jobId: string;
109
125
  };
@@ -207,8 +223,8 @@ export class ContractFunctionSimulator {
207
223
  txContext: request.txContext,
208
224
  callContext,
209
225
  anchorBlockHeader,
210
- utilityExecutor: async call => {
211
- await this.runUtility(call, [], anchorBlockHeader, scopes, jobId);
226
+ utilityExecutor: async (call, execScopes) => {
227
+ await this.runUtility(call, [], anchorBlockHeader, execScopes, jobId);
212
228
  },
213
229
  authWitnesses: request.authWitnesses,
214
230
  capsules: request.capsules,
@@ -261,7 +277,7 @@ export class ContractFunctionSimulator {
261
277
  );
262
278
  const publicFunctionsCalldata = await Promise.all(
263
279
  publicCallRequests.map(async r => {
264
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
280
+ const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
265
281
  return new HashedValues(calldata, r.calldataHash);
266
282
  }),
267
283
  );
@@ -296,7 +312,7 @@ export class ContractFunctionSimulator {
296
312
  call: FunctionCall,
297
313
  authwits: AuthWitness[],
298
314
  anchorBlockHeader: BlockHeader,
299
- scopes: AztecAddress[] | undefined,
315
+ scopes: AccessScopes,
300
316
  jobId: string,
301
317
  ): Promise<Fr[]> {
302
318
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
@@ -345,7 +361,7 @@ export class ContractFunctionSimulator {
345
361
  );
346
362
  });
347
363
 
348
- this.log.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
364
+ this.log.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
349
365
  return witnessMapToFields(acirExecutionResult.returnWitness);
350
366
  } catch (err) {
351
367
  throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
@@ -387,7 +403,8 @@ class OrderedSideEffect<T> {
387
403
  * (allowing state overrides) and is much faster, while still generating a valid
388
404
  * output that can be sent to the node for public simulation
389
405
  * @param privateExecutionResult - The result of the private execution.
390
- * @param contractStore - A provider for contract data in order to get function names and debug info.
406
+ * @param debugFunctionNameGetter - A provider for contract data in order to get function names and debug info.
407
+ * @param node - AztecNode for verifying settled read requests against the note hash and nullifier trees.
391
408
  * @param minRevertibleSideEffectCounterOverride - Optional override for the min revertible side effect counter.
392
409
  * Used by TXE to simulate account contract behavior (setting the counter before app execution).
393
410
  * @returns The simulated proving result.
@@ -395,16 +412,24 @@ class OrderedSideEffect<T> {
395
412
  export async function generateSimulatedProvingResult(
396
413
  privateExecutionResult: PrivateExecutionResult,
397
414
  debugFunctionNameGetter: (contractAddress: AztecAddress, functionSelector: FunctionSelector) => Promise<string>,
415
+ node: AztecNode,
398
416
  minRevertibleSideEffectCounterOverride?: number,
399
417
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
400
- const siloedNoteHashes: OrderedSideEffect<Fr>[] = [];
401
- const nullifiers: OrderedSideEffect<Fr>[] = [];
402
- const taggedPrivateLogs: OrderedSideEffect<PrivateLog>[] = [];
418
+ const taggedPrivateLogs: OrderedSideEffect<PrivateLogData>[] = [];
403
419
  const l2ToL1Messages: OrderedSideEffect<ScopedL2ToL1Message>[] = [];
404
420
  const contractClassLogsHashes: OrderedSideEffect<ScopedLogHash>[] = [];
405
421
  const publicCallRequests: OrderedSideEffect<PublicCallRequest>[] = [];
406
422
  const executionSteps: PrivateExecutionStep[] = [];
407
423
 
424
+ // Unsiloed scoped arrays — used for squashing, read request verification,
425
+ // and siloed at the end only for the surviving items
426
+ const scopedNoteHashes: ScopedNoteHash[] = [];
427
+ const scopedNullifiers: ScopedNullifier[] = [];
428
+
429
+ // Read requests for verification
430
+ const noteHashReadRequests: ScopedReadRequest[] = [];
431
+ const nullifierReadRequests: ScopedReadRequest[] = [];
432
+
408
433
  let publicTeardownCallRequest;
409
434
 
410
435
  const executions = [privateExecutionResult.entrypoint];
@@ -415,38 +440,25 @@ export async function generateSimulatedProvingResult(
415
440
 
416
441
  const { contractAddress } = execution.publicInputs.callContext;
417
442
 
418
- const noteHashesFromExecution = await Promise.all(
419
- execution.publicInputs.noteHashes
420
- .getActiveItems()
421
- .filter(noteHash => !noteHash.isEmpty())
422
- .map(
423
- async noteHash =>
424
- new OrderedSideEffect(await siloNoteHash(contractAddress, noteHash.value), noteHash.counter),
425
- ),
426
- );
427
-
428
- const nullifiersFromExecution = await Promise.all(
429
- execution.publicInputs.nullifiers
443
+ scopedNoteHashes.push(
444
+ ...execution.publicInputs.noteHashes
430
445
  .getActiveItems()
431
- .map(
432
- async nullifier =>
433
- new OrderedSideEffect(await siloNullifier(contractAddress, nullifier.value), nullifier.counter),
434
- ),
446
+ .filter(nh => !nh.isEmpty())
447
+ .map(nh => nh.scope(contractAddress)),
435
448
  );
449
+ scopedNullifiers.push(...execution.publicInputs.nullifiers.getActiveItems().map(n => n.scope(contractAddress)));
436
450
 
437
- const privateLogsFromExecution = await Promise.all(
438
- execution.publicInputs.privateLogs.getActiveItems().map(async metadata => {
439
- metadata.log.fields[0] = await poseidon2HashWithSeparator(
440
- [contractAddress, metadata.log.fields[0]],
441
- GeneratorIndex.PRIVATE_LOG_FIRST_FIELD,
442
- );
443
- return new OrderedSideEffect(metadata.log, metadata.counter);
444
- }),
451
+ taggedPrivateLogs.push(
452
+ ...(await Promise.all(
453
+ execution.publicInputs.privateLogs.getActiveItems().map(async metadata => {
454
+ metadata.log.fields[0] = await computeSiloedPrivateLogFirstField(contractAddress, metadata.log.fields[0]);
455
+ return new OrderedSideEffect(metadata, metadata.counter);
456
+ }),
457
+ )),
445
458
  );
446
459
 
447
- siloedNoteHashes.push(...noteHashesFromExecution);
448
- taggedPrivateLogs.push(...privateLogsFromExecution);
449
- nullifiers.push(...nullifiersFromExecution);
460
+ noteHashReadRequests.push(...execution.publicInputs.noteHashReadRequests.getActiveItems());
461
+ nullifierReadRequests.push(...execution.publicInputs.nullifierReadRequests.getActiveItems());
450
462
  l2ToL1Messages.push(
451
463
  ...execution.publicInputs.l2ToL1Msgs
452
464
  .getActiveItems()
@@ -486,6 +498,47 @@ export async function generateSimulatedProvingResult(
486
498
  });
487
499
  }
488
500
 
501
+ const noteHashNullifierCounterMap = collectNoteHashNullifierCounterMap(privateExecutionResult);
502
+ const minRevertibleSideEffectCounter =
503
+ minRevertibleSideEffectCounterOverride ?? getFinalMinRevertibleSideEffectCounter(privateExecutionResult);
504
+
505
+ const scopedNoteHashesCLA = new ClaimedLengthArray<ScopedNoteHash, typeof MAX_NOTE_HASHES_PER_TX>(
506
+ padArrayEnd(scopedNoteHashes, ScopedNoteHash.empty(), MAX_NOTE_HASHES_PER_TX),
507
+ scopedNoteHashes.length,
508
+ );
509
+ const scopedNullifiersCLA = new ClaimedLengthArray<ScopedNullifier, typeof MAX_NULLIFIERS_PER_TX>(
510
+ padArrayEnd(scopedNullifiers, ScopedNullifier.empty(), MAX_NULLIFIERS_PER_TX),
511
+ scopedNullifiers.length,
512
+ );
513
+
514
+ const { filteredNoteHashes, filteredNullifiers, filteredPrivateLogs } = squashTransientSideEffects(
515
+ taggedPrivateLogs,
516
+ scopedNoteHashesCLA,
517
+ scopedNullifiersCLA,
518
+ noteHashNullifierCounterMap,
519
+ minRevertibleSideEffectCounter,
520
+ );
521
+
522
+ await verifyReadRequests(
523
+ node,
524
+ await privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader.hash(),
525
+ noteHashReadRequests,
526
+ nullifierReadRequests,
527
+ scopedNoteHashesCLA,
528
+ scopedNullifiersCLA,
529
+ );
530
+
531
+ const siloedNoteHashes = await Promise.all(
532
+ filteredNoteHashes
533
+ .sort((a, b) => a.counter - b.counter)
534
+ .map(async nh => new OrderedSideEffect(await siloNoteHash(nh.contractAddress, nh.value), nh.counter)),
535
+ );
536
+ const siloedNullifiers = await Promise.all(
537
+ filteredNullifiers
538
+ .sort((a, b) => a.counter - b.counter)
539
+ .map(async n => new OrderedSideEffect(await siloNullifier(n.contractAddress, n.value), n.counter)),
540
+ );
541
+
489
542
  const constantData = new TxConstantData(
490
543
  privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader,
491
544
  privateExecutionResult.entrypoint.publicInputs.txContext,
@@ -502,11 +555,9 @@ export async function generateSimulatedProvingResult(
502
555
  const getEffect = <T>(orderedSideEffect: OrderedSideEffect<T>) => orderedSideEffect.sideEffect;
503
556
 
504
557
  const isPrivateOnlyTx = privateExecutionResult.publicFunctionCalldata.length === 0;
505
- const minRevertibleSideEffectCounter =
506
- minRevertibleSideEffectCounterOverride ?? getFinalMinRevertibleSideEffectCounter(privateExecutionResult);
507
558
 
508
559
  const [nonRevertibleNullifiers, revertibleNullifiers] = splitOrderedSideEffects(
509
- nullifiers.sort(sortByCounter),
560
+ siloedNullifiers,
510
561
  minRevertibleSideEffectCounter,
511
562
  );
512
563
  const nonceGenerator = privateExecutionResult.firstNullifier;
@@ -520,7 +571,7 @@ export async function generateSimulatedProvingResult(
520
571
  // We must make the note hashes unique by using the
521
572
  // nonce generator and their index in the tx.
522
573
  const uniqueNoteHashes = await Promise.all(
523
- siloedNoteHashes.sort(sortByCounter).map(async (orderedSideEffect, i) => {
574
+ siloedNoteHashes.map(async (orderedSideEffect, i) => {
524
575
  const siloedNoteHash = orderedSideEffect.sideEffect;
525
576
  const nonce = await computeNoteHashNonce(nonceGenerator, i);
526
577
  const uniqueNoteHash = await computeUniqueNoteHash(nonce, siloedNoteHash);
@@ -535,18 +586,18 @@ export async function generateSimulatedProvingResult(
535
586
  ScopedL2ToL1Message.empty(),
536
587
  MAX_L2_TO_L1_MSGS_PER_TX,
537
588
  ),
538
- padArrayEnd(taggedPrivateLogs.sort(sortByCounter).map(getEffect), PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX),
589
+ padArrayEnd(filteredPrivateLogs.sort(sortByCounter).map(getEffect), PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX),
539
590
  padArrayEnd(
540
591
  contractClassLogsHashes.sort(sortByCounter).map(getEffect),
541
592
  ScopedLogHash.empty(),
542
593
  MAX_CONTRACT_CLASS_LOGS_PER_TX,
543
594
  ),
544
595
  );
545
- gasUsed = meterGasUsed(accumulatedDataForRollup);
596
+ gasUsed = meterGasUsed(accumulatedDataForRollup, isPrivateOnlyTx);
546
597
  inputsForRollup = new PartialPrivateTailPublicInputsForRollup(accumulatedDataForRollup);
547
598
  } else {
548
599
  const [nonRevertibleNoteHashes, revertibleNoteHashes] = splitOrderedSideEffects(
549
- siloedNoteHashes.sort(sortByCounter),
600
+ siloedNoteHashes,
550
601
  minRevertibleSideEffectCounter,
551
602
  );
552
603
  const nonRevertibleUniqueNoteHashes = await Promise.all(
@@ -560,7 +611,7 @@ export async function generateSimulatedProvingResult(
560
611
  minRevertibleSideEffectCounter,
561
612
  );
562
613
  const [nonRevertibleTaggedPrivateLogs, revertibleTaggedPrivateLogs] = splitOrderedSideEffects(
563
- taggedPrivateLogs,
614
+ filteredPrivateLogs,
564
615
  minRevertibleSideEffectCounter,
565
616
  );
566
617
  const [nonRevertibleContractClassLogHashes, revertibleContractClassLogHashes] = splitOrderedSideEffects(
@@ -589,9 +640,9 @@ export async function generateSimulatedProvingResult(
589
640
  padArrayEnd(revertibleContractClassLogHashes, ScopedLogHash.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX),
590
641
  padArrayEnd(revertiblePublicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
591
642
  );
592
- gasUsed = meterGasUsed(revertibleData).add(meterGasUsed(nonRevertibleData));
643
+ gasUsed = meterGasUsed(revertibleData, isPrivateOnlyTx).add(meterGasUsed(nonRevertibleData, isPrivateOnlyTx));
593
644
  if (publicTeardownCallRequest) {
594
- gasUsed.add(privateExecutionResult.entrypoint.publicInputs.txContext.gasSettings.teardownGasLimits);
645
+ gasUsed = gasUsed.add(privateExecutionResult.entrypoint.publicInputs.txContext.gasSettings.teardownGasLimits);
595
646
  }
596
647
 
597
648
  inputsForPublic = new PartialPrivateTailPublicInputsForPublic(
@@ -603,9 +654,14 @@ export async function generateSimulatedProvingResult(
603
654
 
604
655
  const publicInputs = new PrivateKernelTailCircuitPublicInputs(
605
656
  constantData,
606
- /*gasUsed=*/ gasUsed.add(Gas.from({ l2Gas: FIXED_L2_GAS, daGas: FIXED_DA_GAS })),
657
+ /*gasUsed=*/ gasUsed.add(
658
+ Gas.from({
659
+ l2Gas: isPrivateOnlyTx ? PRIVATE_TX_L2_GAS_OVERHEAD : PUBLIC_TX_L2_GAS_OVERHEAD,
660
+ daGas: TX_DA_GAS_OVERHEAD,
661
+ }),
662
+ ),
607
663
  /*feePayer=*/ AztecAddress.zero(),
608
- /*includeByTimestamp=*/ 0n,
664
+ /*expirationTimestamp=*/ 0n,
609
665
  hasPublicCalls ? inputsForPublic : undefined,
610
666
  !hasPublicCalls ? inputsForRollup : undefined,
611
667
  );
@@ -617,6 +673,104 @@ export async function generateSimulatedProvingResult(
617
673
  };
618
674
  }
619
675
 
676
+ /**
677
+ * Squashes transient note hashes and nullifiers, mimicking the behavior
678
+ * of the reset kernels. Returns the filtered (surviving) scoped items and private logs.
679
+ */
680
+ function squashTransientSideEffects(
681
+ taggedPrivateLogs: OrderedSideEffect<PrivateLogData>[],
682
+ scopedNoteHashesCLA: ClaimedLengthArray<ScopedNoteHash, typeof MAX_NOTE_HASHES_PER_TX>,
683
+ scopedNullifiersCLA: ClaimedLengthArray<ScopedNullifier, typeof MAX_NULLIFIERS_PER_TX>,
684
+ noteHashNullifierCounterMap: Map<number, number>,
685
+ minRevertibleSideEffectCounter: number,
686
+ ) {
687
+ const { numTransientData, hints: transientDataHints } = buildTransientDataHints(
688
+ scopedNoteHashesCLA,
689
+ scopedNullifiersCLA,
690
+ /*futureNoteHashReads=*/ [],
691
+ /*futureNullifierReads=*/ [],
692
+ /*futureLogs=*/ [],
693
+ noteHashNullifierCounterMap,
694
+ minRevertibleSideEffectCounter,
695
+ );
696
+
697
+ const squashedNoteHashCounters = new Set<number>();
698
+ const squashedNullifierCounters = new Set<number>();
699
+ for (let i = 0; i < numTransientData; i++) {
700
+ const hint = transientDataHints[i];
701
+ squashedNoteHashCounters.add(scopedNoteHashesCLA.array[hint.noteHashIndex].counter);
702
+ squashedNullifierCounters.add(scopedNullifiersCLA.array[hint.nullifierIndex].counter);
703
+ }
704
+
705
+ return {
706
+ filteredNoteHashes: scopedNoteHashesCLA.getActiveItems().filter(nh => !squashedNoteHashCounters.has(nh.counter)),
707
+ filteredNullifiers: scopedNullifiersCLA.getActiveItems().filter(n => !squashedNullifierCounters.has(n.counter)),
708
+ filteredPrivateLogs: taggedPrivateLogs
709
+ .filter(item => !squashedNoteHashCounters.has(item.sideEffect.noteHashCounter))
710
+ .map(item => new OrderedSideEffect(item.sideEffect.log, item.counter)),
711
+ };
712
+ }
713
+
714
+ /**
715
+ * Verifies settled read requests by checking membership in the note hash and nullifier trees
716
+ * at the tx's anchor block, mimicking the behavior of the kernels
717
+ */
718
+ async function verifyReadRequests(
719
+ node: Pick<AztecNode, 'getNoteHashMembershipWitness' | 'getNullifierMembershipWitness'>,
720
+ anchorBlockHash: BlockParameter,
721
+ noteHashReadRequests: ScopedReadRequest[],
722
+ nullifierReadRequests: ScopedReadRequest[],
723
+ scopedNoteHashesCLA: ClaimedLengthArray<ScopedNoteHash, typeof MAX_NOTE_HASHES_PER_TX>,
724
+ scopedNullifiersCLA: ClaimedLengthArray<ScopedNullifier, typeof MAX_NULLIFIERS_PER_TX>,
725
+ ) {
726
+ const noteHashReadRequestsCLA = new ClaimedLengthArray<ScopedReadRequest, typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>(
727
+ padArrayEnd(noteHashReadRequests, ScopedReadRequest.empty(), MAX_NOTE_HASH_READ_REQUESTS_PER_TX),
728
+ noteHashReadRequests.length,
729
+ );
730
+ const nullifierReadRequestsCLA = new ClaimedLengthArray<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>(
731
+ padArrayEnd(nullifierReadRequests, ScopedReadRequest.empty(), MAX_NULLIFIER_READ_REQUESTS_PER_TX),
732
+ nullifierReadRequests.length,
733
+ );
734
+
735
+ const noteHashResetActions = getNoteHashReadRequestResetActions(noteHashReadRequestsCLA, scopedNoteHashesCLA);
736
+ const nullifierResetActions = getNullifierReadRequestResetActions(nullifierReadRequestsCLA, scopedNullifiersCLA);
737
+
738
+ const settledNoteHashReads: { index: number; value: Fr }[] = [];
739
+ for (let i = 0; i < noteHashResetActions.actions.length; i++) {
740
+ if (noteHashResetActions.actions[i] === ReadRequestActionEnum.READ_AS_SETTLED) {
741
+ settledNoteHashReads.push({ index: i, value: noteHashReadRequests[i].value });
742
+ }
743
+ }
744
+
745
+ const settledNullifierReads: { index: number; value: Fr }[] = [];
746
+ for (let i = 0; i < nullifierResetActions.actions.length; i++) {
747
+ if (nullifierResetActions.actions[i] === ReadRequestActionEnum.READ_AS_SETTLED) {
748
+ settledNullifierReads.push({ index: i, value: nullifierReadRequests[i].value });
749
+ }
750
+ }
751
+
752
+ const [noteHashWitnesses, nullifierWitnesses] = await Promise.all([
753
+ Promise.all(settledNoteHashReads.map(({ value }) => node.getNoteHashMembershipWitness(anchorBlockHash, value))),
754
+ Promise.all(settledNullifierReads.map(({ value }) => node.getNullifierMembershipWitness(anchorBlockHash, value))),
755
+ ]);
756
+
757
+ for (let i = 0; i < settledNoteHashReads.length; i++) {
758
+ if (!noteHashWitnesses[i]) {
759
+ throw new Error(
760
+ `Note hash read request at index ${settledNoteHashReads[i].index} is reading an unknown note hash: ${settledNoteHashReads[i].value}`,
761
+ );
762
+ }
763
+ }
764
+
765
+ for (let i = 0; i < settledNullifierReads.length; i++) {
766
+ if (!nullifierWitnesses[i]) {
767
+ throw new Error(
768
+ `Nullifier read request at index ${settledNullifierReads[i].index} is reading an unknown nullifier: ${settledNullifierReads[i].value}`,
769
+ );
770
+ }
771
+ }
772
+ }
773
+
620
774
  function splitOrderedSideEffects<T>(effects: OrderedSideEffect<T>[], minRevertibleSideEffectCounter: number) {
621
775
  const revertibleSideEffects: T[] = [];
622
776
  const nonRevertibleSideEffects: T[] = [];
@@ -630,21 +784,24 @@ function splitOrderedSideEffects<T>(effects: OrderedSideEffect<T>[], minRevertib
630
784
  return [nonRevertibleSideEffects, revertibleSideEffects];
631
785
  }
632
786
 
633
- function meterGasUsed(data: PrivateToRollupAccumulatedData | PrivateToPublicAccumulatedData) {
787
+ function meterGasUsed(data: PrivateToRollupAccumulatedData | PrivateToPublicAccumulatedData, isPrivateOnlyTx: boolean) {
634
788
  let meteredDAFields = 0;
635
789
  let meteredL2Gas = 0;
636
790
 
637
791
  const numNoteHashes = arrayNonEmptyLength(data.noteHashes, hash => hash.isEmpty());
638
792
  meteredDAFields += numNoteHashes;
639
- meteredL2Gas += numNoteHashes * AVM_EMITNOTEHASH_BASE_L2_GAS;
793
+ const noteHashBaseGas = isPrivateOnlyTx ? L2_GAS_PER_NOTE_HASH : AVM_EMITNOTEHASH_BASE_L2_GAS;
794
+ meteredL2Gas += numNoteHashes * noteHashBaseGas;
640
795
 
641
796
  const numNullifiers = arrayNonEmptyLength(data.nullifiers, nullifier => nullifier.isEmpty());
642
797
  meteredDAFields += numNullifiers;
643
- meteredL2Gas += numNullifiers * AVM_EMITNULLIFIER_BASE_L2_GAS;
798
+ const nullifierBaseGas = isPrivateOnlyTx ? L2_GAS_PER_NULLIFIER : AVM_EMITNULLIFIER_BASE_L2_GAS;
799
+ meteredL2Gas += numNullifiers * nullifierBaseGas;
644
800
 
645
801
  const numL2toL1Messages = arrayNonEmptyLength(data.l2ToL1Msgs, msg => msg.isEmpty());
646
802
  meteredDAFields += numL2toL1Messages;
647
- meteredL2Gas += numL2toL1Messages * AVM_SENDL2TOL1MSG_BASE_L2_GAS;
803
+ const l2ToL1MessageBaseGas = isPrivateOnlyTx ? L2_GAS_PER_L2_TO_L1_MSG : AVM_SENDL2TOL1MSG_BASE_L2_GAS;
804
+ meteredL2Gas += numL2toL1Messages * l2ToL1MessageBaseGas;
648
805
 
649
806
  const numPrivatelogs = arrayNonEmptyLength(data.privateLogs, log => log.isEmpty());
650
807
  // Every private log emits its length as an additional field
@@ -652,14 +809,14 @@ function meterGasUsed(data: PrivateToRollupAccumulatedData | PrivateToPublicAccu
652
809
  meteredL2Gas += numPrivatelogs * L2_GAS_PER_PRIVATE_LOG;
653
810
 
654
811
  const numContractClassLogs = arrayNonEmptyLength(data.contractClassLogsHashes, log => log.isEmpty());
655
- // Every contract class log emits its length and contract address as additional fields
812
+ // Every contract class log emits its contract address as an additional field
656
813
  meteredDAFields += data.contractClassLogsHashes.reduce(
657
- (acc, log) => (!log.isEmpty() ? acc + log.logHash.length + 2 : acc),
814
+ (acc, log) => (!log.isEmpty() ? acc + log.logHash.length + 1 : acc),
658
815
  0,
659
816
  );
660
817
  meteredL2Gas += numContractClassLogs * L2_GAS_PER_CONTRACT_CLASS_LOG;
661
818
 
662
- const meteredDAGas = meteredDAFields * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE;
819
+ const meteredDAGas = meteredDAFields * DA_GAS_PER_FIELD;
663
820
 
664
821
  if ((data as PrivateToPublicAccumulatedData).publicCallRequests) {
665
822
  const dataForPublic = data as PrivateToPublicAccumulatedData;
@@ -1,18 +1,18 @@
1
- import { DirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
1
+ import { ExtendedDirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
2
2
 
3
3
  /**
4
- * A map that stores the tagging index for a given directional app tagging secret.
4
+ * A map that stores the tagging index for a given extended directional app tagging secret.
5
5
  * Note: The directional app tagging secret is unique for a (sender, recipient, contract) tuple while the direction
6
6
  * of sender -> recipient matters.
7
7
  */
8
8
  export class ExecutionTaggingIndexCache {
9
9
  private taggingIndexMap: Map<string, number> = new Map();
10
10
 
11
- public getLastUsedIndex(secret: DirectionalAppTaggingSecret): number | undefined {
11
+ public getLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret): number | undefined {
12
12
  return this.taggingIndexMap.get(secret.toString());
13
13
  }
14
14
 
15
- public setLastUsedIndex(secret: DirectionalAppTaggingSecret, index: number) {
15
+ public setLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret, index: number) {
16
16
  const currentValue = this.taggingIndexMap.get(secret.toString());
17
17
  if (currentValue !== undefined && currentValue !== index - 1) {
18
18
  throw new Error(`Invalid tagging index update. Current value: ${currentValue}, new value: ${index}`);
@@ -25,7 +25,7 @@ export class ExecutionTaggingIndexCache {
25
25
  */
26
26
  public getUsedPreTags(): PreTag[] {
27
27
  return Array.from(this.taggingIndexMap.entries()).map(([secret, index]) => ({
28
- secret: DirectionalAppTaggingSecret.fromString(secret),
28
+ extendedSecret: ExtendedDirectionalAppTaggingSecret.fromString(secret),
29
29
  index,
30
30
  }));
31
31
  }
@@ -5,7 +5,7 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import { TxHash } from '@aztec/stdlib/tx';
6
6
 
7
7
  // TODO(#14617): should we compute this from constants? This value is aztec-nr specific.
8
- const MAX_EVENT_SERIALIZED_LEN = 12;
8
+ const MAX_EVENT_SERIALIZED_LEN = 10;
9
9
 
10
10
  /**
11
11
  * Intermediate struct used to perform batch event validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle
@@ -4,7 +4,7 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { TxHash } from '@aztec/stdlib/tx';
5
5
 
6
6
  // TODO(#14617): should we compute this from constants? This value is aztec-nr specific.
7
- export const MAX_NOTE_PACKED_LEN = 10;
7
+ export const MAX_NOTE_PACKED_LEN = 8;
8
8
 
9
9
  /**
10
10
  * Intermediate struct used to perform batch note validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle