@aztec/simulator 0.69.1 → 0.70.0

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 (137) hide show
  1. package/dest/acvm/acvm.d.ts +1 -2
  2. package/dest/acvm/acvm.d.ts.map +1 -1
  3. package/dest/acvm/acvm.js +12 -2
  4. package/dest/acvm/index.d.ts +1 -1
  5. package/dest/acvm/index.d.ts.map +1 -1
  6. package/dest/acvm/index.js +2 -2
  7. package/dest/acvm/oracle/oracle.d.ts +13 -5
  8. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/oracle.js +46 -21
  10. package/dest/acvm/oracle/typed_oracle.d.ts +8 -17
  11. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  12. package/dest/acvm/oracle/typed_oracle.js +16 -23
  13. package/dest/avm/avm_simulator.d.ts.map +1 -1
  14. package/dest/avm/avm_simulator.js +7 -1
  15. package/dest/avm/fixtures/index.d.ts +2 -3
  16. package/dest/avm/fixtures/index.d.ts.map +1 -1
  17. package/dest/avm/fixtures/index.js +4 -4
  18. package/dest/avm/journal/journal.d.ts +3 -4
  19. package/dest/avm/journal/journal.d.ts.map +1 -1
  20. package/dest/avm/journal/journal.js +11 -10
  21. package/dest/avm/journal/nullifiers.d.ts +1 -1
  22. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  23. package/dest/avm/journal/public_storage.d.ts +1 -1
  24. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  25. package/dest/client/client_execution_context.d.ts +29 -18
  26. package/dest/client/client_execution_context.d.ts.map +1 -1
  27. package/dest/client/client_execution_context.js +42 -29
  28. package/dest/client/db_oracle.d.ts +24 -16
  29. package/dest/client/db_oracle.d.ts.map +1 -1
  30. package/dest/client/db_oracle.js +1 -1
  31. package/dest/client/execution_note_cache.d.ts +27 -4
  32. package/dest/client/execution_note_cache.d.ts.map +1 -1
  33. package/dest/client/execution_note_cache.js +62 -12
  34. package/dest/client/index.d.ts +11 -3
  35. package/dest/client/index.d.ts.map +1 -1
  36. package/dest/client/index.js +11 -4
  37. package/dest/client/private_execution.d.ts +3 -2
  38. package/dest/client/private_execution.d.ts.map +1 -1
  39. package/dest/client/private_execution.js +9 -7
  40. package/dest/client/simulator.d.ts +4 -2
  41. package/dest/client/simulator.d.ts.map +1 -1
  42. package/dest/client/simulator.js +13 -8
  43. package/dest/client/unconstrained_execution.d.ts +2 -1
  44. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  45. package/dest/client/unconstrained_execution.js +6 -4
  46. package/dest/client/view_data_oracle.d.ts +4 -10
  47. package/dest/client/view_data_oracle.d.ts.map +1 -1
  48. package/dest/client/view_data_oracle.js +17 -19
  49. package/dest/common/hashed_values_cache.d.ts +28 -0
  50. package/dest/common/hashed_values_cache.d.ts.map +1 -0
  51. package/dest/common/{packed_values_cache.js → hashed_values_cache.js} +22 -22
  52. package/dest/common/index.d.ts +1 -1
  53. package/dest/common/index.js +1 -1
  54. package/dest/common/message_load_oracle_inputs.d.ts +15 -0
  55. package/dest/common/message_load_oracle_inputs.d.ts.map +1 -0
  56. package/dest/common/message_load_oracle_inputs.js +15 -0
  57. package/dest/common/simulation_provider.d.ts +19 -0
  58. package/dest/common/simulation_provider.d.ts.map +1 -0
  59. package/dest/common/simulation_provider.js +27 -0
  60. package/dest/common.d.ts +2 -0
  61. package/dest/common.d.ts.map +1 -0
  62. package/dest/common.js +2 -0
  63. package/dest/providers/acvm_native.d.ts +5 -2
  64. package/dest/providers/acvm_native.d.ts.map +1 -1
  65. package/dest/providers/acvm_native.js +5 -2
  66. package/dest/providers/acvm_wasm.d.ts +8 -2
  67. package/dest/providers/acvm_wasm.d.ts.map +1 -1
  68. package/dest/providers/acvm_wasm.js +31 -5
  69. package/dest/providers/acvm_wasm_with_blobs.d.ts +14 -2
  70. package/dest/providers/acvm_wasm_with_blobs.d.ts.map +1 -1
  71. package/dest/providers/acvm_wasm_with_blobs.js +25 -5
  72. package/dest/providers/factory.d.ts +1 -1
  73. package/dest/providers/factory.d.ts.map +1 -1
  74. package/dest/providers/factory.js +1 -1
  75. package/dest/providers/index.d.ts +1 -1
  76. package/dest/providers/index.d.ts.map +1 -1
  77. package/dest/providers/index.js +2 -2
  78. package/dest/public/db_interfaces.d.ts +1 -1
  79. package/dest/public/db_interfaces.d.ts.map +1 -1
  80. package/dest/public/fixtures/index.d.ts +3 -3
  81. package/dest/public/fixtures/index.d.ts.map +1 -1
  82. package/dest/public/fixtures/index.js +48 -18
  83. package/dest/public/public_db_sources.d.ts +2 -1
  84. package/dest/public/public_db_sources.d.ts.map +1 -1
  85. package/dest/public/public_db_sources.js +2 -2
  86. package/dest/public/public_processor.js +2 -2
  87. package/dest/public/public_tx_context.d.ts +3 -7
  88. package/dest/public/public_tx_context.d.ts.map +1 -1
  89. package/dest/public/public_tx_context.js +7 -20
  90. package/dest/public/public_tx_simulator.js +5 -5
  91. package/{src/index.ts → dest/server.d.ts} +1 -2
  92. package/dest/server.d.ts.map +1 -0
  93. package/dest/server.js +6 -0
  94. package/package.json +11 -12
  95. package/src/acvm/acvm.ts +20 -3
  96. package/src/acvm/index.ts +1 -1
  97. package/src/acvm/oracle/oracle.ts +48 -27
  98. package/src/acvm/oracle/typed_oracle.ts +20 -24
  99. package/src/avm/avm_simulator.ts +6 -0
  100. package/src/avm/fixtures/index.ts +5 -4
  101. package/src/avm/journal/journal.ts +9 -9
  102. package/src/avm/journal/nullifiers.ts +1 -1
  103. package/src/avm/journal/public_storage.ts +1 -1
  104. package/src/client/client_execution_context.ts +47 -30
  105. package/src/client/db_oracle.ts +25 -17
  106. package/src/client/execution_note_cache.ts +67 -14
  107. package/src/client/index.ts +11 -3
  108. package/src/client/private_execution.ts +21 -17
  109. package/src/client/simulator.ts +20 -7
  110. package/src/client/unconstrained_execution.ts +17 -13
  111. package/src/client/view_data_oracle.ts +23 -19
  112. package/src/common/hashed_values_cache.ts +55 -0
  113. package/src/common/index.ts +1 -1
  114. package/src/common/message_load_oracle_inputs.ts +15 -0
  115. package/src/common/simulation_provider.ts +45 -0
  116. package/src/common.ts +1 -0
  117. package/src/providers/acvm_native.ts +12 -2
  118. package/src/providers/acvm_wasm.ts +36 -9
  119. package/src/providers/acvm_wasm_with_blobs.ts +35 -10
  120. package/src/providers/factory.ts +1 -1
  121. package/src/providers/index.ts +1 -1
  122. package/src/public/db_interfaces.ts +1 -1
  123. package/src/public/fixtures/index.ts +62 -26
  124. package/src/public/public_db_sources.ts +3 -6
  125. package/src/public/public_processor.ts +1 -1
  126. package/src/public/public_tx_context.ts +6 -19
  127. package/src/public/public_tx_simulator.ts +4 -4
  128. package/{dest/index.d.ts → src/server.ts} +0 -3
  129. package/dest/common/packed_values_cache.d.ts +0 -28
  130. package/dest/common/packed_values_cache.d.ts.map +0 -1
  131. package/dest/index.d.ts.map +0 -1
  132. package/dest/index.js +0 -8
  133. package/dest/providers/simulation_provider.d.ts +0 -9
  134. package/dest/providers/simulation_provider.d.ts.map +0 -1
  135. package/dest/providers/simulation_provider.js +0 -2
  136. package/src/common/packed_values_cache.ts +0 -55
  137. package/src/providers/simulation_provider.ts +0 -10
