@aztec/pxe 0.0.1-commit.b64cb54f6 → 0.0.1-commit.b6e433891

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 (37) hide show
  1. package/dest/contract_function_simulator/contract_function_simulator.d.ts +6 -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 +21 -3
  4. package/dest/contract_function_simulator/oracle/interfaces.d.ts +3 -2
  5. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +1 -1
  7. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +22 -32
  9. package/dest/contract_function_simulator/oracle/oracle.d.ts +3 -2
  10. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/oracle/oracle.js +25 -4
  12. package/dest/contract_function_simulator/oracle/private_execution.js +3 -1
  13. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -12
  14. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  15. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +0 -14
  16. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +14 -2
  17. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  18. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +22 -0
  19. package/dest/contract_sync/contract_sync_service.d.ts +5 -3
  20. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  21. package/dest/contract_sync/contract_sync_service.js +47 -30
  22. package/dest/oracle_version.d.ts +2 -2
  23. package/dest/oracle_version.js +2 -2
  24. package/dest/pxe.d.ts +5 -3
  25. package/dest/pxe.d.ts.map +1 -1
  26. package/dest/pxe.js +19 -10
  27. package/package.json +16 -16
  28. package/src/contract_function_simulator/contract_function_simulator.ts +30 -4
  29. package/src/contract_function_simulator/oracle/interfaces.ts +2 -1
  30. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +103 -45
  31. package/src/contract_function_simulator/oracle/oracle.ts +25 -4
  32. package/src/contract_function_simulator/oracle/private_execution.ts +1 -1
  33. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +0 -17
  34. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +27 -1
  35. package/src/contract_sync/contract_sync_service.ts +67 -38
  36. package/src/oracle_version.ts +2 -2
  37. package/src/pxe.ts +39 -12
package/src/pxe.ts CHANGED
@@ -107,7 +107,9 @@ export type SimulateTxOpts = {
107
107
  skipTxValidation?: boolean;
108
108
  /** If false, fees are enforced. */
109
109
  skipFeeEnforcement?: boolean;
110
- /** State overrides for the simulation, such as contract instances and artifacts. */
110
+ /** If true, kernel logic is emulated in TS for simulation */
111
+ skipKernels?: boolean;
112
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
111
113
  overrides?: SimulationOverrides;
112
114
  /** Addresses whose private state and keys are accessible during private execution */
113
115
  scopes: AccessScopes;
@@ -420,7 +422,14 @@ export class PXE {
420
422
  ) {
421
423
  try {
422
424
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
423
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
425
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
426
+ call,
427
+ authWitnesses ?? [],
428
+ anchorBlockHeader,
429
+ scopes,
430
+ jobId,
431
+ );
432
+ return { result, offchainEffects };
424
433
  } catch (err) {
425
434
  if (err instanceof SimulationError) {
426
435
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -560,6 +569,9 @@ export class PXE {
560
569
 
561
570
  if (wasAdded) {
562
571
  this.log.info(`Added sender:\n ${sender.toString()}`);
572
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
573
+ // all contracts must re-sync to discover them.
574
+ this.contractSyncService.wipe();
563
575
  } else {
564
576
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
565
577
  }
@@ -889,7 +901,14 @@ export class PXE {
889
901
  */
890
902
  public simulateTx(
891
903
  txRequest: TxExecutionRequest,
892
- { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
904
+ {
905
+ simulatePublic,
906
+ skipTxValidation = false,
907
+ skipFeeEnforcement = false,
908
+ skipKernels = true,
909
+ overrides,
910
+ scopes,
911
+ }: SimulateTxOpts,
893
912
  ): Promise<TxSimulationResult> {
894
913
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
895
914
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -913,17 +932,20 @@ export class PXE {
913
932
  await this.blockStateSynchronizer.sync();
914
933
  const syncTime = syncTimer.ms();
915
934
 
916
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
917
- // Temporary: in case there are overrides, we have to skip the kernels or validations
918
- // will fail. Consider handing control to the user/wallet on whether they want to run them
919
- // or not.
920
935
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
921
936
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
922
- const skipKernels = hasOverriddenContracts;
923
937
 
924
- // Set overridden contracts on the sync service so it knows to skip syncing them
938
+ if (hasOverriddenContracts && !skipKernels) {
939
+ throw new Error(
940
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
941
+ );
942
+ }
943
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
944
+
925
945
  if (hasOverriddenContracts) {
926
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
946
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
947
+ // We exclude them so the sync service skips them entirely.
948
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
927
949
  }
928
950
 
929
951
  // Execution of private functions only; no proving, and no kernel logic.
@@ -1055,7 +1077,7 @@ export class PXE {
1055
1077
  scopes,
1056
1078
  );
1057
1079
 
1058
- const executionResult = await this.#executeUtility(
1080
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1059
1081
  contractFunctionSimulator,
1060
1082
  call,
1061
1083
  authwits ?? [],
@@ -1076,7 +1098,12 @@ export class PXE {
1076
1098
  };
1077
1099
 
1078
1100
  const simulationStats = contractFunctionSimulator.getStats();
1079
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1101
+ return {
1102
+ result: executionResult,
1103
+ offchainEffects,
1104
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1105
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1106
+ };
1080
1107
  } catch (err: any) {
1081
1108
  const { to, name, args } = call;
1082
1109
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');