@aztec/simulator 0.35.0 → 0.36.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 (160) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +6 -5
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +30 -23
  4. package/dest/acvm/oracle/typed_oracle.d.ts +15 -21
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +10 -10
  7. package/dest/avm/avm_execution_environment.d.ts +1 -5
  8. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  9. package/dest/avm/avm_execution_environment.js +5 -8
  10. package/dest/avm/avm_gas.d.ts +1 -9
  11. package/dest/avm/avm_gas.d.ts.map +1 -1
  12. package/dest/avm/avm_gas.js +6 -13
  13. package/dest/avm/avm_machine_state.d.ts +1 -3
  14. package/dest/avm/avm_machine_state.d.ts.map +1 -1
  15. package/dest/avm/avm_machine_state.js +8 -9
  16. package/dest/avm/avm_simulator.js +2 -2
  17. package/dest/avm/fixtures/index.d.ts +2 -6
  18. package/dest/avm/fixtures/index.d.ts.map +1 -1
  19. package/dest/avm/fixtures/index.js +3 -12
  20. package/dest/avm/journal/journal.d.ts +2 -1
  21. package/dest/avm/journal/journal.d.ts.map +1 -1
  22. package/dest/avm/journal/journal.js +8 -17
  23. package/dest/avm/journal/trace.d.ts +3 -1
  24. package/dest/avm/journal/trace.d.ts.map +1 -1
  25. package/dest/avm/journal/trace.js +11 -1
  26. package/dest/avm/journal/trace_types.d.ts +4 -0
  27. package/dest/avm/journal/trace_types.d.ts.map +1 -1
  28. package/dest/avm/journal/trace_types.js +1 -1
  29. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  30. package/dest/avm/opcodes/arithmetic.js +1 -1
  31. package/dest/avm/opcodes/context_getters.d.ts +0 -5
  32. package/dest/avm/opcodes/context_getters.d.ts.map +1 -1
  33. package/dest/avm/opcodes/context_getters.js +1 -8
  34. package/dest/avm/opcodes/contract.d.ts.map +1 -1
  35. package/dest/avm/opcodes/contract.js +1 -3
  36. package/dest/avm/opcodes/environment_getters.d.ts +0 -15
  37. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  38. package/dest/avm/opcodes/environment_getters.js +1 -35
  39. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  40. package/dest/avm/opcodes/external_calls.js +5 -6
  41. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  42. package/dest/avm/opcodes/memory.js +3 -3
  43. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  44. package/dest/avm/opcodes/storage.js +1 -1
  45. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  46. package/dest/avm/serialization/bytecode_serialization.js +3 -8
  47. package/dest/avm/serialization/instruction_serialization.d.ts +42 -47
  48. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  49. package/dest/avm/serialization/instruction_serialization.js +43 -48
  50. package/dest/client/client_execution_context.d.ts +13 -16
  51. package/dest/client/client_execution_context.d.ts.map +1 -1
  52. package/dest/client/client_execution_context.js +36 -34
  53. package/dest/client/db_oracle.d.ts +5 -16
  54. package/dest/client/db_oracle.d.ts.map +1 -1
  55. package/dest/client/db_oracle.js +1 -1
  56. package/dest/client/execution_note_cache.d.ts +6 -2
  57. package/dest/client/execution_note_cache.d.ts.map +1 -1
  58. package/dest/client/execution_note_cache.js +10 -7
  59. package/dest/client/execution_result.d.ts +10 -5
  60. package/dest/client/execution_result.d.ts.map +1 -1
  61. package/dest/client/execution_result.js +7 -1
  62. package/dest/client/private_execution.d.ts.map +1 -1
  63. package/dest/client/private_execution.js +4 -10
  64. package/dest/client/simulator.d.ts +1 -3
  65. package/dest/client/simulator.d.ts.map +1 -1
  66. package/dest/client/simulator.js +5 -9
  67. package/dest/client/view_data_oracle.d.ts +7 -11
  68. package/dest/client/view_data_oracle.d.ts.map +1 -1
  69. package/dest/client/view_data_oracle.js +8 -14
  70. package/dest/mocks/fixtures.d.ts +1 -1
  71. package/dest/mocks/fixtures.d.ts.map +1 -1
  72. package/dest/mocks/fixtures.js +9 -5
  73. package/dest/public/abstract_phase_manager.d.ts +4 -4
  74. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  75. package/dest/public/abstract_phase_manager.js +28 -43
  76. package/dest/public/app_logic_phase_manager.d.ts +1 -7
  77. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  78. package/dest/public/app_logic_phase_manager.js +1 -7
  79. package/dest/public/db.d.ts +6 -7
  80. package/dest/public/db.d.ts.map +1 -1
  81. package/dest/public/execution.d.ts +15 -6
  82. package/dest/public/execution.d.ts.map +1 -1
  83. package/dest/public/execution.js +7 -9
  84. package/dest/public/executor.d.ts +2 -2
  85. package/dest/public/executor.d.ts.map +1 -1
  86. package/dest/public/executor.js +19 -10
  87. package/dest/public/hints_builder.d.ts +10 -8
  88. package/dest/public/hints_builder.d.ts.map +1 -1
  89. package/dest/public/hints_builder.js +29 -35
  90. package/dest/public/public_execution_context.d.ts +8 -13
  91. package/dest/public/public_execution_context.d.ts.map +1 -1
  92. package/dest/public/public_execution_context.js +12 -29
  93. package/dest/public/public_executor.d.ts +2 -2
  94. package/dest/public/public_executor.d.ts.map +1 -1
  95. package/dest/public/public_executor.js +4 -5
  96. package/dest/public/public_processor.d.ts +1 -2
  97. package/dest/public/public_processor.d.ts.map +1 -1
  98. package/dest/public/public_processor.js +1 -1
  99. package/dest/public/setup_phase_manager.d.ts +0 -6
  100. package/dest/public/setup_phase_manager.d.ts.map +1 -1
  101. package/dest/public/setup_phase_manager.js +1 -7
  102. package/dest/public/state_actions.d.ts.map +1 -1
  103. package/dest/public/state_actions.js +3 -1
  104. package/dest/public/tail_phase_manager.d.ts +3 -6
  105. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  106. package/dest/public/tail_phase_manager.js +47 -16
  107. package/dest/public/teardown_phase_manager.d.ts +3 -7
  108. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  109. package/dest/public/teardown_phase_manager.js +14 -7
  110. package/dest/public/transitional_adaptors.d.ts +2 -2
  111. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  112. package/dest/public/transitional_adaptors.js +19 -21
  113. package/dest/public/utils.d.ts.map +1 -1
  114. package/dest/public/utils.js +4 -2
  115. package/dest/test/utils.d.ts.map +1 -1
  116. package/dest/test/utils.js +3 -5
  117. package/package.json +16 -8
  118. package/src/acvm/oracle/oracle.ts +39 -21
  119. package/src/acvm/oracle/typed_oracle.ts +18 -26
  120. package/src/avm/avm_execution_environment.ts +0 -13
  121. package/src/avm/avm_gas.ts +6 -14
  122. package/src/avm/avm_machine_state.ts +8 -11
  123. package/src/avm/avm_simulator.ts +1 -1
  124. package/src/avm/fixtures/index.ts +2 -24
  125. package/src/avm/journal/journal.ts +14 -25
  126. package/src/avm/journal/trace.ts +12 -0
  127. package/src/avm/journal/trace_types.ts +7 -0
  128. package/src/avm/opcodes/arithmetic.ts +2 -2
  129. package/src/avm/opcodes/context_getters.ts +0 -9
  130. package/src/avm/opcodes/contract.ts +0 -2
  131. package/src/avm/opcodes/environment_getters.ts +0 -45
  132. package/src/avm/opcodes/external_calls.ts +5 -6
  133. package/src/avm/opcodes/memory.ts +5 -5
  134. package/src/avm/opcodes/storage.ts +1 -1
  135. package/src/avm/serialization/bytecode_serialization.ts +2 -10
  136. package/src/avm/serialization/instruction_serialization.ts +1 -6
  137. package/src/client/client_execution_context.ts +79 -54
  138. package/src/client/db_oracle.ts +5 -17
  139. package/src/client/execution_note_cache.ts +16 -7
  140. package/src/client/execution_result.ts +17 -6
  141. package/src/client/private_execution.ts +4 -9
  142. package/src/client/simulator.ts +3 -15
  143. package/src/client/view_data_oracle.ts +25 -29
  144. package/src/mocks/fixtures.ts +7 -16
  145. package/src/public/abstract_phase_manager.ts +45 -56
  146. package/src/public/app_logic_phase_manager.ts +6 -6
  147. package/src/public/db.ts +7 -8
  148. package/src/public/execution.ts +22 -18
  149. package/src/public/executor.ts +31 -5
  150. package/src/public/hints_builder.ts +62 -62
  151. package/src/public/public_execution_context.ts +30 -36
  152. package/src/public/public_executor.ts +4 -6
  153. package/src/public/public_processor.ts +1 -1
  154. package/src/public/setup_phase_manager.ts +6 -6
  155. package/src/public/state_actions.ts +2 -0
  156. package/src/public/tail_phase_manager.ts +98 -23
  157. package/src/public/teardown_phase_manager.ts +24 -6
  158. package/src/public/transitional_adaptors.ts +25 -19
  159. package/src/public/utils.ts +3 -1
  160. package/src/test/utils.ts +2 -4
