@aztec/pxe 0.0.1-commit.3100065 → 0.0.1-commit.330febf

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 (207) hide show
  1. package/dest/bin/check_oracle_version.js +5 -46
  2. package/dest/bin/index.d.ts +2 -2
  3. package/dest/bin/index.d.ts.map +1 -1
  4. package/dest/bin/index.js +1 -1
  5. package/dest/bin/oracle_version_helpers.d.ts +8 -39
  6. package/dest/bin/oracle_version_helpers.d.ts.map +1 -1
  7. package/dest/bin/oracle_version_helpers.js +10 -239
  8. package/dest/block_synchronizer/block_synchronizer.d.ts +3 -5
  9. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  10. package/dest/block_synchronizer/block_synchronizer.js +5 -18
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract/contract_class_service.d.ts +1 -8
  13. package/dest/contract/contract_class_service.d.ts.map +1 -1
  14. package/dest/contract/contract_class_service.js +8 -40
  15. package/dest/contract/helpers.d.ts +1 -1
  16. package/dest/contract/helpers.d.ts.map +1 -1
  17. package/dest/contract/helpers.js +3 -3
  18. package/dest/contract/skip_sync_contracts.d.ts +11 -0
  19. package/dest/contract/skip_sync_contracts.d.ts.map +1 -0
  20. package/dest/contract/skip_sync_contracts.js +18 -0
  21. package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -8
  22. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/contract_function_simulator.js +5 -20
  24. package/dest/contract_function_simulator/index.d.ts +3 -3
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.js +1 -2
  27. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +7 -9
  28. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +3 -44
  30. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +5 -4
  31. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +2 -2
  33. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +4 -3
  34. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/oracle_registry.js +15 -6
  36. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +87 -35
  37. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +297 -287
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +11 -8
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +15 -4
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +168 -53
  45. package/dest/entrypoints/client/bundle/index.d.ts +2 -1
  46. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  47. package/dest/entrypoints/client/bundle/index.js +1 -0
  48. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  49. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  50. package/dest/entrypoints/client/bundle/utils.js +10 -4
  51. package/dest/entrypoints/client/lazy/index.d.ts +2 -1
  52. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  53. package/dest/entrypoints/client/lazy/index.js +1 -0
  54. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  55. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  56. package/dest/entrypoints/client/lazy/utils.js +10 -4
  57. package/dest/entrypoints/client/store.d.ts +14 -0
  58. package/dest/entrypoints/client/store.d.ts.map +1 -0
  59. package/dest/entrypoints/client/store.js +42 -0
  60. package/dest/entrypoints/server/index.d.ts +2 -1
  61. package/dest/entrypoints/server/index.d.ts.map +1 -1
  62. package/dest/entrypoints/server/index.js +1 -0
  63. package/dest/entrypoints/server/store.d.ts +18 -0
  64. package/dest/entrypoints/server/store.d.ts.map +1 -0
  65. package/dest/entrypoints/server/store.js +28 -0
  66. package/dest/entrypoints/server/utils.d.ts +1 -1
  67. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  68. package/dest/entrypoints/server/utils.js +8 -2
  69. package/dest/events/event_service.d.ts +13 -6
  70. package/dest/events/event_service.d.ts.map +1 -1
  71. package/dest/events/event_service.js +13 -13
  72. package/dest/logs/log_service.d.ts +15 -6
  73. package/dest/logs/log_service.d.ts.map +1 -1
  74. package/dest/logs/log_service.js +25 -32
  75. package/dest/messages/tx_resolver_service.d.ts +18 -7
  76. package/dest/messages/tx_resolver_service.d.ts.map +1 -1
  77. package/dest/messages/tx_resolver_service.js +13 -7
  78. package/dest/node/benchmarked_node.d.ts +20 -0
  79. package/dest/node/benchmarked_node.d.ts.map +1 -0
  80. package/dest/node/benchmarked_node.js +94 -0
  81. package/dest/node/caching_aztec_node.d.ts +24 -0
  82. package/dest/node/caching_aztec_node.d.ts.map +1 -0
  83. package/dest/node/caching_aztec_node.js +267 -0
  84. package/dest/notes/note_service.d.ts +13 -7
  85. package/dest/notes/note_service.d.ts.map +1 -1
  86. package/dest/notes/note_service.js +10 -10
  87. package/dest/oracle_version.d.ts +2 -2
  88. package/dest/oracle_version.js +5 -5
  89. package/dest/private_kernel/batch_planner.d.ts +1 -1
  90. package/dest/private_kernel/batch_planner.d.ts.map +1 -1
  91. package/dest/private_kernel/batch_planner.js +1 -1
  92. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  93. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  94. package/dest/private_kernel/private_kernel_execution_prover.js +45 -5
  95. package/dest/pxe.d.ts +1 -1
  96. package/dest/pxe.d.ts.map +1 -1
  97. package/dest/pxe.js +39 -19
  98. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  99. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  100. package/dest/storage/contract_store/contract_store.js +2 -2
  101. package/dest/storage/fact_store/fact_store.d.ts +1 -1
  102. package/dest/storage/fact_store/fact_store.js +1 -1
  103. package/dest/storage/fact_store/index.d.ts +2 -2
  104. package/dest/storage/fact_store/index.d.ts.map +1 -1
  105. package/dest/storage/fact_store/index.js +1 -1
  106. package/dest/storage/fact_store/origin_state.d.ts +4 -2
  107. package/dest/storage/fact_store/origin_state.d.ts.map +1 -1
  108. package/dest/storage/fact_store/origin_state.js +8 -1
  109. package/dest/storage/store_identity.d.ts +35 -0
  110. package/dest/storage/store_identity.d.ts.map +1 -0
  111. package/dest/storage/store_identity.js +44 -0
  112. package/dest/storage/tagging_store/sender_tagging_store.d.ts +41 -10
  113. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  114. package/dest/storage/tagging_store/sender_tagging_store.js +81 -29
  115. package/dest/tagging/constants.d.ts +10 -1
  116. package/dest/tagging/constants.d.ts.map +1 -1
  117. package/dest/tagging/constants.js +19 -0
  118. package/dest/tagging/get_all_logs_by_tags.d.ts +29 -8
  119. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  120. package/dest/tagging/get_all_logs_by_tags.js +29 -10
  121. package/dest/tagging/index.d.ts +3 -3
  122. package/dest/tagging/index.d.ts.map +1 -1
  123. package/dest/tagging/index.js +2 -2
  124. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +10 -5
  125. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -1
  126. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +69 -38
  127. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +6 -3
  128. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  129. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +23 -38
  130. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
  131. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
  132. package/dest/tagging/sender_sync/utils/classify_pending_txs.js +61 -0
  133. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +15 -5
  134. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  135. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -35
  136. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
  137. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
  138. package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +41 -0
  139. package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
  140. package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
  141. package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
  142. package/dest/tagging/testing/tag_query_test_utils.d.ts +6 -0
  143. package/dest/tagging/testing/tag_query_test_utils.d.ts.map +1 -0
  144. package/dest/tagging/testing/tag_query_test_utils.js +10 -0
  145. package/package.json +17 -17
  146. package/src/bin/check_oracle_version.ts +5 -56
  147. package/src/bin/index.ts +1 -5
  148. package/src/bin/oracle_version_helpers.ts +11 -292
  149. package/src/block_synchronizer/block_synchronizer.ts +6 -23
  150. package/src/config/package_info.ts +1 -1
  151. package/src/contract/contract_class_service.ts +8 -46
  152. package/src/contract/helpers.ts +3 -3
  153. package/src/contract/skip_sync_contracts.ts +23 -0
  154. package/src/contract_function_simulator/contract_function_simulator.ts +5 -20
  155. package/src/contract_function_simulator/index.ts +23 -3
  156. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +11 -45
  157. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +4 -3
  158. package/src/contract_function_simulator/oracle/oracle_registry.ts +12 -8
  159. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +301 -198
  160. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +19 -9
  161. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +184 -56
  162. package/src/entrypoints/client/bundle/index.ts +1 -0
  163. package/src/entrypoints/client/bundle/utils.ts +15 -3
  164. package/src/entrypoints/client/lazy/index.ts +1 -0
  165. package/src/entrypoints/client/lazy/utils.ts +15 -3
  166. package/src/entrypoints/client/store.ts +54 -0
  167. package/src/entrypoints/server/index.ts +1 -0
  168. package/src/entrypoints/server/store.ts +47 -0
  169. package/src/entrypoints/server/utils.ts +21 -7
  170. package/src/events/event_service.ts +24 -14
  171. package/src/logs/log_service.ts +41 -39
  172. package/src/messages/tx_resolver_service.ts +26 -15
  173. package/src/node/benchmarked_node.ts +140 -0
  174. package/src/node/caching_aztec_node.ts +406 -0
  175. package/src/notes/note_service.ts +20 -14
  176. package/src/oracle_version.ts +5 -5
  177. package/src/private_kernel/batch_planner.ts +0 -1
  178. package/src/private_kernel/private_kernel_execution_prover.ts +90 -4
  179. package/src/pxe.ts +40 -21
  180. package/src/storage/contract_store/contract_store.ts +2 -1
  181. package/src/storage/fact_store/fact_store.ts +1 -1
  182. package/src/storage/fact_store/index.ts +1 -0
  183. package/src/storage/fact_store/origin_state.ts +10 -1
  184. package/src/storage/store_identity.ts +72 -0
  185. package/src/storage/tagging_store/sender_tagging_store.ts +113 -41
  186. package/src/tagging/constants.ts +22 -0
  187. package/src/tagging/get_all_logs_by_tags.ts +47 -11
  188. package/src/tagging/index.ts +7 -2
  189. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +116 -62
  190. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +27 -57
  191. package/src/tagging/sender_sync/utils/classify_pending_txs.ts +91 -0
  192. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +46 -40
  193. package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +64 -0
  194. package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
  195. package/src/tagging/testing/tag_query_test_utils.ts +11 -0
  196. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +0 -39
  197. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +0 -1
  198. package/dest/contract_function_simulator/aztec_node_read_cache.js +0 -60
  199. package/dest/contract_function_simulator/benchmarked_node.d.ts +0 -9
  200. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +0 -1
  201. package/dest/contract_function_simulator/benchmarked_node.js +0 -77
  202. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +0 -17
  203. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +0 -1
  204. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +0 -60
  205. package/src/contract_function_simulator/aztec_node_read_cache.ts +0 -89
  206. package/src/contract_function_simulator/benchmarked_node.ts +0 -103
  207. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +0 -66
