@aztec/pxe 0.0.1-commit.3895657bc → 0.0.1-commit.3e3d0c9cd

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 (83) hide show
  1. package/dest/contract_function_simulator/contract_function_simulator.d.ts +9 -3
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  3. package/dest/contract_function_simulator/contract_function_simulator.js +17 -3
  4. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  5. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/execution_tagging_index_cache.js +17 -9
  7. package/dest/contract_function_simulator/index.d.ts +2 -1
  8. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/index.js +1 -0
  10. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -3
  11. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -4
  13. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  14. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  15. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  16. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +16 -0
  17. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
  18. package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
  19. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -4
  20. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  21. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -5
  22. package/dest/contract_function_simulator/oracle/interfaces.d.ts +13 -9
  23. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  25. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  26. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +43 -0
  27. package/dest/contract_function_simulator/oracle/oracle.d.ts +6 -6
  28. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/oracle/oracle.js +21 -15
  30. package/dest/contract_function_simulator/oracle/private_execution.js +4 -2
  31. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +8 -30
  32. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +7 -37
  34. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +19 -7
  35. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +60 -7
  37. package/dest/messages/message_context_service.d.ts +17 -0
  38. package/dest/messages/message_context_service.d.ts.map +1 -0
  39. package/dest/messages/message_context_service.js +36 -0
  40. package/dest/oracle_version.d.ts +2 -2
  41. package/dest/oracle_version.js +2 -2
  42. package/dest/pxe.d.ts +6 -3
  43. package/dest/pxe.d.ts.map +1 -1
  44. package/dest/pxe.js +27 -17
  45. package/dest/storage/metadata.d.ts +1 -1
  46. package/dest/storage/metadata.js +1 -1
  47. package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
  48. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  49. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  50. package/dest/tagging/index.d.ts +2 -2
  51. package/dest/tagging/index.d.ts.map +1 -1
  52. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
  53. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  54. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
  55. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  56. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  57. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  58. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
  59. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  60. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
  61. package/package.json +16 -16
  62. package/src/contract_function_simulator/contract_function_simulator.ts +25 -3
  63. package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
  64. package/src/contract_function_simulator/index.ts +1 -0
  65. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -5
  66. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  67. package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
  68. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -6
  69. package/src/contract_function_simulator/oracle/interfaces.ts +16 -17
  70. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +142 -0
  71. package/src/contract_function_simulator/oracle/oracle.ts +30 -40
  72. package/src/contract_function_simulator/oracle/private_execution.ts +3 -3
  73. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +9 -53
  74. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +90 -9
  75. package/src/messages/message_context_service.ts +45 -0
  76. package/src/oracle_version.ts +2 -2
  77. package/src/pxe.ts +45 -16
  78. package/src/storage/metadata.ts +1 -1
  79. package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
  80. package/src/tagging/index.ts +1 -1
  81. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
  82. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  83. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
@@ -10,6 +10,7 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
10
10
  * @param end - The ending index (exclusive) of the window to process.
11
11
  * @param aztecNode - The Aztec node instance to query for logs.
12
12
  * @param taggingStore - The data provider to store pending indexes.
13
+ * @param anchorBlockHash - Hash of a block to use as reference block when querying node.
13
14
  * @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
14
15
  * preserving way.
15
16
  */ export async function loadAndStoreNewTaggingIndexes(extendedSecret, start, end, aztecNode, taggingStore, anchorBlockHash, jobId) {
@@ -21,16 +22,18 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
21
22
  index: start + i
22
23
  })));
23
24
  const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode, anchorBlockHash);
24
- const highestIndexMap = getTxHighestIndexMap(txsForTags, start, siloedTagsForWindow.length);
25
- // Now we iterate over the map, reconstruct the preTags and tx hash and store them in the db.
26
- for (const [txHashStr, highestIndex] of highestIndexMap.entries()){
25
+ const txIndexesMap = getTxIndexesMap(txsForTags, start, siloedTagsForWindow.length);
26
+ // Now we iterate over the map, construct the tagging index ranges and store them in the db.
27
+ for (const [txHashStr, indexes] of txIndexesMap.entries()){
27
28
  const txHash = TxHash.fromString(txHashStr);
28
- await taggingStore.storePendingIndexes([
29
+ const ranges = [
29
30
  {
30
31
  extendedSecret,
31
- index: highestIndex
32
+ lowestIndex: Math.min(...indexes),
33
+ highestIndex: Math.max(...indexes)
32
34
  }
33
- ], txHash, jobId);
35
+ ];
36
+ await taggingStore.storePendingIndexes(ranges, txHash, jobId);
34
37
  }
35
38
  }
36
39
  // Returns txs that used the given tags. A tag might have been used in multiple txs and for this reason we return
@@ -41,19 +44,29 @@ async function getTxsContainingTags(tags, aztecNode, anchorBlockHash) {
41
44
  const allLogs = await getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash);
