@aztec/pxe 2.1.0-rc.9 → 3.0.0-devnet.2

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 (194) hide show
  1. package/README.md +5 -5
  2. package/dest/bin/check_oracle_version.js +18 -8
  3. package/dest/config/index.d.ts +8 -8
  4. package/dest/config/index.d.ts.map +1 -1
  5. package/dest/config/index.js +3 -3
  6. package/dest/config/package_info.js +1 -1
  7. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.js +82 -26
  9. package/dest/contract_function_simulator/execution_data_provider.d.ts +27 -38
  10. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/execution_note_cache.d.ts +2 -2
  12. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/execution_note_cache.js +7 -4
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  16. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  17. package/dest/contract_function_simulator/index.d.ts +3 -1
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +2 -1
  20. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  21. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +7 -3
  22. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -0
  23. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  25. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
  26. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  27. package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
  28. package/dest/contract_function_simulator/oracle/index.d.ts +1 -1
  29. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/oracle/index.js +1 -1
  31. package/dest/contract_function_simulator/oracle/interfaces.d.ts +97 -0
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +12 -11
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +79 -76
  37. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -2
  38. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/private_execution.js +6 -15
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +26 -10
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +69 -18
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +10 -22
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +33 -38
  46. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +19 -55
  47. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/pxe_oracle_interface.js +174 -187
  49. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  50. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  51. package/dest/entrypoints/client/bundle/index.js +2 -1
  52. package/dest/entrypoints/client/bundle/utils.d.ts +8 -8
  53. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  54. package/dest/entrypoints/client/bundle/utils.js +8 -8
  55. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  56. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  57. package/dest/entrypoints/client/lazy/index.js +2 -1
  58. package/dest/entrypoints/client/lazy/utils.d.ts +7 -7
  59. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  60. package/dest/entrypoints/client/lazy/utils.js +7 -7
  61. package/dest/entrypoints/server/index.d.ts +3 -1
  62. package/dest/entrypoints/server/index.d.ts.map +1 -1
  63. package/dest/entrypoints/server/index.js +2 -1
  64. package/dest/entrypoints/server/utils.d.ts +4 -23
  65. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  66. package/dest/entrypoints/server/utils.js +4 -25
  67. package/dest/{pxe_service/error_enriching.d.ts → error_enriching.d.ts} +1 -1
  68. package/dest/error_enriching.d.ts.map +1 -0
  69. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +3 -0
  70. package/dest/oracle_version.d.ts +2 -2
  71. package/dest/oracle_version.js +2 -2
  72. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +6 -6
  73. package/dest/private_kernel/private_kernel_execution_prover.d.ts +7 -0
  74. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  75. package/dest/private_kernel/private_kernel_execution_prover.js +23 -18
  76. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +2 -2
  77. package/dest/pxe.d.ts +233 -0
  78. package/dest/pxe.d.ts.map +1 -0
  79. package/dest/{pxe_service/pxe_service.js → pxe.js} +215 -217
  80. package/dest/storage/address_data_provider/address_data_provider.d.ts +1 -3
  81. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
  82. package/dest/storage/address_data_provider/address_data_provider.js +0 -3
  83. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +1 -3
  84. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  85. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -4
  86. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +3 -4
  87. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  88. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -3
  89. package/dest/storage/index.d.ts +0 -1
  90. package/dest/storage/index.d.ts.map +1 -1
  91. package/dest/storage/index.js +0 -1
  92. package/dest/storage/note_data_provider/note_dao.d.ts +1 -1
  93. package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
  94. package/dest/storage/note_data_provider/note_data_provider.d.ts +70 -7
  95. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
  96. package/dest/storage/note_data_provider/note_data_provider.js +120 -72
  97. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +1 -3
  98. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -1
  99. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -3
  100. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +1 -3
  101. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
  102. package/dest/storage/sync_data_provider/sync_data_provider.js +0 -3
  103. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +28 -6
  104. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
  105. package/dest/storage/tagging_data_provider/tagging_data_provider.js +46 -39
  106. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  107. package/dest/synchronizer/synchronizer.js +2 -3
  108. package/dest/tagging/constants.d.ts +2 -0
  109. package/dest/tagging/constants.d.ts.map +1 -0
  110. package/dest/tagging/constants.js +2 -0
  111. package/dest/tagging/index.d.ts +7 -0
  112. package/dest/tagging/index.d.ts.map +1 -0
  113. package/dest/tagging/index.js +5 -0
  114. package/dest/tagging/siloed_tag.d.ts +14 -0
  115. package/dest/tagging/siloed_tag.d.ts.map +1 -0
  116. package/dest/tagging/siloed_tag.js +20 -0
  117. package/dest/tagging/tag.d.ts +12 -0
  118. package/dest/tagging/tag.d.ts.map +1 -0
  119. package/dest/tagging/tag.js +17 -0
  120. package/dest/tagging/utils.d.ts +18 -0
  121. package/dest/tagging/utils.d.ts.map +1 -0
  122. package/dest/tagging/utils.js +24 -0
  123. package/package.json +18 -21
  124. package/src/bin/check_oracle_version.ts +23 -9
  125. package/src/config/index.ts +11 -10
  126. package/src/config/package_info.ts +1 -1
  127. package/src/contract_function_simulator/contract_function_simulator.ts +128 -44
  128. package/src/contract_function_simulator/execution_data_provider.ts +29 -47
  129. package/src/contract_function_simulator/execution_note_cache.ts +11 -6
  130. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  131. package/src/contract_function_simulator/index.ts +3 -1
  132. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +8 -3
  133. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  134. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  135. package/src/contract_function_simulator/oracle/index.ts +1 -1
  136. package/src/contract_function_simulator/oracle/interfaces.ts +160 -0
  137. package/src/contract_function_simulator/oracle/oracle.ts +102 -77
  138. package/src/contract_function_simulator/oracle/private_execution.ts +7 -15
  139. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +106 -45
  140. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +51 -76
  141. package/src/contract_function_simulator/pxe_oracle_interface.ts +199 -218
  142. package/src/entrypoints/client/bundle/index.ts +3 -1
  143. package/src/entrypoints/client/bundle/utils.ts +11 -19
  144. package/src/entrypoints/client/lazy/index.ts +3 -1
  145. package/src/entrypoints/client/lazy/utils.ts +10 -18
  146. package/src/entrypoints/server/index.ts +3 -1
  147. package/src/entrypoints/server/utils.ts +9 -39
  148. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +5 -1
  149. package/src/oracle_version.ts +2 -2
  150. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +6 -6
  151. package/src/private_kernel/private_kernel_execution_prover.ts +35 -23
  152. package/src/{pxe_service/pxe_service.ts → pxe.ts} +230 -261
  153. package/src/storage/address_data_provider/address_data_provider.ts +1 -7
  154. package/src/storage/capsule_data_provider/capsule_data_provider.ts +1 -11
  155. package/src/storage/contract_data_provider/contract_data_provider.ts +3 -9
  156. package/src/storage/index.ts +0 -1
  157. package/src/storage/note_data_provider/note_dao.ts +1 -1
  158. package/src/storage/note_data_provider/note_data_provider.ts +142 -99
  159. package/src/storage/private_event_data_provider/private_event_data_provider.ts +1 -7
  160. package/src/storage/sync_data_provider/sync_data_provider.ts +1 -7
  161. package/src/storage/tagging_data_provider/tagging_data_provider.ts +52 -55
  162. package/src/synchronizer/synchronizer.ts +2 -3
  163. package/src/tagging/constants.ts +2 -0
  164. package/src/tagging/index.ts +6 -0
  165. package/src/tagging/siloed_tag.ts +22 -0
  166. package/src/tagging/tag.ts +16 -0
  167. package/src/tagging/utils.ts +31 -0
  168. package/dest/bin/index.d.ts +0 -3
  169. package/dest/bin/index.d.ts.map +0 -1
  170. package/dest/bin/index.js +0 -48
  171. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +0 -87
  172. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +0 -1
  173. package/dest/contract_function_simulator/oracle/typed_oracle.js +0 -146
  174. package/dest/contract_function_simulator/tagging_utils.d.ts +0 -17
  175. package/dest/contract_function_simulator/tagging_utils.d.ts.map +0 -1
  176. package/dest/contract_function_simulator/tagging_utils.js +0 -23
  177. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  178. package/dest/pxe_service/index.d.ts +0 -3
  179. package/dest/pxe_service/index.d.ts.map +0 -1
  180. package/dest/pxe_service/index.js +0 -2
  181. package/dest/pxe_service/pxe_service.d.ts +0 -101
  182. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  183. package/dest/storage/data_provider.d.ts +0 -4
  184. package/dest/storage/data_provider.d.ts.map +0 -1
  185. package/dest/storage/data_provider.js +0 -1
  186. package/dest/test/pxe_test_suite.d.ts +0 -3
  187. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  188. package/dest/test/pxe_test_suite.js +0 -97
  189. package/src/bin/index.ts +0 -62
  190. package/src/contract_function_simulator/oracle/typed_oracle.ts +0 -289
  191. package/src/contract_function_simulator/tagging_utils.ts +0 -32
  192. package/src/pxe_service/index.ts +0 -2
  193. package/src/storage/data_provider.ts +0 -3
  194. package/src/test/pxe_test_suite.ts +0 -113