@@ -1,6 +1,7 @@
1
+ import { CircuitKind } from '@aztec/bb.js';
1
2
  import { MAX_APPS_PER_KERNEL } from '@aztec/constants';
2
3
  import { uniqueBy } from '@aztec/foundation/collection';
3
- import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto/keys';
4
+ import { vkAsFields } from '@aztec/foundation/crypto/keys';
4
5
  import { Fr } from '@aztec/foundation/curves/bn254';
5
6
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
6
7
  import { pushTestData } from '@aztec/foundation/testing';
@@ -20,9 +21,13 @@ import {
20
21
  type PrivateKernelExecutionProofOutput,
21
22
  PrivateKernelInit2CircuitPrivateInputs,
22
23
  PrivateKernelInit3CircuitPrivateInputs,
24
+ PrivateKernelInit4CircuitPrivateInputs,
25
+ PrivateKernelInit5CircuitPrivateInputs,
23
26
  PrivateKernelInitCircuitPrivateInputs,
24
27
  PrivateKernelInner2CircuitPrivateInputs,
25
28
  PrivateKernelInner3CircuitPrivateInputs,
29
+ PrivateKernelInner4CircuitPrivateInputs,
30
+ PrivateKernelInner5CircuitPrivateInputs,
26
31
  PrivateKernelInnerCircuitPrivateInputs,
27
32
  PrivateKernelResetTailCircuitPrivateInputs,
28
33
  type PrivateKernelSimulateOutput,
@@ -145,6 +150,7 @@ export class PrivateKernelExecutionProver {
145
150
  bytecode: output.bytecode,
146
151
  witness: output.outputWitness,
147
152
  vk: output.verificationKey.keyAsBytes,
153
+ kind: CircuitKind.Kernel,
148
154
  timings: {
149
155
  witgen: witgenTimer.ms(),
150
156
  },
@@ -230,6 +236,7 @@ export class PrivateKernelExecutionProver {
230
236
  bytecode: tailOutput.bytecode,
231
237
  witness: tailOutput.outputWitness,
232
238
  vk: tailOutput.verificationKey.keyAsBytes,
239
+ kind: CircuitKind.Kernel,
233
240
  timings: {
234
241
  witgen: witgenTimer.ms(),
235
242
  },
@@ -261,6 +268,7 @@ export class PrivateKernelExecutionProver {
261
268
  bytecode: hidingOutput.bytecode,
262
269
  witness: hidingOutput.outputWitness,
263
270
  vk: hidingOutput.verificationKey.keyAsBytes,
271
+ kind: CircuitKind.HidingKernel,
264
272
  timings: {
265
273
  witgen: witgenTimer.ms(),
266
274
  },
@@ -270,7 +278,11 @@ export class PrivateKernelExecutionProver {
270
278
  if (profileMode == 'gates' || profileMode == 'full') {
271
279
  for (const entry of executionSteps) {
272
280
  const gateCountTimer = new Timer();
273
- const gateCount = await this.proofCreator.computeGateCountForCircuit(entry.bytecode, entry.functionName);
281
+ const gateCount = await this.proofCreator.computeGateCountForCircuit(
282
+ entry.bytecode,
283
+ entry.functionName,
284
+ entry.kind,
285
+ );
274
286
  entry.gateCount = gateCount;
275
287
  entry.timings.gateCount = gateCountTimer.ms();
276
288
  }
@@ -366,6 +378,7 @@ export class PrivateKernelExecutionProver {
366
378
  bytecode: next.acir,
367
379
  witness: next.partialWitness,
368
380
  vk: next.vk,
381
+ kind: CircuitKind.App,
369
382
  timings: {
370
383
  witgen: next.profileResult?.timings.witgen ?? 0,
371
384
  oracles: next.profileResult?.timings.oracles,
@@ -399,8 +412,8 @@ export class PrivateKernelExecutionProver {
399
412
  ) {
400
413
  const { contractAddress, functionSelector } = publicInputs.callContext;
401
414
 
402
- const vkAsFields = await vkAsFieldsMegaHonk(vkAsBuffer);
403
- const vk = await VerificationKeyAsFields.fromKey(vkAsFields);
415
+ const vkFields = await vkAsFields(vkAsBuffer, CircuitKind.App);
416
+ const vk = await VerificationKeyAsFields.fromKey(vkFields);
404
417
 
405
418
  const { currentContractClassId, publicKeys, saltedInitializationHash } =
406
419
  await this.oracle.getContractAddressPreimage(contractAddress);
@@ -514,6 +527,47 @@ export class PrivateKernelExecutionProver {
514
527
  functionName = 'private_kernel_init_3';
515
528
  break;
516
529
  }
530
+ case 4: {
531
+ const proofInput = new PrivateKernelInit4CircuitPrivateInputs(
532
+ txRequest,
533
+ vkTreeRoot,
534
+ ProtocolContractsList,
535
+ apps[0],
536
+ apps[1],
537
+ apps[2],
538
+ apps[3],
539
+ isPrivateOnlyTx,
540
+ minRevertibleSideEffectCounter,
541
+ );
542
+ this.log.debug(`Calling private kernel init_4 with isPrivateOnly ${isPrivateOnlyTx}`);
543
+ pushTestData('private-kernel-inputs-init-4', proofInput);
544
+ output = generateWitnesses
545
+ ? await this.proofCreator.generateInit4Output(proofInput)
546
+ : await this.proofCreator.simulateInit4(proofInput);
547
+ functionName = 'private_kernel_init_4';
548
+ break;
549
+ }
550
+ case 5: {
551
+ const proofInput = new PrivateKernelInit5CircuitPrivateInputs(
552
+ txRequest,
553
+ vkTreeRoot,
554
+ ProtocolContractsList,
555
+ apps[0],
556
+ apps[1],
557
+ apps[2],
558
+ apps[3],
559
+ apps[4],
560
+ isPrivateOnlyTx,
561
+ minRevertibleSideEffectCounter,
562
+ );
563
+ this.log.debug(`Calling private kernel init_5 with isPrivateOnly ${isPrivateOnlyTx}`);
564
+ pushTestData('private-kernel-inputs-init-5', proofInput);
565
+ output = generateWitnesses
566
+ ? await this.proofCreator.generateInit5Output(proofInput)
567
+ : await this.proofCreator.simulateInit5(proofInput);
568
+ functionName = 'private_kernel_init_5';
569
+ break;
570
+ }
517
571
  default:
518
572
  throw new Error(`Unsupported init kernel batch size: ${apps.length}`);
519
573
  }
@@ -548,6 +602,37 @@ export class PrivateKernelExecutionProver {
548
602
  functionName = 'private_kernel_inner_3';
549
603
  break;
550
604
  }
605
+ case 4: {
606
+ const proofInput = new PrivateKernelInner4CircuitPrivateInputs(
607
+ previousKernelData,
608
+ apps[0],
609
+ apps[1],
610
+ apps[2],
611
+ apps[3],
612
+ );
613
+ pushTestData('private-kernel-inputs-inner-4', proofInput);
614
+ output = generateWitnesses
615
+ ? await this.proofCreator.generateInner4Output(proofInput)
616
+ : await this.proofCreator.simulateInner4(proofInput);
617
+ functionName = 'private_kernel_inner_4';
618
+ break;
619
+ }
620
+ case 5: {
621
+ const proofInput = new PrivateKernelInner5CircuitPrivateInputs(
622
+ previousKernelData,
623
+ apps[0],
624
+ apps[1],
625
+ apps[2],
626
+ apps[3],
627
+ apps[4],
628
+ );
629
+ pushTestData('private-kernel-inputs-inner-5', proofInput);
630
+ output = generateWitnesses
631
+ ? await this.proofCreator.generateInner5Output(proofInput)
632
+ : await this.proofCreator.simulateInner5(proofInput);
633
+ functionName = 'private_kernel_inner_5';
634
+ break;
635
+ }
551
636
  default:
552
637
  throw new Error(`Unsupported inner kernel batch size: ${apps.length}`);
553
638
  }
@@ -558,6 +643,7 @@ export class PrivateKernelExecutionProver {
558
643
  bytecode: output.bytecode,
559
644
  witness: output.outputWitness,
560
645
  vk: output.verificationKey.keyAsBytes,
646
+ kind: CircuitKind.Kernel,
561
647
  timings: {
562
648
  witgen: witgenTimer.ms(),
563
649
  },
package/src/pxe.ts CHANGED
@@ -37,7 +37,7 @@ import type {
37
37
  PrivateKernelTailCircuitPublicInputs,
38
38
  } from '@aztec/stdlib/kernel';
39
39
  import { computeAddressSecret } from '@aztec/stdlib/keys';
40
- import { deriveEcdhSharedSecretPoint } from '@aztec/stdlib/logs';
40
+ import { deriveEcdhSharedSecretPoint, protectFromForgery } from '@aztec/stdlib/logs';
41
41
  import {
42
42
  BlockHeader,
43
43
  type ContractOverrides,
@@ -62,7 +62,6 @@ import { BlockSynchronizer } from './block_synchronizer/index.js';
62
62
  import type { PXEConfig } from './config/index.js';
63
63
  import { ContractClassService } from './contract/contract_class_service.js';
64
64
  import { ContractSyncService } from './contract/contract_sync_service.js';
65
- import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
66
65
  import {
67
66
  ContractFunctionSimulator,
68
67
  generateSimulatedProvingResult,
@@ -74,6 +73,7 @@ import { PrivateEventFilterValidator } from './events/private_event_filter_valid
74
73
  import type { ExecutionHooks } from './hooks/index.js';
75
74
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
76
75
  import { TxResolverService } from './messages/tx_resolver_service.js';
76
+ import { type CachingAztecNode, withCache } from './node/caching_aztec_node.js';
77
77
  import {
78
78
  PrivateKernelExecutionProver,
79
79
  type PrivateKernelExecutionProverConfig,
@@ -230,7 +230,7 @@ export type RegisteredTaggingSecretSource =
230
230
  */
231
231
  export class PXE {
232
232
  private constructor(
233
- private node: AztecNode,
233
+ private node: CachingAztecNode,
234
234
  private nodeDebug: AztecNodeDebug | undefined,
235
235
  private db: AztecAsyncKVStore,
236
236
  private blockStateSynchronizer: BlockSynchronizer,
@@ -315,18 +315,22 @@ export class PXE {
315
315
  l2TipsStore,
316
316
  factStore,
317
317
  } = openPxeStores(store, initialBlockHash);
318
- const contractClassService = new ContractClassService(node, contractStore);
318
+ // Every PXE consumer reads through this one wrapper, so a read cached by one is served to the rest. Only
319
+ // immutable, hash-pinned reads are cached (the rule lives on `withCache`), which makes it safe regardless of
320
+ // the consumer's anchor block; the block synchronizer wipes it on anchor updates to bound memory.
321
+ const readCachedNode = withCache(node);
322
+ const contractClassService = new ContractClassService(readCachedNode, contractStore);
319
323
  const contractSyncService = new ContractSyncService(
320
- node,
324
+ readCachedNode,
321
325
  contractStore,
322
326
  contractClassService,
323
327
  noteStore,
324
328
  createLogger('pxe:contract_sync', bindings),
325
329
  );
326
- const txResolver = new TxResolverService(node);
330
+ const txResolver = new TxResolverService(readCachedNode);
327
331
 
328
332
  const synchronizer = new BlockSynchronizer(
329
- node,
333
+ readCachedNode,
330
334
  store,
331
335
  anchorBlockStore,
332
336
  noteStore,
@@ -334,7 +338,6 @@ export class PXE {
334
338
  factStore,
335
339
  l2TipsStore,
336
340
  contractSyncService,
337
- contractClassService,
338
341
  config,
339
342
  bindings,
340
343
  );
@@ -355,7 +358,7 @@ export class PXE {
355
358
  const jobQueue = new SerialQueue();
356
359
 
357
360
  const pxe = new PXE(
358
- node,
361
+ readCachedNode,
359
362
  nodeDebug,
360
363
  store,
361
364
  synchronizer,
@@ -410,7 +413,7 @@ export class PXE {
410
413
  noteStore: this.noteStore,
411
414
  keyStore: this.keyStore,
412
415
  addressStore: this.addressStore,
413
- aztecNode: BenchmarkedNodeFactory.create(this.node),
416
+ aztecNode: this.node,
414
417
  l2TipsStore: this.l2TipsStore,
415
418
  senderTaggingStore: this.senderTaggingStore,
416
419
  recipientTaggingStore: this.recipientTaggingStore,
@@ -890,9 +893,11 @@ export class PXE {
890
893
  }
891
894
 
892
895
  /**
893
- * Derives the shared secret of a handshake from its ephemeral public key: `S = addressSecret(recipient) * ephPk`,
894
- * the same derivation the recipient-side scan uses for handshakes discovered onchain. The ephemeral key is
895
- * reconstructed from its x-coordinate with a positive y, matching how the protocol generates it.
896
+ * Derives the shared secret of a handshake from its ephemeral public key: the raw ECDH secret
897
+ * `S = addressSecret(recipient) * ephPk` with the forgery protection applied,
898
+ * matching the protected secret the registry stores and the derivation the recipient-side scan uses for
899
+ * handshakes discovered onchain. The ephemeral key is reconstructed from its x-coordinate with a positive y,
900
+ * matching how the protocol generates it.
896
901
  *
897
902
  * @throws If `ephPk` is not the x-coordinate of a Grumpkin curve point, or if `recipient` is not an account of
898
903
  * this PXE, since the derivation needs its keys.
@@ -914,7 +919,8 @@ export class PXE {
914
919
 
915
920
  const ivskM = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
916
921
  const addressSecret = await computeAddressSecret(await completeAddress.getPreaddress(), ivskM);
917
- return deriveEcdhSharedSecretPoint(addressSecret, ephPkPoint);
922
+ const rawSecret = await deriveEcdhSharedSecretPoint(addressSecret, ephPkPoint);
923
+ return protectFromForgery(rawSecret, ephPkPoint, await recipient.toAddressPoint());
918
924
  }
919
925
 
920
926
  /** Registers a resolved shared secret scoped to a recipient. Returns whether it was newly added. */
@@ -1013,6 +1019,7 @@ export class PXE {
1013
1019
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
1014
1020
  return this.#putInJobQueue(async jobId => {
1015
1021
  const totalTimer = new Timer();
1022
+ const recording = this.node.startRecording();
1016
1023
  try {
1017
1024
  const syncTimer = new Timer();
1018
1025
  await this.#maybeSync();
@@ -1060,7 +1067,7 @@ export class PXE {
1060
1067
 
1061
1068
  const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof!, {
1062
1069
  timings,
1063
- nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
1070
+ nodeRPCCalls: recording.stop(),
1064
1071
  });
1065
1072
 
1066
1073
  // We keep track of which tagging indices we've used in this tx so that we don't repeat them in future txs
@@ -1081,6 +1088,9 @@ export class PXE {
1081
1088
  return txProvingResult;
1082
1089
  } catch (err: any) {
1083
1090
  throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
1091
+ } finally {
1092
+ // Idempotent cleanup for the error and early-exit paths. The success path already stopped the recording.
1093
+ recording.stop();
1084
1094
  }
1085
1095
  });
1086
1096
  }
@@ -1098,6 +1108,7 @@ export class PXE {
1098
1108
  // We disable concurrent profiles for consistency with simulateTx.
1099
1109
  return this.#putInJobQueue(async jobId => {
1100
1110
  const totalTimer = new Timer();
1111
+ const recording = this.node.startRecording();
1101
1112
  try {
1102
1113
  const txInfo = {
1103
1114
  origin: txRequest.origin,
@@ -1163,10 +1174,12 @@ export class PXE {
1163
1174
  total - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time }) => acc + time, 0)),
1164
1175
  };
1165
1176
 
1166
- const simulatorStats = contractFunctionSimulator.getStats();
1167
- return new TxProfileResult(executionSteps, { timings, nodeRPCCalls: simulatorStats.nodeRPCCalls });
1177
+ return new TxProfileResult(executionSteps, { timings, nodeRPCCalls: recording.stop() });
1168
1178
  } catch (err: any) {
1169
1179
  throw this.#contextualizeError(err, inspect(txRequest), `profileMode=${profileMode}`);
1180
+ } finally {
1181
+ // Idempotent cleanup for the error and early-exit paths. The success path already stopped the recording.
1182
+ recording.stop();
1170
1183
  }
1171
1184
  });
1172
1185
  }
@@ -1205,6 +1218,7 @@ export class PXE {
1205
1218
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1206
1219
  // delete the same read value, or reading values that another simulation is currently modifying).
1207
1220
  return this.#putInJobQueue(async jobId => {
1221
+ const recording = this.node.startRecording();
1208
1222
  try {
1209
1223
  const totalTimer = new Timer();
1210
1224
  const txInfo = {
@@ -1325,10 +1339,9 @@ export class PXE {
1325
1339
  : {}),
1326
1340
  });
1327
1341
 
1328
- const simulatorStats = contractFunctionSimulator.getStats();
1329
1342
  return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(privateSimulationResult, publicOutput, {
1330
1343
  timings,
1331
- nodeRPCCalls: simulatorStats.nodeRPCCalls,
1344
+ nodeRPCCalls: recording.stop(),
1332
1345
  });
1333
1346
  } catch (err: any) {
1334
1347
  throw this.#contextualizeError(
@@ -1338,6 +1351,9 @@ export class PXE {
1338
1351
  `skipTxValidation=${skipTxValidation}`,
1339
1352
  `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1340
1353
  );
1354
+ } finally {
1355
+ // Idempotent cleanup for the error and early-exit paths. The success path already stopped the recording.
1356
+ recording.stop();
1341
1357
  }
1342
1358
  });
1343
1359
  }
@@ -1354,6 +1370,7 @@ export class PXE {
1354
1370
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1355
1371
  // delete the same read value, or reading values that another execution is currently modifying).
1356
1372
  return this.#putInJobQueue(async jobId => {
1373
+ const recording = this.node.startRecording();
1357
1374
  try {
1358
1375
  const totalTimer = new Timer();
1359
1376
  const syncTimer = new Timer();
@@ -1393,12 +1410,11 @@ export class PXE {
1393
1410
  unaccounted: totalTime - (syncTime + perFunction.reduce((acc, { time }) => acc + time, 0)),
1394
1411
  };
1395
1412
 
1396
- const simulationStats = contractFunctionSimulator.getStats();
1397
1413
  return {
1398
1414
  result: executionResult,
1399
1415
  offchainEffects,
1400
1416
  anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1401
- stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1417
+ stats: { timings, nodeRPCCalls: recording.stop() },
1402
1418
  };
1403
1419
  } catch (err: any) {
1404
1420
  const { to, name, args } = call;
@@ -1408,6 +1424,9 @@ export class PXE {
1408
1424
  `executeUtility ${to}:${name}(${stringifiedArgs})`,
1409
1425
  `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1410
1426
  );
1427
+ } finally {
1428
+ // Idempotent cleanup for the error and early-exit paths. The success path already stopped the recording.
1429
+ recording.stop();
1411
1430
  }
1412
1431
  });
1413
1432
  }
@@ -17,6 +17,7 @@ import {
17
17
  findFunctionAbiBySelector,
18
18
  findFunctionArtifactBySelector,
19
19
  getFunctionDebugMetadata,
20
+ getFunctionReturnType,
20
21
  } from '@aztec/stdlib/abi';
21
22
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
22
23
  import {
@@ -371,7 +372,7 @@ export class ContractStore {
371
372
  hideMsgSender: false,
372
373
  isStatic: functionDao.isStatic,
373
374
  args: encodeArguments(functionDao, args),
374
- returnTypes: functionDao.returnTypes,
375
+ returnType: getFunctionReturnType(functionDao),
375
376
  });
376
377
  }
377
378
  }
@@ -82,7 +82,7 @@ export class FactStore implements StagedStore {
82
82
  }
83
83
 
84
84
  /**
85
- * Records a fact in a collection, visible under the given scope.
85
+ * Records a fact in a collection.
86
86
  *
87
87
  * The collection is created implicitly on the first fact recorded for its key: recording into an existing collection
88
88
  * just adds to it.
@@ -5,6 +5,7 @@ export type { Fact } from './stored_fact.js';
5
5
  export {
6
6
  OriginBlockState,
7
7
  classifyOriginBlockState,
8
+ originBlockStateFromNumber,
8
9
  anchoredTipBlockNumbers,
9
10
  toFactWithOriginState,
10
11
  type TipBlockNumbers,
@@ -12,7 +12,7 @@ import type { Fact } from './stored_fact.js';
12
12
  * - `Finalized`: L1-finalized.
13
13
  *
14
14
  * The numeric discriminants must stay in sync with the Noir `OriginBlockState` in
15
- * `noir-projects/aztec-nr/aztec/src/facts/origin_state.nr`: PXE serializes this value into the `Fact` oracle response
15
+ * `noir-projects/labs/aztec-nr/aztec/src/facts/origin_state.nr`: PXE serializes this value into the `Fact` oracle response
16
16
  * and Noir deserializes it via `from_u8`, which rejects any value outside this set.
17
17
  */
18
18
  export enum OriginBlockState {
@@ -21,6 +21,15 @@ export enum OriginBlockState {
21
21
  Finalized = 3,
22
22
  }
23
23
 
24
+ /** Parses a numeric origin-block-state discriminant, rejecting unknown values. */
25
+ export function originBlockStateFromNumber(value: number): OriginBlockState {
26
+ if (!(value in OriginBlockState)) {
27
+ const validNames = Object.keys(OriginBlockState).filter(k => isNaN(Number(k)));
28
+ throw new Error(`Invalid OriginBlockState value ${value}, expected one of ${validNames.join(', ')}`);
29
+ }
30
+ return value as OriginBlockState;
31
+ }
32
+
24
33
  /** The two chain-tip block numbers needed to classify an origin block (`finalized <= proven` always holds). */
25
34
  export type TipBlockNumbers = { provenBlockNumber: number; finalizedBlockNumber: number };
26
35
 
@@ -0,0 +1,72 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
3
+ import { DatabaseVersion } from '@aztec/stdlib/database-version/version';
4
+
5
+ /** The triple that determine which physical store a logical store name maps to. */
6
+ export type StoreIdentity = {
7
+ /** Chain ID of the L1 the rollup is deployed to. */
8
+ l1ChainId: number;
9
+ /** Address of the rollup contract the store's data pertains to. */
10
+ rollupAddress: EthAddress;
11
+ /** Schema version of the data held in the store. */
12
+ schemaVersion: number;
13
+ };
14
+
15
+ /**
16
+ * Composes the store-name discriminator for a store identity. Two identities map to the same physical store iff
17
+ * their slugs are equal, so the format must stay stable: `<l1ChainId>-<rollupAddress>-v<schemaVersion>` — changing
18
+ * it orphans every existing store.
19
+ */
20
+ export function storeIdentitySlug({ l1ChainId, rollupAddress, schemaVersion }: StoreIdentity): string {
21
+ return `${l1ChainId}-${rollupAddress.toString()}-v${schemaVersion}`;
22
+ }
23
+
24
+ /** Composes the physical store name for a logical store name and identity. */
25
+ export function effectiveStoreName(name: string, identity: StoreIdentity): string {
26
+ return `${name}_${storeIdentitySlug(identity)}`;
27
+ }
28
+
29
+ /**
30
+ * Invariant check for stores whose physical name carries their identity: the recorded version can
31
+ * only disagree with the expected one if there is a store-naming bug.
32
+ */
33
+ export async function assertStoreIdentity(
34
+ store: AztecAsyncKVStore,
35
+ storeName: string,
36
+ identity: StoreIdentity,
37
+ ): Promise<void> {
38
+ const expected = new DatabaseVersion(identity.schemaVersion, identity.rollupAddress);
39
+ const singleton = store.openSingleton<string>('dbVersion');
40
+ const stored = await singleton.getAsync();
41
+ if (stored === undefined) {
42
+ await singleton.set(expected.toBuffer().toString('utf-8'));
43
+ return;
44
+ }
45
+ let storedVersion: DatabaseVersion;
46
+ try {
47
+ storedVersion = DatabaseVersion.fromBuffer(Buffer.from(stored, 'utf-8'));
48
+ } catch {
49
+ throw new StoreIdentityMismatchError(storeName, expected.toString(), stored);
50
+ }
51
+ if (!storedVersion.equals(expected)) {
52
+ throw new StoreIdentityMismatchError(storeName, expected.toString(), storedVersion.toString());
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Thrown when a store's recorded identity does not match the identity it was opened under. Since the identity is
58
+ * part of the physical store name, this can only indicate a store-naming bug; the store is left untouched.
59
+ */
60
+ export class StoreIdentityMismatchError extends Error {
61
+ constructor(
62
+ public readonly storeName: string,
63
+ public readonly expected: string,
64
+ public readonly actual: string,
65
+ ) {
66
+ super(
67
+ `Store '${storeName}' records identity ${actual} but was opened as ${expected}. ` +
68
+ `Refusing to open; data was NOT modified.`,
69
+ );
70
+ this.name = 'StoreIdentityMismatchError';
71
+ }
72
+ }