@aztec/pxe 0.0.1-commit.1bb068fb5 → 0.0.1-commit.217f559981

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 (70) hide show
  1. package/dest/config/package_info.js +1 -1
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -1
  3. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  4. package/dest/contract_function_simulator/contract_function_simulator.js +4 -4
  5. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  6. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -2
  7. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  9. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
  10. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +2 -10
  12. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +1 -1
  13. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +4 -7
  15. package/dest/contract_logging.d.ts +22 -0
  16. package/dest/contract_logging.d.ts.map +1 -0
  17. package/dest/contract_logging.js +23 -0
  18. package/dest/debug/pxe_debug_utils.d.ts +2 -2
  19. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  20. package/dest/debug/pxe_debug_utils.js +4 -4
  21. package/dest/entrypoints/client/bundle/index.d.ts +2 -1
  22. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  23. package/dest/entrypoints/client/bundle/index.js +1 -0
  24. package/dest/entrypoints/client/lazy/index.d.ts +2 -1
  25. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  26. package/dest/entrypoints/client/lazy/index.js +1 -0
  27. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  28. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  29. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  30. package/dest/private_kernel/hints/index.d.ts +1 -1
  31. package/dest/private_kernel/hints/index.js +1 -1
  32. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +4 -4
  33. package/dest/private_kernel/private_kernel_execution_prover.js +6 -6
  34. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  35. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  36. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  37. package/dest/pxe.d.ts +6 -6
  38. package/dest/pxe.d.ts.map +1 -1
  39. package/dest/pxe.js +27 -23
  40. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  41. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  42. package/dest/storage/contract_store/contract_store.js +140 -64
  43. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  44. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  45. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  46. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +4 -4
  47. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  48. package/package.json +16 -16
  49. package/src/config/package_info.ts +1 -1
  50. package/src/contract_function_simulator/contract_function_simulator.ts +4 -5
  51. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  52. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  53. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +2 -11
  54. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +8 -7
  55. package/src/contract_logging.ts +39 -0
  56. package/src/debug/pxe_debug_utils.ts +4 -4
  57. package/src/entrypoints/client/bundle/index.ts +1 -0
  58. package/src/entrypoints/client/lazy/index.ts +1 -0
  59. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  60. package/src/private_kernel/hints/index.ts +1 -1
  61. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +7 -7
  62. package/src/private_kernel/private_kernel_execution_prover.ts +6 -6
  63. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  64. package/src/pxe.ts +33 -30
  65. package/src/storage/contract_store/contract_store.ts +170 -71
  66. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  67. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +4 -4
  68. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  69. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  70. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
