@aztec/pxe 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d

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 (265) 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 +11 -5
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +72 -21
  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 -35
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +198 -84
  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/index.d.ts +2 -2
  22. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/index.js +1 -1
  24. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  25. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +2 -2
  26. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
  29. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  30. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts +17 -13
  33. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  35. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  37. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  39. package/dest/contract_function_simulator/oracle/oracle.d.ts +12 -10
  40. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/oracle.js +67 -44
  42. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  43. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/private_execution.js +0 -35
  45. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +44 -35
  46. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +82 -25
  48. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +66 -33
  49. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +130 -111
  51. package/dest/contract_logging.d.ts +22 -0
  52. package/dest/contract_logging.d.ts.map +1 -0
  53. package/dest/contract_logging.js +23 -0
  54. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  55. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  56. package/dest/contract_sync/contract_sync_service.js +97 -0
  57. package/dest/contract_sync/helpers.d.ts +29 -0
  58. package/dest/contract_sync/helpers.d.ts.map +1 -0
  59. package/dest/contract_sync/helpers.js +55 -0
  60. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  61. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  62. package/dest/debug/pxe_debug_utils.js +28 -17
  63. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  64. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  65. package/dest/entrypoints/client/bundle/index.js +3 -0
  66. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  67. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  68. package/dest/entrypoints/client/bundle/utils.js +21 -7
  69. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  70. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  71. package/dest/entrypoints/client/lazy/index.js +3 -0
  72. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  73. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  74. package/dest/entrypoints/client/lazy/utils.js +22 -8
  75. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  76. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  77. package/dest/entrypoints/server/index.d.ts +5 -1
  78. package/dest/entrypoints/server/index.d.ts.map +1 -1
  79. package/dest/entrypoints/server/index.js +4 -0
  80. package/dest/entrypoints/server/utils.d.ts +1 -1
  81. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  82. package/dest/entrypoints/server/utils.js +28 -9
  83. package/dest/events/event_service.d.ts +6 -6
  84. package/dest/events/event_service.d.ts.map +1 -1
  85. package/dest/events/event_service.js +19 -22
  86. package/dest/events/private_event_filter_validator.d.ts +5 -5
  87. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  88. package/dest/events/private_event_filter_validator.js +5 -6
  89. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  90. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  91. package/dest/job_coordinator/job_coordinator.js +3 -2
  92. package/dest/logs/log_service.d.ts +8 -5
  93. package/dest/logs/log_service.d.ts.map +1 -1
  94. package/dest/logs/log_service.js +28 -30
  95. package/dest/notes/note_service.d.ts +10 -9
  96. package/dest/notes/note_service.d.ts.map +1 -1
  97. package/dest/notes/note_service.js +34 -38
  98. package/dest/notes_filter.d.ts +25 -0
  99. package/dest/notes_filter.d.ts.map +1 -0
  100. package/dest/notes_filter.js +4 -0
  101. package/dest/oracle_version.d.ts +3 -3
  102. package/dest/oracle_version.d.ts.map +1 -1
  103. package/dest/oracle_version.js +4 -3
  104. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  105. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  106. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  107. package/dest/private_kernel/hints/index.d.ts +3 -3
  108. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  109. package/dest/private_kernel/hints/index.js +2 -2
  110. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  111. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  112. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +140 -73
  113. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  114. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  115. package/dest/private_kernel/hints/test_utils.js +203 -0
  116. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  117. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  118. package/dest/private_kernel/private_kernel_execution_prover.js +22 -14
  119. package/dest/private_kernel/private_kernel_oracle.d.ts +23 -24
  120. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  121. package/dest/private_kernel/private_kernel_oracle.js +94 -2
  122. package/dest/pxe.d.ts +75 -58
  123. package/dest/pxe.d.ts.map +1 -1
  124. package/dest/pxe.js +124 -132
  125. package/dest/storage/address_store/address_store.d.ts +1 -1
  126. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  127. package/dest/storage/address_store/address_store.js +12 -11
  128. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  129. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  130. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  131. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  132. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  133. package/dest/storage/capsule_store/capsule_store.js +130 -23
  134. package/dest/storage/contract_store/contract_store.d.ts +42 -16
  135. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  136. package/dest/storage/contract_store/contract_store.js +157 -84
  137. package/dest/storage/metadata.d.ts +1 -1
  138. package/dest/storage/metadata.js +1 -1
  139. package/dest/storage/note_store/note_store.d.ts +50 -51
  140. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  141. package/dest/storage/note_store/note_store.js +284 -263
  142. package/dest/storage/note_store/stored_note.d.ts +16 -0
  143. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  144. package/dest/storage/note_store/stored_note.js +43 -0
  145. package/dest/storage/private_event_store/private_event_store.d.ts +43 -8
  146. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  147. package/dest/storage/private_event_store/private_event_store.js +226 -111
  148. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  149. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  150. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  151. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  152. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  153. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  154. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  155. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  156. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  157. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  158. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  159. package/dest/storage/tagging_store/sender_tagging_store.js +252 -100
  160. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  161. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  162. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  163. package/dest/tagging/index.d.ts +2 -1
  164. package/dest/tagging/index.d.ts.map +1 -1
  165. package/dest/tagging/index.js +1 -0
  166. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  167. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  168. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +10 -10
  169. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  170. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  171. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  172. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  173. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  174. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  175. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +7 -7
  176. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  177. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  178. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  179. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
  180. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  181. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
  182. package/package.json +27 -18
  183. package/src/access_scopes.ts +9 -0
  184. package/src/bin/check_oracle_version.ts +1 -0
  185. package/src/block_synchronizer/block_synchronizer.ts +91 -33
  186. package/src/config/index.ts +14 -0
  187. package/src/config/package_info.ts +1 -1
  188. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  189. package/src/contract_function_simulator/contract_function_simulator.ts +349 -148
  190. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  191. package/src/contract_function_simulator/index.ts +1 -1
  192. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +2 -2
  193. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  194. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  195. package/src/contract_function_simulator/oracle/interfaces.ts +22 -12
  196. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  197. package/src/contract_function_simulator/oracle/oracle.ts +79 -47
  198. package/src/contract_function_simulator/oracle/private_execution.ts +1 -67
  199. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +118 -104
  200. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +197 -116
  201. package/src/contract_logging.ts +39 -0
  202. package/src/contract_sync/contract_sync_service.ts +152 -0
  203. package/src/contract_sync/helpers.ts +98 -0
  204. package/src/debug/pxe_debug_utils.ts +63 -18
  205. package/src/entrypoints/client/bundle/index.ts +3 -0
  206. package/src/entrypoints/client/bundle/utils.ts +16 -15
  207. package/src/entrypoints/client/lazy/index.ts +3 -0
  208. package/src/entrypoints/client/lazy/utils.ts +17 -15
  209. package/src/entrypoints/pxe_creation_options.ts +2 -1
  210. package/src/entrypoints/server/index.ts +4 -0
  211. package/src/entrypoints/server/utils.ts +22 -26
  212. package/src/events/event_service.ts +17 -25
  213. package/src/events/private_event_filter_validator.ts +3 -5
  214. package/src/job_coordinator/job_coordinator.ts +4 -3
  215. package/src/logs/log_service.ts +40 -34
  216. package/src/notes/note_service.ts +41 -45
  217. package/src/notes_filter.ts +26 -0
  218. package/src/oracle_version.ts +4 -3
  219. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  220. package/src/private_kernel/hints/index.ts +2 -2
  221. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +195 -136
  222. package/src/private_kernel/hints/test_utils.ts +325 -0
  223. package/src/private_kernel/private_kernel_execution_prover.ts +26 -16
  224. package/src/private_kernel/private_kernel_oracle.ts +116 -37
  225. package/src/pxe.ts +235 -209
  226. package/src/storage/address_store/address_store.ts +15 -15
  227. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  228. package/src/storage/capsule_store/capsule_store.ts +159 -23
  229. package/src/storage/contract_store/contract_store.ts +186 -96
  230. package/src/storage/metadata.ts +1 -1
  231. package/src/storage/note_store/note_store.ts +326 -320
  232. package/src/storage/note_store/stored_note.ts +48 -0
  233. package/src/storage/private_event_store/private_event_store.ts +292 -124
  234. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  235. package/src/storage/tagging_store/recipient_tagging_store.ts +106 -20
  236. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  237. package/src/storage/tagging_store/sender_tagging_store.ts +293 -108
  238. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  239. package/src/tagging/index.ts +1 -0
  240. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +20 -9
  241. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  242. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  243. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +9 -6
  244. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  245. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
  246. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  247. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  248. package/dest/contract_function_simulator/proxied_node.js +0 -27
  249. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  250. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  251. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  252. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  253. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  254. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  255. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -85
  256. package/dest/public_storage/public_storage_service.d.ts +0 -24
  257. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  258. package/dest/public_storage/public_storage_service.js +0 -26
  259. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  260. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  261. package/dest/tree_membership/tree_membership_service.js +0 -84
  262. package/src/contract_function_simulator/proxied_node.ts +0 -33
  263. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -127
  264. package/src/public_storage/public_storage_service.ts +0 -33
  265. package/src/tree_membership/tree_membership_service.ts +0 -112
