@aztec/simulator 0.81.0 → 0.82.1-alpha-testnet.1

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 (138) hide show
  1. package/dest/common/db_interfaces.d.ts +6 -12
  2. package/dest/common/db_interfaces.d.ts.map +1 -1
  3. package/dest/common/db_interfaces.js +1 -1
  4. package/dest/common/debug_fn_name.js +5 -2
  5. package/dest/common/message_load_oracle_inputs.d.ts +4 -0
  6. package/dest/common/message_load_oracle_inputs.d.ts.map +1 -1
  7. package/dest/common/message_load_oracle_inputs.js +9 -0
  8. package/dest/private/acvm/acvm.d.ts +6 -1
  9. package/dest/private/acvm/acvm.d.ts.map +1 -1
  10. package/dest/private/acvm/acvm.js +7 -13
  11. package/dest/private/acvm/deserialize.d.ts +0 -18
  12. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  13. package/dest/private/acvm/deserialize.js +3 -24
  14. package/dest/private/acvm/oracle/oracle.d.ts +34 -34
  15. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
  16. package/dest/private/acvm/oracle/oracle.js +116 -82
  17. package/dest/private/acvm/oracle/typed_oracle.d.ts +4 -4
  18. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
  19. package/dest/private/acvm/oracle/typed_oracle.js +8 -8
  20. package/dest/private/execution_data_provider.d.ts +3 -9
  21. package/dest/private/execution_data_provider.d.ts.map +1 -1
  22. package/dest/private/hashed_values_cache.d.ts +2 -2
  23. package/dest/private/hashed_values_cache.d.ts.map +1 -1
  24. package/dest/private/hashed_values_cache.js +5 -15
  25. package/dest/private/private_execution.d.ts +2 -2
  26. package/dest/private/private_execution.d.ts.map +1 -1
  27. package/dest/private/private_execution.js +4 -7
  28. package/dest/private/private_execution_oracle.d.ts +9 -37
  29. package/dest/private/private_execution_oracle.d.ts.map +1 -1
  30. package/dest/private/private_execution_oracle.js +32 -92
  31. package/dest/private/providers/acvm_native.d.ts +6 -4
  32. package/dest/private/providers/acvm_native.d.ts.map +1 -1
  33. package/dest/private/providers/acvm_native.js +6 -3
  34. package/dest/private/providers/acvm_wasm.d.ts +6 -7
  35. package/dest/private/providers/acvm_wasm.d.ts.map +1 -1
  36. package/dest/private/providers/acvm_wasm.js +13 -15
  37. package/dest/private/providers/acvm_wasm_with_blobs.d.ts +5 -5
  38. package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -1
  39. package/dest/private/providers/acvm_wasm_with_blobs.js +7 -9
  40. package/dest/private/providers/circuit_recording/circuit_recorder.d.ts +90 -0
  41. package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +1 -0
  42. package/dest/private/providers/circuit_recording/circuit_recorder.js +246 -0
  43. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts +18 -0
  44. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +1 -0
  45. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.js +39 -0
  46. package/dest/private/providers/simulation_provider.d.ts +21 -7
  47. package/dest/private/providers/simulation_provider.d.ts.map +1 -1
  48. package/dest/private/simulator.d.ts +3 -2
  49. package/dest/private/simulator.d.ts.map +1 -1
  50. package/dest/private/simulator.js +14 -4
  51. package/dest/private/unconstrained_execution.d.ts +2 -2
  52. package/dest/private/unconstrained_execution.d.ts.map +1 -1
  53. package/dest/private/unconstrained_execution.js +1 -2
  54. package/dest/private/unconstrained_execution_oracle.d.ts +1 -1
  55. package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
  56. package/dest/private/unconstrained_execution_oracle.js +3 -3
  57. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  58. package/dest/public/avm/avm_simulator.js +0 -2
  59. package/dest/public/avm/fixtures/avm_simulation_tester.js +2 -2
  60. package/dest/public/avm/fixtures/index.d.ts +2 -1
  61. package/dest/public/avm/fixtures/index.d.ts.map +1 -1
  62. package/dest/public/avm/fixtures/index.js +7 -12
  63. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +2 -2
  64. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
  65. package/dest/public/avm/fixtures/simple_contract_data_source.js +1 -1
  66. package/dest/public/avm/journal/journal.d.ts +2 -2
  67. package/dest/public/avm/journal/journal.d.ts.map +1 -1
  68. package/dest/public/avm/journal/journal.js +4 -4
  69. package/dest/public/avm/test_utils.js +1 -1
  70. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +2 -2
  71. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  72. package/dest/public/fixtures/public_tx_simulation_tester.js +27 -47
  73. package/dest/public/fixtures/utils.d.ts +2 -2
  74. package/dest/public/fixtures/utils.d.ts.map +1 -1
  75. package/dest/public/fixtures/utils.js +18 -22
  76. package/dest/public/index.d.ts +1 -2
  77. package/dest/public/index.d.ts.map +1 -1
  78. package/dest/public/index.js +1 -1
  79. package/dest/public/public_db_sources.d.ts +1 -1
  80. package/dest/public/public_db_sources.d.ts.map +1 -1
  81. package/dest/public/public_db_sources.js +4 -4
  82. package/dest/public/public_processor/public_processor.js +1 -1
  83. package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -10
  84. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  85. package/dest/public/public_tx_simulator/public_tx_context.js +4 -22
  86. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -3
  87. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  88. package/dest/public/public_tx_simulator/public_tx_simulator.js +20 -24
  89. package/dest/public/utils.d.ts +2 -4
  90. package/dest/public/utils.d.ts.map +1 -1
  91. package/dest/public/utils.js +4 -21
  92. package/dest/testing.d.ts +2 -0
  93. package/dest/testing.d.ts.map +1 -0
  94. package/dest/testing.js +1 -0
  95. package/package.json +15 -14
  96. package/src/common/db_interfaces.ts +6 -13
  97. package/src/common/debug_fn_name.ts +5 -5
  98. package/src/common/message_load_oracle_inputs.ts +8 -0
  99. package/src/private/acvm/acvm.ts +8 -24
  100. package/src/private/acvm/deserialize.ts +3 -30
  101. package/src/private/acvm/oracle/oracle.ts +148 -144
  102. package/src/private/acvm/oracle/typed_oracle.ts +12 -14
  103. package/src/private/execution_data_provider.ts +6 -10
  104. package/src/private/hashed_values_cache.ts +6 -14
  105. package/src/private/private_execution.ts +11 -11
  106. package/src/private/private_execution_oracle.ts +39 -138
  107. package/src/private/providers/acvm_native.ts +17 -6
  108. package/src/private/providers/acvm_wasm.ts +27 -20
  109. package/src/private/providers/acvm_wasm_with_blobs.ts +15 -12
  110. package/src/private/providers/circuit_recording/circuit_recorder.ts +283 -0
  111. package/src/private/providers/circuit_recording/simulation_provider_recorder_wrapper.ts +82 -0
  112. package/src/private/providers/simulation_provider.ts +30 -5
  113. package/src/private/simulator.ts +19 -5
  114. package/src/private/unconstrained_execution.ts +8 -4
  115. package/src/private/unconstrained_execution_oracle.ts +3 -6
  116. package/src/public/avm/avm_simulator.ts +0 -2
  117. package/src/public/avm/fixtures/avm_simulation_tester.ts +2 -2
  118. package/src/public/avm/fixtures/index.ts +15 -17
  119. package/src/public/avm/fixtures/simple_contract_data_source.ts +2 -2
  120. package/src/public/avm/journal/journal.ts +7 -7
  121. package/src/public/avm/test_utils.ts +1 -1
  122. package/src/public/fixtures/public_tx_simulation_tester.ts +31 -88
  123. package/src/public/fixtures/utils.ts +28 -26
  124. package/src/public/index.ts +1 -2
  125. package/src/public/public_db_sources.ts +4 -4
  126. package/src/public/public_processor/public_processor.ts +1 -1
  127. package/src/public/public_tx_simulator/public_tx_context.ts +12 -32
  128. package/src/public/public_tx_simulator/public_tx_simulator.ts +24 -30
  129. package/src/public/utils.ts +5 -21
  130. package/src/testing.ts +1 -0
  131. package/dest/public/avm/bytecode_utils.d.ts +0 -5
  132. package/dest/public/avm/bytecode_utils.d.ts.map +0 -1
  133. package/dest/public/avm/bytecode_utils.js +0 -17
  134. package/dest/public/execution.d.ts +0 -108
  135. package/dest/public/execution.d.ts.map +0 -1
  136. package/dest/public/execution.js +0 -9
  137. package/src/public/avm/bytecode_utils.ts +0 -17
  138. package/src/public/execution.ts +0 -140