@@ -1,4 +1,14 @@
1
1
  import {
2
+ AVM_EMITNOTEHASH_BASE_L2_GAS,
3
+ AVM_EMITNULLIFIER_BASE_L2_GAS,
4
+ AVM_SENDL2TOL1MSG_BASE_L2_GAS,
5
+ DA_BYTES_PER_FIELD,
6
+ DA_GAS_PER_BYTE,
7
+ FIXED_AVM_STARTUP_L2_GAS,
8
+ FIXED_DA_GAS,
9
+ FIXED_L2_GAS,
10
+ L2_GAS_PER_CONTRACT_CLASS_LOG,
11
+ L2_GAS_PER_PRIVATE_LOG,
2
12
  MAX_CONTRACT_CLASS_LOGS_PER_TX,
3
13
  MAX_ENQUEUED_CALLS_PER_TX,
4
14
  MAX_L2_TO_L1_MSGS_PER_TX,
@@ -6,13 +16,13 @@ import {
6
16
  MAX_NULLIFIERS_PER_TX,
7
17
  MAX_PRIVATE_LOGS_PER_TX,
8
18
  } from '@aztec/constants';
9
- import { padArrayEnd } from '@aztec/foundation/collection';
19
+ import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
10
20
  import { poseidon2Hash } from '@aztec/foundation/crypto';
11
21
  import { Fr } from '@aztec/foundation/fields';
12
22
  import { type Logger, createLogger } from '@aztec/foundation/log';
13
23
  import { Timer } from '@aztec/foundation/timer';
14
24
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
15
- import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
25
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
16
26
  import {
17
27
  type CircuitSimulator,
18
28
  ExecutionError,
@@ -49,11 +59,13 @@ import {
49
59
  TxConstantData,
50
60
  TxExecutionRequest,
51
61
  collectNested,
62
+ getFinalMinRevertibleSideEffectCounter,
52
63
  } from '@aztec/stdlib/tx';
53
64
 
54
65
  import type { ContractDataProvider } from '../storage/index.js';
55
66
  import type { ExecutionDataProvider } from './execution_data_provider.js';
56
67
  import { ExecutionNoteCache } from './execution_note_cache.js';
68
+ import { ExecutionTaggingIndexCache } from './execution_tagging_index_cache.js';
57
69
  import { HashedValuesCache } from './hashed_values_cache.js';
58
70
  import { Oracle } from './oracle/oracle.js';
59
71
  import { executePrivateFunction, verifyCurrentClassId } from './oracle/private_execution.js';
@@ -94,7 +106,7 @@ export class ContractFunctionSimulator {
94
106
  scopes?: AztecAddress[],
95
107
  ): Promise<PrivateExecutionResult> {
96
108
  const simulatorSetupTimer = new Timer();
97
- const header = await this.executionDataProvider.getBlockHeader();
109
+ const anchorBlockHeader = await this.executionDataProvider.getAnchorBlockHeader();
98
110
 
99
111
  await verifyCurrentClassId(contractAddress, this.executionDataProvider);
100
112
 
@@ -122,23 +134,25 @@ export class ContractFunctionSimulator {
122
134
 
123
135
  const txRequestHash = await request.toTxRequest().hash();
124
136
  const noteCache = new ExecutionNoteCache(txRequestHash);
137
+ const taggingIndexCache = new ExecutionTaggingIndexCache();
125
138
 
126
139
  const privateExecutionOracle = new PrivateExecutionOracle(
127
140
  request.firstCallArgsHash,
128
141
  request.txContext,
129
142
  callContext,
130
- header,
143
+ anchorBlockHeader,
131
144
  request.authWitnesses,
132
145
  request.capsules,
133
146
  HashedValuesCache.create(request.argsOfCalls),
134
147
  noteCache,
148
+ taggingIndexCache,
135
149
  this.executionDataProvider,
136
- this.simulator,
137
150
  0, // totalPublicArgsCount
138
151
  startSideEffectCounter,
139
152
  undefined, // log
140
153
  scopes,
141
154
  senderForTags,
155
+ this.simulator,
142
156
  );
143
157
 
144
158
  const setupTime = simulatorSetupTimer.ms();
@@ -358,30 +372,35 @@ export async function generateSimulatedProvingResult(
358
372
  }
359
373
 
360
374
  const constantData = new TxConstantData(
361
- privateExecutionResult.entrypoint.publicInputs.historicalHeader,
375
+ privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader,
362
376
  privateExecutionResult.entrypoint.publicInputs.txContext,
363
377
  getVKTreeRoot(),
364
- protocolContractTreeRoot,
378
+ protocolContractsHash,
365
379
  );
366
380
 
367
381
  const hasPublicCalls = privateExecutionResult.publicFunctionCalldata.length !== 0;
368
382
  let inputsForRollup;
369
383
  let inputsForPublic;
384
+ let gasUsed;
370
385
 
371
386
  const sortByCounter = <T>(a: OrderedSideEffect<T>, b: OrderedSideEffect<T>) => a.counter - b.counter;
372
387
  const getEffect = <T>(orderedSideEffect: OrderedSideEffect<T>) => orderedSideEffect.sideEffect;
373
388
 
374
- const sortedNullifiers = nullifiers.sort(sortByCounter).map(getEffect);
389
+ const isPrivateOnlyTx = privateExecutionResult.publicFunctionCalldata.length === 0;
390
+ const minRevertibleSideEffectCounter = getFinalMinRevertibleSideEffectCounter(privateExecutionResult);
375
391
 
376
- // If the tx generated no nullifiers, the nonce generator (txRequest hash)
377
- // is injected as the first nullifier as per protocol rules.
378
- if (sortedNullifiers.length === 0) {
379
- sortedNullifiers.push(nonceGenerator);
392
+ const [nonRevertibleNullifiers, revertibleNullifiers] = splitOrderedSideEffects(
393
+ nullifiers.sort(sortByCounter),
394
+ minRevertibleSideEffectCounter,
395
+ );
396
+ if (nonRevertibleNullifiers.length > 0 && !nonRevertibleNullifiers[0].equals(nonceGenerator)) {
397
+ throw new Error('The first non revertible nullifier should be equal to the nonce generator. This is a bug!');
398
+ } else {
399
+ nonRevertibleNullifiers.unshift(nonceGenerator);
380
400
  }
381
401
 
382
- // Private only
383
- if (privateExecutionResult.publicFunctionCalldata.length === 0) {
384
- // In case the tx only contains private functions, we must make the note hashes unique by using the
402
+ if (isPrivateOnlyTx) {
403
+ // We must make the note hashes unique by using the
385
404
  // nonce generator and their index in the tx.
386
405
  const uniqueNoteHashes = await Promise.all(
387
406
  siloedNoteHashes.sort(sortByCounter).map(async (orderedSideEffect, i) => {
@@ -393,7 +412,7 @@ export async function generateSimulatedProvingResult(
393
412
  );
394
413
  const accumulatedDataForRollup = new PrivateToRollupAccumulatedData(
395
414
  padArrayEnd(uniqueNoteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
396
- padArrayEnd(sortedNullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX),
415
+ padArrayEnd(nonRevertibleNullifiers.concat(revertibleNullifiers), Fr.ZERO, MAX_NULLIFIERS_PER_TX),
397
416
  padArrayEnd(
398
417
  l2ToL1Messages.sort(sortByCounter).map(getEffect),
399
418
  ScopedL2ToL1Message.empty(),
@@ -406,39 +425,51 @@ export async function generateSimulatedProvingResult(
406
425
  MAX_CONTRACT_CLASS_LOGS_PER_TX,
407
426
  ),
408
427
  );
409
-
428
+ gasUsed = meterGasUsed(accumulatedDataForRollup);
410
429
  inputsForRollup = new PartialPrivateTailPublicInputsForRollup(accumulatedDataForRollup);
411
430
  } else {
412
- const nonRevertibleData = PrivateToPublicAccumulatedData.empty();
431
+ const [nonRevertibleNoteHashes, revertibleNoteHashes] = splitOrderedSideEffects(
432
+ siloedNoteHashes.sort(sortByCounter),
433
+ minRevertibleSideEffectCounter,
434
+ );
435
+ const [nonRevertibleL2ToL1Messages, revertibleL2ToL1Messages] = splitOrderedSideEffects(
436
+ l2ToL1Messages.sort(sortByCounter),
437
+ minRevertibleSideEffectCounter,
438
+ );
439
+ const [nonRevertibleTaggedPrivateLogs, revertibleTaggedPrivateLogs] = splitOrderedSideEffects(
440
+ taggedPrivateLogs,
441
+ minRevertibleSideEffectCounter,
442
+ );
443
+ const [nonRevertibleContractClassLogHashes, revertibleContractClassLogHashes] = splitOrderedSideEffects(
444
+ contractClassLogsHashes.sort(sortByCounter),
445
+ minRevertibleSideEffectCounter,
446
+ );
447
+ const [nonRevertiblePublicCallRequests, revertiblePublicCallRequests] = splitOrderedSideEffects(
448
+ publicCallRequests.sort(sortByCounter),
449
+ minRevertibleSideEffectCounter,
450
+ );
413
451
 
414
- // The nullifier array contains the nonce generator in position 0
415
- // Here we remove it from the revertible data and
416
- // add it as the first non-revertible nullifier (we can't have dupes!)
417
- // This is because public processor will use that first non-revertible nullifier
418
- // as the nonce generator for the note hashes in the revertible part of the tx.
419
- const [firstNullifier] = sortedNullifiers.splice(0, 1);
420
- nonRevertibleData.nullifiers[0] = firstNullifier;
452
+ const nonRevertibleData = new PrivateToPublicAccumulatedData(
453
+ padArrayEnd(nonRevertibleNoteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
454
+ padArrayEnd(nonRevertibleNullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX),
455
+ padArrayEnd(nonRevertibleL2ToL1Messages, ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX),
456
+ padArrayEnd(nonRevertibleTaggedPrivateLogs, PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX),
457
+ padArrayEnd(nonRevertibleContractClassLogHashes, ScopedLogHash.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX),
458
+ padArrayEnd(nonRevertiblePublicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
459
+ );
421
460
 
422
461
  const revertibleData = new PrivateToPublicAccumulatedData(
423
- padArrayEnd(siloedNoteHashes.sort(sortByCounter).map(getEffect), Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
424
- padArrayEnd(sortedNullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX),
425
- padArrayEnd(
426
- l2ToL1Messages.sort(sortByCounter).map(getEffect),
427
- ScopedL2ToL1Message.empty(),
428
- MAX_L2_TO_L1_MSGS_PER_TX,
429
- ),
430
- padArrayEnd(taggedPrivateLogs.sort(sortByCounter).map(getEffect), PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX),
431
- padArrayEnd(
432
- contractClassLogsHashes.sort(sortByCounter).map(getEffect),
433
- ScopedLogHash.empty(),
434
- MAX_CONTRACT_CLASS_LOGS_PER_TX,
435
- ),
436
- padArrayEnd(
437
- publicCallRequests.sort(sortByCounter).map(getEffect),
438
- PublicCallRequest.empty(),
439
- MAX_ENQUEUED_CALLS_PER_TX,
440
- ),
462
+ padArrayEnd(revertibleNoteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
463
+ padArrayEnd(revertibleNullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX),
464
+ padArrayEnd(revertibleL2ToL1Messages, ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX),
465
+ padArrayEnd(revertibleTaggedPrivateLogs, PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX),
466
+ padArrayEnd(revertibleContractClassLogHashes, ScopedLogHash.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX),
467
+ padArrayEnd(revertiblePublicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
441
468
  );
469
+ gasUsed = meterGasUsed(revertibleData).add(meterGasUsed(nonRevertibleData));
470
+ if (publicTeardownCallRequest) {
471
+ gasUsed.add(privateExecutionResult.entrypoint.publicInputs.txContext.gasSettings.teardownGasLimits);
472
+ }
442
473
 
443
474
  inputsForPublic = new PartialPrivateTailPublicInputsForPublic(
444
475
  nonRevertibleData,
@@ -449,7 +480,7 @@ export async function generateSimulatedProvingResult(
449
480
 
450
481
  const publicInputs = new PrivateKernelTailCircuitPublicInputs(
451
482
  constantData,
452
- /*gasUsed=*/ new Gas(0, 0),
483
+ /*gasUsed=*/ gasUsed.add(Gas.from({ l2Gas: FIXED_L2_GAS, daGas: FIXED_DA_GAS })),
453
484
  /*feePayer=*/ AztecAddress.zero(),
454
485
  /*includeByTimestamp=*/ 0n,
455
486
  hasPublicCalls ? inputsForPublic : undefined,
@@ -462,3 +493,56 @@ export async function generateSimulatedProvingResult(
462
493
  executionSteps: executionSteps,
463
494
  };
464
495
  }
496
+
497
+ function splitOrderedSideEffects<T>(effects: OrderedSideEffect<T>[], minRevertibleSideEffectCounter: number) {
498
+ const revertibleSideEffects: T[] = [];
499
+ const nonRevertibleSideEffects: T[] = [];
500
+ effects.forEach(effect => {
501
+ if (effect.counter < minRevertibleSideEffectCounter) {
502
+ nonRevertibleSideEffects.push(effect.sideEffect);
503
+ } else {
504
+ revertibleSideEffects.push(effect.sideEffect);
505
+ }
506
+ });
507
+ return [nonRevertibleSideEffects, revertibleSideEffects];
508
+ }
509
+
510
+ function meterGasUsed(data: PrivateToRollupAccumulatedData | PrivateToPublicAccumulatedData) {
511
+ let meteredDAFields = 0;
512
+ let meteredL2Gas = 0;
513
+
514
+ const numNoteHashes = arrayNonEmptyLength(data.noteHashes, hash => hash.isEmpty());
515
+ meteredDAFields += numNoteHashes;
516
+ meteredL2Gas += numNoteHashes * AVM_EMITNOTEHASH_BASE_L2_GAS;
517
+
518
+ const numNullifiers = arrayNonEmptyLength(data.nullifiers, nullifier => nullifier.isEmpty());
519
+ meteredDAFields += numNullifiers;
520
+ meteredL2Gas += numNullifiers * AVM_EMITNULLIFIER_BASE_L2_GAS;
521
+
522
+ const numL2toL1Messages = arrayNonEmptyLength(data.l2ToL1Msgs, msg => msg.isEmpty());
523
+ meteredDAFields += numL2toL1Messages;
524
+ meteredL2Gas += numL2toL1Messages * AVM_SENDL2TOL1MSG_BASE_L2_GAS;
525
+
526
+ const numPrivatelogs = arrayNonEmptyLength(data.privateLogs, log => log.isEmpty());
527
+ // Every private log emits its length as an additional field
528
+ meteredDAFields += data.privateLogs.reduce((acc, log) => (!log.isEmpty() ? acc + log.emittedLength + 1 : acc), 0);
529
+ meteredL2Gas += numPrivatelogs * L2_GAS_PER_PRIVATE_LOG;
530
+
531
+ const numContractClassLogs = arrayNonEmptyLength(data.contractClassLogsHashes, log => log.isEmpty());
532
+ // Every contract class log emits its length and contract address as additional fields
533
+ meteredDAFields += data.contractClassLogsHashes.reduce(
534
+ (acc, log) => (!log.isEmpty() ? acc + log.logHash.length + 2 : acc),
535
+ 0,
536
+ );
537
+ meteredL2Gas += numContractClassLogs * L2_GAS_PER_CONTRACT_CLASS_LOG;
538
+
539
+ const meteredDAGas = meteredDAFields * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE;
540
+
541
+ if ((data as PrivateToPublicAccumulatedData).publicCallRequests) {
542
+ const dataForPublic = data as PrivateToPublicAccumulatedData;
543
+
544
+ const numPublicCallRequests = arrayNonEmptyLength(dataForPublic.publicCallRequests, req => req.isEmpty());
545
+ meteredL2Gas += numPublicCallRequests * FIXED_AVM_STARTUP_L2_GAS;
546
+ }
547
+ return Gas.from({ l2Gas: meteredL2Gas, daGas: meteredDAGas });
548
+ }
@@ -5,14 +5,13 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { L2Block } from '@aztec/stdlib/block';
6
6
  import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
7
7
  import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
8
- import { IndexedTaggingSecret } from '@aztec/stdlib/logs';
8
+ import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
9
9
  import type { NoteStatus } from '@aztec/stdlib/note';
10
10
  import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
11
11
  import type { BlockHeader, NodeStats } from '@aztec/stdlib/tx';
12
- import type { UInt64 } from '@aztec/stdlib/types';
13
12
 
13
+ import type { NoteData } from './oracle/interfaces.js';
14
14
  import type { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
15
- import type { NoteData } from './oracle/typed_oracle.js';
16
15
 
17
16
  /**
18
17
  * Error thrown when a contract is not found in the database.
@@ -146,11 +145,12 @@ export interface ExecutionDataProvider {
146
145
  ): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>>;
147
146
 
148
147
  /**
149
- * Retrieve the latest block header synchronized by the PXE.
150
- * @dev This structure is fed into the circuits simulator and is used to prove against certain historical roots.
151
- * @returns The BlockHeader object.
148
+ * Retrieve the latest block header synchronized by the execution data provider. This block header is referred
149
+ * to as the anchor block header in Aztec terminology and it defines the state that is used during private function
150
+ * execution.
151
+ * @returns The anchor block header.
152
152
  */
153
- getBlockHeader(): Promise<BlockHeader>;
153
+ getAnchorBlockHeader(): Promise<BlockHeader>;
154
154
 
155
155
  /**
156
156
  * Fetches the index and sibling path of a leaf at a given block from a given tree.
@@ -215,54 +215,36 @@ export interface ExecutionDataProvider {
215
215
  assertCompatibleOracleVersion(version: number): void;
216
216
 
217
217
  /**
218
- * Fetches the latest block number synchronized by the node.
219
- * @returns The block number.
220
- */
221
- getBlockNumber(): Promise<number>;
222
-
223
- /**
224
- * Fetches the timestamp of the latest block synchronized by the node.
225
- * @returns The timestamp.
226
- */
227
- getTimestamp(): Promise<UInt64>;
228
-
229
- /**
230
- * Fetches the current chain id.
231
- * @returns The chain id.
232
- */
233
- getChainId(): Promise<number>;
234
-
235
- /**
236
- * Fetches the current chain id.
237
- * @returns The chain id.
238
- */
239
- getVersion(): Promise<number>;
240
-
241
- /**
242
- * Returns the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
243
- * Includes the next index to be used used for tagging with this secret.
218
+ * Calculates the directional app tagging secret for a given contract, sender and recipient.
244
219
  * @param contractAddress - The contract address to silo the secret for
245
220
  * @param sender - The address sending the note
246
221
  * @param recipient - The address receiving the note
247
- * @returns A tagging secret that can be used to tag notes.
222
+ * @returns The directional app tagging secret
248
223
  */
249
- getIndexedTaggingSecretAsSender(
224
+ calculateDirectionalAppTaggingSecret(
250
225
  contractAddress: AztecAddress,
251
226
  sender: AztecAddress,
252
227
  recipient: AztecAddress,
253
- ): Promise<IndexedTaggingSecret>;
228
+ ): Promise<DirectionalAppTaggingSecret>;
254
229
 
255
230
  /**
256
- * Increments the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
257
- * @param contractAddress - The contract address to silo the secret for
258
- * @param sender - The address sending the note
259
- * @param recipient - The address receiving the note
231
+ * Updates the local index of the shared tagging secret of a (sender, recipient, contract) tuple if a log with
232
+ * a larger index is found from the node.
233
+ * @param secret - The secret that's unique for (sender, recipient, contract) tuple while the direction
234
+ * of sender -> recipient matters.
235
+ * @param contractAddress - The address of the contract that the logs are tagged for. Needs to be provided to store
236
+ * because the function performs second round of siloing which is necessary because kernels do it as well (they silo
237
+ * first field of the private log which corresponds to the tag).
260
238
  */
261
- incrementAppTaggingSecretIndexAsSender(
262
- contractAddress: AztecAddress,
263
- sender: AztecAddress,
264
- recipient: AztecAddress,
265
- ): Promise<void>;
239
+ syncTaggedLogsAsSender(secret: DirectionalAppTaggingSecret, contractAddress: AztecAddress): Promise<void>;
240
+
241
+ /**
242
+ * Returns the last used index when sending a log with a given secret.
243
+ * @param secret - The directional app tagging secret.
244
+ * @returns The last used index for the given directional app tagging secret, or undefined if we never sent a log
245
+ * from this sender to a recipient in a given contract (implicitly included in the secret).
246
+ */
247
+ getLastUsedIndexAsSender(secret: DirectionalAppTaggingSecret): Promise<number | undefined>;
266
248
 
267
249
  /**
268
250
  * Synchronizes the private logs tagged with scoped addresses and all the senders in the address book. Stores the found
@@ -301,9 +283,9 @@ export interface ExecutionDataProvider {
301
283
  ): Promise<void>;
302
284
 
303
285
  /**
304
- * Removes all of a contract's notes that have been nullified from the note database.
286
+ * Looks for nullifiers of active contract notes and marks them as nullified in the db if a nullifier is found.
305
287
  */
306
- removeNullifiedNotes(contractAddress: AztecAddress): Promise<void>;
288
+ syncNoteNullifiers(contractAddress: AztecAddress): Promise<void>;
307
289
 
308
290
  /**
309
291
  * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
@@ -2,7 +2,7 @@ import { Fr } from '@aztec/foundation/fields';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
4
4
 
5
- import type { NoteData } from './oracle/typed_oracle.js';
5
+ import type { NoteData } from './oracle/interfaces.js';
6
6
 
7
7
  interface PendingNote {
8
8
  note: NoteData;
@@ -126,7 +126,7 @@ export class ExecutionNoteCache {
126
126
  * transaction (and thus not a new note).
127
127
  */
128
128
  public async nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, noteHash: Fr) {
129
- const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
129
+ const siloedNullifier = (await siloNullifier(contractAddress, innerNullifier)).toBigInt();
130
130
  let nullifiedNoteHashCounter: number | undefined = undefined;
131
131
  // Find and remove the matching new note and log(s) if the emitted noteHash is not empty.
132
132
  if (!noteHash.isEmpty()) {
@@ -158,7 +158,7 @@ export class ExecutionNoteCache {
158
158
  * @param innerNullifier
159
159
  */
160
160
  public async nullifierCreated(contractAddress: AztecAddress, innerNullifier: Fr) {
161
- const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
161
+ const siloedNullifier = (await siloNullifier(contractAddress, innerNullifier)).toBigInt();
162
162
  this.recordNullifier(contractAddress, siloedNullifier);
163
163
  }
164
164
 
@@ -208,10 +208,15 @@ export class ExecutionNoteCache {
208
208
  return [...this.allNullifiers].map(n => new Fr(n));
209
209
  }
210
210
 
211
- recordNullifier(contractAddress: AztecAddress, siloedNullifier: Fr) {
211
+ recordNullifier(contractAddress: AztecAddress, siloedNullifier: bigint) {
212
212
  const nullifiers = this.getNullifiers(contractAddress);
213
- nullifiers.add(siloedNullifier.toBigInt());
213
+
214
+ if (nullifiers.has(siloedNullifier)) {
215
+ throw new Error(`Duplicate siloed nullifier ${siloedNullifier} emitted by contract ${contractAddress}`);
216
+ }
217
+
218
+ nullifiers.add(siloedNullifier);
214
219
  this.nullifierMap.set(contractAddress.toBigInt(), nullifiers);
215
- this.allNullifiers.add(siloedNullifier.toBigInt());
220
+ this.allNullifiers.add(siloedNullifier);
216
221
  }
217
222
  }
@@ -0,0 +1,32 @@
1
+ import { DirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
2
+
3
+ /**
4
+ * A map that stores the tagging index for a given directional app tagging secret.
5
+ * Note: The directional app tagging secret is unique for a (sender, recipient, contract) tuple while the direction
6
+ * of sender -> recipient matters.
7
+ */
8
+ export class ExecutionTaggingIndexCache {
9
+ private taggingIndexMap: Map<string, number> = new Map();
10
+
11
+ public getLastUsedIndex(secret: DirectionalAppTaggingSecret): number | undefined {
12
+ return this.taggingIndexMap.get(secret.toString());
13
+ }
14
+
15
+ public setLastUsedIndex(secret: DirectionalAppTaggingSecret, index: number) {
16
+ const currentValue = this.taggingIndexMap.get(secret.toString());
17
+ if (currentValue !== undefined && currentValue !== index - 1) {
18
+ throw new Error(`Invalid tagging index update. Current value: ${currentValue}, new value: ${index}`);
19
+ }
20
+ this.taggingIndexMap.set(secret.toString(), index);
21
+ }
22
+
23
+ /**
24
+ * Returns the pre tags that were used in this execution (and that need to be stored in the db).
25
+ */
26
+ public getUsedPreTags(): PreTag[] {
27
+ return Array.from(this.taggingIndexMap.entries()).map(([secret, index]) => ({
28
+ secret: DirectionalAppTaggingSecret.fromString(secret),
29
+ index,
30
+ }));
31
+ }
32
+ }
@@ -1,7 +1,8 @@
1
1
  export { ExecutionNoteCache } from './execution_note_cache.js';
2
+ export { ExecutionTaggingIndexCache } from './execution_tagging_index_cache.js';
2
3
  export { HashedValuesCache } from './hashed_values_cache.js';
3
4
  export { pickNotes } from './pick_notes.js';
4
- export { type NoteData, TypedOracle } from './oracle/typed_oracle.js';
5
+ export type { NoteData, IMiscOracle, IUtilityExecutionOracle, IPrivateExecutionOracle } from './oracle/interfaces.js';
5
6
  export { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
6
7
  export { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
7
8
  export { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
@@ -9,3 +10,4 @@ export { Oracle } from './oracle/oracle.js';
9
10
  export { executePrivateFunction, extractPrivateCircuitPublicInputs } from './oracle/private_execution.js';
10
11
  export { generateSimulatedProvingResult } from './contract_function_simulator.js';
11
12
  export { packAsRetrievedNote } from './oracle/note_packing_utils.js';
13
+ export { UtilityContext } from './noir-structs/utility_context.js';
@@ -1,9 +1,12 @@
1
- import { MAX_NOTE_HASHES_PER_TX, PRIVATE_LOG_CIPHERTEXT_LEN, PUBLIC_LOG_PLAINTEXT_LEN } from '@aztec/constants';
1
+ import { MAX_NOTE_HASHES_PER_TX, PRIVATE_LOG_CIPHERTEXT_LEN } from '@aztec/constants';
2
2
  import { range } from '@aztec/foundation/array';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
4
  import type { TxHash } from '@aztec/stdlib/tx';
5
5
 
6
- const MAX_LOG_CONTENT_LEN = Math.max(PUBLIC_LOG_PLAINTEXT_LEN, PRIVATE_LOG_CIPHERTEXT_LEN);
6
+ import { MAX_NOTE_PACKED_LEN } from './note_validation_request.js';
7
+
8
+ const MAX_PUBLIC_LOG_LEN_FOR_NOTE_COMPLETION = MAX_NOTE_PACKED_LEN;
9
+ const MAX_LOG_CONTENT_LEN = Math.max(MAX_PUBLIC_LOG_LEN_FOR_NOTE_COMPLETION, PRIVATE_LOG_CIPHERTEXT_LEN);
7
10
 
8
11
  /**
9
12
  * Intermediate struct used to perform batch log retrieval by PXE. The `utilityBulkRetrieveLogs` oracle stores values of this
@@ -19,7 +22,9 @@ export class LogRetrievalResponse {
19
22
 
20
23
  toFields(): Fr[] {
21
24
  return [
22
- ...serializeBoundedVec(this.logPayload, MAX_LOG_CONTENT_LEN),
25
+ // We need to trim the payload since public logs can be larger than MAX_LOG_CONTENT_LEN.
26
+ // This is currently not a problem since this class is only used with public logs for note completion.
27
+ ...serializeBoundedVec(this.logPayload.slice(0, MAX_LOG_CONTENT_LEN), MAX_LOG_CONTENT_LEN),
23
28
  this.txHash.hash,
24
29
  ...serializeBoundedVec(this.uniqueNoteHashesInTx, MAX_NOTE_HASHES_PER_TX),
25
30
  this.firstNullifierInTx,
@@ -4,7 +4,7 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { TxHash } from '@aztec/stdlib/tx';
5
5
 
6
6
  // TODO(#14617): should we compute this from constants? This value is aztec-nr specific.
7
- const MAX_NOTE_PACKED_LEN = 12;
7
+ export const MAX_NOTE_PACKED_LEN = 12;
8
8
 
9
9
  /**
10
10
  * Intermediate struct used to perform batch note validation by PXE. The `utilityValidateEnqueuedNotesAndEvents` oracle
@@ -0,0 +1,42 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import type { FieldsOf } from '@aztec/foundation/types';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { UInt64 } from '@aztec/stdlib/types';
5
+
6
+ /**
7
+ * TypeScript counterpart of utility_context.nr. Used only as a return value for the utilityGetUtilityContext oracle.
8
+ */
9
+ export class UtilityContext {
10
+ private constructor(
11
+ public readonly blockNumber: number,
12
+ public readonly timestamp: UInt64,
13
+ public readonly contractAddress: AztecAddress,
14
+ public readonly version: Fr,
15
+ public readonly chainId: Fr,
16
+ ) {}
17
+
18
+ static from(fields: FieldsOf<UtilityContext>) {
19
+ return new UtilityContext(
20
+ fields.blockNumber,
21
+ fields.timestamp,
22
+ fields.contractAddress,
23
+ fields.version,
24
+ fields.chainId,
25
+ );
26
+ }
27
+
28
+ /**
29
+ * Returns a representation of the utility context as expected by intrinsic Noir deserialization.
30
+ * The order of the fields has to be the same as the order of the fields in the utility_context.nr.
31
+ */
32
+ public toNoirRepresentation(): (string | string[])[] {
33
+ // TODO(#12874): remove the stupid as string conversion by modifying ForeignCallOutput type in acvm.js
34
+ return [
35
+ new Fr(this.blockNumber).toString() as string,
36
+ new Fr(this.timestamp).toString() as string,
37
+ this.contractAddress.toString() as string,
38
+ this.version.toString() as string,
39
+ this.chainId.toString() as string,
40
+ ];
41
+ }
42
+ }
@@ -1,7 +1,7 @@
1
1
  import type { Oracle } from './oracle.js';
2
2
 
3
3
  export * from './oracle.js';
4
- export * from './typed_oracle.js';
4
+ export * from './interfaces.js';
5
5
 
6
6
  /**
7
7
  * A conditional type that takes a type `T` and returns a union of its method names.