@@ -0,0 +1,39 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { type LogLevel, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { DebugLog } from '@aztec/stdlib/logs';
5
+
6
+ /** Resolves a contract address to a human-readable name, if available. */
7
+ export type ContractNameResolver = (address: AztecAddress) => Promise<string | undefined>;
8
+
9
+ /**
10
+ * Creates a logger whose output is prefixed with `contract_log::<name>(<addrAbbrev>)`.
11
+ */
12
+ export async function createContractLogger(
13
+ contractAddress: AztecAddress,
14
+ getContractName: ContractNameResolver,
15
+ options?: { instanceId?: string },
16
+ ): Promise<Logger> {
17
+ const addrAbbrev = contractAddress.toString().slice(0, 10);
18
+ const name = await getContractName(contractAddress);
19
+ const module = name ? `contract_log::${name}(${addrAbbrev})` : `contract_log::Unknown(${addrAbbrev})`;
20
+ return createLogger(module, options);
21
+ }
22
+
23
+ /**
24
+ * Formats and emits a single contract log message through the given logger.
25
+ */
26
+ export function logContractMessage(logger: Logger, level: LogLevel, message: string, fields: Fr[]): void {
27
+ logger[level](applyStringFormatting(message, fields));
28
+ }
29
+
30
+ /**
31
+ * Displays debug logs collected during public function simulation,
32
+ * using the `contract_log::` prefixed logger format.
33
+ */
34
+ export async function displayDebugLogs(debugLogs: DebugLog[], getContractName: ContractNameResolver): Promise<void> {
35
+ for (const log of debugLogs) {
36
+ const logger = await createContractLogger(log.contractAddress, getContractName);
37
+ logContractMessage(logger, log.level, log.message, log.fields);
38
+ }
39
+ }
@@ -18,7 +18,7 @@ import type { NoteStore } from '../storage/note_store/note_store.js';
18
18
  export class PXEDebugUtils {
19
19
  #putJobInQueue!: <T>(job: (jobId: string) => Promise<T>) => Promise<T>;
20
20
  #getSimulatorForTx!: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator;
21
- #simulateUtility!: (
21
+ #executeUtility!: (
22
22
  contractFunctionSimulator: ContractFunctionSimulator,
23
23
  call: FunctionCall,
24
24
  authWitnesses: AuthWitness[] | undefined,
@@ -37,7 +37,7 @@ export class PXEDebugUtils {
37
37
  public setPXEHelpers(
38
38
  putJobInQueue: <T>(job: (jobId: string) => Promise<T>) => Promise<T>,
39
39
  getSimulatorForTx: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator,
40
- simulateUtility: (
40
+ executeUtility: (
41
41
  contractFunctionSimulator: ContractFunctionSimulator,
42
42
  call: FunctionCall,
43
43
  authWitnesses: AuthWitness[] | undefined,
@@ -47,7 +47,7 @@ export class PXEDebugUtils {
47
47
  ) {
48
48
  this.#putJobInQueue = putJobInQueue;
49
49
  this.#getSimulatorForTx = getSimulatorForTx;
50
- this.#simulateUtility = simulateUtility;
50
+ this.#executeUtility = executeUtility;
51
51
  }
52
52
 
53
53
  /**
@@ -73,7 +73,7 @@ export class PXEDebugUtils {
73
73
  filter.contractAddress,
74
74
  null,
75
75
  async (privateSyncCall, execScopes) =>
76
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
76
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
77
77
  anchorBlockHeader,
78
78
  jobId,
79
79
  filter.scopes,
@@ -3,6 +3,7 @@ export * from '../../../notes_filter.js';
3
3
  export * from '../../../pxe.js';
4
4
  export * from '../../../config/index.js';
5
5
  export * from '../../../error_enriching.js';
6
+ export * from '../../../contract_logging.js';
6
7
  export * from '../../../storage/index.js';
7
8
  export * from './utils.js';
8
9
  export type { PXECreationOptions } from '../../pxe_creation_options.js';
@@ -4,5 +4,6 @@ export * from '../../../pxe.js';
4
4
  export * from '../../../config/index.js';
5
5
  export * from '../../../storage/index.js';
6
6
  export * from '../../../error_enriching.js';
7
+ export * from '../../../contract_logging.js';
7
8
  export * from './utils.js';
8
9
  export { type PXECreationOptions } from '../../pxe_creation_options.js';
@@ -1,4 +1,4 @@
1
- import { MAX_INCLUDE_BY_TIMESTAMP_DURATION } from '@aztec/constants';
1
+ import { MAX_TX_LIFETIME } from '@aztec/constants';
2
2
  import type { PrivateKernelCircuitPublicInputs } from '@aztec/stdlib/kernel';
3
3
  import type { UInt64 } from '@aztec/stdlib/types';
4
4
 
@@ -8,12 +8,12 @@ const ROUNDED_DURATIONS = [
8
8
  1, // 1 second
9
9
  ];
10
10
 
11
- function roundTimestamp(blockTimestamp: bigint, includeByTimestamp: bigint): UInt64 {
11
+ function roundTimestamp(blockTimestamp: bigint, expirationTimestamp: bigint): UInt64 {
12
12
  return ROUNDED_DURATIONS.reduce((timestamp, duration) => {
13
13
  if (timestamp <= blockTimestamp) {
14
14
  // The timestamp must be greater than the block timestamp.
15
15
  // If it is too small, round it down again using a smaller duration.
16
- const totalDuration = includeByTimestamp - blockTimestamp;
16
+ const totalDuration = expirationTimestamp - blockTimestamp;
17
17
  const roundedDuration = totalDuration - (totalDuration % BigInt(duration));
18
18
  return blockTimestamp + roundedDuration;
19
19
  }
@@ -21,36 +21,36 @@ function roundTimestamp(blockTimestamp: bigint, includeByTimestamp: bigint): UIn
21
21
  }, 0n);
22
22
  }
23
23
 
24
- export function computeTxIncludeByTimestamp(
24
+ export function computeTxExpirationTimestamp(
25
25
  previousKernel: PrivateKernelCircuitPublicInputs,
26
- maxDuration = MAX_INCLUDE_BY_TIMESTAMP_DURATION,
26
+ txLifetime = MAX_TX_LIFETIME,
27
27
  ): UInt64 {
28
- if (maxDuration > MAX_INCLUDE_BY_TIMESTAMP_DURATION) {
28
+ if (txLifetime > MAX_TX_LIFETIME) {
29
29
  throw new Error(
30
- `Custom max duration cannot be greater than the max allowed. Max allowed: ${MAX_INCLUDE_BY_TIMESTAMP_DURATION}. Custom value: ${maxDuration}.`,
30
+ `Custom tx lifetime cannot be greater than the max allowed. Max allowed: ${MAX_TX_LIFETIME}. Custom value: ${txLifetime}.`,
31
31
  );
32
32
  }
33
33
 
34
34
  const anchorBlockTimestamp = previousKernel.constants.anchorBlockHeader.globalVariables.timestamp;
35
- const maxTimestamp = anchorBlockTimestamp + BigInt(maxDuration);
36
- const includeByTimestamp = previousKernel.includeByTimestamp;
35
+ const maxTimestamp = anchorBlockTimestamp + BigInt(txLifetime);
36
+ const expirationTimestamp = previousKernel.expirationTimestamp;
37
37
 
38
- // If the includeByTimestamp set during the tx execution is greater than or equal to the max allowed duration,
38
+ // If the expirationTimestamp set during the tx execution is greater than or equal to the max allowed duration,
39
39
  // use the maximum allowed timestamp.
40
40
  // Note: It shouldn't be larger than the max allowed duration, but we check for it anyway.
41
- if (includeByTimestamp >= maxTimestamp) {
41
+ if (expirationTimestamp >= maxTimestamp) {
42
42
  return maxTimestamp;
43
43
  }
44
44
 
45
45
  // Round it down to the nearest hour/min/second to reduce precision and avoid revealing the exact value.
46
46
  // This makes it harder for others to infer what function calls may have been used to produce a specific timestamp.
47
- const roundedTimestamp = roundTimestamp(anchorBlockTimestamp, includeByTimestamp);
47
+ const roundedTimestamp = roundTimestamp(anchorBlockTimestamp, expirationTimestamp);
48
48
 
49
49
  // The tx can't be published if the timestamp is the same or less than the anchor block's timestamp.
50
50
  // Future blocks will have a greater timestamp, so the tx would never be included.
51
51
  if (roundedTimestamp <= anchorBlockTimestamp) {
52
52
  throw new Error(
53
- `Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${includeByTimestamp}.`,
53
+ `Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${expirationTimestamp}.`,
54
54
  );
55
55
  }
56
56
 
@@ -1,2 +1,2 @@
1
1
  export * from './private_kernel_reset_private_inputs_builder.js';
2
- export * from './compute_tx_include_by_timestamp.js';
2
+ export * from './compute_tx_expiration_timestamp.js';
@@ -26,7 +26,7 @@ import {
26
26
  type PrivateKernelSimulateOutput,
27
27
  ReadRequestActionEnum,
28
28
  ReadRequestResetActions,
29
- type ScopedKeyValidationRequestAndGenerator,
29
+ type ScopedKeyValidationRequestAndSeparator,
30
30
  ScopedNoteHash,
31
31
  ScopedNullifier,
32
32
  ScopedReadRequest,
@@ -68,9 +68,9 @@ function getNullifierMembershipWitnessResolver(oracle: PrivateKernelOracle) {
68
68
  };
69
69
  }
70
70
 
71
- async function getMasterSecretKeysAndAppKeyGenerators(
71
+ async function getMasterSecretKeysAndKeyTypeDomainSeparators(
72
72
  keyValidationRequests: ClaimedLengthArray<
73
- ScopedKeyValidationRequestAndGenerator,
73
+ ScopedKeyValidationRequestAndSeparator,
74
74
  typeof MAX_KEY_VALIDATION_REQUESTS_PER_TX
75
75
  >,
76
76
  numRequestsToVerify: number,
@@ -189,8 +189,8 @@ export class PrivateKernelResetPrivateInputsBuilder {
189
189
  this.previousKernel.validationRequests.nullifierReadRequests,
190
190
  this.nullifierResetActions,
191
191
  ),
192
- getMasterSecretKeysAndAppKeyGenerators(
193
- this.previousKernel.validationRequests.scopedKeyValidationRequestsAndGenerators,
192
+ getMasterSecretKeysAndKeyTypeDomainSeparators(
193
+ this.previousKernel.validationRequests.scopedKeyValidationRequestsAndSeparators,
194
194
  dimensions.KEY_VALIDATION,
195
195
  oracle,
196
196
  ),
@@ -357,8 +357,8 @@ export class PrivateKernelResetPrivateInputsBuilder {
357
357
  }
358
358
 
359
359
  private needsResetNullifierKeys() {
360
- const numCurr = this.previousKernel.validationRequests.scopedKeyValidationRequestsAndGenerators.claimedLength;
361
- const numNext = this.nextIteration ? this.nextIteration.keyValidationRequestsAndGenerators.claimedLength : 0;
360
+ const numCurr = this.previousKernel.validationRequests.scopedKeyValidationRequestsAndSeparators.claimedLength;
361
+ const numNext = this.nextIteration ? this.nextIteration.keyValidationRequestsAndSeparators.claimedLength : 0;
362
362
  const maxAmountToKeep = !this.nextIteration ? 0 : MAX_KEY_VALIDATION_REQUESTS_PER_TX;
363
363
  if (numCurr + numNext <= maxAmountToKeep) {
364
364
  return false;
@@ -260,20 +260,20 @@ export class PrivateKernelExecutionProver {
260
260
  // TODO: Enable padding once we better understand the final amounts to pad to.
261
261
  const paddedSideEffectAmounts = PaddedSideEffectAmounts.empty();
262
262
 
263
- // Use the aggregated includeByTimestamp set throughout the tx execution.
264
- // TODO: Call `computeTxIncludeByTimestamp` to round the value down and reduce precision, improving privacy.
265
- const includeByTimestampUpperBound = previousKernelData.publicInputs.includeByTimestamp;
263
+ // Use the aggregated expirationTimestamp set throughout the tx execution.
264
+ // TODO: Call `computeTxExpirationTimestamp` to round the value down and reduce precision, improving privacy.
265
+ const expirationTimestampUpperBound = previousKernelData.publicInputs.expirationTimestamp;
266
266
  const anchorBlockTimestamp = previousKernelData.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp;
267
- if (includeByTimestampUpperBound <= anchorBlockTimestamp) {
267
+ if (expirationTimestampUpperBound <= anchorBlockTimestamp) {
268
268
  throw new Error(
269
- `Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${includeByTimestampUpperBound}.`,
269
+ `Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${expirationTimestampUpperBound}.`,
270
270
  );
271
271
  }
272
272
 
273
273
  const privateInputs = new PrivateKernelTailCircuitPrivateInputs(
274
274
  previousKernelData,
275
275
  paddedSideEffectAmounts,
276
- includeByTimestampUpperBound,
276
+ expirationTimestampUpperBound,
277
277
  );
278
278
 
279
279
  const witgenTimer = new Timer();
@@ -8,11 +8,7 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
8
8
  import type { FunctionSelector } from '@aztec/stdlib/abi';
9
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
10
  import { BlockHash } from '@aztec/stdlib/block';
11
- import {
12
- type ContractInstanceWithAddress,
13
- computeContractClassIdPreimage,
14
- computeSaltedInitializationHash,
15
- } from '@aztec/stdlib/contract';
11
+ import { type ContractInstanceWithAddress, computeSaltedInitializationHash } from '@aztec/stdlib/contract';
16
12
  import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
17
13
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
18
14
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
@@ -49,11 +45,15 @@ export class PrivateKernelOracle {
49
45
 
50
46
  /** Retrieves the preimage of a contract class id from the contract classes db. */
51
47
  public async getContractClassIdPreimage(contractClassId: Fr) {
52
- const contractClass = await this.contractStore.getContractClass(contractClassId);
48
+ const contractClass = await this.contractStore.getContractClassWithPreimage(contractClassId);
53
49
  if (!contractClass) {
54
50
  throw new Error(`Contract class not found when getting class id preimage. Class id: ${contractClassId}.`);
55
51
  }
56
- return computeContractClassIdPreimage(contractClass);
52
+ return {
53
+ artifactHash: contractClass.artifactHash,
54
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
55
+ publicBytecodeCommitment: contractClass.publicBytecodeCommitment,
56
+ };
57
57
  }
58
58
 
59
59
  /** Returns a membership witness with the sibling path and leaf index in our private functions tree. */
package/src/pxe.ts CHANGED
@@ -47,7 +47,7 @@ import {
47
47
  TxProfileResult,
48
48
  TxProvingResult,
49
49
  TxSimulationResult,
50
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
51
51
  } from '@aztec/stdlib/tx';
52
52
 
53
53
  import { inspect } from 'util';
@@ -61,6 +61,7 @@ import {
61
61
  generateSimulatedProvingResult,
62
62
  } from './contract_function_simulator/contract_function_simulator.js';
63
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
64
65
  import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
66
  import { readCurrentClassId } from './contract_sync/helpers.js';
66
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
@@ -111,8 +112,8 @@ export type SimulateTxOpts = {
111
112
  scopes: AccessScopes;
112
113
  };
113
114
 
114
- /** Options for PXE.simulateUtility. */
115
- export type SimulateUtilityOpts = {
115
+ /** Options for PXE.executeUtility. */
116
+ export type ExecuteUtilityOpts = {
116
117
  /** The authentication witnesses required for the function call. */
117
118
  authwits?: AuthWitness[];
118
119
  /** The accounts whose notes we can access in this call */
@@ -264,7 +265,7 @@ export class PXE {
264
265
  debugUtils.setPXEHelpers(
265
266
  pxe.#putInJobQueue.bind(pxe),
266
267
  pxe.#getSimulatorForTx.bind(pxe),
267
- pxe.#simulateUtility.bind(pxe),
268
+ pxe.#executeUtility.bind(pxe),
268
269
  );
269
270
 
270
271
  pxe.jobQueue.start();
@@ -344,9 +345,8 @@ export class PXE {
344
345
  async #registerProtocolContracts() {
345
346
  const registered: Record<string, string> = {};
346
347
  for (const name of protocolContractNames) {
347
- const { address, contractClass, instance, artifact } =
348
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
349
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
348
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
349
+ await this.contractStore.addContractArtifact(artifact);
350
350
  await this.contractStore.addContractInstance(instance);
351
351
  registered[name] = address.toString();
352
352
  }
@@ -370,7 +370,7 @@ export class PXE {
370
370
  contractAddress,
371
371
  functionSelector,
372
372
  (privateSyncCall, execScopes) =>
373
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
373
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
374
374
  anchorBlockHeader,
375
375
  jobId,
376
376
  scopes,
@@ -394,16 +394,16 @@ export class PXE {
394
394
  }
395
395
 
396
396
  /**
397
- * Simulate a utility function call on the given contract.
397
+ * Execute a utility function call on the given contract.
398
398
  * @param contractFunctionSimulator - The simulator to use for the function call.
399
399
  * @param call - The function call to execute.
400
400
  * @param authWitnesses - Authentication witnesses required for the function call.
401
401
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
402
402
  * accounts if not specified.
403
403
  * @param jobId - The job ID for staged writes.
404
- * @returns The simulation result containing the outputs of the utility function.
404
+ * @returns The execution result containing the outputs of the utility function.
405
405
  */
406
- async #simulateUtility(
406
+ async #executeUtility(
407
407
  contractFunctionSimulator: ContractFunctionSimulator,
408
408
  call: FunctionCall,
409
409
  authWitnesses: AuthWitness[] | undefined,
@@ -601,8 +601,7 @@ export class PXE {
601
601
  * @param artifact - The build artifact for the contract class.
602
602
  */
603
603
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
604
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
605
- await this.contractStore.addContractArtifact(contractClassId, artifact);
604
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
606
605
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
607
606
  }
608
607
 
@@ -621,17 +620,17 @@ export class PXE {
621
620
  if (artifact) {
622
621
  // If the user provides an artifact, validate it against the expected class id and register it
623
622
  const contractClass = await getContractClassFromArtifact(artifact);
624
- const contractClassId = contractClass.id;
625
- if (!contractClassId.equals(instance.currentContractClassId)) {
623
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
626
624
  throw new Error(
627
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
625
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
628
626
  );
629
627
  }
630
628
  const computedAddress = await computeContractAddressFromInstance(instance);
631
629
  if (!computedAddress.equals(instance.address)) {
632
630
  throw new Error('Added a contract in which the address does not match the contract instance.');
633
631
  }
634
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
632
+
633
+ await this.contractStore.addContractArtifact(artifact, contractClass);
635
634
 
636
635
  const publicFunctionSignatures = artifact.functions
637
636
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -680,15 +679,16 @@ export class PXE {
680
679
  throw new Error('Could not update contract to a class different from the current one.');
681
680
  }
682
681
 
683
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
684
-
685
682
  const publicFunctionSignatures = artifact.functions
686
683
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
687
684
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
688
685
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
689
686
 
690
687
  currentInstance.currentContractClassId = contractClass.id;
691
- await this.contractStore.addContractInstance(currentInstance);
688
+ await Promise.all([
689
+ this.contractStore.addContractArtifact(artifact, contractClass),
690
+ this.contractStore.addContractInstance(currentInstance),
691
+ ]);
692
692
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
693
693
  });
694
694
  }
@@ -947,6 +947,9 @@ export class PXE {
947
947
  const publicSimulationTimer = new Timer();
948
948
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
949
949
  publicSimulationTime = publicSimulationTimer.ms();
950
+ if (publicOutput?.debugLogs?.length) {
951
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
952
+ }
950
953
  }
951
954
 
952
955
  let validationTime: number | undefined;
@@ -1013,16 +1016,16 @@ export class PXE {
1013
1016
  }
1014
1017
 
1015
1018
  /**
1016
- * Simulates the execution of a contract utility function.
1019
+ * Executes a contract utility function.
1017
1020
  * @param call - The function call containing the function details, arguments, and target contract address.
1018
1021
  */
1019
- public simulateUtility(
1022
+ public executeUtility(
1020
1023
  call: FunctionCall,
1021
- { authwits, scopes }: SimulateUtilityOpts = { scopes: 'ALL_SCOPES' },
1022
- ): Promise<UtilitySimulationResult> {
1023
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1024
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1025
+ ): Promise<UtilityExecutionResult> {
1026
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1024
1027
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1025
- // delete the same read value, or reading values that another simulation is currently modifying).
1028
+ // delete the same read value, or reading values that another execution is currently modifying).
1026
1029
  return this.#putInJobQueue(async jobId => {
1027
1030
  try {
1028
1031
  const totalTimer = new Timer();
@@ -1037,13 +1040,13 @@ export class PXE {
1037
1040
  call.to,
1038
1041
  call.selector,
1039
1042
  (privateSyncCall, execScopes) =>
1040
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1043
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1041
1044
  anchorBlockHeader,
1042
1045
  jobId,
1043
1046
  scopes,
1044
1047
  );
1045
1048
 
1046
- const executionResult = await this.#simulateUtility(
1049
+ const executionResult = await this.#executeUtility(
1047
1050
  contractFunctionSimulator,
1048
1051
  call,
1049
1052
  authwits ?? [],
@@ -1070,7 +1073,7 @@ export class PXE {
1070
1073
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1071
1074
  throw this.#contextualizeError(
1072
1075
  err,
1073
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1076
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1074
1077
  `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1075
1078
  );
1076
1079
  }
@@ -1108,7 +1111,7 @@ export class PXE {
1108
1111
  filter.contractAddress,
1109
1112
  null,
1110
1113
  async (privateSyncCall, execScopes) =>
1111
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1114
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1112
1115
  anchorBlockHeader,
1113
1116
  jobId,
1114
1117
  filter.scopes,