@@ -1,25 +1,50 @@
1
- import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types';
1
+ import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types/server';
2
2
  import { type NoirCompiledCircuit } from '@aztec/types/noir';
3
3
 
4
- import { executeCircuit } from '@noir-lang/acvm_js';
4
+ import { type ExecutionError, executeCircuit } from '@noir-lang/acvm_js';
5
5
  import { type WitnessMap } from '@noir-lang/types';
6
6
 
7
- import { type SimulationProvider } from './simulation_provider.js';
7
+ import { type ACIRCallback, type ACIRExecutionResult } from '../acvm/acvm.js';
8
+ import { type ACVMWitness } from '../acvm/acvm_types.js';
9
+ import { type SimulationProvider, parseErrorPayload } from '../common/simulation_provider.js';
8
10
 
11
+ /**
12
+ * A simulation provider that uses the WASM simulator with the ability to handle blobs via the foreign call handler.
13
+ * This class is temporary while brillig cannot handle the blob math, and it is kept separate
14
+ * because the zkg commitment library used in the blob code is not browser compatible.
15
+ *
16
+ * It is only used in the context of server-side code executing simulated protocol circuits.
17
+ */
9
18
  export class WASMSimulatorWithBlobs implements SimulationProvider {
10
- async simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
19
+ async executeProtocolCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
11
20
  // Execute the circuit on those initial witness values
12
21
  //
13
22
  // Decode the bytecode from base64 since the acvm does not know about base64 encoding
14
23
  const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
15
24
  //
16
25
  // Execute the circuit
17
- const _witnessMap = await executeCircuit(
18
- decodedBytecode,
19
- input,
20
- foreignCallHandler, // handle calls to debug_log and evaluate_blobs mock
21
- );
26
+ try {
27
+ const _witnessMap = await executeCircuit(
28
+ decodedBytecode,
29
+ input,
30
+ foreignCallHandler, // handle calls to debug_log and evaluate_blobs mock
31
+ );
22
32
 
23
- return _witnessMap;
33
+ return _witnessMap;
34
+ } catch (err) {
35
+ // Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
36
+ if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
37
+ throw parseErrorPayload(compiledCircuit.abi, err as ExecutionError);
38
+ }
39
+ throw new Error(`Circuit execution failed: ${err}`);
40
+ }
41
+ }
42
+
43
+ executeUserCircuit(
44
+ _acir: Buffer,
45
+ _initialWitness: ACVMWitness,
46
+ _callback: ACIRCallback,
47
+ ): Promise<ACIRExecutionResult> {
48
+ throw new Error('Not implemented');
24
49
  }