@@ -28,15 +28,12 @@ export class HashedValuesCache {
28
28
  * @param hash - The hash to get the preimage of.
29
29
  * @returns The preimage.
30
30
  */
31
- public getPreimage(hash: Fr): Fr[] {
32
- if (hash.equals(Fr.ZERO)) {
31
+ public getPreimage(hash: Fr): Fr[] | undefined {
32
+ if (hash.isEmpty()) {
33
33
  return [];
34
+ } else {
35
+ return this.cache.get(hash.toBigInt());
34
36
  }
35
- const hashedValues = this.cache.get(hash.toBigInt());
36
- if (!hashedValues) {
37
- throw new Error(`Preimage for hash ${hash.toString()} not found in cache`);
38
- }
39
- return hashedValues;
40
37
  }
41
38
 
42
39
  /**
@@ -44,12 +41,7 @@ export class HashedValuesCache {
44
41
  * @param values - The values to store.
45
42
  * @returns The hash of the values.
46
43
  */
47
- public async store(values: Fr[]) {
48
- if (values.length === 0) {
49
- return Fr.ZERO;
50
- }
51
- const hashedValues = await HashedValues.fromValues(values);
52
- this.cache.set(hashedValues.hash.toBigInt(), hashedValues.values);
53
- return hashedValues.hash;
44
+ public store(values: Fr[], hash: Fr) {
45
+ this.cache.set(hash.toBigInt(), values);
54
46
  }
55
47
  }
@@ -3,7 +3,12 @@ import { Fr } from '@aztec/foundation/fields';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { Timer } from '@aztec/foundation/timer';
5
5
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
6
- import { type FunctionArtifact, type FunctionSelector, countArgumentsSize } from '@aztec/stdlib/abi';
6
+ import {
7
+ type FunctionArtifact,
8
+ type FunctionArtifactWithContractName,
9
+ type FunctionSelector,
10
+ countArgumentsSize,
11
+ } from '@aztec/stdlib/abi';
7
12
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
13
  import type { ContractInstance } from '@aztec/stdlib/contract';
9
14
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
@@ -13,7 +18,7 @@ import type { CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
13
18
  import { PrivateCallExecutionResult } from '@aztec/stdlib/tx';
14
19
 
15
20
  import { ExecutionError, resolveAssertionMessageFromError } from '../common/errors.js';
16
- import { fromACVMField, witnessMapToFields } from './acvm/deserialize.js';
21
+ import { witnessMapToFields } from './acvm/deserialize.js';
17
22
  import { type ACVMWitness, Oracle, extractCallStack } from './acvm/index.js';
18
23
  import type { ExecutionDataProvider } from './execution_data_provider.js';
19
24
  import type { PrivateExecutionOracle } from './private_execution_oracle.js';
@@ -25,19 +30,18 @@ import type { SimulationProvider } from './providers/simulation_provider.js';
25
30
  export async function executePrivateFunction(
26
31
  simulator: SimulationProvider,
27
32
  privateExecutionOracle: PrivateExecutionOracle,
28
- artifact: FunctionArtifact,
33
+ artifact: FunctionArtifactWithContractName,
29
34
  contractAddress: AztecAddress,
30
35
  functionSelector: FunctionSelector,
31
36
  log = createLogger('simulator:private_execution'),
32
37
  ): Promise<PrivateCallExecutionResult> {
33
38
  const functionName = await privateExecutionOracle.getDebugFunctionName();
34
39
  log.verbose(`Executing private function ${functionName}`, { contract: contractAddress });
35
- const acir = artifact.bytecode;
36
40
  const initialWitness = privateExecutionOracle.getInitialWitness(artifact);
37
41
  const acvmCallback = new Oracle(privateExecutionOracle);
38
42
  const timer = new Timer();
39
43
  const acirExecutionResult = await simulator
40
- .executeUserCircuit(acir, initialWitness, acvmCallback)
44
+ .executeUserCircuit(initialWitness, artifact, acvmCallback)
41
45
  .catch((err: Error) => {
42
46
  err.message = resolveAssertionMessageFromError(err, artifact);
43
47
  throw new ExecutionError(
@@ -73,13 +77,11 @@ export async function executePrivateFunction(
73
77
  const newNotes = privateExecutionOracle.getNewNotes();
74
78
  const noteHashNullifierCounterMap = privateExecutionOracle.getNoteHashNullifierCounterMap();
75
79
  const nestedExecutions = privateExecutionOracle.getNestedExecutions();
76
- const enqueuedPublicFunctionCalls = privateExecutionOracle.getEnqueuedPublicFunctionCalls();
77
- const publicTeardownFunctionCall = privateExecutionOracle.getPublicTeardownFunctionCall();
78
80
 
79
81
  log.debug(`Returning from call to ${contractAddress.toString()}:${functionSelector}`);
80
82
 
81
83
  return new PrivateCallExecutionResult(
82
- acir,
84
+ artifact.bytecode,
83
85
  Buffer.from(artifact.verificationKey!, 'base64'),
84
86
  partialWitness,
85
87
  publicInputs,
@@ -88,8 +90,6 @@ export async function executePrivateFunction(
88
90
  noteHashNullifierCounterMap,
89
91
  rawReturnValues,
90
92
  nestedExecutions,
91
- enqueuedPublicFunctionCalls,
92
- publicTeardownFunctionCall,
93
93
  contractClassLogs,
94
94
  );
95
95
  }
@@ -113,7 +113,7 @@ export function extractPrivateCircuitPublicInputs(
113
113
  if (returnedField === undefined) {
114
114
  throw new Error(`Missing return value for index ${i}`);
115
115
  }
116
- returnData.push(fromACVMField(returnedField));
116
+ returnData.push(Fr.fromString(returnedField));
117
117
  }
118
118
  return PrivateCircuitPublicInputs.fromFields(returnData);
119
119
  }
@@ -1,8 +1,4 @@
1
- import {
2
- MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS,
3
- PRIVATE_CONTEXT_INPUTS_LENGTH,
4
- PUBLIC_DISPATCH_SELECTOR,
5
- } from '@aztec/constants';
1
+ import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS, PRIVATE_CONTEXT_INPUTS_LENGTH } from '@aztec/constants';
6
2
  import { Fr } from '@aztec/foundation/fields';
7
3
  import { createLogger } from '@aztec/foundation/log';
8
4
  import {
@@ -23,10 +19,8 @@ import {
23
19
  CallContext,
24
20
  Capsule,
25
21
  CountedContractClassLog,
26
- CountedPublicExecutionRequest,
27
22
  NoteAndSlot,
28
23
  PrivateCallExecutionResult,
29
- PublicExecutionRequest,
30
24
  type TxContext,
31
25
  } from '@aztec/stdlib/tx';
32
26
 
@@ -64,8 +58,6 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
64
58
  private noteHashNullifierCounterMap: Map<number, number> = new Map();
65
59
  private contractClassLogs: CountedContractClassLog[] = [];
66
60
  private nestedExecutions: PrivateCallExecutionResult[] = [];
67
- private enqueuedPublicFunctionCalls: CountedPublicExecutionRequest[] = [];
68
- private publicTeardownFunctionCall: PublicExecutionRequest = PublicExecutionRequest.empty();
69
61
 
70
62
  constructor(
71
63
  private readonly argsHash: Fr,
@@ -80,7 +72,7 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
80
72
  private readonly noteCache: ExecutionNoteCache,
81
73
  executionDataProvider: ExecutionDataProvider,
82
74
  private provider: SimulationProvider,
83
- private totalPublicArgsCount: number,
75
+ private totalPublicCalldataCount: number,
84
76
  protected sideEffectCounter: number = 0,
85
77
  log = createLogger('simulator:client_execution_context'),
86
78
  scopes?: AztecAddress[],
@@ -100,8 +92,8 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
100
92
 
101
93
  const args = this.executionCache.getPreimage(this.argsHash);
102
94
 
103
- if (args.length !== argumentsSize) {
104
- throw new Error(`Invalid arguments size: expected ${argumentsSize}, got ${args.length}`);
95
+ if (args?.length !== argumentsSize) {
96
+ throw new Error(`Invalid arguments size: expected ${argumentsSize}, got ${args?.length}`);
105
97
  }
106
98
 
107
99
  const privateContextInputs = new PrivateContextInputs(
@@ -152,27 +144,13 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
152
144
  return this.nestedExecutions;
153
145
  }
154
146
 
155
- /**
156
- * Return the enqueued public function calls during this execution.
157
- */
158
- public getEnqueuedPublicFunctionCalls() {
159
- return this.enqueuedPublicFunctionCalls;
160
- }
161
-
162
- /**
163
- * Return the public teardown function call set during this execution.
164
- */
165
- public getPublicTeardownFunctionCall() {
166
- return this.publicTeardownFunctionCall;
167
- }
168
-
169
147
  /**
170
148
  * Store values in the execution cache.
171
149
  * @param values - Values to store.
172
150
  * @returns The hash of the values.
173
151
  */
174
- public override storeInExecutionCache(values: Fr[]): Promise<Fr> {
175
- return this.executionCache.store(values);
152
+ public override storeInExecutionCache(values: Fr[], hash: Fr) {
153
+ return this.executionCache.store(values, hash);
176
154
  }
177
155
 
178
156
  /**
@@ -181,7 +159,11 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
181
159
  * @returns The values.
182
160
  */
183
161
  public override loadFromExecutionCache(hash: Fr): Promise<Fr[]> {
184
- return Promise.resolve(this.executionCache.getPreimage(hash));
162
+ const preimage = this.executionCache.getPreimage(hash);
163
+ if (!preimage) {
164
+ throw new Error(`Preimage for hash ${hash.toString()} not found in cache`);
165
+ }
166
+ return Promise.resolve(preimage);
185
167
  }
186
168
 
187
169
  /**
@@ -413,7 +395,7 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
413
395
  this.noteCache,
414
396
  this.executionDataProvider,
415
397
  this.provider,
416
- this.totalPublicArgsCount,
398
+ this.totalPublicCalldataCount,
417
399
  sideEffectCounter,
418
400
  this.log,
419
401
  this.scopes,
@@ -440,131 +422,50 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
440
422
  };
441
423
  }
442
424
 
443
- /**
444
- * Creates a PublicExecutionRequest object representing the request to call a public function.
445
- * @param targetContractAddress - The address of the contract to call.
446
- * @param functionSelector - The function selector of the function to call.
447
- * @param argsHash - The arguments hash to pass to the function.
448
- * @param sideEffectCounter - The side effect counter at the start of the call.
449
- * @param isStaticCall - Whether the call is a static call.
450
- * @returns The public call stack item with the request information.
451
- */
452
- protected async createPublicExecutionRequest(
453
- callType: 'enqueued' | 'teardown',
454
- targetContractAddress: AztecAddress,
455
- functionSelector: FunctionSelector,
456
- argsHash: Fr,
457
- sideEffectCounter: number,
458
- isStaticCall: boolean,
459
- ) {
460
- const targetArtifact = await this.executionDataProvider.getFunctionArtifact(
461
- targetContractAddress,
462
- functionSelector,
463
- );
464
- const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
465
- const args = this.executionCache.getPreimage(argsHash);
466
-
467
- this.log.verbose(
468
- `Created ${callType} public execution request to ${targetArtifact.name}@${targetContractAddress}`,
469
- {
470
- sideEffectCounter,
471
- isStaticCall,
472
- functionSelector,
473
- targetContractAddress,
474
- callType,
475
- },
476
- );
477
-
478
- const request = PublicExecutionRequest.from({
479
- args,
480
- callContext: derivedCallContext,
481
- });
425
+ #onNewPublicFunctionCall(calldataHash: Fr) {
426
+ const calldata = this.executionCache.getPreimage(calldataHash);
427
+ if (!calldata) {
428
+ throw new Error('Calldata for public call not found in cache');
429
+ }
482
430
 
483
- if (callType === 'enqueued') {
484
- this.enqueuedPublicFunctionCalls.push(new CountedPublicExecutionRequest(request, sideEffectCounter));
485
- } else {
486
- this.publicTeardownFunctionCall = request;
431
+ this.totalPublicCalldataCount += calldata.length;
432
+ if (this.totalPublicCalldataCount > MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS) {
433
+ throw new Error(`Too many total args to all enqueued public calls! (> ${MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS})`);
487
434
  }
488
435
  }
489
436
 
490
437
  /**
491
- * Creates and enqueues a PublicExecutionRequest object representing the request to call a public function. No function
492
- * is actually called, since that must happen on the sequencer side. All the fields related to the result
493
- * of the execution are empty.
438
+ * Verify relevant information when a public function is enqueued.
494
439
  * @param targetContractAddress - The address of the contract to call.
495
- * @param functionSelector - The function selector of the function to call.
496
- * @param argsHash - The arguments hash to pass to the function.
440
+ * @param calldataHash - The hash of the function selector and arguments.
497
441
  * @param sideEffectCounter - The side effect counter at the start of the call.
498
442
  * @param isStaticCall - Whether the call is a static call.
499
- * @returns The public call stack item with the request information.
500
443
  */
501
- public override async enqueuePublicFunctionCall(
502
- targetContractAddress: AztecAddress,
503
- functionSelector: FunctionSelector,
504
- argsHash: Fr,
505
- sideEffectCounter: number,
506
- isStaticCall: boolean,
507
- ): Promise<Fr> {
508
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
509
- // WARNING: This is insecure and should be temporary!
510
- // The oracle re-hashes the arguments and returns a new args_hash.
511
- // new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
512
- // We don't validate or compute it in the circuit because a) it's harder to do with slices, and
513
- // b) this is only temporary.
514
- const newArgs = [functionSelector.toField(), ...this.executionCache.getPreimage(argsHash)];
515
- const newArgsHash = await this.executionCache.store(newArgs);
516
- await this.createPublicExecutionRequest(
517
- 'enqueued',
518
- targetContractAddress,
519
- FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
520
- newArgsHash,
521
- sideEffectCounter,
522
- isStaticCall,
523
- );
524
- this.totalPublicArgsCount += newArgs.length;
525
- if (this.totalPublicArgsCount > MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS) {
526
- throw new Error(`Too many total args to all enqueued public calls! (> ${MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS})`);
527
- }
528
- return newArgsHash;
444
+ public override notifyEnqueuedPublicFunctionCall(
445
+ _targetContractAddress: AztecAddress,
446
+ calldataHash: Fr,
447
+ _sideEffectCounter: number,
448
+ _isStaticCall: boolean,
449
+ ) {
450
+ this.#onNewPublicFunctionCall(calldataHash);
451
+ return Promise.resolve();
529
452
  }
530
453
 
531
454
  /**
532
- * Creates a PublicExecutionRequest and sets it as the public teardown function. No function
533
- * is actually called, since that must happen on the sequencer side. All the fields related to the result
534
- * of the execution are empty.
455
+ * Verify relevant information when a public teardown function is set.
535
456
  * @param targetContractAddress - The address of the contract to call.
536
- * @param functionSelector - The function selector of the function to call.
537
457
  * @param argsHash - The arguments hash to pass to the function.
538
458
  * @param sideEffectCounter - The side effect counter at the start of the call.
539
459
  * @param isStaticCall - Whether the call is a static call.
540
- * @returns The public call stack item with the request information.
541
460
  */
542
- public override async setPublicTeardownFunctionCall(
543
- targetContractAddress: AztecAddress,
544
- functionSelector: FunctionSelector,
545
- argsHash: Fr,
546
- sideEffectCounter: number,
547
- isStaticCall: boolean,
548
- ): Promise<Fr> {
549
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
550
- // WARNING: This is insecure and should be temporary!
551
- // The oracle rehashes the arguments and returns a new args_hash.
552
- // new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
553
- // We don't validate or compute it in the circuit because a) it's harder to do with slices, and
554
- // b) this is only temporary.
555
- const newArgsHash = await this.executionCache.store([
556
- functionSelector.toField(),
557
- ...this.executionCache.getPreimage(argsHash),
558
- ]);
559
- await this.createPublicExecutionRequest(
560
- 'teardown',
561
- targetContractAddress,
562
- FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
563
- newArgsHash,
564
- sideEffectCounter,
565
- isStaticCall,
566
- );
567
- return newArgsHash;
461
+ public override notifySetPublicTeardownFunctionCall(
462
+ _targetContractAddress: AztecAddress,
463
+ calldataHash: Fr,
464
+ _sideEffectCounter: number,
465
+ _isStaticCall: boolean,
466
+ ) {
467
+ this.#onNewPublicFunctionCall(calldataHash);
468
+ return Promise.resolve();
568
469
  }
569
470
 
570
471
  public override notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): Promise<void> {
@@ -1,8 +1,10 @@
1
1
  import { runInDirectory } from '@aztec/foundation/fs';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
- import type { WitnessMap } from '@aztec/noir-types';
5
- import type { NoirCompiledCircuit } from '@aztec/stdlib/noir';
4
+ import type { WitnessMap } from '@aztec/noir-acvm_js';
5
+ import type { ForeignCallHandler } from '@aztec/noir-protocol-circuits-types/types';
6
+ import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
7
+ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
6
8
 
7
9
  import * as proc from 'child_process';
8
10
  import { promises as fs } from 'fs';
@@ -136,12 +138,21 @@ export async function executeNativeCircuit(
136
138
 
137
139
  export class NativeACVMSimulator implements SimulationProvider {
138
140
  constructor(private workingDirectory: string, private pathToAcvm: string, private witnessFilename?: string) {}
139
- async executeProtocolCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
141
+
142
+ async executeProtocolCircuit(
143
+ input: ACVMWitness,
144
+ artifact: NoirCompiledCircuitWithName,
145
+ callback: ForeignCallHandler | undefined,
146
+ ): Promise<ACVMWitness> {
140
147
  // Execute the circuit on those initial witness values
141
148
 
149
+ if (callback) {
150
+ throw new Error('Native ACVM simulator does not support foreign calls. Ignoring callback.');
151
+ }
152
+
142
153
  const operation = async (directory: string) => {
143
154
  // Decode the bytecode from base64 since the acvm does not know about base64 encoding
144
- const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
155
+ const decodedBytecode = Buffer.from(artifact.bytecode, 'base64');
145
156
  // Execute the circuit
146
157
  const result = await executeNativeCircuit(
147
158
  input,
@@ -162,8 +173,8 @@ export class NativeACVMSimulator implements SimulationProvider {
162
173
  }
163
174
 
164
175
  executeUserCircuit(
165
- _acir: Buffer,
166
- _initialWitness: ACVMWitness,
176
+ _input: ACVMWitness,
177
+ _artifact: FunctionArtifactWithContractName,
167
178
  _callback: ACIRCallback,
168
179
  ): Promise<ACIRExecutionResult> {
169
180
  throw new Error('Not implemented');
@@ -1,11 +1,10 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
- import initACVM, { type ExecutionError, executeCircuit } from '@aztec/noir-acvm_js';
2
+ import initACVM, { type ExecutionError, type ForeignCallHandler, executeCircuit } from '@aztec/noir-acvm_js';
3
3
  import initAbi from '@aztec/noir-noirc_abi';
4
- import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types/client';
5
- import type { WitnessMap } from '@aztec/noir-types';
6
- import type { NoirCompiledCircuit } from '@aztec/stdlib/noir';
4
+ import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
5
+ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
7
6
 
8
- import { type ACIRCallback, acvm } from '../acvm/acvm.js';
7
+ import { type ACIRCallback, type ACIRExecutionResult, acvm } from '../acvm/acvm.js';
9
8
  import type { ACVMWitness } from '../acvm/acvm_types.js';
10
9
  import { type SimulationProvider, enrichNoirError } from './simulation_provider.js';
11
10
 
@@ -22,41 +21,49 @@ export class WASMSimulator implements SimulationProvider {
22
21
  }
23
22
  }
24
23
 
25
- async executeProtocolCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
26
- this.log.debug('init', { hash: compiledCircuit.hash });
24
+ async executeProtocolCircuit(
25
+ input: ACVMWitness,
26
+ artifact: NoirCompiledCircuitWithName,
27
+ callback: ForeignCallHandler,
28
+ ): Promise<ACVMWitness> {
29
+ this.log.debug('init', { hash: artifact.hash });
27
30
  await this.init();
28
- // Execute the circuit on those initial witness values
29
- //
31
+
30
32
  // Decode the bytecode from base64 since the acvm does not know about base64 encoding
31
- const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
33
+ const decodedBytecode = Buffer.from(artifact.bytecode, 'base64');
32
34
  //
33
35
  // Execute the circuit
34
36
  try {
35
- const _witnessMap = await executeCircuit(
37
+ const result = await executeCircuit(
36
38
  decodedBytecode,
37
39
  input,
38
- foreignCallHandler, // handle calls to debug_log
40
+ callback, // handle calls to debug_log
39
41
  );
40
- this.log.debug('execution successful', { hash: compiledCircuit.hash });
41
- return _witnessMap;
42
+ this.log.debug('execution successful', { hash: artifact.hash });
43
+ return result;
42
44
  } catch (err) {
43
- // Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
45
+ // Typescript types caught errors as unknown or any, so we need to narrow its type to check if it has raw
46
+ // assertion payload.
44
47
  if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
45
- const parsed = enrichNoirError(compiledCircuit, err as ExecutionError);
48
+ const parsed = enrichNoirError(artifact, err as ExecutionError);
46
49
  this.log.debug('execution failed', {
47
- hash: compiledCircuit.hash,
50
+ hash: artifact.hash,
48
51
  error: parsed,
49
52
  message: parsed.message,
50
53
  });
51
54
  throw parsed;
52
55
  }
53
- this.log.debug('execution failed', { hash: compiledCircuit.hash, error: err });
56
+ this.log.debug('execution failed', { hash: artifact.hash, error: err });
54
57
  throw new Error(`Circuit execution failed: ${err}`);
55
58
  }
56
59
  }
57
60
 
58
- async executeUserCircuit(acir: Buffer, initialWitness: ACVMWitness, callback: ACIRCallback) {
61
+ async executeUserCircuit(
62
+ input: ACVMWitness,
63
+ artifact: FunctionArtifactWithContractName,
64
+ callback: ACIRCallback,
65
+ ): Promise<ACIRExecutionResult> {
59
66
  await this.init();
60
- return acvm(acir, initialWitness, callback);
67
+ return acvm(artifact.bytecode, input, callback);
61
68
  }
62
69
  }
@@ -1,7 +1,7 @@
1
- import { type ExecutionError, executeCircuit } from '@aztec/noir-acvm_js';
2
- import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types/server';
1
+ import { type ExecutionError, type ForeignCallHandler, executeCircuit } from '@aztec/noir-acvm_js';
3
2
  import type { WitnessMap } from '@aztec/noir-types';
4
- import type { NoirCompiledCircuit } from '@aztec/stdlib/noir';
3
+ import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
4
+ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
5
5
 
6
6
  import type { ACIRCallback, ACIRExecutionResult } from '../acvm/acvm.js';
7
7
  import type { ACVMWitness } from '../acvm/acvm_types.js';
@@ -15,33 +15,36 @@ import { type SimulationProvider, enrichNoirError } from './simulation_provider.
15
15
  * It is only used in the context of server-side code executing simulated protocol circuits.
16
16
  */
17
17
  export class WASMSimulatorWithBlobs implements SimulationProvider {
18
- async executeProtocolCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
19
- // Execute the circuit on those initial witness values
20
- //
18
+ async executeProtocolCircuit(
19
+ input: WitnessMap,
20
+ artifact: NoirCompiledCircuitWithName,
21
+ callback: ForeignCallHandler,
22
+ ): Promise<WitnessMap> {
21
23
  // Decode the bytecode from base64 since the acvm does not know about base64 encoding
22
- const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
24
+ const decodedBytecode = Buffer.from(artifact.bytecode, 'base64');
23
25
  //
24
26
  // Execute the circuit
25
27
  try {
26
28
  const _witnessMap = await executeCircuit(
27
29
  decodedBytecode,
28
30
  input,
29
- foreignCallHandler, // handle calls to debug_log and evaluate_blobs mock
31
+ callback, // handle calls to debug_log and evaluate_blobs mock
30
32
  );
31
33
 
32
34
  return _witnessMap;
33
35
  } catch (err) {
34
- // Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
36
+ // Typescript types caught errors as unknown or any, so we need to narrow its type to check if it has raw
37
+ // assertion payload.
35
38
  if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
36
- throw enrichNoirError(compiledCircuit, err as ExecutionError);
39
+ throw enrichNoirError(artifact, err as ExecutionError);
37
40
  }
38
41
  throw new Error(`Circuit execution failed: ${err}`);
39
42
  }
40
43
  }
41
44
 
42
45
  executeUserCircuit(
43
- _acir: Buffer,
44
- _initialWitness: ACVMWitness,
46
+ _input: ACVMWitness,
47
+ _artifact: FunctionArtifactWithContractName,
45
48
  _callback: ACIRCallback,
46
49
  ): Promise<ACIRExecutionResult> {
47
50
  throw new Error('Not implemented');