@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,7 +28,7 @@ export function mockStorageReadWithMap(worldStateDB: PublicTreesDB, mockedStorag
28
28
  }
29
29
 
30
30
  export function mockNoteHashExists(worldStateDB: PublicTreesDB, _leafIndex: Fr, value?: Fr) {
31
- (worldStateDB as jest.Mocked<PublicTreesDB>).getCommitmentValue.mockImplementation((index: bigint) => {
31
+ (worldStateDB as jest.Mocked<PublicTreesDB>).getNoteHash.mockImplementation((index: bigint) => {
32
32
  if (index == _leafIndex.toBigInt()) {
33
33
  return Promise.resolve(value);
34
34
  } else {
@@ -1,19 +1,19 @@
1
- import { PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
1
+ import { asyncMap } from '@aztec/foundation/async-map';
2
2
  import { Fr } from '@aztec/foundation/fields';
3
- import { type ContractArtifact, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
+ import { type ContractArtifact, encodeArguments } from '@aztec/stdlib/abi';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import { GasFees } from '@aztec/stdlib/gas';
6
6
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
7
- import { PublicExecutionRequest, type Tx } from '@aztec/stdlib/tx';
8
- import { CallContext, GlobalVariables } from '@aztec/stdlib/tx';
7
+ import { PublicCallRequest } from '@aztec/stdlib/kernel';
8
+ import { GlobalVariables, PublicCallRequestWithCalldata, type Tx } from '@aztec/stdlib/tx';
9
9
  import { NativeWorldStateService } from '@aztec/world-state';
10
10
 
11
11
  import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
12
- import { getContractFunctionArtifact, getFunctionSelector } from '../avm/fixtures/index.js';
12
+ import { getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/index.js';
13
13
  import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
14
14
  import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
15
15
  import { type PublicTxResult, PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
16
- import { createTxForPublicCalls } from './index.js';
16
+ import { createTxForPublicCalls } from './utils.js';
17
17
 
18
18
  const TIMESTAMP = new Fr(99833);
19
19
  const DEFAULT_GAS_FEES = new GasFees(2, 3);
@@ -54,68 +54,13 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
54
54
  /* need some unique first nullifier for note-nonce computations */
55
55
  firstNullifier = new Fr(420000 + this.txCount++),
56
56
  ): Promise<Tx> {
57
- const setupExecutionRequests: PublicExecutionRequest[] = [];
58
- for (let i = 0; i < setupCalls.length; i++) {
59
- const address = setupCalls[i].address;
60
- const contractArtifact =
61
- setupCalls[i].contractArtifact || (await this.contractDataSource.getContractArtifact(address));
62
- if (!contractArtifact) {
63
- throw new Error(`Contract artifact not found for address: ${address}`);
64
- }
65
- const req = await executionRequestForCall(
66
- contractArtifact,
67
- sender,
68
- address,
69
- setupCalls[i].fnName,
70
- setupCalls[i].args,
71
- setupCalls[i].isStaticCall,
72
- );
73
- setupExecutionRequests.push(req);
74
- }
75
- const appExecutionRequests: PublicExecutionRequest[] = [];
76
- for (let i = 0; i < appCalls.length; i++) {
77
- const address = appCalls[i].address;
78
- const contractArtifact =
79
- appCalls[i].contractArtifact || (await this.contractDataSource.getContractArtifact(address));
80
- if (!contractArtifact) {
81
- throw new Error(`Contract artifact not found for address: ${address}`);
82
- }
83
- const req = await executionRequestForCall(
84
- contractArtifact,
85
- sender,
86
- address,
87
- appCalls[i].fnName,
88
- appCalls[i].args,
89
- appCalls[i].isStaticCall,
90
- );
91
- appExecutionRequests.push(req);
92
- }
57
+ const setupCallRequests = await asyncMap(setupCalls, call => this.#createPubicCallRequestForCall(call, sender));
58
+ const appCallRequests = await asyncMap(appCalls, call => this.#createPubicCallRequestForCall(call, sender));
59
+ const teardownCallRequest = teardownCall
60
+ ? await this.#createPubicCallRequestForCall(teardownCall, sender)
61
+ : undefined;
93
62
 
94
- let teardownExecutionRequest: PublicExecutionRequest | undefined = undefined;
95
- if (teardownCall) {
96
- const address = teardownCall.address;
97
- const contractArtifact =
98
- teardownCall.contractArtifact || (await this.contractDataSource.getContractArtifact(address));
99
- if (!contractArtifact) {
100
- throw new Error(`Contract artifact not found for address: ${address}`);
101
- }
102
- teardownExecutionRequest = await executionRequestForCall(
103
- contractArtifact,
104
- sender,
105
- address,
106
- teardownCall.fnName,
107
- teardownCall.args,
108
- teardownCall.isStaticCall,
109
- );
110
- }
111
-
112
- return await createTxForPublicCalls(
113
- firstNullifier,
114
- setupExecutionRequests,
115
- appExecutionRequests,
116
- teardownExecutionRequest,
117
- feePayer,
118
- );
63
+ return createTxForPublicCalls(firstNullifier, setupCallRequests, appCallRequests, teardownCallRequest, feePayer);
119
64
  }
120
65
 
121
66
  public async simulateTx(
@@ -143,28 +88,26 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
143
88
 
144
89
  return avmResult;
145
90
  }
146
- }
147
91
 
148
- async function executionRequestForCall(
149
- contractArtifact: ContractArtifact,
150
- sender: AztecAddress,
151
- address: AztecAddress,
152
- fnName: string,
153
- args: Fr[] = [],
154
- isStaticCall: boolean = false,
155
- ): Promise<PublicExecutionRequest> {
156
- const fnSelector = await getFunctionSelector(fnName, contractArtifact);
157
- const fnAbi = getContractFunctionArtifact(fnName, contractArtifact);
158
- const encodedArgs = encodeArguments(fnAbi!, args);
159
- const calldata = [fnSelector.toField(), ...encodedArgs];
160
-
161
- const callContext = new CallContext(
162
- sender,
163
- address,
164
- /*selector=*/ new FunctionSelector(PUBLIC_DISPATCH_SELECTOR),
165
- isStaticCall,
166
- );
167
- return new PublicExecutionRequest(callContext, calldata);
92
+ async #createPubicCallRequestForCall(
93
+ call: TestEnqueuedCall,
94
+ sender: AztecAddress,
95
+ ): Promise<PublicCallRequestWithCalldata> {
96
+ const address = call.address;
97
+ const contractArtifact = call.contractArtifact || (await this.contractDataSource.getContractArtifact(address));
98
+ if (!contractArtifact) {
99
+ throw new Error(`Contract artifact not found for address: ${address}`);
100
+ }
101
+
102
+ const fnSelector = await getFunctionSelector(call.fnName, contractArtifact);
103
+ const fnAbi = getContractFunctionAbi(call.fnName, contractArtifact)!;
104
+ const encodedArgs = encodeArguments(fnAbi, call.args);
105
+ const calldata = [fnSelector.toField(), ...encodedArgs];
106
+ const isStaticCall = call.isStaticCall ?? false;
107
+ const request = await PublicCallRequest.fromCalldata(sender, address, isStaticCall, calldata);
108
+
109
+ return new PublicCallRequestWithCalldata(request, calldata);
110
+ }
168
111
  }
169
112
 
170
113
  export function defaultGlobals() {
@@ -24,28 +24,33 @@ import {
24
24
  countAccumulatedItems,
25
25
  } from '@aztec/stdlib/kernel';
26
26
  import { ContractClassLog, PrivateLog } from '@aztec/stdlib/logs';
27
- import { type PublicExecutionRequest, Tx } from '@aztec/stdlib/tx';
28
- import { BlockHeader, TxConstantData, TxContext } from '@aztec/stdlib/tx';
27
+ import { ClientIvcProof } from '@aztec/stdlib/proofs';
28
+ import {
29
+ BlockHeader,
30
+ HashedValues,
31
+ PublicCallRequestWithCalldata,
32
+ Tx,
33
+ TxConstantData,
34
+ TxContext,
35
+ } from '@aztec/stdlib/tx';
29
36
 
30
37
  import { strict as assert } from 'assert';
31
38
 
32
39
  /**
33
40
  * Craft a carrier transaction for some public calls for simulation by PublicTxSimulator.
34
41
  */
35
- export async function createTxForPublicCalls(
42
+ export function createTxForPublicCalls(
36
43
  firstNullifier: Fr,
37
- setupExecutionRequests: PublicExecutionRequest[],
38
- appExecutionRequests: PublicExecutionRequest[],
39
- teardownExecutionRequest?: PublicExecutionRequest,
44
+ setupCallRequests: PublicCallRequestWithCalldata[],
45
+ appCallRequests: PublicCallRequestWithCalldata[],
46
+ teardownCallRequest?: PublicCallRequestWithCalldata,
40
47
  feePayer = AztecAddress.zero(),
41
48
  gasUsedByPrivate: Gas = Gas.empty(),
42
- ): Promise<Tx> {
49
+ ): Tx {
43
50
  assert(
44
- setupExecutionRequests.length > 0 || appExecutionRequests.length > 0 || teardownExecutionRequest !== undefined,
51
+ setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
45
52
  "Can't create public tx with no enqueued calls",
46
53
  );
47
- const setupCallRequests = await Promise.all(setupExecutionRequests.map(er => er.toCallRequest()));
48
- const appCallRequests = await Promise.all(appExecutionRequests.map(er => er.toCallRequest()));
49
54
  // use max limits
50
55
  const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
51
56
 
@@ -55,17 +60,18 @@ export async function createTxForPublicCalls(
55
60
 
56
61
  // We reverse order because the simulator expects it to be like a "stack" of calls to pop from
57
62
  for (let i = setupCallRequests.length - 1; i >= 0; i--) {
58
- forPublic.nonRevertibleAccumulatedData.publicCallRequests[i] = setupCallRequests[i];
63
+ forPublic.nonRevertibleAccumulatedData.publicCallRequests[setupCallRequests.length - i - 1] =
64
+ setupCallRequests[i].request;
59
65
  }
60
66
  for (let i = appCallRequests.length - 1; i >= 0; i--) {
61
- forPublic.revertibleAccumulatedData.publicCallRequests[i] = appCallRequests[i];
67
+ forPublic.revertibleAccumulatedData.publicCallRequests[appCallRequests.length - i - 1] = appCallRequests[i].request;
62
68
  }
63
- if (teardownExecutionRequest) {
64
- forPublic.publicTeardownCallRequest = await teardownExecutionRequest.toCallRequest();
69
+ if (teardownCallRequest) {
70
+ forPublic.publicTeardownCallRequest = teardownCallRequest.request;
65
71
  }
66
72
 
67
73
  const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
68
- const teardownGasLimits = teardownExecutionRequest ? gasLimits : Gas.empty();
74
+ const teardownGasLimits = teardownCallRequest ? gasLimits : Gas.empty();
69
75
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
70
76
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
71
77
  const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
@@ -77,18 +83,14 @@ export async function createTxForPublicCalls(
77
83
  feePayer,
78
84
  forPublic,
79
85
  );
80
- const tx = Tx.newWithTxData(txData, teardownExecutionRequest);
81
86
 
82
- // Reverse order because the simulator expects it to be like a "stack" of calls to pop from.
83
- // Also push app calls before setup calls for this reason.
84
- for (let i = appExecutionRequests.length - 1; i >= 0; i--) {
85
- tx.enqueuedPublicFunctionCalls.push(appExecutionRequests[i]);
86
- }
87
- for (let i = setupExecutionRequests.length - 1; i >= 0; i--) {
88
- tx.enqueuedPublicFunctionCalls.push(setupExecutionRequests[i]);
89
- }
87
+ const calldata = [
88
+ ...setupCallRequests,
89
+ ...appCallRequests,
90
+ ...(teardownCallRequest ? [teardownCallRequest] : []),
91
+ ].map(r => new HashedValues(r.calldata, r.request.calldataHash));
90
92
 
91
- return tx;
93
+ return new Tx(txData, ClientIvcProof.empty(), [], calldata);
92
94
  }
93
95
 
94
96
  export function createTxForPrivateOnly(feePayer = AztecAddress.zero(), gasUsedByPrivate: Gas = new Gas(10, 10)): Tx {
@@ -110,7 +112,7 @@ export function createTxForPrivateOnly(feePayer = AztecAddress.zero(), gasUsedBy
110
112
  /*forPublic=*/ undefined,
111
113
  forRollup,
112
114
  );
113
- return Tx.newWithTxData(txData);
115
+ return new Tx(txData, ClientIvcProof.empty(), [], []);
114
116
  }
115
117
 
116
118
  export async function addNewContractClassToTx(
@@ -1,9 +1,8 @@
1
1
  export * from '../common/db_interfaces.js';
2
2
  export * from './public_tx_simulator/public_tx_simulator.js';
3
- export { type EnqueuedPublicCallExecutionResult, type PublicFunctionCallResult } from './execution.js';
4
3
  export * from './public_db_sources.js';
5
4
  export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
6
5
  export { SideEffectTrace } from './side_effect_trace.js';
7
- export { getExecutionRequestsByPhase } from './utils.js';
8
6
  export { PublicTxSimulationTester } from './fixtures/index.js';
9
7
  export * from './avm/index.js';
8
+ export { getCallRequestsWithCalldataByPhase } from './utils.js';
@@ -271,7 +271,7 @@ export class PublicContractsDB implements PublicContractsDBInterface {
271
271
  }
272
272
 
273
273
  public async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
274
- return await this.dataSource.getContractFunctionName(address, selector);
274
+ return await this.dataSource.getDebugFunctionName(address, selector);
275
275
  }
276
276
  }
277
277
 
@@ -431,13 +431,13 @@ export class PublicTreesDB extends ForwardMerkleTree implements PublicStateDBInt
431
431
  return leafValue;
432
432
  }
433
433
 
434
- public async getCommitmentValue(leafIndex: bigint): Promise<Fr | undefined> {
434
+ public async getNoteHash(leafIndex: bigint): Promise<Fr | undefined> {
435
435
  const timer = new Timer();
436
436
  const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
437
- this.logger.debug(`[DB] Fetched commitment leaf value`, {
437
+ this.logger.debug(`[DB] Fetched note hash leaf value`, {
438
438
  eventName: 'public-db-access',
439
439
  duration: timer.ms(),
440
- operation: 'get-commitment-leaf-value',
440
+ operation: 'get-note-hash',
441
441
  } satisfies PublicDBAccessStats);
442
442
  return leafValue;
443
443
  }
@@ -321,7 +321,7 @@ export class PublicProcessor implements Traceable {
321
321
  this.log.verbose(
322
322
  !tx.hasPublicCalls()
323
323
  ? `Processed tx ${processedTx.hash} with no public calls in ${time}ms`
324
- : `Processed tx ${processedTx.hash} with ${tx.enqueuedPublicFunctionCalls.length} public calls in ${time}ms`,
324
+ : `Processed tx ${processedTx.hash} with ${tx.numberOfPublicCalls()} public calls in ${time}ms`,
325
325
  {
326
326
  txHash: processedTx.hash,
327
327
  txFee: processedTx.txEffect.transactionFee.toBigInt(),
@@ -26,7 +26,7 @@ import {
26
26
  import { MerkleTreeId } from '@aztec/stdlib/trees';
27
27
  import {
28
28
  type GlobalVariables,
29
- type PublicExecutionRequest,
29
+ PublicCallRequestWithCalldata,
30
30
  type StateReference,
31
31
  TreeSnapshots,
32
32
  type Tx,
@@ -42,7 +42,7 @@ import { AvmPersistableStateManager } from '../avm/index.js';
42
42
  import { HintingPublicContractsDB } from '../hinting_db_sources.js';
43
43
  import type { PublicTreesDB } from '../public_db_sources.js';
44
44
  import { SideEffectArrayLengths, SideEffectTrace } from '../side_effect_trace.js';
45
- import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js';
45
+ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
46
46
 
47
47
  /**
48
48
  * The transaction-level context for public execution.
@@ -70,12 +70,9 @@ export class PublicTxContext {
70
70
  private readonly gasSettings: GasSettings,
71
71
  private readonly gasUsedByPrivate: Gas,
72
72
  private readonly gasAllocatedToPublic: Gas,
73
- private readonly setupCallRequests: PublicCallRequest[],
74
- private readonly appLogicCallRequests: PublicCallRequest[],
75
- private readonly teardownCallRequests: PublicCallRequest[],
76
- private readonly setupExecutionRequests: PublicExecutionRequest[],
77
- private readonly appLogicExecutionRequests: PublicExecutionRequest[],
78
- private readonly teardownExecutionRequests: PublicExecutionRequest[],
73
+ private readonly setupCallRequests: PublicCallRequestWithCalldata[],
74
+ private readonly appLogicCallRequests: PublicCallRequestWithCalldata[],
75
+ private readonly teardownCallRequests: PublicCallRequestWithCalldata[],
79
76
  public readonly nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
80
77
  public readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
81
78
  public readonly feePayer: AztecAddress,
@@ -135,12 +132,9 @@ export class PublicTxContext {
135
132
  gasSettings,
136
133
  gasUsedByPrivate,
137
134
  gasAllocatedToPublic,
138
- getCallRequestsByPhase(tx, TxExecutionPhase.SETUP),
139
- getCallRequestsByPhase(tx, TxExecutionPhase.APP_LOGIC),
140
- getCallRequestsByPhase(tx, TxExecutionPhase.TEARDOWN),
141
- getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP),
142
- getExecutionRequestsByPhase(tx, TxExecutionPhase.APP_LOGIC),
143
- getExecutionRequestsByPhase(tx, TxExecutionPhase.TEARDOWN),
135
+ getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP),
136
+ getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.APP_LOGIC),
137
+ getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.TEARDOWN),
144
138
  tx.data.forPublic!.nonRevertibleAccumulatedData,
145
139
  tx.data.forPublic!.revertibleAccumulatedData,
146
140
  tx.data.feePayer,
@@ -218,7 +212,7 @@ export class PublicTxContext {
218
212
  /**
219
213
  * Get the call requests for the specified phase (including args hashes).
220
214
  */
221
- getCallRequestsForPhase(phase: TxExecutionPhase): PublicCallRequest[] {
215
+ getCallRequestsForPhase(phase: TxExecutionPhase): PublicCallRequestWithCalldata[] {
222
216
  switch (phase) {
223
217
  case TxExecutionPhase.SETUP:
224
218
  return this.setupCallRequests;
@@ -229,20 +223,6 @@ export class PublicTxContext {
229
223
  }
230
224
  }
231
225
 
232
- /**
233
- * Get the call requests for the specified phase (including actual args).
234
- */
235
- getExecutionRequestsForPhase(phase: TxExecutionPhase): PublicExecutionRequest[] {
236
- switch (phase) {
237
- case TxExecutionPhase.SETUP:
238
- return this.setupExecutionRequests;
239
- case TxExecutionPhase.APP_LOGIC:
240
- return this.appLogicExecutionRequests;
241
- case TxExecutionPhase.TEARDOWN:
242
- return this.teardownExecutionRequests;
243
- }
244
- }
245
-
246
226
  /**
247
227
  * How much gas is left as of the specified phase?
248
228
  */
@@ -353,10 +333,10 @@ export class PublicTxContext {
353
333
  /*startGasUsed=*/ this.gasUsedByPrivate,
354
334
  this.gasSettings,
355
335
  this.feePayer,
356
- this.setupCallRequests,
357
- this.appLogicCallRequests,
336
+ this.setupCallRequests.map(r => r.request),
337
+ this.appLogicCallRequests.map(r => r.request),
358
338
  /*teardownCallRequest=*/ this.teardownCallRequests.length
359
- ? this.teardownCallRequests[0]
339
+ ? this.teardownCallRequests[0].request
360
340
  : PublicCallRequest.empty(),
361
341
  endTreeSnapshots,
362
342
  /*endGasUsed=*/ this.getTotalGasUsed(),
@@ -13,13 +13,12 @@ import {
13
13
  } from '@aztec/stdlib/avm';
14
14
  import { SimulationError } from '@aztec/stdlib/errors';
15
15
  import type { Gas, GasUsed } from '@aztec/stdlib/gas';
16
- import type { PublicCallRequest } from '@aztec/stdlib/kernel';
17
16
  import { ProvingRequestType } from '@aztec/stdlib/proofs';
18
17
  import type { AvmSimulationStats } from '@aztec/stdlib/stats';
19
18
  import {
20
19
  type GlobalVariables,
21
20
  NestedProcessReturnValues,
22
- PublicExecutionRequest,
21
+ PublicCallRequestWithCalldata,
23
22
  Tx,
24
23
  TxExecutionPhase,
25
24
  } from '@aztec/stdlib/tx';
@@ -83,7 +82,7 @@ export class PublicTxSimulator {
83
82
  const startTime = process.hrtime.bigint();
84
83
 
85
84
  const txHash = await tx.getTxHash();
86
- this.log.debug(`Simulating ${tx.enqueuedPublicFunctionCalls.length} public calls for tx ${txHash}`, { txHash });
85
+ this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
87
86
 
88
87
  const context = await PublicTxContext.create(
89
88
  this.treesDB,
@@ -232,13 +231,11 @@ export class PublicTxSimulator {
232
231
  */
233
232
  private async simulatePhase(phase: TxExecutionPhase, context: PublicTxContext): Promise<ProcessedPhase> {
234
233
  const callRequests = context.getCallRequestsForPhase(phase);
235
- const executionRequests = context.getExecutionRequestsForPhase(phase);
236
234
 
237
235
  this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.txHash}`, {
238
236
  txHash: context.txHash.toString(),
239
237
  phase: TxExecutionPhase[phase],
240
238
  callRequests: callRequests.length,
241
- executionRequests: executionRequests.length,
242
239
  });
243
240
 
244
241
  const returnValues: NestedProcessReturnValues[] = [];
@@ -251,9 +248,8 @@ export class PublicTxSimulator {
251
248
  }
252
249
 
253
250
  const callRequest = callRequests[i];
254
- const executionRequest = executionRequests[i];
255
251
 
256
- const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest, executionRequest);
252
+ const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
257
253
 
258
254
  returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
259
255
 
@@ -276,44 +272,42 @@ export class PublicTxSimulator {
276
272
  * Simulate an enqueued public call.
277
273
  * @param phase - The current phase of public execution
278
274
  * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
279
- * @param callRequest - The enqueued call to execute
280
- * @param executionRequest - The execution request (includes args)
275
+ * @param callRequest - The public function call request, including the calldata.
281
276
  * @returns The result of execution.
282
277
  */
283
- @trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, _callRequest, executionRequest) => ({
278
+ @trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, callRequest) => ({
284
279
  [Attributes.TX_HASH]: context.txHash.toString(),
285
- [Attributes.TARGET_ADDRESS]: executionRequest.callContext.contractAddress.toString(),
286
- [Attributes.SENDER_ADDRESS]: executionRequest.callContext.msgSender.toString(),
280
+ [Attributes.TARGET_ADDRESS]: callRequest.request.contractAddress.toString(),
281
+ [Attributes.SENDER_ADDRESS]: callRequest.request.msgSender.toString(),
287
282
  [Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString(),
288
283
  }))
289
284
  private async simulateEnqueuedCall(
290
285
  phase: TxExecutionPhase,
291
286
  context: PublicTxContext,
292
- callRequest: PublicCallRequest,
293
- executionRequest: PublicExecutionRequest,
287
+ callRequest: PublicCallRequestWithCalldata,
294
288
  ): Promise<AvmFinalizedCallResult> {
295
289
  const stateManager = context.state.getActiveStateManager();
296
- const address = executionRequest.callContext.contractAddress;
297
- const fnName = await getPublicFunctionDebugName(this.contractsDB, address, executionRequest.args);
290
+ const contractAddress = callRequest.request.contractAddress;
291
+ const fnName = await getPublicFunctionDebugName(this.contractsDB, contractAddress, callRequest.calldata);
298
292
 
299
293
  const allocatedGas = context.getGasLeftAtPhase(phase);
300
294
 
301
295
  // The reason we need enqueued hints at all (and cannot just use the public inputs) is
302
296
  // because they don't have the actual calldata, just the hash of it.
303
297
  // If/when we pass the whole TX to C++, we can remove this class of hints.
304
- stateManager.traceEnqueuedCall(callRequest);
298
+ stateManager.traceEnqueuedCall(callRequest.request);
305
299
  context.hints.enqueuedCalls.push(
306
300
  new AvmEnqueuedCallHint(
307
- executionRequest.callContext.msgSender,
308
- executionRequest.callContext.contractAddress,
309
- executionRequest.args,
310
- executionRequest.callContext.isStaticCall,
301
+ callRequest.request.msgSender,
302
+ contractAddress,
303
+ callRequest.calldata,
304
+ callRequest.request.isStaticCall,
311
305
  ),
312
306
  );
313
307
 
314
308
  const result = await this.simulateEnqueuedCallInternal(
315
309
  context.state.getActiveStateManager(),
316
- executionRequest,
310
+ callRequest,
317
311
  allocatedGas,
318
312
  /*transactionFee=*/ context.getTransactionFee(phase),
319
313
  fnName,
@@ -326,7 +320,7 @@ export class PublicTxSimulator {
326
320
  );
327
321
 
328
322
  if (result.reverted) {
329
- const culprit = `${executionRequest.callContext.contractAddress}:${executionRequest.callContext.functionSelector}`;
323
+ const culprit = `${contractAddress}:${callRequest.functionSelector}`;
330
324
  context.revert(phase, result.revertReason, culprit); // throws if in setup (non-revertible) phase
331
325
  }
332
326
 
@@ -342,26 +336,26 @@ export class PublicTxSimulator {
342
336
  *
343
337
  * @param stateManager - The state manager for AvmSimulation
344
338
  * @param context - The context of the currently executing public transaction portion
345
- * @param executionRequest - The execution request (includes args)
339
+ * @param callRequest - The public function call request, including the calldata.
346
340
  * @param allocatedGas - The gas allocated to the enqueued call
347
341
  * @param fnName - The name of the function
348
342
  * @returns The result of execution.
349
343
  */
350
344
  @trackSpan(
351
345
  'PublicTxSimulator.simulateEnqueuedCallInternal',
352
- (_stateManager, _executionRequest, _allocatedGas, _transactionFee, fnName) => ({
346
+ (_stateManager, _callRequest, _allocatedGas, _transactionFee, fnName) => ({
353
347
  [Attributes.APP_CIRCUIT_NAME]: fnName,
354
348
  }),
355
349
  )
356
350
  private async simulateEnqueuedCallInternal(
357
351
  stateManager: AvmPersistableStateManager,
358
- executionRequest: PublicExecutionRequest,
352
+ { request, calldata }: PublicCallRequestWithCalldata,
359
353
  allocatedGas: Gas,
360
354
  transactionFee: Fr,
361
355
  fnName: string,
362
356
  ): Promise<AvmFinalizedCallResult> {
363
- const address = executionRequest.callContext.contractAddress;
364
- const sender = executionRequest.callContext.msgSender;
357
+ const address = request.contractAddress;
358
+ const sender = request.msgSender;
365
359
 
366
360
  this.log.debug(
367
361
  `Executing enqueued public call to external function ${fnName}@${address} with ${allocatedGas.l2Gas} allocated L2 gas.`,
@@ -374,8 +368,8 @@ export class PublicTxSimulator {
374
368
  sender,
375
369
  transactionFee,
376
370
  this.globalVariables,
377
- executionRequest.callContext.isStaticCall,
378
- executionRequest.args,
371
+ request.isStaticCall,
372
+ calldata,
379
373
  allocatedGas,
380
374
  );
381
375
  const avmCallResult = await simulator.execute();
@@ -1,29 +1,13 @@
1
- import type { PublicCallRequest } from '@aztec/stdlib/kernel';
2
- import { type PublicExecutionRequest, type Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
1
+ import { PublicCallRequestWithCalldata, type Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
3
2
 
4
- export function getExecutionRequestsByPhase(tx: Tx, phase: TxExecutionPhase): PublicExecutionRequest[] {
3
+ export function getCallRequestsWithCalldataByPhase(tx: Tx, phase: TxExecutionPhase): PublicCallRequestWithCalldata[] {
5
4
  switch (phase) {
6
5
  case TxExecutionPhase.SETUP:
7
- return tx.getNonRevertiblePublicExecutionRequests();
6
+ return tx.getNonRevertiblePublicCallRequestsWithCalldata();
8
7
  case TxExecutionPhase.APP_LOGIC:
9
- return tx.getRevertiblePublicExecutionRequests();
8
+ return tx.getRevertiblePublicCallRequestsWithCalldata();
10
9
  case TxExecutionPhase.TEARDOWN: {
11
- const request = tx.getPublicTeardownExecutionRequest();
12
- return request ? [request] : [];
13
- }
14
- default:
15
- throw new Error(`Unknown phase: ${phase}`);
16
- }
17
- }
18
-
19
- export function getCallRequestsByPhase(tx: Tx, phase: TxExecutionPhase): PublicCallRequest[] {
20
- switch (phase) {
21
- case TxExecutionPhase.SETUP:
22
- return tx.data.getNonRevertiblePublicCallRequests();
23
- case TxExecutionPhase.APP_LOGIC:
24
- return tx.data.getRevertiblePublicCallRequests();
25
- case TxExecutionPhase.TEARDOWN: {
26
- const request = tx.data.getTeardownPublicCallRequest();
10
+ const request = tx.getTeardownPublicCallRequestWithCalldata();
27
11
  return request ? [request] : [];
28
12
  }
29
13
  default:
package/src/testing.ts ADDED
@@ -0,0 +1 @@
1
+ export { SimulationProviderRecorderWrapper } from './private/providers/circuit_recording/simulation_provider_recorder_wrapper.js';
@@ -1,5 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- export declare function markBytecodeAsAvm(bytecode: Buffer): Buffer;
4
- export declare function isAvmBytecode(bytecode: Buffer): boolean;
5
- //# sourceMappingURL=bytecode_utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bytecode_utils.d.ts","sourceRoot":"","sources":["../../../src/public/avm/bytecode_utils.ts"],"names":[],"mappings":";;AASA,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGvD"}
@@ -1,17 +0,0 @@
1
- import { Opcode } from './serialization/instruction_serialization.js';
2
- const AVM_MAGIC_SUFFIX = Buffer.from([
3
- Opcode.MOV_16,
4
- 0x00,
5
- ...Buffer.from('18ca', 'hex'),
6
- ...Buffer.from('18ca', 'hex')
7
- ]);
8
- export function markBytecodeAsAvm(bytecode) {
9
- return Buffer.concat([
10
- bytecode,
11
- AVM_MAGIC_SUFFIX
12
- ]);
13
- }
14
- export function isAvmBytecode(bytecode) {
15
- const magicSize = AVM_MAGIC_SUFFIX.length;
16
- return bytecode.subarray(-magicSize).equals(AVM_MAGIC_SUFFIX);
17
- }