@aztec/pxe 0.0.1-commit.c7c42ec → 0.0.1-commit.c949de6bc

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 (274) 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/bin/check_oracle_version.js +1 -1
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +13 -5
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +74 -20
  8. package/dest/config/index.d.ts +3 -1
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +17 -0
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  13. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +57 -34
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +199 -81
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
  24. package/dest/contract_function_simulator/index.d.ts +2 -2
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.js +1 -1
  27. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -4
  30. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
  31. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
  33. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  34. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  36. package/dest/contract_function_simulator/oracle/interfaces.d.ts +17 -13
  37. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  39. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  41. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  43. package/dest/contract_function_simulator/oracle/oracle.d.ts +12 -10
  44. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/oracle.js +67 -44
  46. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  47. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/oracle/private_execution.js +1 -37
  49. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +45 -47
  50. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +91 -60
  52. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +67 -33
  53. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +131 -110
  55. package/dest/contract_logging.d.ts +22 -0
  56. package/dest/contract_logging.d.ts.map +1 -0
  57. package/dest/contract_logging.js +23 -0
  58. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  59. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  60. package/dest/contract_sync/contract_sync_service.js +97 -0
  61. package/dest/contract_sync/helpers.d.ts +29 -0
  62. package/dest/contract_sync/helpers.d.ts.map +1 -0
  63. package/dest/contract_sync/helpers.js +55 -0
  64. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  65. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  66. package/dest/debug/pxe_debug_utils.js +28 -17
  67. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  68. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  69. package/dest/entrypoints/client/bundle/index.js +3 -0
  70. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  71. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  72. package/dest/entrypoints/client/bundle/utils.js +31 -8
  73. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  74. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  75. package/dest/entrypoints/client/lazy/index.js +3 -0
  76. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  77. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  78. package/dest/entrypoints/client/lazy/utils.js +32 -9
  79. package/dest/entrypoints/pxe_creation_options.d.ts +5 -3
  80. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  81. package/dest/entrypoints/server/index.d.ts +5 -1
  82. package/dest/entrypoints/server/index.d.ts.map +1 -1
  83. package/dest/entrypoints/server/index.js +4 -0
  84. package/dest/entrypoints/server/utils.d.ts +1 -1
  85. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  86. package/dest/entrypoints/server/utils.js +39 -16
  87. package/dest/events/event_service.d.ts +6 -6
  88. package/dest/events/event_service.d.ts.map +1 -1
  89. package/dest/events/event_service.js +19 -22
  90. package/dest/events/private_event_filter_validator.d.ts +5 -5
  91. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  92. package/dest/events/private_event_filter_validator.js +5 -6
  93. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  94. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  95. package/dest/job_coordinator/job_coordinator.js +94 -0
  96. package/dest/logs/log_service.d.ts +8 -5
  97. package/dest/logs/log_service.d.ts.map +1 -1
  98. package/dest/logs/log_service.js +31 -33
  99. package/dest/notes/note_service.d.ts +10 -9
  100. package/dest/notes/note_service.d.ts.map +1 -1
  101. package/dest/notes/note_service.js +34 -38
  102. package/dest/notes_filter.d.ts +25 -0
  103. package/dest/notes_filter.d.ts.map +1 -0
  104. package/dest/notes_filter.js +4 -0
  105. package/dest/oracle_version.d.ts +3 -3
  106. package/dest/oracle_version.d.ts.map +1 -1
  107. package/dest/oracle_version.js +4 -3
  108. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  109. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  110. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  111. package/dest/private_kernel/hints/index.d.ts +3 -3
  112. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  113. package/dest/private_kernel/hints/index.js +2 -2
  114. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  115. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  116. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +141 -74
  117. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  118. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  119. package/dest/private_kernel/hints/test_utils.js +203 -0
  120. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  121. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  122. package/dest/private_kernel/private_kernel_execution_prover.js +24 -17
  123. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -24
  124. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  125. package/dest/private_kernel/private_kernel_oracle.js +94 -2
  126. package/dest/pxe.d.ts +76 -58
  127. package/dest/pxe.d.ts.map +1 -1
  128. package/dest/pxe.js +151 -136
  129. package/dest/storage/address_store/address_store.d.ts +1 -1
  130. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  131. package/dest/storage/address_store/address_store.js +12 -11
  132. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  133. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  134. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  135. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  136. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  137. package/dest/storage/capsule_store/capsule_store.js +130 -23
  138. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  139. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  140. package/dest/storage/contract_store/contract_store.js +157 -72
  141. package/dest/storage/metadata.d.ts +1 -1
  142. package/dest/storage/metadata.js +1 -1
  143. package/dest/storage/note_store/note_store.d.ts +50 -51
  144. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  145. package/dest/storage/note_store/note_store.js +284 -263
  146. package/dest/storage/note_store/stored_note.d.ts +16 -0
  147. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  148. package/dest/storage/note_store/stored_note.js +43 -0
  149. package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
  150. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  151. package/dest/storage/private_event_store/private_event_store.js +231 -73
  152. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  153. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  154. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  155. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +16 -9
  156. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  157. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  158. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  159. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  160. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  161. package/dest/storage/tagging_store/sender_tagging_store.d.ts +20 -10
  162. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  163. package/dest/storage/tagging_store/sender_tagging_store.js +254 -102
  164. package/dest/tagging/constants.d.ts +2 -0
  165. package/dest/tagging/constants.d.ts.map +1 -0
  166. package/dest/tagging/constants.js +10 -0
  167. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  168. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  169. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  170. package/dest/tagging/index.d.ts +4 -3
  171. package/dest/tagging/index.d.ts.map +1 -1
  172. package/dest/tagging/index.js +3 -11
  173. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -5
  174. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  175. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +13 -13
  176. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  177. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -7
  178. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  179. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +16 -12
  180. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -8
  181. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  182. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +9 -12
  183. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  184. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  185. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  186. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +7 -7
  187. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  188. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +23 -19
  189. package/package.json +27 -18
  190. package/src/access_scopes.ts +9 -0
  191. package/src/bin/check_oracle_version.ts +1 -0
  192. package/src/block_synchronizer/block_synchronizer.ts +93 -32
  193. package/src/config/index.ts +14 -0
  194. package/src/config/package_info.ts +1 -1
  195. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  196. package/src/contract_function_simulator/contract_function_simulator.ts +353 -140
  197. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  198. package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
  199. package/src/contract_function_simulator/index.ts +1 -1
  200. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +6 -2
  201. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  202. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  203. package/src/contract_function_simulator/oracle/interfaces.ts +22 -12
  204. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  205. package/src/contract_function_simulator/oracle/oracle.ts +79 -47
  206. package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
  207. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +131 -140
  208. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +198 -115
  209. package/src/contract_logging.ts +39 -0
  210. package/src/contract_sync/contract_sync_service.ts +152 -0
  211. package/src/contract_sync/helpers.ts +98 -0
  212. package/src/debug/pxe_debug_utils.ts +63 -18
  213. package/src/entrypoints/client/bundle/index.ts +3 -0
  214. package/src/entrypoints/client/bundle/utils.ts +23 -16
  215. package/src/entrypoints/client/lazy/index.ts +3 -0
  216. package/src/entrypoints/client/lazy/utils.ts +24 -17
  217. package/src/entrypoints/pxe_creation_options.ts +4 -2
  218. package/src/entrypoints/server/index.ts +4 -0
  219. package/src/entrypoints/server/utils.ts +33 -41
  220. package/src/events/event_service.ts +19 -25
  221. package/src/events/private_event_filter_validator.ts +3 -5
  222. package/src/job_coordinator/job_coordinator.ts +150 -0
  223. package/src/logs/log_service.ts +51 -40
  224. package/src/notes/note_service.ts +41 -45
  225. package/src/notes_filter.ts +26 -0
  226. package/src/oracle_version.ts +4 -3
  227. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  228. package/src/private_kernel/hints/index.ts +2 -2
  229. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +196 -138
  230. package/src/private_kernel/hints/test_utils.ts +325 -0
  231. package/src/private_kernel/private_kernel_execution_prover.ts +27 -19
  232. package/src/private_kernel/private_kernel_oracle.ts +116 -36
  233. package/src/pxe.ts +283 -202
  234. package/src/storage/address_store/address_store.ts +15 -15
  235. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  236. package/src/storage/capsule_store/capsule_store.ts +159 -23
  237. package/src/storage/contract_store/contract_store.ts +186 -76
  238. package/src/storage/metadata.ts +1 -1
  239. package/src/storage/note_store/note_store.ts +326 -320
  240. package/src/storage/note_store/stored_note.ts +48 -0
  241. package/src/storage/private_event_store/private_event_store.ts +301 -79
  242. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  243. package/src/storage/tagging_store/recipient_tagging_store.ts +111 -21
  244. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  245. package/src/storage/tagging_store/sender_tagging_store.ts +297 -112
  246. package/src/tagging/constants.ts +10 -0
  247. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  248. package/src/tagging/index.ts +3 -12
  249. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +27 -16
  250. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  251. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
  252. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +13 -15
  253. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
  254. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +26 -23
  255. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  256. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  257. package/dest/contract_function_simulator/proxied_node.js +0 -27
  258. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  259. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  260. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  261. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  262. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  263. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  264. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  265. package/dest/public_storage/public_storage_service.d.ts +0 -24
  266. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  267. package/dest/public_storage/public_storage_service.js +0 -26
  268. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  269. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  270. package/dest/tree_membership/tree_membership_service.js +0 -84
  271. package/src/contract_function_simulator/proxied_node.ts +0 -33
  272. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
  273. package/src/public_storage/public_storage_service.ts +0 -33
  274. package/src/tree_membership/tree_membership_service.ts +0 -112