@@ -14,7 +14,7 @@ import { Fr } from '@aztec/foundation/fields';
14
14
  import { createDebugLogger } from '@aztec/foundation/log';
15
15
  import { type ContractInstance } from '@aztec/types/contracts';
16
16
 
17
- import { type NoteData, TypedOracle } from '../acvm/index.js';
17
+ import { type NoteData, type NullifierKeys, TypedOracle } from '../acvm/index.js';
18
18
  import { type DBOracle } from './db_oracle.js';
19
19
  import { pickNotes } from './pick_notes.js';
20
20
 
@@ -35,11 +35,14 @@ export class ViewDataOracle extends TypedOracle {
35
35
  }
36
36
 
37
37
  /**
38
- * Return the nullifier key pair of an account to use in a specific contract.
39
- * @param account - The account address of the nullifier key.
38
+ * Retrieve nullifier keys associated with a specific account and app/contract address.
39
+ *
40
+ * @param accountAddress - The account address.
41
+ * @returns A Promise that resolves to nullifier keys of a requested account and contract.
42
+ * @throws An error if the account is not registered in the database.
40
43
  */
41
- public getNullifierKeyPair(account: AztecAddress) {
42
- return this.db.getNullifierKeyPair(account, this.contractAddress);
44
+ public override getNullifierKeys(account: AztecAddress): Promise<NullifierKeys> {
45
+ return this.db.getNullifierKeys(account, this.contractAddress);
43
46
  }
44
47
 
45
48
  /**
@@ -49,7 +52,7 @@ export class ViewDataOracle extends TypedOracle {
49
52
  * @param leafValue - The leaf value
50
53
  * @returns The index and sibling path concatenated [index, sibling_path]
51
54
  */
52
- public async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
55
+ public override async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
53
56
  const index = await this.db.findLeafIndex(blockNumber, treeId, leafValue);
54
57
  if (!index) {
55
58
  throw new Error(`Leaf value: ${leafValue} not found in ${MerkleTreeId[treeId]}`);
@@ -65,7 +68,7 @@ export class ViewDataOracle extends TypedOracle {
65
68
  * @param leafIndex - Index of the leaf to get sibling path for
66
69
  * @returns The sibling path.
67
70
  */
68
- public getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: Fr): Promise<Fr[]> {
71
+ public override getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: Fr): Promise<Fr[]> {
69
72
  return this.db.getSiblingPath(blockNumber, treeId, leafIndex.toBigInt());
70
73
  }
71
74
 
@@ -75,7 +78,7 @@ export class ViewDataOracle extends TypedOracle {
75
78
  * @param nullifier - Nullifier we try to find witness for.
76
79
  * @returns The nullifier membership witness (if found).
77
80
  */
78
- public async getNullifierMembershipWitness(
81
+ public override async getNullifierMembershipWitness(
79
82
  blockNumber: number,
80
83
  nullifier: Fr,
81
84
  ): Promise<NullifierMembershipWitness | undefined> {
@@ -91,7 +94,7 @@ export class ViewDataOracle extends TypedOracle {
91
94
  * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
92
95
  * we are trying to prove non-inclusion for.
93
96
  */
94
- public async getLowNullifierMembershipWitness(
97
+ public override async getLowNullifierMembershipWitness(
95
98
  blockNumber: number,
96
99
  nullifier: Fr,
97
100
  ): Promise<NullifierMembershipWitness | undefined> {
@@ -104,7 +107,10 @@ export class ViewDataOracle extends TypedOracle {
104
107
  * @param leafSlot - The slot of the public data tree to get the witness for.
105
108
  * @returns - The witness
106
109
  */
107
- public async getPublicDataTreeWitness(blockNumber: number, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
110
+ public override async getPublicDataTreeWitness(
111
+ blockNumber: number,
112
+ leafSlot: Fr,
113
+ ): Promise<PublicDataWitness | undefined> {
108
114
  return await this.db.getPublicDataTreeWitness(blockNumber, leafSlot);
109
115
  }
110
116
 
@@ -113,7 +119,7 @@ export class ViewDataOracle extends TypedOracle {
113
119
  * @param blockNumber - The number of a block of which to get the block header.
114
120
  * @returns Block extracted from a block with block number `blockNumber`.
115
121
  */
116
- public async getHeader(blockNumber: number): Promise<Header | undefined> {
122
+ public override async getHeader(blockNumber: number): Promise<Header | undefined> {
117
123
  const block = await this.db.getBlock(blockNumber);
118
124
  if (!block) {
119
125
  return undefined;
@@ -126,7 +132,7 @@ export class ViewDataOracle extends TypedOracle {
126
132
  * @param address - Address to fetch the complete address for.
127
133
  * @returns A complete address associated with the input address.
128
134
  */
129
- public getCompleteAddress(address: AztecAddress): Promise<CompleteAddress> {
135
+ public override getCompleteAddress(address: AztecAddress): Promise<CompleteAddress> {
130
136
  return this.db.getCompleteAddress(address);
131
137
  }
132
138
 
@@ -135,7 +141,7 @@ export class ViewDataOracle extends TypedOracle {
135
141
  * @param address - Address.
136
142
  * @returns A contract instance.
137
143
  */
138
- public getContractInstance(address: AztecAddress): Promise<ContractInstance> {
144
+ public override getContractInstance(address: AztecAddress): Promise<ContractInstance> {
139
145
  return this.db.getContractInstance(address);
140
146
  }
141
147
 
@@ -145,7 +151,7 @@ export class ViewDataOracle extends TypedOracle {
145
151
  * @param messageHash - Hash of the message to authenticate.
146
152
  * @returns Authentication witness for the requested message hash.
147
153
  */
148
- public getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
154
+ public override getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
149
155
  return Promise.resolve(
150
156
  this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness ?? this.db.getAuthWitness(messageHash),
151
157
  );
@@ -156,7 +162,7 @@ export class ViewDataOracle extends TypedOracle {
156
162
  * @returns The capsule values
157
163
  * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle.
158
164
  */
159
- public popCapsule(): Promise<Fr[]> {
165
+ public override popCapsule(): Promise<Fr[]> {
160
166
  return this.db.popCapsule();
161
167
  }
162
168
 
@@ -181,7 +187,7 @@ export class ViewDataOracle extends TypedOracle {
181
187
  * @param status - The status of notes to fetch.
182
188
  * @returns Array of note data.
183
189
  */
184
- public async getNotes(
190
+ public override async getNotes(
185
191
  storageSlot: Fr,
186
192
  numSelects: number,
187
193
  selectByIndexes: number[],
@@ -218,7 +224,7 @@ export class ViewDataOracle extends TypedOracle {
218
224
  * @param innerNullifier - The inner nullifier.
219
225
  * @returns A boolean indicating whether the nullifier exists in the tree or not.
220
226
  */
221
- public async checkNullifierExists(innerNullifier: Fr) {
227
+ public override async checkNullifierExists(innerNullifier: Fr) {
222
228
  const nullifier = siloNullifier(this.contractAddress, innerNullifier!);
223
229
  const index = await this.db.getNullifierIndex(nullifier);
224
230
  return index !== undefined;
@@ -232,26 +238,16 @@ export class ViewDataOracle extends TypedOracle {
232
238
  * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
233
239
  * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
234
240
  */
235
- public async getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
241
+ public override async getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
236
242
  return await this.db.getL1ToL2MembershipWitness(contractAddress, messageHash, secret);
237
243
  }
238
244
 
239
- /**
240
- * Retrieves the portal contract address associated with the given contract address.
241
- * Throws an error if the input contract address is not found or invalid.
242
- * @param contractAddress - The address of the contract whose portal address is to be fetched.
243
- * @returns The portal contract address.
244
- */
245
- public getPortalContractAddress(contractAddress: AztecAddress) {
246
- return this.db.getPortalContractAddress(contractAddress);
247
- }
248
-
249
245
  /**
250
246
  * Read the public storage data.
251
247
  * @param startStorageSlot - The starting storage slot.
252
248
  * @param numberOfElements - Number of elements to read from the starting storage slot.
253
249
  */
254
- public async storageRead(startStorageSlot: Fr, numberOfElements: number) {
250
+ public override async storageRead(startStorageSlot: Fr, numberOfElements: number) {
255
251
  const values = [];
256
252
  for (let i = 0n; i < numberOfElements; i++) {
257
253
  const storageSlot = new Fr(startStorageSlot.value + i);
@@ -5,11 +5,9 @@ import {
5
5
  CallContext,
6
6
  CallRequest,
7
7
  type ContractStorageUpdateRequest,
8
- EthAddress,
9
8
  Fr,
10
9
  FunctionData,
11
10
  Gas,
12
- GasSettings,
13
11
  MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
14
12
  type PrivateKernelTailCircuitPublicInputs,
15
13
  type PublicCallRequest,
@@ -67,18 +65,7 @@ export class PublicExecutionResultBuilder {
67
65
  revertReason?: SimulationError;
68
66
  }) {
69
67
  const builder = new PublicExecutionResultBuilder({
70
- callContext: new CallContext(
71
- from,
72
- tx.to,
73
- EthAddress.ZERO,
74
- tx.functionData.selector,
75
- Gas.test(),
76
- false,
77
- false,
78
- 0,
79
- GasSettings.default(),
80
- Fr.ZERO,
81
- ),
68
+ callContext: new CallContext(from, tx.to, tx.functionData.selector, false, false, 0),
82
69
  contractAddress: tx.to,
83
70
  functionData: tx.functionData,
84
71
  args: tx.args,
@@ -115,7 +102,7 @@ export class PublicExecutionResultBuilder {
115
102
  return this;
116
103
  }
117
104
 
118
- build(): PublicExecutionResult {
105
+ build(overrides: Partial<PublicExecutionResult> = {}): PublicExecutionResult {
119
106
  return {
120
107
  execution: this._execution,
121
108
  nestedExecutions: this._nestedExecutions,
@@ -127,12 +114,16 @@ export class PublicExecutionResultBuilder {
127
114
  newNullifiers: [],
128
115
  newL2ToL1Messages: [],
129
116
  contractStorageReads: [],
117
+ unencryptedLogsHashes: [],
130
118
  unencryptedLogs: UnencryptedFunctionL2Logs.empty(),
131
119
  startSideEffectCounter: Fr.ZERO,
132
120
  endSideEffectCounter: Fr.ZERO,
133
121
  reverted: this._reverted,
134
122
  revertReason: this._revertReason,
135
- gasLeft: this._execution.callContext.gasLeft.mul(0.9),
123
+ startGasLeft: Gas.test(),
124
+ endGasLeft: Gas.test(),
125
+ transactionFee: Fr.ZERO,
126
+ ...overrides,
136
127
  };
137
128
  }
138
129
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  MerkleTreeId,
3
+ type ProcessReturnValues,
3
4
  type PublicKernelRequest,
4
5
  type SimulationError,
5
6
  type Tx,
@@ -26,7 +27,10 @@ import {
26
27
  MAX_PUBLIC_DATA_READS_PER_TX,
27
28
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
28
29
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
30
+ MAX_UNENCRYPTED_LOGS_PER_CALL,
29
31
  MembershipWitness,
32
+ NoteHash,
33
+ Nullifier,
30
34
  type PrivateKernelTailCircuitPublicInputs,
31
35
  type Proof,
32
36
  PublicCallData,
@@ -41,19 +45,11 @@ import {
41
45
  ReadRequest,
42
46
  RevertCode,
43
47
  SideEffect,
44
- SideEffectLinkedToNoteHash,
45
48
  VK_TREE_HEIGHT,
46
49
  VerificationKey,
47
50
  makeEmptyProof,
48
51
  } from '@aztec/circuits.js';
49
52
  import { computeVarArgsHash } from '@aztec/circuits.js/hash';
50
- import {
51
- type AbiType,
52
- type DecodedReturn,
53
- type FunctionArtifact,
54
- type ProcessReturnValues,
55
- decodeReturnValues,
56
- } from '@aztec/foundation/abi';
57
53
  import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
58
54
  import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
59
55
  import { type Tuple } from '@aztec/foundation/serialize';
@@ -232,17 +228,18 @@ export abstract class AbstractPhaseManager {
232
228
 
233
229
  const newUnencryptedFunctionLogs: UnencryptedFunctionL2Logs[] = [];
234
230
 
231
+ // Transaction fee is zero for all phases except teardown
232
+ const transactionFee = this.getTransactionFee(tx, previousPublicKernelOutput);
233
+
235
234
  // TODO(#1684): Should multiple separately enqueued public calls be treated as
236
235
  // separate public callstacks to be proven by separate public kernel sequences
237
236
  // and submitted separately to the base rollup?
238
237
 
239
- const returns = [];
238
+ let returns: ProcessReturnValues = undefined;
240
239
 
241
240
  for (const enqueuedCall of enqueuedCalls) {
242
241
  const executionStack: (PublicExecution | PublicExecutionResult)[] = [enqueuedCall];
243
242
 
244
- let currentReturn: DecodedReturn | undefined = undefined;
245
-
246
243
  // Keep track of which result is for the top/enqueued call
247
244
  let enqueuedExecutionResult: PublicExecutionResult | undefined;
248
245
 
@@ -250,9 +247,17 @@ export abstract class AbstractPhaseManager {
250
247
  const current = executionStack.pop()!;
251
248
  const isExecutionRequest = !isPublicExecutionResult(current);
252
249
  const sideEffectCounter = lastSideEffectCounter(tx) + 1;
250
+ const availableGas = this.getAvailableGas(tx, previousPublicKernelOutput);
253
251
 
254
252
  const result = isExecutionRequest
255
- ? await this.publicExecutor.simulate(current, this.globalVariables, sideEffectCounter)
253
+ ? await this.publicExecutor.simulate(
254
+ current,
255
+ this.globalVariables,
256
+ availableGas,
257
+ tx.data.constants.txContext,
258
+ transactionFee,
259
+ sideEffectCounter,
260
+ )
256
261
  : current;
257
262
 
258
263
  const functionSelector = result.execution.functionData.selector.toString();
@@ -301,21 +306,12 @@ export abstract class AbstractPhaseManager {
301
306
 
302
307
  if (!enqueuedExecutionResult) {
303
308
  enqueuedExecutionResult = result;
304
-
305
- // TODO(#5450) Need to use the proper return values here
306
- const returnTypes: AbiType[] = [
307
- { kind: 'array', length: result.returnValues.length, type: { kind: 'field' } },
308
- ];
309
- const mockArtifact = { returnTypes } as any as FunctionArtifact;
310
-
311
- currentReturn = decodeReturnValues(mockArtifact, result.returnValues);
309
+ returns = result.returnValues;
312
310
  }
313
311
  }
314
312
  // HACK(#1622): Manually patches the ordering of public state actions
315
313
  // TODO(#757): Enforce proper ordering of public state actions
316
314
  patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!, this.phase);
317
-
318
- returns.push(currentReturn);
319
315
  }
320
316
 
321
317
  // TODO(#3675): This should be done in a public kernel circuit
@@ -324,6 +320,17 @@ export abstract class AbstractPhaseManager {
324
320
  return [publicKernelInputs, kernelOutput, kernelProof, newUnencryptedFunctionLogs, undefined, returns];
325
321
  }
326
322
 
323
+ protected getAvailableGas(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs) {
324
+ return tx.data.constants.txContext.gasSettings
325
+ .getLimits() // No need to subtract teardown limits since they are already included in end.gasUsed
326
+ .sub(previousPublicKernelOutput.end.gasUsed)
327
+ .sub(previousPublicKernelOutput.endNonRevertibleData.gasUsed);
328
+ }
329
+
330
+ protected getTransactionFee(_tx: Tx, _previousPublicKernelOutput: PublicKernelCircuitPublicInputs) {
331
+ return Fr.ZERO;
332
+ }
333
+
327
334
  protected async runKernelCircuit(
328
335
  previousOutput: PublicKernelCircuitPublicInputs,
329
336
  previousProof: Proof,
@@ -364,7 +371,7 @@ export abstract class AbstractPhaseManager {
364
371
  return new PublicKernelData(previousOutput, previousProof, vk, vkIndex, vkSiblingPath);
365
372
  }
366
373
 
367
- protected async getPublicCircuitPublicInputs(result: PublicExecutionResult) {
374
+ protected async getPublicCallStackItem(result: PublicExecutionResult, isExecutionRequest = false) {
368
375
  const publicDataTreeInfo = await this.db.getTreeInfo(MerkleTreeId.PUBLIC_DATA_TREE);
369
376
  this.historicalHeader.state.partial.publicDataTree.root = Fr.fromBuffer(publicDataTreeInfo.root);
370
377
 
@@ -375,16 +382,14 @@ export abstract class AbstractPhaseManager {
375
382
  MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
376
383
  );
377
384
 
378
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) --> set this in Noir
379
- const unencryptedLogsHash = Fr.fromBuffer(result.unencryptedLogs.hash());
380
385
  const unencryptedLogPreimagesLength = new Fr(result.unencryptedLogs.getSerializedLength());
381
386
 
382
- return PublicCircuitPublicInputs.from({
387
+ const publicCircuitPublicInputs = PublicCircuitPublicInputs.from({
383
388
  callContext: result.execution.callContext,
384
389
  proverAddress: AztecAddress.ZERO,
385
390
  argsHash: computeVarArgsHash(result.execution.args),
386
- newNoteHashes: padArrayEnd(result.newNoteHashes, SideEffect.empty(), MAX_NEW_NOTE_HASHES_PER_CALL),
387
- newNullifiers: padArrayEnd(result.newNullifiers, SideEffectLinkedToNoteHash.empty(), MAX_NEW_NULLIFIERS_PER_CALL),
391
+ newNoteHashes: padArrayEnd(result.newNoteHashes, NoteHash.empty(), MAX_NEW_NOTE_HASHES_PER_CALL),
392
+ newNullifiers: padArrayEnd(result.newNullifiers, Nullifier.empty(), MAX_NEW_NULLIFIERS_PER_CALL),
388
393
  newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, L2ToL1Message.empty(), MAX_NEW_L2_TO_L1_MSGS_PER_CALL),
389
394
  startSideEffectCounter: result.startSideEffectCounter,
390
395
  endSideEffectCounter: result.endSideEffectCounter,
@@ -410,20 +415,25 @@ export abstract class AbstractPhaseManager {
410
415
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
411
416
  ),
412
417
  publicCallStackHashes,
413
- unencryptedLogsHash,
418
+ unencryptedLogsHashes: padArrayEnd(
419
+ result.unencryptedLogsHashes,
420
+ SideEffect.empty(),
421
+ MAX_UNENCRYPTED_LOGS_PER_CALL,
422
+ ),
414
423
  unencryptedLogPreimagesLength,
415
424
  historicalHeader: this.historicalHeader,
425
+ globalVariables: this.globalVariables,
426
+ startGasLeft: Gas.from(result.startGasLeft),
427
+ endGasLeft: Gas.from(result.endGasLeft),
428
+ transactionFee: result.transactionFee,
416
429
  // TODO(@just-mitch): need better mapping from simulator to revert code.
417
430
  revertCode: result.reverted ? RevertCode.REVERTED : RevertCode.OK,
418
- gasLeft: Gas.from(result.gasLeft),
419
431
  });
420
- }
421
432
 
422
- protected async getPublicCallStackItem(result: PublicExecutionResult, isExecutionRequest = false) {
423
433
  return new PublicCallStackItem(
424
434
  result.execution.contractAddress,
425
435
  result.execution.functionData,
426
- await this.getPublicCircuitPublicInputs(result),
436
+ publicCircuitPublicInputs,
427
437
  isExecutionRequest,
428
438
  );
429
439
  }
@@ -461,8 +471,7 @@ export abstract class AbstractPhaseManager {
461
471
  c.toCallRequest(callStackItem.publicInputs.callContext),
462
472
  );
463
473
  const publicCallStack = padArrayEnd(publicCallRequests, CallRequest.empty(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL);
464
- const portalContractAddress = result.execution.callContext.portalContractAddress.toField();
465
- return new PublicCallData(callStackItem, publicCallStack, makeEmptyProof(), portalContractAddress, bytecodeHash);
474
+ return new PublicCallData(callStackItem, publicCallStack, makeEmptyProof(), bytecodeHash);
466
475
  }
467
476
  }
468
477
 
@@ -518,29 +527,9 @@ function patchPublicStorageActionOrdering(
518
527
  // so the returned result will be a subset of the public kernel output.
519
528
 
520
529
  const simPublicDataReads = collectPublicDataReads(execResult);
521
- // verify that each read is in the kernel output
522
- for (const read of simPublicDataReads) {
523
- if (!publicDataReads.find(item => item.equals(read))) {
524
- throw new Error(
525
- `Public data reads from simulator do not match those from public kernel.\nFrom simulator: ${simPublicDataReads
526
- .map(p => p.toFriendlyJSON())
527
- .join(', ')}\nFrom public kernel: ${publicDataReads.map(i => i.toFriendlyJSON()).join(', ')}`,
528
- );
529
- }
530
- }
531
530
 
532
531
  const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(execResult);
533
- for (const update of simPublicDataUpdateRequests) {
534
- if (!publicDataUpdateRequests.find(item => item.equals(update))) {
535
- throw new Error(
536
- `Public data update requests from simulator do not match those from public kernel.\nFrom simulator: ${simPublicDataUpdateRequests
537
- .map(p => p.toFriendlyJSON())
538
- .join(', ')}\nFrom public kernel revertible: ${publicDataUpdateRequests
539
- .map(i => i.toFriendlyJSON())
540
- .join(', ')}`,
541
- );
542
- }
543
- }
532
+
544
533
  // We only want to reorder the items from the public inputs of the
545
534
  // most recently processed top/enqueued call.
546
535
 
@@ -17,14 +17,14 @@ import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simul
17
17
  */
18
18
  export class AppLogicPhaseManager extends AbstractPhaseManager {
19
19
  constructor(
20
- protected db: MerkleTreeOperations,
21
- protected publicExecutor: PublicExecutor,
22
- protected publicKernel: PublicKernelCircuitSimulator,
23
- protected globalVariables: GlobalVariables,
24
- protected historicalHeader: Header,
20
+ db: MerkleTreeOperations,
21
+ publicExecutor: PublicExecutor,
22
+ publicKernel: PublicKernelCircuitSimulator,
23
+ globalVariables: GlobalVariables,
24
+ historicalHeader: Header,
25
25
  protected publicContractsDB: ContractsDataSourcePublicDB,
26
26
  protected publicStateDB: PublicStateDB,
27
- public phase: PublicKernelPhase = PublicKernelPhase.APP_LOGIC,
27
+ phase: PublicKernelPhase = PublicKernelPhase.APP_LOGIC,
28
28
  ) {
29
29
  super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
30
30
  }
package/src/public/db.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type NullifierMembershipWitness } from '@aztec/circuit-types';
2
- import { type EthAddress, type FunctionSelector, type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
2
+ import { type FunctionSelector, type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
3
3
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
4
4
  import { type Fr } from '@aztec/foundation/fields';
5
5
  import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
@@ -61,13 +61,6 @@ export interface PublicContractsDB {
61
61
  */
62
62
  getBytecode(address: AztecAddress, selector: FunctionSelector): Promise<Buffer | undefined>;
63
63
 
64
- /**
65
- * Returns the portal contract address for an L2 address.
66
- * @param address - The L2 contract address.
67
- * @returns The portal contract address or undefined if not found.
68
- */
69
- getPortalContractAddress(address: AztecAddress): Promise<EthAddress | undefined>;
70
-
71
64
  /**
72
65
  * Returns a publicly deployed contract instance.
73
66
  * @param address - Address of the contract.
@@ -92,6 +85,12 @@ export interface CommitmentsDB {
92
85
  secret: Fr,
93
86
  ): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>>;
94
87
 
88
+ /**
89
+ * @param leafIndex the leaf to look up
90
+ * @returns The l1 to l2 leaf value or undefined if not found.
91
+ */
92
+ getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr | undefined>;
93
+
95
94
  /**
96
95
  * Gets the index of a commitment in the note hash tree.
97
96
  * @param commitment - The commitment.
@@ -1,16 +1,16 @@
1
1
  import { type SimulationError, type UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
2
2
  import {
3
- type AztecAddress,
4
3
  type ContractStorageRead,
5
4
  type ContractStorageUpdateRequest,
6
5
  type Fr,
7
6
  type L2ToL1Message,
7
+ type NoteHash,
8
+ type Nullifier,
8
9
  type PublicCallRequest,
9
10
  PublicDataRead,
10
11
  PublicDataUpdateRequest,
11
12
  type ReadRequest,
12
13
  type SideEffect,
13
- type SideEffectLinkedToNoteHash,
14
14
  } from '@aztec/circuits.js';
15
15
  import { computePublicDataTreeLeafSlot, computePublicDataTreeValue } from '@aztec/circuits.js/hash';
16
16
 
@@ -25,7 +25,7 @@ export interface PublicExecutionResult {
25
25
  /** The return values of the function. */
26
26
  returnValues: Fr[];
27
27
  /** The new note hashes to be inserted into the note hashes tree. */
28
- newNoteHashes: SideEffect[];
28
+ newNoteHashes: NoteHash[];
29
29
  /** The new l2 to l1 messages generated in this call. */
30
30
  newL2ToL1Messages: L2ToL1Message[];
31
31
  /** The side effect counter at the start of the function call. */
@@ -33,7 +33,7 @@ export interface PublicExecutionResult {
33
33
  /** The side effect counter after executing this function call */
34
34
  endSideEffectCounter: Fr;
35
35
  /** The new nullifiers to be inserted into the nullifier tree. */
36
- newNullifiers: SideEffectLinkedToNoteHash[];
36
+ newNullifiers: Nullifier[];
37
37
  /** The nullifier read requests emitted in this call. */
38
38
  nullifierReadRequests: ReadRequest[];
39
39
  /** The nullifier non existent read requests emitted in this call. */
@@ -44,9 +44,14 @@ export interface PublicExecutionResult {
44
44
  contractStorageUpdateRequests: ContractStorageUpdateRequest[];
45
45
  /** The results of nested calls. */
46
46
  nestedExecutions: this[];
47
+ /**
48
+ * The hashed logs with side effect counter.
49
+ * Note: required as we don't track the counter anywhere else.
50
+ */
51
+ unencryptedLogsHashes: SideEffect[];
47
52
  /**
48
53
  * Unencrypted logs emitted during execution of this function call.
49
- * Note: These are preimages to `unencryptedLogsHash`.
54
+ * Note: These are preimages to `unencryptedLogsHashes`.
50
55
  */
51
56
  unencryptedLogs: UnencryptedFunctionL2Logs;
52
57
  /**
@@ -57,8 +62,12 @@ export interface PublicExecutionResult {
57
62
  * The revert reason if the execution reverted.
58
63
  */
59
64
  revertReason: SimulationError | undefined;
65
+ /** How much gas was available for this public execution. */
66
+ startGasLeft: Gas;
60
67
  /** How much gas was left after this public execution. */
61
- gasLeft: Gas;
68
+ endGasLeft: Gas;
69
+ /** Transaction fee set for this tx. */
70
+ transactionFee: Fr;
62
71
  }
63
72
 
64
73
  /**
@@ -85,10 +94,8 @@ export function isPublicExecutionResult(
85
94
  */
86
95
  export function collectPublicDataReads(execResult: PublicExecutionResult): PublicDataRead[] {
87
96
  // HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed
88
- const contractAddress = execResult.execution.callContext.storageContractAddress;
89
-
90
97
  const thisExecPublicDataReads = execResult.contractStorageReads.map(read =>
91
- contractStorageReadToPublicDataRead(read, contractAddress),
98
+ contractStorageReadToPublicDataRead(read),
92
99
  );
93
100
  const unsorted = [
94
101
  ...thisExecPublicDataReads,
@@ -105,10 +112,8 @@ export function collectPublicDataReads(execResult: PublicExecutionResult): Publi
105
112
  */
106
113
  export function collectPublicDataUpdateRequests(execResult: PublicExecutionResult): PublicDataUpdateRequest[] {
107
114
  // HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed
108
- const contractAddress = execResult.execution.callContext.storageContractAddress;
109
-
110
115
  const thisExecPublicDataUpdateRequests = execResult.contractStorageUpdateRequests.map(update =>
111
- contractStorageUpdateRequestToPublicDataUpdateRequest(update, contractAddress),
116
+ contractStorageUpdateRequestToPublicDataUpdateRequest(update),
112
117
  );
113
118
  const unsorted = [
114
119
  ...thisExecPublicDataUpdateRequests,
@@ -123,9 +128,9 @@ export function collectPublicDataUpdateRequests(execResult: PublicExecutionResul
123
128
  * @param contractAddress - the contract address of the read
124
129
  * @returns The public data read.
125
130
  */
126
- function contractStorageReadToPublicDataRead(read: ContractStorageRead, contractAddress: AztecAddress): PublicDataRead {
131
+ function contractStorageReadToPublicDataRead(read: ContractStorageRead): PublicDataRead {
127
132
  return new PublicDataRead(
128
- computePublicDataTreeLeafSlot(contractAddress, read.storageSlot),
133
+ computePublicDataTreeLeafSlot(read.contractAddress!, read.storageSlot),
129
134
  computePublicDataTreeValue(read.currentValue),
130
135
  read.sideEffectCounter!,
131
136
  );
@@ -139,10 +144,9 @@ function contractStorageReadToPublicDataRead(read: ContractStorageRead, contract
139
144
  */
140
145
  function contractStorageUpdateRequestToPublicDataUpdateRequest(
141
146
  update: ContractStorageUpdateRequest,
142
- contractAddress: AztecAddress,
143
147
  ): PublicDataUpdateRequest {
144
148
  return new PublicDataUpdateRequest(
145
- computePublicDataTreeLeafSlot(contractAddress, update.storageSlot),
149
+ computePublicDataTreeLeafSlot(update.contractAddress!, update.storageSlot),
146
150
  computePublicDataTreeValue(update.newValue),
147
151
  update.sideEffectCounter!,
148
152
  );
@@ -154,8 +158,8 @@ function contractStorageUpdateRequestToPublicDataUpdateRequest(
154
158
  */
155
159
 
156
160
  export function checkValidStaticCall(
157
- newNoteHashes: SideEffect[],
158
- newNullifiers: SideEffectLinkedToNoteHash[],
161
+ newNoteHashes: NoteHash[],
162
+ newNullifiers: Nullifier[],
159
163
  contractStorageUpdateRequests: ContractStorageUpdateRequest[],
160
164
  newL2ToL1Messages: L2ToL1Message[],
161
165
  unencryptedLogs: UnencryptedFunctionL2Logs,