42
45
  return allLogs.map((logs)=>logs.map((log)=>log.txHash));
43
46
  }
44
- // Returns a map of txHash to the highest index for that txHash.
45
- function getTxHighestIndexMap(txHashesForTags, start, count) {
47
+ // Returns a map of txHash to all indexes for that txHash.
48
+ function getTxIndexesMap(txHashesForTags, start, count) {
46
49
  if (txHashesForTags.length !== count) {
47
50
  throw new Error(`Number of tx hashes arrays does not match number of tags. ${txHashesForTags.length} !== ${count}`);
48
51
  }
49
- const highestIndexMap = new Map();
52
+ const indexesMap = new Map();
53
+ // Iterate over indexes
50
54
  for(let i = 0; i < txHashesForTags.length; i++){
51
55
  const taggingIndex = start + i;
52
56
  const txHashesForTag = txHashesForTags[i];
57
+ // iterate over tx hashes that used that index (tag)
53
58
  for (const txHash of txHashesForTag){
54
59
  const key = txHash.toString();
55
- highestIndexMap.set(key, Math.max(highestIndexMap.get(key) ?? 0, taggingIndex));
60
+ const existing = indexesMap.get(key);
61
+ // Add the index to the tx's indexes
62
+ if (existing) {
63
+ existing.push(taggingIndex);
64
+ } else {
65
+ indexesMap.set(key, [
66
+ taggingIndex
67
+ ]);
68
+ }
56
69
  }
57
70
  }
58
- return highestIndexMap;
71
+ return indexesMap;
59
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/pxe",
3
- "version": "0.0.1-commit.3895657bc",
3
+ "version": "0.0.1-commit.3e3d0c9cd",
4
4
  "type": "module",
5
5
  "typedocOptions": {
6
6
  "entryPoints": [
@@ -70,19 +70,19 @@
70
70
  ]
71
71
  },
72
72
  "dependencies": {
73
- "@aztec/bb-prover": "0.0.1-commit.3895657bc",
74
- "@aztec/bb.js": "0.0.1-commit.3895657bc",
75
- "@aztec/builder": "0.0.1-commit.3895657bc",
76
- "@aztec/constants": "0.0.1-commit.3895657bc",
77
- "@aztec/ethereum": "0.0.1-commit.3895657bc",
78
- "@aztec/foundation": "0.0.1-commit.3895657bc",
79
- "@aztec/key-store": "0.0.1-commit.3895657bc",
80
- "@aztec/kv-store": "0.0.1-commit.3895657bc",
81
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.3895657bc",
82
- "@aztec/noir-types": "0.0.1-commit.3895657bc",
83
- "@aztec/protocol-contracts": "0.0.1-commit.3895657bc",
84
- "@aztec/simulator": "0.0.1-commit.3895657bc",
85
- "@aztec/stdlib": "0.0.1-commit.3895657bc",
73
+ "@aztec/bb-prover": "0.0.1-commit.3e3d0c9cd",
74
+ "@aztec/bb.js": "0.0.1-commit.3e3d0c9cd",
75
+ "@aztec/builder": "0.0.1-commit.3e3d0c9cd",
76
+ "@aztec/constants": "0.0.1-commit.3e3d0c9cd",
77
+ "@aztec/ethereum": "0.0.1-commit.3e3d0c9cd",
78
+ "@aztec/foundation": "0.0.1-commit.3e3d0c9cd",
79
+ "@aztec/key-store": "0.0.1-commit.3e3d0c9cd",
80
+ "@aztec/kv-store": "0.0.1-commit.3e3d0c9cd",
81
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.3e3d0c9cd",
82
+ "@aztec/noir-types": "0.0.1-commit.3e3d0c9cd",
83
+ "@aztec/protocol-contracts": "0.0.1-commit.3e3d0c9cd",
84
+ "@aztec/simulator": "0.0.1-commit.3e3d0c9cd",
85
+ "@aztec/stdlib": "0.0.1-commit.3e3d0c9cd",
86
86
  "koa": "^2.16.1",
87
87
  "koa-router": "^13.1.1",
88
88
  "lodash.omit": "^4.5.0",
@@ -91,8 +91,8 @@
91
91
  "viem": "npm:@aztec/viem@2.38.2"
92
92
  },
93
93
  "devDependencies": {
94
- "@aztec/merkle-tree": "0.0.1-commit.3895657bc",
95
- "@aztec/noir-test-contracts.js": "0.0.1-commit.3895657bc",
94
+ "@aztec/noir-test-contracts.js": "0.0.1-commit.3e3d0c9cd",
95
+ "@aztec/world-state": "0.0.1-commit.3e3d0c9cd",
96
96
  "@jest/globals": "^30.0.0",
97
97
  "@types/jest": "^30.0.0",
98
98
  "@types/lodash.omit": "^4.5.7",
@@ -17,6 +17,7 @@ import {
17
17
  MAX_NULLIFIERS_PER_TX,
18
18
  MAX_NULLIFIER_READ_REQUESTS_PER_TX,
19
19
  MAX_PRIVATE_LOGS_PER_TX,
20
+ MAX_TX_LIFETIME,
20
21
  PRIVATE_TX_L2_GAS_OVERHEAD,
21
22
  PUBLIC_TX_L2_GAS_OVERHEAD,
22
23
  TX_DA_GAS_OVERHEAD,
@@ -79,6 +80,7 @@ import {
79
80
  BlockHeader,
80
81
  CallContext,
81
82
  HashedValues,
83
+ type OffchainEffect,
82
84
  PrivateExecutionResult,
83
85
  TxConstantData,
84
86
  TxExecutionRequest,
@@ -89,6 +91,7 @@ import {
89
91
 
90
92
  import type { AccessScopes } from '../access_scopes.js';
91
93
  import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
94
+ import type { MessageContextService } from '../messages/message_context_service.js';
92
95
  import type { AddressStore } from '../storage/address_store/address_store.js';
93
96
  import type { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
94
97
  import type { ContractStore } from '../storage/contract_store/contract_store.js';
@@ -138,6 +141,7 @@ export type ContractFunctionSimulatorArgs = {
138
141
  privateEventStore: PrivateEventStore;
139
142
  simulator: CircuitSimulator;
140
143
  contractSyncService: ContractSyncService;
144
+ messageContextService: MessageContextService;
141
145
  };
142
146
 
143
147
  /**
@@ -157,6 +161,7 @@ export class ContractFunctionSimulator {
157
161
  private readonly privateEventStore: PrivateEventStore;
158
162
  private readonly simulator: CircuitSimulator;
159
163
  private readonly contractSyncService: ContractSyncService;
164
+ private readonly messageContextService: MessageContextService;
160
165
 
161
166
  constructor(args: ContractFunctionSimulatorArgs) {
162
167
  this.contractStore = args.contractStore;
@@ -171,6 +176,7 @@ export class ContractFunctionSimulator {
171
176
  this.privateEventStore = args.privateEventStore;
172
177
  this.simulator = args.simulator;
173
178
  this.contractSyncService = args.contractSyncService;
179
+ this.messageContextService = args.messageContextService;
174
180
  this.log = createLogger('simulator');
175
181
  }
176
182
 
@@ -241,6 +247,7 @@ export class ContractFunctionSimulator {
241
247
  senderAddressBookStore: this.senderAddressBookStore,
242
248
  capsuleStore: this.capsuleStore,
243
249
  privateEventStore: this.privateEventStore,
250
+ messageContextService: this.messageContextService,
244
251
  contractSyncService: this.contractSyncService,
245
252
  jobId,
246
253
  totalPublicCalldataCount: 0,
@@ -314,7 +321,7 @@ export class ContractFunctionSimulator {
314
321
  anchorBlockHeader: BlockHeader,
315
322
  scopes: AccessScopes,
316
323
  jobId: string,
317
- ): Promise<Fr[]> {
324
+ ): Promise<{ result: Fr[]; offchainEffects: OffchainEffect[] }> {
318
325
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
319
326
 
320
327
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
@@ -335,6 +342,7 @@ export class ContractFunctionSimulator {
335
342
  senderAddressBookStore: this.senderAddressBookStore,
336
343
  capsuleStore: this.capsuleStore,
337
344
  privateEventStore: this.privateEventStore,
345
+ messageContextService: this.messageContextService,
338
346
  jobId,
339
347
  scopes,
340
348
  });
@@ -362,7 +370,10 @@ export class ContractFunctionSimulator {
362
370
  });
363
371
 
364
372
  this.log.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
365
- return witnessMapToFields(acirExecutionResult.returnWitness);
373
+ return {
374
+ result: witnessMapToFields(acirExecutionResult.returnWitness),
375
+ offchainEffects: oracle.getOffchainEffects(),
376
+ };
366
377
  } catch (err) {
367
378
  throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
368
379
  }
@@ -432,12 +443,23 @@ export async function generateSimulatedProvingResult(
432
443
 
433
444
  let publicTeardownCallRequest;
434
445
 
446
+ // We set expiration timestamp to anchor_block_timestamp + MAX_TX_LIFETIME (24h) just like kernels do
447
+ let expirationTimestamp =
448
+ privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader.globalVariables.timestamp +
449
+ BigInt(MAX_TX_LIFETIME);
450
+
435
451
  const executions = [privateExecutionResult.entrypoint];
436
452
 
437
453
  while (executions.length !== 0) {
438
454
  const execution = executions.shift()!;
439
455
  executions.unshift(...execution!.nestedExecutionResults);
440
456
 
457
+ // Just like kernels we overwrite the default value if the call sets it.
458
+ const callExpirationTimestamp = execution.publicInputs.expirationTimestamp;
459
+ if (callExpirationTimestamp !== 0n && callExpirationTimestamp < expirationTimestamp) {
460
+ expirationTimestamp = callExpirationTimestamp;
461
+ }
462
+
441
463
  const { contractAddress } = execution.publicInputs.callContext;
442
464
 
443
465
  scopedNoteHashes.push(
@@ -661,7 +683,7 @@ export async function generateSimulatedProvingResult(
661
683
  }),
662
684
  ),
663
685
  /*feePayer=*/ AztecAddress.zero(),
664
- /*expirationTimestamp=*/ 0n,
686
+ /*expirationTimestamp=*/ expirationTimestamp,
665
687
  hasPublicCalls ? inputsForPublic : undefined,
666
688
  !hasPublicCalls ? inputsForRollup : undefined,
667
689
  );
@@ -1,32 +1,37 @@
1
- import { ExtendedDirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
1
+ import { ExtendedDirectionalAppTaggingSecret, type TaggingIndexRange } from '@aztec/stdlib/logs';
2
2
 
3
3
  /**
4
- * A map that stores the tagging index for a given extended directional app tagging secret.
4
+ * A map that stores the tagging index range for a given extended directional app tagging secret.
5
5
  * Note: The directional app tagging secret is unique for a (sender, recipient, contract) tuple while the direction
6
6
  * of sender -> recipient matters.
7
7
  */
8
8
  export class ExecutionTaggingIndexCache {
9
- private taggingIndexMap: Map<string, number> = new Map();
9
+ private taggingIndexMap: Map<string, { lowestIndex: number; highestIndex: number }> = new Map();
10
10
 
11
11
  public getLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret): number | undefined {
12
- return this.taggingIndexMap.get(secret.toString());
12
+ return this.taggingIndexMap.get(secret.toString())?.highestIndex;
13
13
  }
14
14
 
15
15
  public setLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret, index: number) {
16
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}`);
17
+ if (currentValue !== undefined && currentValue.highestIndex !== index - 1) {
18
+ throw new Error(`Invalid tagging index update. Current value: ${currentValue.highestIndex}, new value: ${index}`);
19
+ }
20
+ if (currentValue !== undefined) {
21
+ currentValue.highestIndex = index;
22
+ } else {
23
+ this.taggingIndexMap.set(secret.toString(), { lowestIndex: index, highestIndex: index });
19
24
  }
20
- this.taggingIndexMap.set(secret.toString(), index);
21
25
  }
22
26
 
23
27
  /**
24
- * Returns the pre-tags that were used in this execution (and that need to be stored in the db).
28
+ * Returns the tagging index ranges that were used in this execution (and that need to be stored in the db).
25
29
  */
26
- public getUsedPreTags(): PreTag[] {
27
- return Array.from(this.taggingIndexMap.entries()).map(([secret, index]) => ({
30
+ public getUsedTaggingIndexRanges(): TaggingIndexRange[] {
31
+ return Array.from(this.taggingIndexMap.entries()).map(([secret, { lowestIndex, highestIndex }]) => ({
28
32
  extendedSecret: ExtendedDirectionalAppTaggingSecret.fromString(secret),
29
- index,
33
+ lowestIndex,
34
+ highestIndex,
30
35
  }));
31
36
  }
32
37
  }
@@ -4,6 +4,7 @@ export { HashedValuesCache } from './hashed_values_cache.js';
4
4
  export { pickNotes } from './pick_notes.js';
5
5
  export type { NoteData, IMiscOracle, IUtilityExecutionOracle, IPrivateExecutionOracle } from './oracle/interfaces.js';
6
6
  export { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
7
+ export { MessageContextService } from '../messages/message_context_service.js';
7
8
  export { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
8
9
  export { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
9
10
  export { Oracle } from './oracle/oracle.js';
@@ -4,9 +4,6 @@ import { EventSelector } from '@aztec/stdlib/abi';
4
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import { TxHash } from '@aztec/stdlib/tx';
6
6
 
7
- // TODO(#14617): should we compute this from constants? This value is aztec-nr specific.
8
- const MAX_EVENT_SERIALIZED_LEN = 10;
9
-
10
7
  /**
11
8
  * Intermediate struct used to perform batch event validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle
12
9
  * expects for values of this type to be stored in a `CapsuleArray`.
@@ -22,7 +19,7 @@ export class EventValidationRequest {
22
19
  public recipient: AztecAddress,
23
20
  ) {}
24
21
 
25
- static fromFields(fields: Fr[] | FieldReader): EventValidationRequest {
22
+ static fromFields(fields: Fr[], maxEventSerializedLen: number): EventValidationRequest {
26
23
  const reader = FieldReader.asReader(fields);
27
24
 
28
25
  const contractAddress = AztecAddress.fromField(reader.readField());
@@ -30,7 +27,7 @@ export class EventValidationRequest {
30
27
 
31
28
  const randomness = reader.readField();
32
29
 
33
- const eventStorage = reader.readFieldArray(MAX_EVENT_SERIALIZED_LEN);
30
+ const eventStorage = reader.readFieldArray(maxEventSerializedLen);
34
31
  const eventLen = reader.readField().toNumber();
35
32
  const serializedEvent = eventStorage.slice(0, eventLen);
36
33
 
@@ -38,6 +35,12 @@ export class EventValidationRequest {
38
35
  const txHash = TxHash.fromField(reader.readField());
39
36
  const recipient = AztecAddress.fromField(reader.readField());
40
37
 
38
+ if (reader.remainingFields() !== 0) {
39
+ throw new Error(
40
+ `Error converting array of fields to EventValidationRequest: expected ${reader.cursor} fields but received ${fields.length} (maxEventSerializedLen=${maxEventSerializedLen}).`,
41
+ );
42
+ }
43
+
41
44
  return new EventValidationRequest(
42
45
  contractAddress,
43
46
  eventTypeId,
@@ -3,10 +3,7 @@ import { range } from '@aztec/foundation/array';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import type { TxHash } from '@aztec/stdlib/tx';
5
5
 
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);
6
+ const MAX_LOG_CONTENT_LEN = PRIVATE_LOG_CIPHERTEXT_LEN;
10
7
 
11
8
  /**
12
9
  * Intermediate struct used to perform batch log retrieval by PXE. The `utilityBulkRetrieveLogs` oracle stores values of this
@@ -0,0 +1,55 @@
1
+ import { MAX_NOTE_HASHES_PER_TX } from '@aztec/constants';
2
+ import { range } from '@aztec/foundation/array';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import type { TxHash } from '@aztec/stdlib/tx';
5
+
6
+ /**
7
+ * Intermediate struct used to return resolved message contexts from PXE. The
8
+ * `utilityResolveMessageContexts` oracle stores values of this type in a CapsuleArray.
9
+ */
10
+ export class MessageTxContext {
11
+ constructor(
12
+ public txHash: TxHash,
13
+ public uniqueNoteHashesInTx: Fr[],
14
+ public firstNullifierInTx: Fr,
15
+ ) {}
16
+
17
+ toFields(): Fr[] {
18
+ return [
19
+ this.txHash.hash,
20
+ ...serializeBoundedVec(this.uniqueNoteHashesInTx, MAX_NOTE_HASHES_PER_TX),
21
+ this.firstNullifierInTx,
22
+ ];
23
+ }
24
+
25
+ static toEmptyFields(): Fr[] {
26
+ const serializationLen =
27
+ 1 /* txHash */ + MAX_NOTE_HASHES_PER_TX + 1 /* uniqueNoteHashesInTx BVec */ + 1; /* firstNullifierInTx */
28
+ return range(serializationLen).map(_ => Fr.zero());
29
+ }
30
+
31
+ static toSerializedOption(response: MessageTxContext | null): Fr[] {
32
+ if (response) {
33
+ return [new Fr(1), ...response.toFields()];
34
+ } else {
35
+ return [new Fr(0), ...MessageTxContext.toEmptyFields()];
36
+ }
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Helper function to serialize a bounded vector according to Noir's BoundedVec format
42
+ * @param values - The values to serialize
43
+ * @param maxLength - The maximum length of the bounded vector
44
+ * @returns The serialized bounded vector as Fr[]
45
+ */
46
+ function serializeBoundedVec(values: Fr[], maxLength: number): Fr[] {
47
+ if (values.length > maxLength) {
48
+ throw new Error(`Attempted to serialize ${values} values into a BoundedVec with max length ${maxLength}`);
49
+ }
50
+
51
+ const lengthDiff = maxLength - values.length;
52
+ const zeroPaddingArray = Array(lengthDiff).fill(Fr.ZERO);
53
+ const storage = values.concat(zeroPaddingArray);
54
+ return [...storage, new Fr(values.length)];
55
+ }
@@ -3,9 +3,6 @@ import { FieldReader } from '@aztec/foundation/serialize';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { TxHash } from '@aztec/stdlib/tx';
5
5
 
6
- // TODO(#14617): should we compute this from constants? This value is aztec-nr specific.
7
- export const MAX_NOTE_PACKED_LEN = 8;
8
-
9
6
  /**
10
7
  * Intermediate struct used to perform batch note validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle
11
8
  * expects for values of this type to be stored in a `CapsuleArray`.
@@ -24,7 +21,7 @@ export class NoteValidationRequest {
24
21
  public recipient: AztecAddress,
25
22
  ) {}
26
23
 
27
- static fromFields(fields: Fr[] | FieldReader): NoteValidationRequest {
24
+ static fromFields(fields: Fr[], maxNotePackedLen: number): NoteValidationRequest {
28
25
  const reader = FieldReader.asReader(fields);
29
26
 
30
27
  const contractAddress = AztecAddress.fromField(reader.readField());
@@ -33,7 +30,7 @@ export class NoteValidationRequest {
33
30
  const randomness = reader.readField();
34
31
  const noteNonce = reader.readField();
35
32
 
36
- const contentStorage = reader.readFieldArray(MAX_NOTE_PACKED_LEN);
33
+ const contentStorage = reader.readFieldArray(maxNotePackedLen);
37
34
  const contentLen = reader.readField().toNumber();
38
35
  const content = contentStorage.slice(0, contentLen);
39
36
 
@@ -44,7 +41,7 @@ export class NoteValidationRequest {
44
41
 
45
42
  if (reader.remainingFields() !== 0) {
46
43
  throw new Error(
47
- `Error converting array of fields to NoteValidationRequest. Hint: check that MAX_NOTE_PACKED_LEN is consistent with private_notes::MAX_NOTE_PACKED_LEN in Aztec-nr.`,
44
+ `Error converting array of fields to NoteValidationRequest: expected ${reader.cursor} fields but received ${fields.length} (maxNotePackedLen=${maxNotePackedLen}).`,
48
45
  );
49
46
  }
50
47
 
@@ -6,8 +6,9 @@ import { MembershipWitness } from '@aztec/foundation/trees';
6
6
  import type { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
7
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
8
  import { BlockHash } from '@aztec/stdlib/block';
9
- import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
9
+ import type { ContractInstance, PartialAddress } from '@aztec/stdlib/contract';
10
10
  import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
11
+ import type { PublicKeys } from '@aztec/stdlib/keys';
11
12
  import type { ContractClassLog, Tag } from '@aztec/stdlib/logs';
12
13
  import type { Note, NoteStatus } from '@aztec/stdlib/note';
13
14
  import { type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
@@ -85,7 +86,9 @@ export interface IUtilityExecutionOracle {
85
86
  nullifier: Fr,
86
87
  ): Promise<NullifierMembershipWitness | undefined>;
87
88
  getBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined>;
88
- tryGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<CompleteAddress | undefined>;
89
+ tryGetPublicKeysAndPartialAddress(
90
+ account: AztecAddress,
91
+ ): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined>;
89
92
  getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined>;
90
93
  getNotes(
91
94
  owner: AztecAddress | undefined,
@@ -121,18 +124,26 @@ export interface IUtilityExecutionOracle {
121
124
  contractAddress: AztecAddress,
122
125
  noteValidationRequestsArrayBaseSlot: Fr,
123
126
  eventValidationRequestsArrayBaseSlot: Fr,
127
+ maxNotePackedLen: number,
128
+ maxEventSerializedLen: number,
124
129
  ): Promise<void>;
125
130
  bulkRetrieveLogs(
126
131
  contractAddress: AztecAddress,
127
132
  logRetrievalRequestsArrayBaseSlot: Fr,
128
133
  logRetrievalResponsesArrayBaseSlot: Fr,
129
134
  ): Promise<void>;
135
+ utilityResolveMessageContexts(
136
+ contractAddress: AztecAddress,
137
+ messageContextRequestsArrayBaseSlot: Fr,
138
+ messageContextResponsesArrayBaseSlot: Fr,
139
+ ): Promise<void>;
130
140
  storeCapsule(contractAddress: AztecAddress, key: Fr, capsule: Fr[]): Promise<void>;
131
141
  loadCapsule(contractAddress: AztecAddress, key: Fr): Promise<Fr[] | null>;
132
142
  deleteCapsule(contractAddress: AztecAddress, key: Fr): Promise<void>;
133
143
  copyCapsule(contractAddress: AztecAddress, srcKey: Fr, dstKey: Fr, numEntries: number): Promise<void>;
134
144
  aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
135
145
  getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point>;
146
+ emitOffchainEffect(data: Fr[]): Promise<void>;
136
147
  }
137
148
 
138
149
  /**
@@ -164,22 +175,10 @@ export interface IPrivateExecutionOracle {
164
175
  sideEffectCounter: number,
165
176
  isStaticCall: boolean,
166
177
  ): Promise<{ endSideEffectCounter: Fr; returnsHash: Fr }>;
167
- notifyEnqueuedPublicFunctionCall(
168
- targetContractAddress: AztecAddress,
169
- calldataHash: Fr,
170
- sideEffectCounter: number,
171
- isStaticCall: boolean,
172
- ): Promise<void>;
173
- notifySetPublicTeardownFunctionCall(
174
- targetContractAddress: AztecAddress,
175
- calldataHash: Fr,
176
- sideEffectCounter: number,
177
- isStaticCall: boolean,
178
- ): Promise<void>;
179
- notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): Promise<void>;
180
- isSideEffectCounterRevertible(sideEffectCounter: number): Promise<boolean>;
178
+ validatePublicCalldata(calldataHash: Fr): Promise<void>;
179
+ notifyRevertiblePhaseStart(minRevertibleSideEffectCounter: number): Promise<void>;
180
+ inRevertiblePhase(sideEffectCounter: number): Promise<boolean>;
181
181
  getSenderForTags(): Promise<AztecAddress | undefined>;
182
182
  setSenderForTags(senderForTags: AztecAddress): Promise<void>;
183
183
  getNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Tag>;
184
- emitOffchainEffect(data: Fr[]): Promise<void>;
185
184
  }
@@ -0,0 +1,142 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { ACIRCallback, ACVMField } from '@aztec/simulator/client';
3
+
4
+ import type { Oracle } from './oracle.js';
5
+
6
+ /**
7
+ * Builds legacy oracle name callbacks for pinned protocol contracts whose artifacts are committed and cannot be
8
+ * changed.
9
+ * TODO(F-416): Remove these aliases on v5 when protocol contracts are redeployed.
10
+ */
11
+ export function buildLegacyOracleCallbacks(oracle: Oracle): ACIRCallback {
12
+ return {
13
+ // Simple prefix renames (privateXxx/utilityXxx → aztec_prv_/aztec_utl_)
14
+ utilityLog: (
15
+ level: ACVMField[],
16
+ message: ACVMField[],
17
+ _ignoredFieldsSize: ACVMField[],
18
+ fields: ACVMField[],
19
+ ): Promise<ACVMField[]> => oracle.aztec_utl_log(level, message, _ignoredFieldsSize, fields),
20
+ utilityAssertCompatibleOracleVersion: (version: ACVMField[]): Promise<ACVMField[]> =>
21
+ oracle.aztec_utl_assertCompatibleOracleVersion(version),
22
+ utilityLoadCapsule: (
23
+ contractAddress: ACVMField[],
24
+ slot: ACVMField[],
25
+ tSize: ACVMField[],
26
+ ): Promise<(ACVMField | ACVMField[])[]> => oracle.aztec_utl_loadCapsule(contractAddress, slot, tSize),
27
+ privateStoreInExecutionCache: (values: ACVMField[], hash: ACVMField[]): Promise<ACVMField[]> =>
28
+ oracle.aztec_prv_storeInExecutionCache(values, hash),
29
+ privateLoadFromExecutionCache: (returnsHash: ACVMField[]): Promise<ACVMField[][]> =>
30
+ oracle.aztec_prv_loadFromExecutionCache(returnsHash),
31
+ privateCallPrivateFunction: (
32
+ contractAddress: ACVMField[],
33
+ functionSelector: ACVMField[],
34
+ argsHash: ACVMField[],
35
+ sideEffectCounter: ACVMField[],
36
+ isStaticCall: ACVMField[],
37
+ ): Promise<ACVMField[][]> =>
38
+ oracle.aztec_prv_callPrivateFunction(
39
+ contractAddress,
40
+ functionSelector,
41
+ argsHash,
42
+ sideEffectCounter,
43
+ isStaticCall,
44
+ ),
45
+ privateIsNullifierPending: (innerNullifier: ACVMField[], contractAddress: ACVMField[]): Promise<ACVMField[]> =>
46
+ oracle.aztec_prv_isNullifierPending(innerNullifier, contractAddress),
47
+ privateNotifyCreatedNullifier: (innerNullifier: ACVMField[]): Promise<ACVMField[]> =>
48
+ oracle.aztec_prv_notifyCreatedNullifier(innerNullifier),
49
+ privateNotifyCreatedContractClassLog: (
50
+ contractAddress: ACVMField[],
51
+ message: ACVMField[],
52
+ length: ACVMField[],
53
+ counter: ACVMField[],
54
+ ): Promise<ACVMField[]> =>
55
+ oracle.aztec_prv_notifyCreatedContractClassLog(contractAddress, message, length, counter),
56
+ utilityGetUtilityContext: (): Promise<(ACVMField | ACVMField[])[]> => oracle.aztec_utl_getUtilityContext(),
57
+ utilityStorageRead: (
58
+ blockHash: ACVMField[],
59
+ contractAddress: ACVMField[],
60
+ startStorageSlot: ACVMField[],
61
+ numberOfElements: ACVMField[],
62
+ ): Promise<ACVMField[][]> =>
63
+ oracle.aztec_utl_storageRead(blockHash, contractAddress, startStorageSlot, numberOfElements),
64
+ utilityStoreCapsule: (
65
+ contractAddress: ACVMField[],
66
+ slot: ACVMField[],
67
+ capsule: ACVMField[],
68
+ ): Promise<ACVMField[]> => oracle.aztec_utl_storeCapsule(contractAddress, slot, capsule),
69
+ utilityCopyCapsule: (
70
+ contractAddress: ACVMField[],
71
+ srcSlot: ACVMField[],
72
+ dstSlot: ACVMField[],
73
+ numEntries: ACVMField[],
74
+ ): Promise<ACVMField[]> => oracle.aztec_utl_copyCapsule(contractAddress, srcSlot, dstSlot, numEntries),
75
+ utilityDeleteCapsule: (contractAddress: ACVMField[], slot: ACVMField[]): Promise<ACVMField[]> =>
76
+ oracle.aztec_utl_deleteCapsule(contractAddress, slot),
77
+ utilityAes128Decrypt: (
78
+ ciphertextBVecStorage: ACVMField[],
79
+ ciphertextLength: ACVMField[],
80
+ iv: ACVMField[],
81
+ symKey: ACVMField[],
82
+ ): Promise<(ACVMField | ACVMField[])[]> =>
83
+ oracle.aztec_utl_aes128Decrypt(ciphertextBVecStorage, ciphertextLength, iv, symKey),
84
+ utilityGetSharedSecret: (
85
+ address: ACVMField[],
86
+ ephPKField0: ACVMField[],
87
+ ephPKField1: ACVMField[],
88
+ ephPKField2: ACVMField[],
89
+ ): Promise<ACVMField[]> => oracle.aztec_utl_getSharedSecret(address, ephPKField0, ephPKField1, ephPKField2),
90
+ utilityFetchTaggedLogs: (pendingTaggedLogArrayBaseSlot: ACVMField[]): Promise<ACVMField[]> =>
91
+ oracle.aztec_utl_fetchTaggedLogs(pendingTaggedLogArrayBaseSlot),
92
+ utilityBulkRetrieveLogs: (
93
+ contractAddress: ACVMField[],
94
+ logRetrievalRequestsArrayBaseSlot: ACVMField[],
95
+ logRetrievalResponsesArrayBaseSlot: ACVMField[],
96
+ ): Promise<ACVMField[]> =>
97
+ oracle.aztec_utl_bulkRetrieveLogs(
98
+ contractAddress,
99
+ logRetrievalRequestsArrayBaseSlot,
100
+ logRetrievalResponsesArrayBaseSlot,
101
+ ),
102
+ utilityGetL1ToL2MembershipWitness: (
103
+ contractAddress: ACVMField[],
104
+ messageHash: ACVMField[],
105
+ secret: ACVMField[],
106
+ ): Promise<(ACVMField | ACVMField[])[]> =>
107
+ oracle.aztec_utl_getL1ToL2MembershipWitness(contractAddress, messageHash, secret),
108
+ utilityEmitOffchainEffect: (data: ACVMField[]): Promise<ACVMField[]> => oracle.aztec_utl_emitOffchainEffect(data),
109
+ // Adapter: old 3-param signature → new 5-param with injected constants.
110
+ // Values derived from: MAX_MESSAGE_CONTENT_LEN(11) - RESERVED_FIELDS (3 for notes, 1 for events).
111
+ utilityValidateAndStoreEnqueuedNotesAndEvents: (
112
+ contractAddress: ACVMField[],
113
+ noteValidationRequestsArrayBaseSlot: ACVMField[],
114
+ eventValidationRequestsArrayBaseSlot: ACVMField[],
115
+ ): Promise<ACVMField[]> =>
116
+ oracle.aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
117
+ contractAddress,
118
+ noteValidationRequestsArrayBaseSlot,
119
+ eventValidationRequestsArrayBaseSlot,
120
+ [new Fr(8).toString()],
121
+ [new Fr(10).toString()],
122
+ ),
123
+ // Renames (same signature, different oracle name)
124
+ privateNotifySetMinRevertibleSideEffectCounter: (counter: ACVMField[]): Promise<ACVMField[]> =>
125
+ oracle.aztec_prv_notifyRevertiblePhaseStart(counter),
126
+ privateIsSideEffectCounterRevertible: (sideEffectCounter: ACVMField[]): Promise<ACVMField[]> =>
127
+ oracle.aztec_prv_inRevertiblePhase(sideEffectCounter),
128
+ // Signature changes: old 4-param oracles → new 1-param validatePublicCalldata
129
+ privateNotifyEnqueuedPublicFunctionCall: (
130
+ _contractAddress: ACVMField[],
131
+ calldataHash: ACVMField[],
132
+ _sideEffectCounter: ACVMField[],
133
+ _isStaticCall: ACVMField[],
134
+ ): Promise<ACVMField[]> => oracle.aztec_prv_validatePublicCalldata(calldataHash),
135
+ privateNotifySetPublicTeardownFunctionCall: (
136
+ _contractAddress: ACVMField[],
137
+ calldataHash: ACVMField[],
138
+ _sideEffectCounter: ACVMField[],
139
+ _isStaticCall: ACVMField[],
140
+ ): Promise<ACVMField[]> => oracle.aztec_prv_validatePublicCalldata(calldataHash),
141
+ };
142
+ }