@@ -1,4 +1,4 @@
1
- import { MAX_INCLUDE_BY_TIMESTAMP_DURATION } from '@aztec/constants';
1
+ import { MAX_TX_LIFETIME } from '@aztec/constants';
2
2
  import type { PrivateKernelCircuitPublicInputs } from '@aztec/stdlib/kernel';
3
3
  import type { UInt64 } from '@aztec/stdlib/types';
4
4
 
@@ -8,12 +8,12 @@ const ROUNDED_DURATIONS = [
8
8
  1, // 1 second
9
9
  ];
10
10
 
11
- function roundTimestamp(blockTimestamp: bigint, includeByTimestamp: bigint): UInt64 {
11
+ function roundTimestamp(blockTimestamp: bigint, expirationTimestamp: bigint): UInt64 {
12
12
  return ROUNDED_DURATIONS.reduce((timestamp, duration) => {
13
13
  if (timestamp <= blockTimestamp) {
14
14
  // The timestamp must be greater than the block timestamp.
15
15
  // If it is too small, round it down again using a smaller duration.
16
- const totalDuration = includeByTimestamp - blockTimestamp;
16
+ const totalDuration = expirationTimestamp - blockTimestamp;
17
17
  const roundedDuration = totalDuration - (totalDuration % BigInt(duration));
18
18
  return blockTimestamp + roundedDuration;
19
19
  }
@@ -21,36 +21,36 @@ function roundTimestamp(blockTimestamp: bigint, includeByTimestamp: bigint): UIn
21
21
  }, 0n);
22
22
  }
23
23
 
24
- export function computeTxIncludeByTimestamp(
24
+ export function computeTxExpirationTimestamp(
25
25
  previousKernel: PrivateKernelCircuitPublicInputs,
26
- maxDuration = MAX_INCLUDE_BY_TIMESTAMP_DURATION,
26
+ txLifetime = MAX_TX_LIFETIME,
27
27
  ): UInt64 {
28
- if (maxDuration > MAX_INCLUDE_BY_TIMESTAMP_DURATION) {
28
+ if (txLifetime > MAX_TX_LIFETIME) {
29
29
  throw new Error(
30
- `Custom max duration cannot be greater than the max allowed. Max allowed: ${MAX_INCLUDE_BY_TIMESTAMP_DURATION}. Custom value: ${maxDuration}.`,
30
+ `Custom tx lifetime cannot be greater than the max allowed. Max allowed: ${MAX_TX_LIFETIME}. Custom value: ${txLifetime}.`,
31
31
  );
32
32
  }
33
33
 
34
34
  const anchorBlockTimestamp = previousKernel.constants.anchorBlockHeader.globalVariables.timestamp;
35
- const maxTimestamp = anchorBlockTimestamp + BigInt(maxDuration);
36
- const includeByTimestamp = previousKernel.includeByTimestamp;
35
+ const maxTimestamp = anchorBlockTimestamp + BigInt(txLifetime);
36
+ const expirationTimestamp = previousKernel.expirationTimestamp;
37
37
 
38
- // If the includeByTimestamp set during the tx execution is greater than or equal to the max allowed duration,
38
+ // If the expirationTimestamp set during the tx execution is greater than or equal to the max allowed duration,
39
39
  // use the maximum allowed timestamp.
40
40
  // Note: It shouldn't be larger than the max allowed duration, but we check for it anyway.
41
- if (includeByTimestamp >= maxTimestamp) {
41
+ if (expirationTimestamp >= maxTimestamp) {
42
42
  return maxTimestamp;
43
43
  }
44
44
 
45
45
  // Round it down to the nearest hour/min/second to reduce precision and avoid revealing the exact value.
46
46
  // This makes it harder for others to infer what function calls may have been used to produce a specific timestamp.
47
- const roundedTimestamp = roundTimestamp(anchorBlockTimestamp, includeByTimestamp);
47
+ const roundedTimestamp = roundTimestamp(anchorBlockTimestamp, expirationTimestamp);
48
48
 
49
49
  // The tx can't be published if the timestamp is the same or less than the anchor block's timestamp.
50
50
  // Future blocks will have a greater timestamp, so the tx would never be included.
51
51
  if (roundedTimestamp <= anchorBlockTimestamp) {
52
52
  throw new Error(
53
- `Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${includeByTimestamp}.`,
53
+ `Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${expirationTimestamp}.`,
54
54
  );
55
55
  }
56
56
 
@@ -1,2 +1,2 @@
1
- export * from './build_private_kernel_reset_private_inputs.js';
2
- export * from './compute_tx_include_by_timestamp.js';
1
+ export * from './private_kernel_reset_private_inputs_builder.js';
2
+ export * from './compute_tx_expiration_timestamp.js';
@@ -10,7 +10,7 @@ import {
10
10
  import { makeTuple } from '@aztec/foundation/array';
11
11
  import { padArrayEnd } from '@aztec/foundation/collection';
12
12
  import type { Fr } from '@aztec/foundation/curves/bn254';
13
- import { type Tuple, assertLength } from '@aztec/foundation/serialize';
13
+ import { assertLength } from '@aztec/foundation/serialize';
14
14
  import { MembershipWitness } from '@aztec/foundation/trees';
15
15
  import { privateKernelResetDimensionsConfig } from '@aztec/noir-protocol-circuits-types/client';
16
16
  import {
@@ -26,14 +26,12 @@ import {
26
26
  type PrivateKernelSimulateOutput,
27
27
  ReadRequestActionEnum,
28
28
  ReadRequestResetActions,
29
- type ScopedKeyValidationRequestAndGenerator,
30
- ScopedNoteHash,
31
- ScopedNullifier,
32
- ScopedReadRequest,
29
+ type ScopedKeyValidationRequestAndSeparator,
33
30
  TransientDataSquashingHint,
34
31
  buildNoteHashReadRequestHintsFromResetActions,
35
32
  buildNullifierReadRequestHintsFromResetActions,
36
33
  buildTransientDataHints,
34
+ countSquashedLogs,
37
35
  findPrivateKernelResetDimensions,
38
36
  getNoteHashReadRequestResetActions,
39
37
  getNullifierReadRequestResetActions,
@@ -44,15 +42,6 @@ import { VkData } from '@aztec/stdlib/vks';
44
42
 
45
43
  import type { PrivateKernelOracle } from '../private_kernel_oracle.js';
46
44
 
47
- function collectNestedReadRequests<N extends number>(
48
- executionStack: PrivateCallExecutionResult[],
49
- extractReadRequests: (execution: PrivateCallExecutionResult) => ClaimedLengthArray<ScopedReadRequest, N>,
50
- ): ScopedReadRequest[] {
51
- return collectNested(executionStack, executionResult => {
52
- return extractReadRequests(executionResult).getActiveItems();
53
- });
54
- }
55
-
56
45
  function getNullifierMembershipWitnessResolver(oracle: PrivateKernelOracle) {
57
46
  return async (nullifier: Fr) => {
58
47
  const res = await oracle.getNullifierMembershipWitness(nullifier);
@@ -68,9 +57,9 @@ function getNullifierMembershipWitnessResolver(oracle: PrivateKernelOracle) {
68
57
  };
69
58
  }
70
59
 
71
- async function getMasterSecretKeysAndAppKeyGenerators(
60
+ async function getMasterSecretKeysAndKeyTypeDomainSeparators(
72
61
  keyValidationRequests: ClaimedLengthArray<
73
- ScopedKeyValidationRequestAndGenerator,
62
+ ScopedKeyValidationRequestAndSeparator,
74
63
  typeof MAX_KEY_VALIDATION_REQUESTS_PER_TX
75
64
  >,
76
65
  numRequestsToVerify: number,
@@ -91,11 +80,14 @@ export class PrivateKernelResetPrivateInputsBuilder {
91
80
  // If there's no next iteration, it's the final reset.
92
81
  private nextIteration?: PrivateCircuitPublicInputs;
93
82
 
94
- private noteHashResetActions: ReadRequestResetActions<typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>;
95
- private nullifierResetActions: ReadRequestResetActions<typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>;
83
+ private noteHashResetActions = ReadRequestResetActions.empty(MAX_NOTE_HASH_READ_REQUESTS_PER_TX);
84
+ private nullifierResetActions = ReadRequestResetActions.empty(MAX_NULLIFIER_READ_REQUESTS_PER_TX);
96
85
  private numTransientData?: number;
97
- private transientDataSquashingHints: Tuple<TransientDataSquashingHint, typeof MAX_NULLIFIERS_PER_TX>;
98
- private requestedDimensions: PrivateKernelResetDimensions;
86
+ private transientDataSquashingHints = makeTuple(
87
+ MAX_NULLIFIERS_PER_TX,
88
+ () => new TransientDataSquashingHint(MAX_NULLIFIERS_PER_TX, MAX_NOTE_HASHES_PER_TX),
89
+ );
90
+ private requestedDimensions = PrivateKernelResetDimensions.empty();
99
91
 
100
92
  constructor(
101
93
  private previousKernelOutput: PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>,
@@ -104,21 +96,18 @@ export class PrivateKernelResetPrivateInputsBuilder {
104
96
  private splitCounter: number,
105
97
  ) {
106
98
  this.previousKernel = previousKernelOutput.publicInputs;
107
- this.requestedDimensions = PrivateKernelResetDimensions.empty();
108
- this.noteHashResetActions = ReadRequestResetActions.empty(MAX_NOTE_HASH_READ_REQUESTS_PER_TX);
109
- this.nullifierResetActions = ReadRequestResetActions.empty(MAX_NULLIFIER_READ_REQUESTS_PER_TX);
110
- this.transientDataSquashingHints = makeTuple(
111
- MAX_NULLIFIERS_PER_TX,
112
- () => new TransientDataSquashingHint(MAX_NULLIFIERS_PER_TX, MAX_NOTE_HASHES_PER_TX),
113
- );
114
99
  this.nextIteration = executionStack[this.executionStack.length - 1]?.publicInputs;
115
100
  }
116
101
 
102
+ getRequestedDimensions(): PrivateKernelResetDimensions {
103
+ return this.requestedDimensions;
104
+ }
105
+
117
106
  needsReset(): boolean {
118
107
  const fns: (() => boolean)[] = [
119
108
  () => this.needsResetNoteHashReadRequests(),
120
109
  () => this.needsResetNullifierReadRequests(),
121
- () => this.needsResetNullifierKeys(),
110
+ () => this.needsResetKeyValidationRequests(),
122
111
  () => this.needsResetTransientData(),
123
112
  ];
124
113
 
@@ -138,15 +127,14 @@ export class PrivateKernelResetPrivateInputsBuilder {
138
127
  }
139
128
  }
140
129
 
141
- async build(oracle: PrivateKernelOracle, noteHashLeafIndexMap: Map<bigint, bigint>) {
130
+ async build(oracle: PrivateKernelOracle) {
142
131
  if (privateKernelResetDimensionNames.every(name => !this.requestedDimensions[name])) {
143
132
  throw new Error('Reset is not required.');
144
133
  }
145
134
 
146
135
  const isInner = !!this.nextIteration;
147
136
 
148
- // "final" reset must be done at most once.
149
- // Because the code that silo note hashes can't be run repeatedly.
137
+ // "final" reset must be done exactly once, because siloing can't be run repeatedly.
150
138
  // The dimensions found must be big enough to reset all values, i.e. empty remainder.
151
139
  const allowRemainder = isInner;
152
140
 
@@ -157,16 +145,6 @@ export class PrivateKernelResetPrivateInputsBuilder {
157
145
  allowRemainder,
158
146
  );
159
147
 
160
- const previousVkMembershipWitness = await oracle.getVkMembershipWitness(
161
- this.previousKernelOutput.verificationKey.keyAsFields,
162
- );
163
- const vkData = new VkData(
164
- this.previousKernelOutput.verificationKey,
165
- Number(previousVkMembershipWitness.leafIndex),
166
- previousVkMembershipWitness.siblingPath,
167
- );
168
- const previousKernelData = new PrivateKernelData(this.previousKernelOutput.publicInputs, vkData);
169
-
170
148
  this.reduceReadRequestActions(
171
149
  this.noteHashResetActions,
172
150
  dimensions.NOTE_HASH_PENDING_READ,
@@ -178,30 +156,51 @@ export class PrivateKernelResetPrivateInputsBuilder {
178
156
  dimensions.NULLIFIER_SETTLED_READ,
179
157
  );
180
158
 
181
- // TODO: Enable padding when we have a better idea what are the final amounts we should pad to.
182
- const paddedSideEffects = PaddedSideEffects.empty();
183
-
184
- return new PrivateKernelResetCircuitPrivateInputs(
185
- previousKernelData,
186
- paddedSideEffects,
187
- new PrivateKernelResetHints(
188
- await buildNoteHashReadRequestHintsFromResetActions(
159
+ // Execute all the expensive node querying operations in parallel.
160
+ const [previousVkMembershipWitness, noteHashReadRequestHints, nullifierReadRequestHints, keyValidationHints] =
161
+ await Promise.all([
162
+ oracle.getVkMembershipWitness(this.previousKernelOutput.verificationKey.keyAsFields),
163
+ buildNoteHashReadRequestHintsFromResetActions<
164
+ typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
165
+ typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX
166
+ >(
189
167
  oracle,
190
168
  this.previousKernel.validationRequests.noteHashReadRequests,
191
169
  this.previousKernel.end.noteHashes,
192
170
  this.noteHashResetActions,
193
- noteHashLeafIndexMap,
194
171
  ),
195
- await buildNullifierReadRequestHintsFromResetActions(
172
+ buildNullifierReadRequestHintsFromResetActions<
173
+ typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX,
174
+ typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX
175
+ >(
196
176
  { getNullifierMembershipWitness: getNullifierMembershipWitnessResolver(oracle) },
197
177
  this.previousKernel.validationRequests.nullifierReadRequests,
198
178
  this.nullifierResetActions,
199
179
  ),
200
- await getMasterSecretKeysAndAppKeyGenerators(
201
- this.previousKernel.validationRequests.scopedKeyValidationRequestsAndGenerators,
180
+ getMasterSecretKeysAndKeyTypeDomainSeparators(
181
+ this.previousKernel.validationRequests.scopedKeyValidationRequestsAndSeparators,
202
182
  dimensions.KEY_VALIDATION,
203
183
  oracle,
204
184
  ),
185
+ ]);
186
+
187
+ const vkData = new VkData(
188
+ this.previousKernelOutput.verificationKey,
189
+ Number(previousVkMembershipWitness.leafIndex),
190
+ previousVkMembershipWitness.siblingPath,
191
+ );
192
+ const previousKernelData = new PrivateKernelData(this.previousKernelOutput.publicInputs, vkData);
193
+
194
+ // TODO: Enable padding when we have a better idea what are the final amounts we should pad to.
195
+ const paddedSideEffects = PaddedSideEffects.empty();
196
+
197
+ return new PrivateKernelResetCircuitPrivateInputs(
198
+ previousKernelData,
199
+ paddedSideEffects,
200
+ new PrivateKernelResetHints(
201
+ noteHashReadRequestHints,
202
+ nullifierReadRequestHints,
203
+ keyValidationHints,
205
204
  this.transientDataSquashingHints,
206
205
  ),
207
206
  dimensions,
@@ -235,24 +234,17 @@ export class PrivateKernelResetPrivateInputsBuilder {
235
234
  resetActions.pendingReadHints = resetActions.pendingReadHints.slice(0, maxPending);
236
235
  }
237
236
 
238
- private needsResetNoteHashReadRequests(forceResetAll = false) {
237
+ private needsResetNoteHashReadRequests(forceReset = false) {
239
238
  const numCurr = this.previousKernel.validationRequests.noteHashReadRequests.claimedLength;
240
239
  const numNext = this.nextIteration ? this.nextIteration.noteHashReadRequests.claimedLength : 0;
241
- const maxAmountToKeep = !this.nextIteration || forceResetAll ? 0 : MAX_NOTE_HASH_READ_REQUESTS_PER_TX;
240
+ const maxAmountToKeep = !this.nextIteration || forceReset ? 0 : MAX_NOTE_HASH_READ_REQUESTS_PER_TX;
242
241
  if (numCurr + numNext <= maxAmountToKeep) {
243
242
  return false;
244
243
  }
245
244
 
246
- const futureNoteHashes = collectNested(this.executionStack, executionResult => {
247
- return executionResult.publicInputs.noteHashes
248
- .getActiveItems()
249
- .map(noteHash => new ScopedNoteHash(noteHash, executionResult.publicInputs.callContext.contractAddress));
250
- });
251
-
252
245
  const resetActions = getNoteHashReadRequestResetActions(
253
246
  this.previousKernel.validationRequests.noteHashReadRequests,
254
247
  this.previousKernel.end.noteHashes,
255
- futureNoteHashes,
256
248
  );
257
249
 
258
250
  const numPendingReads = resetActions.pendingReadHints.length;
@@ -261,53 +253,72 @@ export class PrivateKernelResetPrivateInputsBuilder {
261
253
  0,
262
254
  );
263
255
 
256
+ const totalReadsToReset = numPendingReads + numSettledReads;
257
+ const minResetNeeded = numCurr + numNext - maxAmountToKeep;
258
+ if (totalReadsToReset < minResetNeeded) {
259
+ if (!this.nextIteration) {
260
+ // In the final reset, all note hashes have been emitted. So if we can't reset all requests, at least one
261
+ // pending read request doesn't match any of them.
262
+ throw new Error('No matching note hash found for note hash read request.');
263
+ } else if (!forceReset) {
264
+ // A pending read request can only be reset if its note hash has already been included (e.g. a parent call might
265
+ // be reading a note hash emitted by a child call. The read request of the parent call is included before the note
266
+ // hash of the child call).
267
+ // If we can't clear enough read requests to make room for the next iteration's reads, we're stuck.
268
+ throw new Error('Number of note hash read requests exceeds the limit.');
269
+ } else if (totalReadsToReset == 0) {
270
+ // It's transient data squashing asking for the read requests to be reset first (forceReset == true), and
271
+ // there's nothing to reset, returns false and let needsResetTransientData throw a more descriptive error.
272
+ return false;
273
+ }
274
+ // Otherwise, forceReset is true, we should proceed to reset as many as we can.
275
+ }
276
+
264
277
  if (!this.nextIteration) {
278
+ // If there's no next iteration, we need to reset all the read requests.
265
279
  this.noteHashResetActions = resetActions;
266
280
  this.requestedDimensions.NOTE_HASH_PENDING_READ = numPendingReads;
267
281
  this.requestedDimensions.NOTE_HASH_SETTLED_READ = numSettledReads;
268
282
  } else {
269
- // Pick only one dimension to reset if next iteration is not empty.
283
+ // If there's a next iteration, only one dimension can be reset at a time.
284
+ // So we pick the dimension that has more read requests to reset.
270
285
  if (numPendingReads > numSettledReads) {
271
- this.requestedDimensions.NOTE_HASH_PENDING_READ = numPendingReads;
272
- this.noteHashResetActions.actions = assertLength(
286
+ // Reset the pending read requests.
287
+ const pendingOnlyActions = assertLength(
273
288
  resetActions.actions.map(action =>
274
289
  action === ReadRequestActionEnum.READ_AS_PENDING ? action : ReadRequestActionEnum.SKIP,
275
290
  ),
276
291
  MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
277
292
  );
278
- this.noteHashResetActions.pendingReadHints = resetActions.pendingReadHints;
293
+ this.noteHashResetActions = new ReadRequestResetActions(pendingOnlyActions, resetActions.pendingReadHints);
294
+ this.requestedDimensions.NOTE_HASH_PENDING_READ = numPendingReads;
279
295
  } else {
280
- this.requestedDimensions.NOTE_HASH_SETTLED_READ = numSettledReads;
281
- this.noteHashResetActions.actions = assertLength(
296
+ // Reset the settled read requests.
297
+ const settledOnlyActions = assertLength(
282
298
  resetActions.actions.map(action =>
283
299
  action === ReadRequestActionEnum.READ_AS_SETTLED ? action : ReadRequestActionEnum.SKIP,
284
300
  ),
285
301
  MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
286
302
  );
303
+ this.noteHashResetActions = new ReadRequestResetActions(settledOnlyActions, []);
304
+ this.requestedDimensions.NOTE_HASH_SETTLED_READ = numSettledReads;
287
305
  }
288
306
  }
289
307
 
290
308
  return true;
291
309
  }
292
310
 
293
- private needsResetNullifierReadRequests(forceResetAll = false) {
311
+ private needsResetNullifierReadRequests(forceReset = false) {
294
312
  const numCurr = this.previousKernel.validationRequests.nullifierReadRequests.claimedLength;
295
313
  const numNext = this.nextIteration ? this.nextIteration.nullifierReadRequests.claimedLength : 0;
296
- const maxAmountToKeep = !this.nextIteration || forceResetAll ? 0 : MAX_NULLIFIER_READ_REQUESTS_PER_TX;
314
+ const maxAmountToKeep = !this.nextIteration || forceReset ? 0 : MAX_NULLIFIER_READ_REQUESTS_PER_TX;
297
315
  if (numCurr + numNext <= maxAmountToKeep) {
298
316
  return false;
299
317
  }
300
318
 
301
- const futureNullifiers = collectNested(this.executionStack, executionResult => {
302
- return executionResult.publicInputs.nullifiers
303
- .getActiveItems()
304
- .map(nullifier => new ScopedNullifier(nullifier, executionResult.publicInputs.callContext.contractAddress));
305
- });
306
-
307
319
  const resetActions = getNullifierReadRequestResetActions(
308
320
  this.previousKernel.validationRequests.nullifierReadRequests,
309
321
  this.previousKernel.end.nullifiers,
310
- futureNullifiers,
311
322
  );
312
323
 
313
324
  const numPendingReads = resetActions.pendingReadHints.length;
@@ -316,38 +327,63 @@ export class PrivateKernelResetPrivateInputsBuilder {
316
327
  0,
317
328
  );
318
329
 
330
+ const totalReadsToReset = numPendingReads + numSettledReads;
331
+ const minResetNeeded = numCurr + numNext - maxAmountToKeep;
332
+ if (totalReadsToReset < minResetNeeded) {
333
+ if (!this.nextIteration) {
334
+ // In the final reset, all nullifiers have been emitted. So if we can't reset all requests, at least one pending
335
+ // read request doesn't match any of them.
336
+ throw new Error('No matching nullifier found for nullifier read request.');
337
+ } else if (!forceReset) {
338
+ // A pending read request can only be reset if its nullifier has already been included (e.g. a parent call might
339
+ // be reading a nullifier emitted by a child call. The read request of the parent call is included before the
340
+ // nullifier of the child call).
341
+ // If we can't clear enough read requests to make room for the next iteration's reads, we're stuck.
342
+ throw new Error('Number of nullifier read requests exceeds the limit.');
343
+ } else if (totalReadsToReset == 0) {
344
+ // It's transient data squashing asking for the read requests to be reset first (forceReset == true), and
345
+ // there's nothing to reset, returns false and let needsResetTransientData throw a more descriptive error.
346
+ return false;
347
+ }
348
+ // Otherwise, forceReset is true, we should proceed to reset as many as we can.
349
+ }
350
+
319
351
  if (!this.nextIteration) {
352
+ // If there's no next iteration, we need to reset all the read requests.
320
353
  this.nullifierResetActions = resetActions;
321
354
  this.requestedDimensions.NULLIFIER_PENDING_READ = numPendingReads;
322
355
  this.requestedDimensions.NULLIFIER_SETTLED_READ = numSettledReads;
323
356
  } else {
324
- // Pick only one dimension to reset if next iteration is not empty.
357
+ // If there's a next iteration, we can only reset one dimension at a time.
325
358
  if (numPendingReads > numSettledReads) {
326
- this.requestedDimensions.NULLIFIER_PENDING_READ = numPendingReads;
327
- this.nullifierResetActions.actions = assertLength(
359
+ // Reset the pending read requests.
360
+ const pendingOnlyActions = assertLength(
328
361
  resetActions.actions.map(action =>
329
362
  action === ReadRequestActionEnum.READ_AS_PENDING ? action : ReadRequestActionEnum.SKIP,
330
363
  ),
331
364
  MAX_NULLIFIER_READ_REQUESTS_PER_TX,
332
365
  );
333
- this.nullifierResetActions.pendingReadHints = resetActions.pendingReadHints;
366
+ this.nullifierResetActions = new ReadRequestResetActions(pendingOnlyActions, resetActions.pendingReadHints);
367
+ this.requestedDimensions.NULLIFIER_PENDING_READ = numPendingReads;
334
368
  } else {
335
- this.requestedDimensions.NULLIFIER_SETTLED_READ = numSettledReads;
336
- this.nullifierResetActions.actions = assertLength(
369
+ // Reset the settled read requests.
370
+ const settledOnlyActions = assertLength(
337
371
  resetActions.actions.map(action =>
338
372
  action === ReadRequestActionEnum.READ_AS_SETTLED ? action : ReadRequestActionEnum.SKIP,
339
373
  ),
340
374
  MAX_NULLIFIER_READ_REQUESTS_PER_TX,
341
375
  );
376
+ this.nullifierResetActions = new ReadRequestResetActions(settledOnlyActions, []);
377
+ this.requestedDimensions.NULLIFIER_SETTLED_READ = numSettledReads;
342
378
  }
343
379
  }
344
380
 
345
381
  return true;
346
382
  }
347
383
 
348
- private needsResetNullifierKeys() {
349
- const numCurr = this.previousKernel.validationRequests.scopedKeyValidationRequestsAndGenerators.claimedLength;
350
- const numNext = this.nextIteration ? this.nextIteration.keyValidationRequestsAndGenerators.claimedLength : 0;
384
+ private needsResetKeyValidationRequests() {
385
+ const numCurr = this.previousKernel.validationRequests.scopedKeyValidationRequestsAndSeparators.claimedLength;
386
+ const numNext = this.nextIteration ? this.nextIteration.keyValidationRequestsAndSeparators.claimedLength : 0;
351
387
  const maxAmountToKeep = !this.nextIteration ? 0 : MAX_KEY_VALIDATION_REQUESTS_PER_TX;
352
388
  if (numCurr + numNext <= maxAmountToKeep) {
353
389
  return false;
@@ -359,9 +395,6 @@ export class PrivateKernelResetPrivateInputsBuilder {
359
395
  }
360
396
 
361
397
  private needsResetTransientData() {
362
- // Initialize this to 0 so that needsSilo can be run.
363
- this.numTransientData = 0;
364
-
365
398
  const nextAccumNoteHashes =
366
399
  this.previousKernel.end.noteHashes.claimedLength + (this.nextIteration?.noteHashes.claimedLength ?? 0);
367
400
  const noteHashWillOverflow = nextAccumNoteHashes > MAX_NOTE_HASHES_PER_TX;
@@ -376,19 +409,19 @@ export class PrivateKernelResetPrivateInputsBuilder {
376
409
  return false;
377
410
  }
378
411
 
379
- const futureNoteHashReads = collectNestedReadRequests(
380
- this.executionStack,
381
- executionResult => executionResult.publicInputs.noteHashReadRequests,
412
+ const futureNoteHashReads = collectNested(this.executionStack, executionResult =>
413
+ executionResult.publicInputs.noteHashReadRequests.getActiveItems(),
414
+ );
415
+ const futureNullifierReads = collectNested(this.executionStack, executionResult =>
416
+ executionResult.publicInputs.nullifierReadRequests.getActiveItems(),
382
417
  );
383
- const futureNullifierReads = collectNestedReadRequests(
384
- this.executionStack,
385
- executionResult => executionResult.publicInputs.nullifierReadRequests,
418
+ const futureLogs = collectNested(this.executionStack, executionResult =>
419
+ executionResult.publicInputs.privateLogs.getActiveItems(),
386
420
  );
387
- // TODO(#15902): Collect future logs and only allow squashing a note hash when all its logs have been emitted
388
- // (i.e. none of the future logs are linked to the to-be-squashed note hashes).
389
421
  if (this.nextIteration) {
390
- // If it's not the final reset, only one dimension will be reset at a time.
391
- // The note hashes and nullifiers for the remaining read requests can't be squashed.
422
+ // If it's not the final reset, only one dimension will be reset at a time. Since we are resetting the transient
423
+ // data, the note hash and nullifier read requests in the previous kernel won't be squashed and need to be
424
+ // included in the future read requests.
392
425
  futureNoteHashReads.push(...this.previousKernel.validationRequests.noteHashReadRequests.getActiveItems());
393
426
  futureNullifierReads.push(...this.previousKernel.validationRequests.nullifierReadRequests.getActiveItems());
394
427
  }
@@ -398,27 +431,50 @@ export class PrivateKernelResetPrivateInputsBuilder {
398
431
  this.previousKernel.end.nullifiers,
399
432
  futureNoteHashReads,
400
433
  futureNullifierReads,
434
+ futureLogs,
401
435
  this.noteHashNullifierCounterMap,
402
436
  this.splitCounter,
403
437
  );
404
438
 
405
- if (this.nextIteration && !numTransientData) {
406
- const forceResetAll = true;
407
- const canClearReadRequests =
408
- (noteHashWillOverflow && this.needsResetNoteHashReadRequests(forceResetAll)) ||
409
- (nullifierWillOverflow && this.needsResetNullifierReadRequests(forceResetAll)) ||
410
- (logsWillOverflow && this.needsResetNoteHashReadRequests(forceResetAll));
411
- if (!canClearReadRequests) {
412
- const overflownData = noteHashWillOverflow
413
- ? 'note hashes'
414
- : nullifierWillOverflow
415
- ? 'nullifiers'
416
- : 'private logs';
417
- throw new Error(`Number of ${overflownData} exceeds the limit.`);
439
+ if (this.nextIteration) {
440
+ const noteHashOverflowBy = noteHashWillOverflow
441
+ ? nextAccumNoteHashes - MAX_NOTE_HASHES_PER_TX - numTransientData
442
+ : 0;
443
+ const nullifierOverflowBy = nullifierWillOverflow
444
+ ? nextAccumNullifiers - MAX_NULLIFIERS_PER_TX - numTransientData
445
+ : 0;
446
+ const numSquashedLogs = logsWillOverflow
447
+ ? countSquashedLogs(
448
+ this.previousKernel.end.noteHashes,
449
+ this.previousKernel.end.privateLogs,
450
+ transientDataSquashingHints.slice(0, numTransientData),
451
+ )
452
+ : 0;
453
+ const logsOverflowBy = logsWillOverflow ? nextAccumLogs - MAX_PRIVATE_LOGS_PER_TX - numSquashedLogs : 0;
454
+
455
+ if (noteHashOverflowBy > 0 || nullifierOverflowBy > 0 || logsOverflowBy > 0) {
456
+ // There's not enough transient data to squash to clear space for the overflow. It may be because some data is
457
+ // still required for read requests. Force a reset of the read requests first, and return to transient data
458
+ // squashing in the next round of reset.
459
+ // Note that clearing the read requests might not be enough to clear more space for the overflow. In this case,
460
+ // running the next reset will fail at the following check.
461
+ // Only one dimension can be reset at a time for an inner reset, so we try the note hash read requests first
462
+ // (which also helps with log overflow), then fall back to nullifier read requests.
463
+ const forceReset = true;
464
+ if ((noteHashOverflowBy > 0 || logsOverflowBy > 0) && this.needsResetNoteHashReadRequests(forceReset)) {
465
+ return true;
466
+ }
467
+ if (nullifierOverflowBy > 0 && this.needsResetNullifierReadRequests(forceReset)) {
468
+ return true;
469
+ }
470
+ if (noteHashWillOverflow) {
471
+ throw new Error('Number of note hashes exceeds the limit.');
472
+ }
473
+ if (nullifierWillOverflow) {
474
+ throw new Error('Number of nullifiers exceeds the limit.');
475
+ }
476
+ throw new Error('Number of private logs exceeds the limit.');
418
477
  }
419
- // Clearing the read requests might not be enough to squash the overflown data.
420
- // In this case, the next iteration will fail at the above check.
421
- return true;
422
478
  }
423
479
 
424
480
  this.numTransientData = numTransientData;
@@ -433,10 +489,13 @@ export class PrivateKernelResetPrivateInputsBuilder {
433
489
  throw new Error('`needsResetTransientData` must be run before `needsSiloNoteHashes`.');
434
490
  }
435
491
 
436
- const numNoteHashes = this.previousKernel.end.noteHashes
437
- .getActiveItems()
438
- .filter(n => !n.contractAddress.isZero()).length;
439
- const numToSilo = Math.max(0, numNoteHashes - this.numTransientData);
492
+ const noteHashes = this.previousKernel.end.noteHashes;
493
+ if (noteHashes.claimedLength > 0 && noteHashes.array[0].contractAddress.isZero()) {
494
+ // Already siloed.
495
+ return false;
496
+ }
497
+
498
+ const numToSilo = noteHashes.claimedLength - this.numTransientData;
440
499
  this.requestedDimensions.NOTE_HASH_SILOING = numToSilo;
441
500
 
442
501
  return numToSilo > 0;
@@ -447,15 +506,14 @@ export class PrivateKernelResetPrivateInputsBuilder {
447
506
  throw new Error('`needsResetTransientData` must be run before `needsSiloNullifiers`.');
448
507
  }
449
508
 
450
- const numNullifiers = this.previousKernel.end.nullifiers
451
- .getActiveItems()
452
- .filter(n => !n.contractAddress.isZero()).length;
453
- const numToSilo = Math.max(0, numNullifiers - this.numTransientData);
454
- // Include the first nullifier if there's something to silo.
455
- // The reset circuit checks that capped_size must be greater than or equal to all non-empty nullifiers.
456
- // Which includes the first nullifier, even though its contract address is always zero and doesn't need siloing.
457
- const cappedSize = numToSilo ? numToSilo + 1 : 0;
458
- this.requestedDimensions.NULLIFIER_SILOING = cappedSize;
509
+ const nullifiers = this.previousKernel.end.nullifiers;
510
+ if (nullifiers.claimedLength > 0 && nullifiers.array[0].contractAddress.isZero()) {
511
+ // Already siloed.
512
+ return false;
513
+ }
514
+
515
+ const numToSilo = nullifiers.claimedLength - this.numTransientData;
516
+ this.requestedDimensions.NULLIFIER_SILOING = numToSilo;
459
517
 
460
518
  return numToSilo > 0;
461
519
  }
@@ -466,17 +524,17 @@ export class PrivateKernelResetPrivateInputsBuilder {
466
524
  }
467
525
 
468
526
  const privateLogs = this.previousKernel.end.privateLogs;
469
- const numLogs = privateLogs.getActiveItems().filter(l => !l.contractAddress.isZero()).length;
527
+ if (privateLogs.claimedLength > 0 && privateLogs.array[0].contractAddress.isZero()) {
528
+ // Already siloed.
529
+ return false;
530
+ }
470
531
 
471
- const noteHashes = this.previousKernel.end.noteHashes;
472
- const squashedNoteHashCounters = this.transientDataSquashingHints
473
- .filter(h => h.noteHashIndex < noteHashes.claimedLength)
474
- .map(h => noteHashes.array[h.noteHashIndex].counter);
475
- const numSquashedLogs = privateLogs
476
- .getActiveItems()
477
- .filter(l => squashedNoteHashCounters.includes(l.inner.noteHashCounter)).length;
478
-
479
- const numToSilo = numLogs - numSquashedLogs;
532
+ const numSquashedLogs = countSquashedLogs(
533
+ this.previousKernel.end.noteHashes,
534
+ privateLogs,
535
+ this.transientDataSquashingHints.slice(0, this.numTransientData),
536
+ );
537
+ const numToSilo = privateLogs.claimedLength - numSquashedLogs;
480
538
  this.requestedDimensions.PRIVATE_LOG_SILOING = numToSilo;
481
539
 
482
540
  return numToSilo > 0;