@@ -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
 
@@ -145,8 +134,7 @@ export class PrivateKernelResetPrivateInputsBuilder {
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,29 +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
171
  ),
194
- await buildNullifierReadRequestHintsFromResetActions(
172
+ buildNullifierReadRequestHintsFromResetActions<
173
+ typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX,
174
+ typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX
175
+ >(
195
176
  { getNullifierMembershipWitness: getNullifierMembershipWitnessResolver(oracle) },
196
177
  this.previousKernel.validationRequests.nullifierReadRequests,
197
178
  this.nullifierResetActions,
198
179
  ),
199
- await getMasterSecretKeysAndAppKeyGenerators(
200
- this.previousKernel.validationRequests.scopedKeyValidationRequestsAndGenerators,
180
+ getMasterSecretKeysAndKeyTypeDomainSeparators(
181
+ this.previousKernel.validationRequests.scopedKeyValidationRequestsAndSeparators,
201
182
  dimensions.KEY_VALIDATION,
202
183
  oracle,
203
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,
204
204
  this.transientDataSquashingHints,
205
205
  ),
206
206
  dimensions,
@@ -234,24 +234,17 @@ export class PrivateKernelResetPrivateInputsBuilder {
234
234
  resetActions.pendingReadHints = resetActions.pendingReadHints.slice(0, maxPending);
235
235
  }
236
236
 
237
- private needsResetNoteHashReadRequests(forceResetAll = false) {
237
+ private needsResetNoteHashReadRequests(forceReset = false) {
238
238
  const numCurr = this.previousKernel.validationRequests.noteHashReadRequests.claimedLength;
239
239
  const numNext = this.nextIteration ? this.nextIteration.noteHashReadRequests.claimedLength : 0;
240
- 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;
241
241
  if (numCurr + numNext <= maxAmountToKeep) {
242
242
  return false;
243
243
  }
244
244
 
245
- const futureNoteHashes = collectNested(this.executionStack, executionResult => {
246
- return executionResult.publicInputs.noteHashes
247
- .getActiveItems()
248
- .map(noteHash => new ScopedNoteHash(noteHash, executionResult.publicInputs.callContext.contractAddress));
249
- });
250
-
251
245
  const resetActions = getNoteHashReadRequestResetActions(
252
246
  this.previousKernel.validationRequests.noteHashReadRequests,
253
247
  this.previousKernel.end.noteHashes,
254
- futureNoteHashes,
255
248
  );
256
249
 
257
250
  const numPendingReads = resetActions.pendingReadHints.length;
@@ -260,53 +253,72 @@ export class PrivateKernelResetPrivateInputsBuilder {
260
253
  0,
261
254
  );
262
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
+
263
277
  if (!this.nextIteration) {
278
+ // If there's no next iteration, we need to reset all the read requests.
264
279
  this.noteHashResetActions = resetActions;
265
280
  this.requestedDimensions.NOTE_HASH_PENDING_READ = numPendingReads;
266
281
  this.requestedDimensions.NOTE_HASH_SETTLED_READ = numSettledReads;
267
282
  } else {
268
- // 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.
269
285
  if (numPendingReads > numSettledReads) {
270
- this.requestedDimensions.NOTE_HASH_PENDING_READ = numPendingReads;
271
- this.noteHashResetActions.actions = assertLength(
286
+ // Reset the pending read requests.
287
+ const pendingOnlyActions = assertLength(
272
288
  resetActions.actions.map(action =>
273
289
  action === ReadRequestActionEnum.READ_AS_PENDING ? action : ReadRequestActionEnum.SKIP,
274
290
  ),
275
291
  MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
276
292
  );
277
- this.noteHashResetActions.pendingReadHints = resetActions.pendingReadHints;
293
+ this.noteHashResetActions = new ReadRequestResetActions(pendingOnlyActions, resetActions.pendingReadHints);
294
+ this.requestedDimensions.NOTE_HASH_PENDING_READ = numPendingReads;
278
295
  } else {
279
- this.requestedDimensions.NOTE_HASH_SETTLED_READ = numSettledReads;
280
- this.noteHashResetActions.actions = assertLength(
296
+ // Reset the settled read requests.
297
+ const settledOnlyActions = assertLength(
281
298
  resetActions.actions.map(action =>
282
299
  action === ReadRequestActionEnum.READ_AS_SETTLED ? action : ReadRequestActionEnum.SKIP,
283
300
  ),
284
301
  MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
285
302
  );
303
+ this.noteHashResetActions = new ReadRequestResetActions(settledOnlyActions, []);
304
+ this.requestedDimensions.NOTE_HASH_SETTLED_READ = numSettledReads;
286
305
  }
287
306
  }
288
307
 
289
308
  return true;
290
309
  }
291
310
 
292
- private needsResetNullifierReadRequests(forceResetAll = false) {
311
+ private needsResetNullifierReadRequests(forceReset = false) {
293
312
  const numCurr = this.previousKernel.validationRequests.nullifierReadRequests.claimedLength;
294
313
  const numNext = this.nextIteration ? this.nextIteration.nullifierReadRequests.claimedLength : 0;
295
- 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;
296
315
  if (numCurr + numNext <= maxAmountToKeep) {
297
316
  return false;
298
317
  }
299
318
 
300
- const futureNullifiers = collectNested(this.executionStack, executionResult => {
301
- return executionResult.publicInputs.nullifiers
302
- .getActiveItems()
303
- .map(nullifier => new ScopedNullifier(nullifier, executionResult.publicInputs.callContext.contractAddress));
304
- });
305
-
306
319
  const resetActions = getNullifierReadRequestResetActions(
307
320
  this.previousKernel.validationRequests.nullifierReadRequests,
308
321
  this.previousKernel.end.nullifiers,
309
- futureNullifiers,
310
322
  );
311
323
 
312
324
  const numPendingReads = resetActions.pendingReadHints.length;
@@ -315,38 +327,63 @@ export class PrivateKernelResetPrivateInputsBuilder {
315
327
  0,
316
328
  );
317
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
+
318
351
  if (!this.nextIteration) {
352
+ // If there's no next iteration, we need to reset all the read requests.
319
353
  this.nullifierResetActions = resetActions;
320
354
  this.requestedDimensions.NULLIFIER_PENDING_READ = numPendingReads;
321
355
  this.requestedDimensions.NULLIFIER_SETTLED_READ = numSettledReads;
322
356
  } else {
323
- // 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.
324
358
  if (numPendingReads > numSettledReads) {
325
- this.requestedDimensions.NULLIFIER_PENDING_READ = numPendingReads;
326
- this.nullifierResetActions.actions = assertLength(
359
+ // Reset the pending read requests.
360
+ const pendingOnlyActions = assertLength(
327
361
  resetActions.actions.map(action =>
328
362
  action === ReadRequestActionEnum.READ_AS_PENDING ? action : ReadRequestActionEnum.SKIP,
329
363
  ),
330
364
  MAX_NULLIFIER_READ_REQUESTS_PER_TX,
331
365
  );
332
- this.nullifierResetActions.pendingReadHints = resetActions.pendingReadHints;
366
+ this.nullifierResetActions = new ReadRequestResetActions(pendingOnlyActions, resetActions.pendingReadHints);
367
+ this.requestedDimensions.NULLIFIER_PENDING_READ = numPendingReads;
333
368
  } else {
334
- this.requestedDimensions.NULLIFIER_SETTLED_READ = numSettledReads;
335
- this.nullifierResetActions.actions = assertLength(
369
+ // Reset the settled read requests.
370
+ const settledOnlyActions = assertLength(
336
371
  resetActions.actions.map(action =>
337
372
  action === ReadRequestActionEnum.READ_AS_SETTLED ? action : ReadRequestActionEnum.SKIP,
338
373
  ),
339
374
  MAX_NULLIFIER_READ_REQUESTS_PER_TX,
340
375
  );
376
+ this.nullifierResetActions = new ReadRequestResetActions(settledOnlyActions, []);
377
+ this.requestedDimensions.NULLIFIER_SETTLED_READ = numSettledReads;
341
378
  }
342
379
  }
343
380
 
344
381
  return true;
345
382
  }
346
383
 
347
- private needsResetNullifierKeys() {
348
- const numCurr = this.previousKernel.validationRequests.scopedKeyValidationRequestsAndGenerators.claimedLength;
349
- 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;
350
387
  const maxAmountToKeep = !this.nextIteration ? 0 : MAX_KEY_VALIDATION_REQUESTS_PER_TX;
351
388
  if (numCurr + numNext <= maxAmountToKeep) {
352
389
  return false;
@@ -358,9 +395,6 @@ export class PrivateKernelResetPrivateInputsBuilder {
358
395
  }
359
396
 
360
397
  private needsResetTransientData() {
361
- // Initialize this to 0 so that needsSilo can be run.
362
- this.numTransientData = 0;
363
-
364
398
  const nextAccumNoteHashes =
365
399
  this.previousKernel.end.noteHashes.claimedLength + (this.nextIteration?.noteHashes.claimedLength ?? 0);
366
400
  const noteHashWillOverflow = nextAccumNoteHashes > MAX_NOTE_HASHES_PER_TX;
@@ -375,19 +409,19 @@ export class PrivateKernelResetPrivateInputsBuilder {
375
409
  return false;
376
410
  }
377
411
 
378
- const futureNoteHashReads = collectNestedReadRequests(
379
- this.executionStack,
380
- 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(),
381
417
  );
382
- const futureNullifierReads = collectNestedReadRequests(
383
- this.executionStack,
384
- executionResult => executionResult.publicInputs.nullifierReadRequests,
418
+ const futureLogs = collectNested(this.executionStack, executionResult =>
419
+ executionResult.publicInputs.privateLogs.getActiveItems(),
385
420
  );
386
- // TODO(#15902): Collect future logs and only allow squashing a note hash when all its logs have been emitted
387
- // (i.e. none of the future logs are linked to the to-be-squashed note hashes).
388
421
  if (this.nextIteration) {
389
- // If it's not the final reset, only one dimension will be reset at a time.
390
- // 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.
391
425
  futureNoteHashReads.push(...this.previousKernel.validationRequests.noteHashReadRequests.getActiveItems());
392
426
  futureNullifierReads.push(...this.previousKernel.validationRequests.nullifierReadRequests.getActiveItems());
393
427
  }
@@ -397,27 +431,50 @@ export class PrivateKernelResetPrivateInputsBuilder {
397
431
  this.previousKernel.end.nullifiers,
398
432
  futureNoteHashReads,
399
433
  futureNullifierReads,
434
+ futureLogs,
400
435
  this.noteHashNullifierCounterMap,
401
436
  this.splitCounter,
402
437
  );
403
438
 
404
- if (this.nextIteration && !numTransientData) {
405
- const forceResetAll = true;
406
- const canClearReadRequests =
407
- (noteHashWillOverflow && this.needsResetNoteHashReadRequests(forceResetAll)) ||
408
- (nullifierWillOverflow && this.needsResetNullifierReadRequests(forceResetAll)) ||
409
- (logsWillOverflow && this.needsResetNoteHashReadRequests(forceResetAll));
410
- if (!canClearReadRequests) {
411
- const overflownData = noteHashWillOverflow
412
- ? 'note hashes'
413
- : nullifierWillOverflow
414
- ? 'nullifiers'
415
- : 'private logs';
416
- 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.');
417
477
  }
418
- // Clearing the read requests might not be enough to squash the overflown data.
419
- // In this case, the next iteration will fail at the above check.
420
- return true;
421
478
  }
422
479
 
423
480
  this.numTransientData = numTransientData;
@@ -432,10 +489,13 @@ export class PrivateKernelResetPrivateInputsBuilder {
432
489
  throw new Error('`needsResetTransientData` must be run before `needsSiloNoteHashes`.');
433
490
  }
434
491
 
435
- const numNoteHashes = this.previousKernel.end.noteHashes
436
- .getActiveItems()
437
- .filter(n => !n.contractAddress.isZero()).length;
438
- 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;
439
499
  this.requestedDimensions.NOTE_HASH_SILOING = numToSilo;
440
500
 
441
501
  return numToSilo > 0;
@@ -446,15 +506,14 @@ export class PrivateKernelResetPrivateInputsBuilder {
446
506
  throw new Error('`needsResetTransientData` must be run before `needsSiloNullifiers`.');
447
507
  }
448
508
 
449
- const numNullifiers = this.previousKernel.end.nullifiers
450
- .getActiveItems()
451
- .filter(n => !n.contractAddress.isZero()).length;
452
- const numToSilo = Math.max(0, numNullifiers - this.numTransientData);
453
- // Include the first nullifier if there's something to silo.
454
- // The reset circuit checks that capped_size must be greater than or equal to all non-empty nullifiers.
455
- // Which includes the first nullifier, even though its contract address is always zero and doesn't need siloing.
456
- const cappedSize = numToSilo ? numToSilo + 1 : 0;
457
- 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;
458
517
 
459
518
  return numToSilo > 0;
460
519
  }
@@ -465,17 +524,17 @@ export class PrivateKernelResetPrivateInputsBuilder {
465
524
  }
466
525
 
467
526
  const privateLogs = this.previousKernel.end.privateLogs;
468
- 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
+ }
469
531
 
470
- const noteHashes = this.previousKernel.end.noteHashes;
471
- const squashedNoteHashCounters = this.transientDataSquashingHints
472
- .filter(h => h.noteHashIndex < noteHashes.claimedLength)
473
- .map(h => noteHashes.array[h.noteHashIndex].counter);
474
- const numSquashedLogs = privateLogs
475
- .getActiveItems()
476
- .filter(l => squashedNoteHashCounters.includes(l.inner.noteHashCounter)).length;
477
-
478
- 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;
479
538
  this.requestedDimensions.PRIVATE_LOG_SILOING = numToSilo;
480
539
 
481
540
  return numToSilo > 0;