25
50
  }
@@ -2,9 +2,9 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import { promises as fs } from 'fs';
4
4
 
5
+ import { type SimulationProvider } from '../common/simulation_provider.js';
5
6
  import { NativeACVMSimulator } from './acvm_native.js';
6
7
  import { WASMSimulator } from './acvm_wasm.js';
7
- import { type SimulationProvider } from './simulation_provider.js';
8
8
 
9
9
  export type SimulationProviderConfig = {
10
10
  acvmBinaryPath?: string;
@@ -1,4 +1,4 @@
1
1
  export * from './acvm_native.js';
2
2
  export * from './acvm_wasm_with_blobs.js';
3
- export * from './simulation_provider.js';
3
+ export * from '../common/simulation_provider.js';
4
4
  export * from './factory.js';
@@ -7,7 +7,7 @@ import {
7
7
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
8
8
  import { type Fr } from '@aztec/foundation/fields';
9
9
 
10
- import { type MessageLoadOracleInputs } from '../acvm/index.js';
10
+ import { type MessageLoadOracleInputs } from '../common/message_load_oracle_inputs.js';
11
11
 
12
12
  /**
13
13
  * Database interface for providing access to public state.
@@ -32,25 +32,26 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
32
32
  import { Fr, Point } from '@aztec/foundation/fields';
33
33
  import { openTmpStore } from '@aztec/kv-store/lmdb';
34
34
  import { AvmTestContractArtifact } from '@aztec/noir-contracts.js/AvmTest';
35
- import {
36
- AvmEphemeralForest,
37
- AvmSimulator,
38
- PublicEnqueuedCallSideEffectTrace,
39
- PublicTxSimulator,
40
- WorldStateDB,
41
- } from '@aztec/simulator';
42
35
  import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
43
36
  import { MerkleTrees } from '@aztec/world-state';
44
37
 
45
38
  import { strict as assert } from 'assert';
46
39
 
47
40
  import { initContext, initExecutionEnvironment, initPersistableStateManager } from '../../avm/fixtures/index.js';
41
+ import { AvmEphemeralForest, AvmSimulator } from '../../server.js';
42
+ import { PublicEnqueuedCallSideEffectTrace } from '../enqueued_call_side_effect_trace.js';
43
+ import { WorldStateDB } from '../public_db_sources.js';
44
+ import { PublicTxSimulator } from '../public_tx_simulator.js';
48
45
 
49
46
  const TIMESTAMP = new Fr(99833);
50
47
 
51
48
  export async function simulateAvmTestContractGenerateCircuitInputs(
52
- functionName: string,
53
- args: Fr[] = [],
49
+ setupFunctionNames: string[],
50
+ setupArgs: Fr[][] = [],
51
+ appFunctionNames: string[],
52
+ appArgs: Fr[][] = [],
53
+ teardownFunctionName?: string,
54
+ teardownArgs: Fr[] = [],
54
55
  expectRevert: boolean = false,
55
56
  contractDataSource = new MockedAvmTestContractDataSource(),
56
57
  assertionErrString?: string,
@@ -71,17 +72,37 @@ export async function simulateAvmTestContractGenerateCircuitInputs(
71
72
  );
72
73
 
73
74
  const sender = AztecAddress.random();
74
- const functionSelector = getAvmTestContractFunctionSelector(functionName);
75
- args = [functionSelector.toField(), ...args];
76
75
  const callContext = new CallContext(
77
76
  sender,
78
77
  contractDataSource.firstContractInstance.address,
79
78
  contractDataSource.fnSelector,
80
79
  /*isStaticCall=*/ false,
81
80
  );
82
- const executionRequest = new PublicExecutionRequest(callContext, args);
81
+ const setupExecutionRequests: PublicExecutionRequest[] = [];
82
+ // we reverse order because the simulator expects it to be like a "stack" of calls to pop from
83
+ for (let i = setupFunctionNames.length - 1; i >= 0; i--) {
84
+ const functionSelector = getAvmTestContractFunctionSelector(setupFunctionNames[i]);
85
+ const fnArgs = [functionSelector.toField(), ...setupArgs[i]];
86
+ const executionRequest = new PublicExecutionRequest(callContext, fnArgs);
87
+ setupExecutionRequests.push(executionRequest);
88
+ }
89
+ const appExecutionRequests: PublicExecutionRequest[] = [];
90
+ // we reverse order because the simulator expects it to be like a "stack" of calls to pop from
91
+ for (let i = appFunctionNames.length - 1; i >= 0; i--) {
92
+ const functionSelector = getAvmTestContractFunctionSelector(appFunctionNames[i]);
93
+ const fnArgs = [functionSelector.toField(), ...appArgs[i]];
94
+ const executionRequest = new PublicExecutionRequest(callContext, fnArgs);
95
+ appExecutionRequests.push(executionRequest);
96
+ }
97
+
98
+ let teardownExecutionRequest: PublicExecutionRequest | undefined = undefined;
99
+ if (teardownFunctionName) {
100
+ const functionSelector = getAvmTestContractFunctionSelector(teardownFunctionName);
101
+ const fnArgs = [functionSelector.toField(), ...teardownArgs];
102
+ teardownExecutionRequest = new PublicExecutionRequest(callContext, fnArgs);
103
+ }
83
104
 
84
- const tx: Tx = createTxForPublicCall(executionRequest);
105
+ const tx: Tx = createTxForPublicCalls(setupExecutionRequests, appExecutionRequests, teardownExecutionRequest);
85
106
 
86
107
  const avmResult = await simulator.simulate(tx);
87
108
 
@@ -141,27 +162,38 @@ export async function simulateAvmTestContractCall(
141
162
  }
142
163
 
143
164
  /**
144
- * Craft a carrier transaction for a public call for simulation by PublicTxSimulator.
165
+ * Craft a carrier transaction for some public calls for simulation by PublicTxSimulator.
145
166
  */
146
- export function createTxForPublicCall(
147
- executionRequest: PublicExecutionRequest,
167
+ export function createTxForPublicCalls(
168
+ setupExecutionRequests: PublicExecutionRequest[],
169
+ appExecutionRequests: PublicExecutionRequest[],
170
+ teardownExecutionRequest?: PublicExecutionRequest,
148
171
  gasUsedByPrivate: Gas = Gas.empty(),
149
- isTeardown: boolean = false,
150
172
  ): Tx {
151
- const callRequest = executionRequest.toCallRequest();
173
+ assert(
174
+ setupExecutionRequests.length > 0 || appExecutionRequests.length > 0 || teardownExecutionRequest !== undefined,
175
+ "Can't create public tx with no enqueued calls",
176
+ );
177
+ const setupCallRequests = setupExecutionRequests.map(er => er.toCallRequest());
178
+ const appCallRequests = appExecutionRequests.map(er => er.toCallRequest());
152
179
  // use max limits
153
180
  const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
154
181
 
155
182
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
156
183
  // TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.
157
184
  forPublic.nonRevertibleAccumulatedData.nullifiers[0] = Fr.random(); // fake tx nullifier
158
- if (isTeardown) {
159
- forPublic.publicTeardownCallRequest = callRequest;
160
- } else {
161
- forPublic.revertibleAccumulatedData.publicCallRequests[0] = callRequest;
185
+
186
+ for (let i = 0; i < setupExecutionRequests.length; i++) {
187
+ forPublic.nonRevertibleAccumulatedData.publicCallRequests[i] = setupCallRequests[i];
188
+ }
189
+ for (let i = 0; i < appCallRequests.length; i++) {
190
+ forPublic.revertibleAccumulatedData.publicCallRequests[i] = appCallRequests[i];
191
+ }
192
+ if (teardownExecutionRequest) {
193
+ forPublic.publicTeardownCallRequest = teardownExecutionRequest.toCallRequest();
162
194
  }
163
195
 
164
- const teardownGasLimits = isTeardown ? gasLimits : Gas.empty();
196
+ const teardownGasLimits = teardownExecutionRequest ? gasLimits : Gas.empty();
165
197
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
166
198
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
167
199
  const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
@@ -173,9 +205,13 @@ export function createTxForPublicCall(
173
205
  AztecAddress.zero(),
174
206
  forPublic,
175
207
  );
176
- const tx = isTeardown ? Tx.newWithTxData(txData, executionRequest) : Tx.newWithTxData(txData);
177
- if (!isTeardown) {
178
- tx.enqueuedPublicFunctionCalls[0] = executionRequest;
208
+ const tx = Tx.newWithTxData(txData, teardownExecutionRequest);
209
+
210
+ for (let i = 0; i < setupExecutionRequests.length; i++) {
211
+ tx.enqueuedPublicFunctionCalls.push(setupExecutionRequests[i]);
212
+ }
213
+ for (let i = 0; i < appExecutionRequests.length; i++) {
214
+ tx.enqueuedPublicFunctionCalls.push(appExecutionRequests[i]);
179
215
  }
180
216
 
181
217
  return tx;
@@ -24,12 +24,9 @@ import { createLogger } from '@aztec/foundation/log';
24
24
  import { Timer } from '@aztec/foundation/timer';
25
25
  import { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
26
26
  import { ContractInstanceDeployedEvent } from '@aztec/protocol-contracts/instance-deployer';
27
- import {
28
- type CommitmentsDB,
29
- MessageLoadOracleInputs,
30
- type PublicContractsDB,
31
- type PublicStateDB,
32
- } from '@aztec/simulator';
27
+
28
+ import { MessageLoadOracleInputs } from '../common/message_load_oracle_inputs.js';
29
+ import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from './db_interfaces.js';
33
30
 
34
31
  /**
35
32
  * Implements the PublicContractsDB using a ContractDataSource.
@@ -290,7 +290,7 @@ export class PublicProcessor implements Traceable {
290
290
  return [result, failed, returns];
291
291
  }
292
292
 
293
- @trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.tryGetTxHash()?.toString() }))
293
+ @trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash().toString() }))
294
294
  private async processTx(tx: Tx, deadline?: Date): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
295
295
  const [time, [processedTx, returnValues]] = await elapsed(() => this.processTxWithinDeadline(tx, deadline));
296
296
 
@@ -7,7 +7,7 @@ import {
7
7
  type SimulationError,
8
8
  type Tx,
9
9
  TxExecutionPhase,
10
- TxHash,
10
+ type TxHash,
11
11
  } from '@aztec/circuit-types';
12
12
  import {
13
13
  AvmCircuitInputs,
@@ -61,6 +61,7 @@ export class PublicTxContext {
61
61
  public avmProvingRequest: AvmProvingRequest | undefined; // FIXME(dbanks12): remove
62
62
 
63
63
  constructor(
64
+ public readonly txHash: TxHash,
64
65
  public readonly state: PhaseStateManager,
65
66
  private readonly globalVariables: GlobalVariables,
66
67
  private readonly startStateReference: StateReference,
@@ -103,12 +104,14 @@ export class PublicTxContext {
103
104
  previousAccumulatedDataArrayLengths,
104
105
  );
105
106
 
107
+ const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
108
+
106
109
  // Transaction level state manager that will be forked for revertible phases.
107
110
  const txStateManager = await AvmPersistableStateManager.create(
108
111
  worldStateDB,
109
112
  enqueuedCallTrace,
110
113
  doMerkleOperations,
111
- fetchTxHash(nonRevertibleAccumulatedDataFromPrivate),
114
+ firstNullifier,
112
115
  );
113
116
 
114
117
  const gasSettings = tx.data.constants.txContext.gasSettings;
@@ -117,6 +120,7 @@ export class PublicTxContext {
117
120
  const gasAllocatedToPublic = applyMaxToAvailableGas(gasSettings.gasLimits.sub(gasUsedByPrivate));
118
121
 
119
122
  return new PublicTxContext(
123
+ tx.getTxHash(),
120
124
  new PhaseStateManager(txStateManager),
121
125
  globalVariables,
122
126
  await db.getStateReference(),
@@ -188,14 +192,6 @@ export class PublicTxContext {
188
192
  return this.revertCode;
189
193
  }
190
194
 
191
- /**
192
- * Construct & return transaction hash.
193
- * @returns The transaction's hash.
194
- */
195
- getTxHash(): TxHash {
196
- return fetchTxHash(this.nonRevertibleAccumulatedDataFromPrivate);
197
- }
198
-
199
195
  /**
200
196
  * Are there any call requests for the speciiied phase?
201
197
  */
@@ -452,12 +448,3 @@ function applyMaxToAvailableGas(availableGas: Gas) {
452
448
  /*l2Gas=*/ Math.min(availableGas.l2Gas, MAX_L2_GAS_PER_TX_PUBLIC_PORTION),
453
449
  );
454
450
  }
455
-
456
- function fetchTxHash(nonRevertibleAccumulatedData: PrivateToPublicAccumulatedData): TxHash {
457
- // Private kernel functions are executed client side and for this reason tx hash is already set as first nullifier
458
- const firstNullifier = nonRevertibleAccumulatedData.nullifiers[0];
459
- if (!firstNullifier || firstNullifier.isZero()) {
460
- throw new Error(`Cannot get tx hash since first nullifier is missing`);
461
- }
462
- return new TxHash(firstNullifier);
463
- }
@@ -219,8 +219,8 @@ export class PublicTxSimulator {
219
219
  const callRequests = context.getCallRequestsForPhase(phase);
220
220
  const executionRequests = context.getExecutionRequestsForPhase(phase);
221
221
 
222
- this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.getTxHash()}`, {
223
- txHash: context.getTxHash().toString(),
222
+ this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.txHash}`, {
223
+ txHash: context.txHash.toString(),
224
224
  phase: TxExecutionPhase[phase],
225
225
  callRequests: callRequests.length,
226
226
  executionRequests: executionRequests.length,
@@ -266,7 +266,7 @@ export class PublicTxSimulator {
266
266
  * @returns The result of execution.
267
267
  */
268
268
  @trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, _callRequest, executionRequest) => ({
269
- [Attributes.TX_HASH]: context.getTxHash().toString(),
269
+ [Attributes.TX_HASH]: context.txHash.toString(),
270
270
  [Attributes.TARGET_ADDRESS]: executionRequest.callContext.contractAddress.toString(),
271
271
  [Attributes.SENDER_ADDRESS]: executionRequest.callContext.msgSender.toString(),
272
272
  [Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString(),
@@ -294,7 +294,7 @@ export class PublicTxSimulator {
294
294
  const gasUsed = allocatedGas.sub(result.gasLeft); // by enqueued call
295
295
  context.consumeGas(phase, gasUsed);
296
296
  this.log.debug(
297
- `Simulated enqueued public call consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`,
297
+ `Simulated enqueued public call (${fnName}) consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`,
298
298
  );
299
299
 
300
300
  stateManager.traceEnqueuedCall(callRequest, executionRequest.args, result.reverted);
@@ -1,8 +1,5 @@
1
- export * from './acvm/index.js';
2
1
  export * from './avm/index.js';
3
- export * from './client/index.js';
4
2
  export * from './common/index.js';
5
3
  export * from './public/index.js';
6
4
  export * from './providers/index.js';
7
5
  export * from './stats/index.js';
8
- //# sourceMappingURL=index.d.ts.map
@@ -1,28 +0,0 @@
1
- import { PackedValues } from '@aztec/circuit-types';
2
- import { Fr } from '@aztec/circuits.js';
3
- /**
4
- * A cache for packed values (arguments, returns) during transaction execution.
5
- */
6
- export declare class PackedValuesCache {
7
- private cache;
8
- constructor(initialArguments?: PackedValues[]);
9
- /**
10
- * Creates a new packed values cache.
11
- * @param initialArguments - The initial arguments to add to the cache.
12
- * @returns The new packed values cache.
13
- */
14
- static create(initialArguments?: PackedValues[]): PackedValuesCache;
15
- /**
16
- * Unpacks packed values.
17
- * @param hash - The hash of the packed values.
18
- * @returns The unpacked values.
19
- */
20
- unpack(hash: Fr): Fr[];
21
- /**
22
- * Packs values.
23
- * @param values - The values to pack.
24
- * @returns The hash of the packed values.
25
- */
26
- pack(values: Fr[]): Fr;
27
- }
28
- //# sourceMappingURL=packed_values_cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"packed_values_cache.d.ts","sourceRoot":"","sources":["../../src/common/packed_values_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,KAAK,CAAoB;gBAErB,gBAAgB,GAAE,YAAY,EAAO;IAOjD;;;;OAIG;WACW,MAAM,CAAC,gBAAgB,GAAE,YAAY,EAAO;IAI1D;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE;IAW7B;;;;OAIG;IACI,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE;CAQzB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
package/dest/index.js DELETED
@@ -1,8 +0,0 @@
1
- export * from './acvm/index.js';
2
- export * from './avm/index.js';
3
- export * from './client/index.js';
4
- export * from './common/index.js';
5
- export * from './public/index.js';
6
- export * from './providers/index.js';
7
- export * from './stats/index.js';
8
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLGdCQUFnQixDQUFDO0FBQy9CLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyxtQkFBbUIsQ0FBQztBQUNsQyxjQUFjLG1CQUFtQixDQUFDO0FBQ2xDLGNBQWMsc0JBQXNCLENBQUM7QUFDckMsY0FBYyxrQkFBa0IsQ0FBQyJ9
@@ -1,9 +0,0 @@
1
- import { type NoirCompiledCircuit } from '@aztec/types/noir';
2
- import { type WitnessMap } from '@noir-lang/types';
3
- /**
4
- * Low level simulation interface
5
- */
6
- export interface SimulationProvider {
7
- simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap>;
8
- }
9
- //# sourceMappingURL=simulation_provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"simulation_provider.d.ts","sourceRoot":"","sources":["../../src/providers/simulation_provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC/F"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2ltdWxhdGlvbl9wcm92aWRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcm92aWRlcnMvc2ltdWxhdGlvbl9wcm92aWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
@@ -1,55 +0,0 @@
1
- import { PackedValues } from '@aztec/circuit-types';
2
- import { Fr } from '@aztec/circuits.js';
3
-
4
- /**
5
- * A cache for packed values (arguments, returns) during transaction execution.
6
- */
7
- export class PackedValuesCache {
8
- private cache: Map<bigint, Fr[]>;
9
-
10
- constructor(initialArguments: PackedValues[] = []) {
11
- this.cache = new Map();
12
- for (const initialArg of initialArguments) {
13
- this.cache.set(initialArg.hash.toBigInt(), initialArg.values);
14
- }
15
- }
16
-
17
- /**
18
- * Creates a new packed values cache.
19
- * @param initialArguments - The initial arguments to add to the cache.
20
- * @returns The new packed values cache.
21
- */
22
- public static create(initialArguments: PackedValues[] = []) {
23
- return new PackedValuesCache(initialArguments);
24
- }
25
-
26
- /**
27
- * Unpacks packed values.
28
- * @param hash - The hash of the packed values.
29
- * @returns The unpacked values.
30
- */
31
- public unpack(hash: Fr): Fr[] {
32
- if (hash.equals(Fr.ZERO)) {
33
- return [];
34
- }
35
- const packedValues = this.cache.get(hash.value);
36
- if (!packedValues) {
37
- throw new Error(`Packed values for hash ${hash.toString()} not found in cache`);
38
- }
39
- return packedValues;
40
- }
41
-
42
- /**
43
- * Packs values.
44
- * @param values - The values to pack.
45
- * @returns The hash of the packed values.
46
- */
47
- public pack(values: Fr[]) {
48
- if (values.length === 0) {
49
- return Fr.ZERO;
50
- }
51
- const packedValues = PackedValues.fromValues(values);
52
- this.cache.set(packedValues.hash.value, packedValues.values);
53
- return packedValues.hash;
54
- }
55
- }
@@ -1,10 +0,0 @@
1
- import { type NoirCompiledCircuit } from '@aztec/types/noir';
2
-
3
- import { type WitnessMap } from '@noir-lang/types';
4
-
5
- /**
6
- * Low level simulation interface
7
- */
8
- export interface SimulationProvider {
9
- simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap>;
10
- }