@aztec/simulator 0.35.1 → 0.37.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 +7 -5
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +50 -23
  4. package/dest/acvm/oracle/typed_oracle.d.ts +17 -22
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +13 -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 +13 -17
  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 +14 -11
  68. package/dest/client/view_data_oracle.d.ts.map +1 -1
  69. package/dest/client/view_data_oracle.js +17 -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 +63 -22
  119. package/src/acvm/oracle/typed_oracle.ts +23 -27
  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 +14 -18
  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 +35 -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
@@ -1,14 +1,24 @@
1
- import { type PublicKernelRequest, PublicKernelType, type Tx } from '@aztec/circuit-types';
2
1
  import {
3
- type Fr,
2
+ type PublicKernelRequest,
3
+ PublicKernelType,
4
+ type Tx,
5
+ UnencryptedFunctionL2Logs,
6
+ type UnencryptedL2Log,
7
+ } from '@aztec/circuit-types';
8
+ import {
9
+ Fr,
4
10
  type GlobalVariables,
5
11
  type Header,
6
12
  type KernelCircuitPublicInputs,
7
13
  MAX_NEW_NOTE_HASHES_PER_TX,
14
+ MAX_NEW_NULLIFIERS_PER_TX,
15
+ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
16
+ type MAX_UNENCRYPTED_LOGS_PER_TX,
17
+ type NoteHash,
8
18
  type Proof,
9
19
  type PublicKernelCircuitPublicInputs,
10
20
  PublicKernelTailCircuitPrivateInputs,
11
- type SideEffect,
21
+ SideEffect,
12
22
  makeEmptyProof,
13
23
  mergeAccumulatedData,
14
24
  sortByCounter,
@@ -23,14 +33,14 @@ import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simul
23
33
 
24
34
  export class TailPhaseManager extends AbstractPhaseManager {
25
35
  constructor(
26
- protected db: MerkleTreeOperations,
27
- protected publicExecutor: PublicExecutor,
28
- protected publicKernel: PublicKernelCircuitSimulator,
29
- protected globalVariables: GlobalVariables,
30
- protected historicalHeader: Header,
36
+ db: MerkleTreeOperations,
37
+ publicExecutor: PublicExecutor,
38
+ publicKernel: PublicKernelCircuitSimulator,
39
+ globalVariables: GlobalVariables,
40
+ historicalHeader: Header,
31
41
  protected publicContractsDB: ContractsDataSourcePublicDB,
32
42
  protected publicStateDB: PublicStateDB,
33
- public readonly phase: PublicKernelPhase = PublicKernelPhase.TAIL,
43
+ phase: PublicKernelPhase = PublicKernelPhase.TAIL,
34
44
  ) {
35
45
  super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
36
46
  }
@@ -47,7 +57,8 @@ export class TailPhaseManager extends AbstractPhaseManager {
47
57
  throw err;
48
58
  },
49
59
  );
50
-
60
+ // Temporary hack. Should sort them in the tail circuit.
61
+ this.patchLogsOrdering(tx, previousPublicKernelOutput);
51
62
  // commit the state updates from this transaction
52
63
  await this.publicStateDB.commit();
53
64
 
@@ -71,13 +82,17 @@ export class TailPhaseManager extends AbstractPhaseManager {
71
82
  previousOutput: PublicKernelCircuitPublicInputs,
72
83
  previousProof: Proof,
73
84
  ): Promise<[PublicKernelTailCircuitPrivateInputs, KernelCircuitPublicInputs]> {
85
+ // Temporary hack. Should sort them in the tail circuit.
86
+ previousOutput.end.unencryptedLogsHashes = this.sortLogsHashes<typeof MAX_UNENCRYPTED_LOGS_PER_TX>(
87
+ previousOutput.end.unencryptedLogsHashes,
88
+ );
74
89
  const [inputs, output] = await this.simulate(previousOutput, previousProof);
75
90
 
76
91
  // Temporary hack. Should sort them in the tail circuit.
77
92
  const noteHashes = mergeAccumulatedData(
78
- MAX_NEW_NOTE_HASHES_PER_TX,
79
93
  previousOutput.endNonRevertibleData.newNoteHashes,
80
94
  previousOutput.end.newNoteHashes,
95
+ MAX_NEW_NOTE_HASHES_PER_TX,
81
96
  );
82
97
  output.end.newNoteHashes = this.sortNoteHashes<typeof MAX_NEW_NOTE_HASHES_PER_TX>(noteHashes);
83
98
 
@@ -88,33 +103,93 @@ export class TailPhaseManager extends AbstractPhaseManager {
88
103
  previousOutput: PublicKernelCircuitPublicInputs,
89
104
  previousProof: Proof,
90
105
  ): Promise<[PublicKernelTailCircuitPrivateInputs, KernelCircuitPublicInputs]> {
106
+ const inputs = await this.buildPrivateInputs(previousOutput, previousProof);
107
+ // We take a deep copy (clone) of these to pass to the prover
108
+ return [inputs.clone(), await this.publicKernel.publicKernelCircuitTail(inputs)];
109
+ }
110
+
111
+ private async buildPrivateInputs(previousOutput: PublicKernelCircuitPublicInputs, previousProof: Proof) {
91
112
  const previousKernel = this.getPreviousKernelData(previousOutput, previousProof);
92
113
 
93
114
  const { validationRequests, endNonRevertibleData, end } = previousOutput;
94
- const nullifierReadRequestHints = await this.hintsBuilder.getNullifierReadRequestHints(
95
- validationRequests.nullifierReadRequests,
115
+
116
+ const pendingNullifiers = mergeAccumulatedData(
96
117
  endNonRevertibleData.newNullifiers,
97
118
  end.newNullifiers,
119
+ MAX_NEW_NULLIFIERS_PER_TX,
120
+ );
121
+
122
+ const nullifierReadRequestHints = await this.hintsBuilder.getNullifierReadRequestHints(
123
+ validationRequests.nullifierReadRequests,
124
+ pendingNullifiers,
98
125
  );
126
+
99
127
  const nullifierNonExistentReadRequestHints = await this.hintsBuilder.getNullifierNonExistentReadRequestHints(
100
128
  validationRequests.nullifierNonExistentReadRequests,
101
- endNonRevertibleData.newNullifiers,
102
- end.newNullifiers,
129
+ pendingNullifiers,
103
130
  );
104
131
 
105
- // We take a deep copy (clone) of these to pass to the prover
106
- const inputs = new PublicKernelTailCircuitPrivateInputs(
132
+ const pendingPublicDataWrites = mergeAccumulatedData(
133
+ endNonRevertibleData.publicDataUpdateRequests,
134
+ end.publicDataUpdateRequests,
135
+ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
136
+ );
137
+
138
+ const publicDataHints = await this.hintsBuilder.getPublicDataHints(
139
+ validationRequests.publicDataReads,
140
+ pendingPublicDataWrites,
141
+ );
142
+
143
+ const publicDataReadRequestHints = this.hintsBuilder.getPublicDataReadRequestHints(
144
+ validationRequests.publicDataReads,
145
+ pendingPublicDataWrites,
146
+ publicDataHints,
147
+ );
148
+
149
+ const currentState = await this.db.getStateReference();
150
+
151
+ return new PublicKernelTailCircuitPrivateInputs(
107
152
  previousKernel,
108
153
  nullifierReadRequestHints,
109
154
  nullifierNonExistentReadRequestHints,
155
+ publicDataHints,
156
+ publicDataReadRequestHints,
157
+ currentState.partial,
110
158
  );
111
- return [inputs.clone(), await this.publicKernel.publicKernelCircuitTail(inputs)];
112
159
  }
113
160
 
114
- private sortNoteHashes<N extends number>(noteHashes: Tuple<SideEffect, N>): Tuple<Fr, N> {
115
- return sortByCounter(noteHashes.map(n => ({ ...n, counter: n.counter.toNumber() }))).map(n => n.value) as Tuple<
116
- Fr,
117
- N
118
- >;
161
+ private sortNoteHashes<N extends number>(noteHashes: Tuple<NoteHash, N>): Tuple<Fr, N> {
162
+ return sortByCounter(noteHashes).map(n => n.value) as Tuple<Fr, N>;
163
+ }
164
+
165
+ private sortLogsHashes<N extends number>(unencryptedLogsHashes: Tuple<SideEffect, N>): Tuple<SideEffect, N> {
166
+ return sortByCounter(
167
+ unencryptedLogsHashes.map(n => ({ ...n, counter: n.counter.toNumber(), isEmpty: () => n.isEmpty() })),
168
+ ).map(h => new SideEffect(h.value, new Fr(h.counter))) as Tuple<SideEffect, N>;
169
+ }
170
+
171
+ // As above, this is a hack for unencrypted logs ordering, now they are sorted. Since the public kernel
172
+ // cannot keep track of side effects that happen after or before a nested call, we override the gathered logs.
173
+ // As a sanity check, we at least verify that the elements are the same, so we are only tweaking their ordering.
174
+ // See same fn in pxe_service.ts
175
+ // Added as part of resolving #5017
176
+ private patchLogsOrdering(tx: Tx, publicInputs: PublicKernelCircuitPublicInputs) {
177
+ const unencLogs = tx.unencryptedLogs.unrollLogs();
178
+ const sortedUnencLogs = publicInputs.end.unencryptedLogsHashes;
179
+
180
+ const finalUnencLogs: UnencryptedL2Log[] = [];
181
+ sortedUnencLogs.forEach((sideEffect: SideEffect) => {
182
+ if (!sideEffect.isEmpty()) {
183
+ const isLog = (log: UnencryptedL2Log) => Fr.fromBuffer(log.hash()).equals(sideEffect.value);
184
+ const thisLogIndex = unencLogs.findIndex(isLog);
185
+ finalUnencLogs.push(unencLogs[thisLogIndex]);
186
+ }
187
+ });
188
+ const unencryptedLogs = new UnencryptedFunctionL2Logs(finalUnencLogs);
189
+
190
+ tx.unencryptedLogs.functionLogs[0] = unencryptedLogs;
191
+ for (let i = 1; i < tx.unencryptedLogs.functionLogs.length; i++) {
192
+ tx.unencryptedLogs.functionLogs[i] = UnencryptedFunctionL2Logs.empty();
193
+ }
119
194
  }
120
195
  }
@@ -1,5 +1,7 @@
1
1
  import { type PublicKernelRequest, PublicKernelType, type Tx } from '@aztec/circuit-types';
2
2
  import {
3
+ type Fr,
4
+ type Gas,
3
5
  type GlobalVariables,
4
6
  type Header,
5
7
  type Proof,
@@ -8,6 +10,8 @@ import {
8
10
  import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
9
11
  import { type MerkleTreeOperations } from '@aztec/world-state';
10
12
 
13
+ import { inspect } from 'util';
14
+
11
15
  import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
12
16
  import { type ContractsDataSourcePublicDB } from './public_executor.js';
13
17
  import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
@@ -17,14 +21,14 @@ import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simul
17
21
  */
18
22
  export class TeardownPhaseManager extends AbstractPhaseManager {
19
23
  constructor(
20
- protected db: MerkleTreeOperations,
21
- protected publicExecutor: PublicExecutor,
22
- protected publicKernel: PublicKernelCircuitSimulator,
23
- protected globalVariables: GlobalVariables,
24
- protected historicalHeader: Header,
24
+ db: MerkleTreeOperations,
25
+ publicExecutor: PublicExecutor,
26
+ publicKernel: PublicKernelCircuitSimulator,
27
+ globalVariables: GlobalVariables,
28
+ historicalHeader: Header,
25
29
  protected publicContractsDB: ContractsDataSourcePublicDB,
26
30
  protected publicStateDB: PublicStateDB,
27
- public phase: PublicKernelPhase = PublicKernelPhase.TEARDOWN,
31
+ phase: PublicKernelPhase = PublicKernelPhase.TEARDOWN,
28
32
  ) {
29
33
  super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
30
34
  }
@@ -63,4 +67,18 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
63
67
  returnValues: undefined,
64
68
  };
65
69
  }
70
+
71
+ protected override getTransactionFee(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs): Fr {
72
+ const gasSettings = tx.data.constants.txContext.gasSettings;
73
+ const gasFees = this.globalVariables.gasFees;
74
+ // No need to add teardown limits since they are already included in end.gasUsed
75
+ const gasUsed = previousPublicKernelOutput.end.gasUsed.add(previousPublicKernelOutput.endNonRevertibleData.gasUsed);
76
+ const txFee = gasSettings.inclusionFee.add(gasUsed.computeFee(gasFees));
77
+ this.log.debug(`Computed tx fee`, { txFee, gasUsed: inspect(gasUsed), gasFees: inspect(gasFees) });
78
+ return txFee;
79
+ }
80
+
81
+ protected override getAvailableGas(tx: Tx, _previousPublicKernelOutput: PublicKernelCircuitPublicInputs): Gas {
82
+ return tx.data.constants.txContext.gasSettings.getTeardownLimits();
83
+ }
66
84
  }
@@ -6,12 +6,14 @@ import {
6
6
  ContractStorageUpdateRequest,
7
7
  FunctionData,
8
8
  Gas,
9
+ type GasSettings,
9
10
  type GlobalVariables,
10
11
  type Header,
11
12
  L2ToL1Message,
13
+ NoteHash,
14
+ Nullifier,
12
15
  ReadRequest,
13
16
  SideEffect,
14
- SideEffectLinkedToNoteHash,
15
17
  } from '@aztec/circuits.js';
16
18
  import { Fr } from '@aztec/foundation/fields';
17
19
 
@@ -37,14 +39,13 @@ export function createAvmExecutionEnvironment(
37
39
  current: PublicExecution,
38
40
  header: Header,
39
41
  globalVariables: GlobalVariables,
42
+ gasSettings: GasSettings,
43
+ transactionFee: Fr,
40
44
  ): AvmExecutionEnvironment {
41
45
  return new AvmExecutionEnvironment(
42
46
  current.contractAddress,
43
47
  current.callContext.storageContractAddress,
44
- current.callContext.msgSender, // TODO: origin is not available
45
48
  current.callContext.msgSender,
46
- current.callContext.portalContractAddress,
47
- globalVariables.gasFees.feePerL1Gas,
48
49
  globalVariables.gasFees.feePerL2Gas,
49
50
  globalVariables.gasFees.feePerDaGas,
50
51
  /*contractCallDepth=*/ Fr.zero(),
@@ -53,8 +54,8 @@ export function createAvmExecutionEnvironment(
53
54
  current.callContext.isStaticCall,
54
55
  current.callContext.isDelegateCall,
55
56
  current.args,
56
- current.callContext.gasSettings,
57
- current.callContext.transactionFee,
57
+ gasSettings,
58
+ transactionFee,
58
59
  current.functionData.selector,
59
60
  );
60
61
  }
@@ -64,14 +65,10 @@ export function createPublicExecutionContext(avmContext: AvmContext, calldata: F
64
65
  const callContext = CallContext.from({
65
66
  msgSender: avmContext.environment.sender,
66
67
  storageContractAddress: avmContext.environment.storageAddress,
67
- portalContractAddress: avmContext.environment.portal,
68
68
  functionSelector: avmContext.environment.temporaryFunctionSelector,
69
- gasLeft: Gas.from(avmContext.machineState.gasLeft),
70
69
  isDelegateCall: avmContext.environment.isDelegateCall,
71
70
  isStaticCall: avmContext.environment.isStaticCall,
72
71
  sideEffectCounter: sideEffectCounter,
73
- gasSettings: avmContext.environment.gasSettings,
74
- transactionFee: avmContext.environment.transactionFee,
75
72
  });
76
73
  const functionData = new FunctionData(avmContext.environment.temporaryFunctionSelector, /*isPrivate=*/ false);
77
74
  const execution: PublicExecution = {
@@ -91,6 +88,9 @@ export function createPublicExecutionContext(avmContext: AvmContext, calldata: F
91
88
  avmContext.persistableState.hostStorage.publicStateDb,
92
89
  avmContext.persistableState.hostStorage.contractsDb,
93
90
  avmContext.persistableState.hostStorage.commitmentsDb,
91
+ Gas.from(avmContext.machineState.gasLeft),
92
+ avmContext.environment.transactionFee,
93
+ avmContext.environment.gasSettings,
94
94
  );
95
95
 
96
96
  return context;
@@ -113,10 +113,10 @@ export async function convertAvmResults(
113
113
  const execution = executionContext.execution;
114
114
 
115
115
  const contractStorageReads: ContractStorageRead[] = newWorldState.storageReads.map(
116
- read => new ContractStorageRead(read.slot, read.value, read.counter.toNumber()),
116
+ read => new ContractStorageRead(read.slot, read.value, read.counter.toNumber(), read.storageAddress),
117
117
  );
118
118
  const contractStorageUpdateRequests: ContractStorageUpdateRequest[] = newWorldState.storageWrites.map(
119
- write => new ContractStorageUpdateRequest(write.slot, write.value, write.counter.toNumber()),
119
+ write => new ContractStorageUpdateRequest(write.slot, write.value, write.counter.toNumber(), write.storageAddress),
120
120
  );
121
121
  // We need to write the storage updates to the DB, because that's what the ACVM expects.
122
122
  // Assumes the updates are in the right order.
@@ -125,7 +125,7 @@ export async function convertAvmResults(
125
125
  }
126
126
 
127
127
  const newNoteHashes = newWorldState.newNoteHashes.map(
128
- noteHash => new SideEffect(noteHash.noteHash, noteHash.counter),
128
+ noteHash => new NoteHash(noteHash.noteHash, noteHash.counter.toNumber()),
129
129
  );
130
130
  const nullifierReadRequests: ReadRequest[] = newWorldState.nullifierChecks
131
131
  .filter(nullifierCheck => nullifierCheck.exists)
@@ -133,17 +133,20 @@ export async function convertAvmResults(
133
133
  const nullifierNonExistentReadRequests: ReadRequest[] = newWorldState.nullifierChecks
134
134
  .filter(nullifierCheck => !nullifierCheck.exists)
135
135
  .map(nullifierCheck => new ReadRequest(nullifierCheck.nullifier, nullifierCheck.counter.toNumber()));
136
- const newNullifiers: SideEffectLinkedToNoteHash[] = newWorldState.newNullifiers.map(
136
+ const newNullifiers: Nullifier[] = newWorldState.newNullifiers.map(
137
137
  tracedNullifier =>
138
- new SideEffectLinkedToNoteHash(
138
+ new Nullifier(
139
139
  /*value=*/ tracedNullifier.nullifier,
140
+ tracedNullifier.counter.toNumber(),
140
141
  /*noteHash=*/ Fr.ZERO, // NEEDED?
141
- tracedNullifier.counter,
142
142
  ),
143
143
  );
144
144
  const unencryptedLogs: UnencryptedFunctionL2Logs = new UnencryptedFunctionL2Logs(
145
145
  newWorldState.newLogs.map(log => new UnencryptedL2Log(log.contractAddress, log.selector, log.data)),
146
146
  );
147
+ const unencryptedLogsHashes = newWorldState.newLogsHashes.map(
148
+ logHash => new SideEffect(logHash.logHash, logHash.counter),
149
+ );
147
150
  const newL2ToL1Messages = newWorldState.newL1Messages.map(m => new L2ToL1Message(m.recipient, m.content));
148
151
 
149
152
  const returnValues = result.output;
@@ -167,10 +170,13 @@ export async function convertAvmResults(
167
170
  contractStorageUpdateRequests,
168
171
  returnValues,
169
172
  nestedExecutions,
173
+ unencryptedLogsHashes,
170
174
  unencryptedLogs,
171
175
  reverted: result.reverted,
172
176
  revertReason: result.revertReason ? createSimulationError(result.revertReason) : undefined,
173
- gasLeft: endMachineState.gasLeft,
177
+ startGasLeft: executionContext.availableGas,
178
+ endGasLeft: endMachineState.gasLeft,
179
+ transactionFee: executionContext.transactionFee,
174
180
  };
175
181
  }
176
182
 
@@ -211,7 +217,7 @@ export function updateAvmContextFromPublicExecutionResult(ctx: AvmContext, resul
211
217
  ctx.persistableState.trace.newNullifiers.push({
212
218
  storageAddress: ctx.environment.storageAddress,
213
219
  nullifier: nullifier.value,
214
- counter: nullifier.counter,
220
+ counter: new Fr(nullifier.counter),
215
221
  });
216
222
  }
217
223
 
@@ -219,7 +225,7 @@ export function updateAvmContextFromPublicExecutionResult(ctx: AvmContext, resul
219
225
  ctx.persistableState.trace.newNoteHashes.push({
220
226
  storageAddress: ctx.environment.storageAddress,
221
227
  noteHash: noteHash.value,
222
- counter: noteHash.counter,
228
+ counter: new Fr(noteHash.counter),
223
229
  });
224
230
  }
225
231
 
@@ -14,6 +14,7 @@ export function lastSideEffectCounter(tx: Tx): number {
14
14
  ...data.endNonRevertibleData.publicCallStack,
15
15
  ...data.end.newNoteHashes,
16
16
  ...data.end.newNullifiers,
17
+ ...data.end.unencryptedLogsHashes,
17
18
  ...data.end.publicCallStack,
18
19
  ];
19
20
 
@@ -23,7 +24,8 @@ export function lastSideEffectCounter(tx: Tx): number {
23
24
  // look at both start and end counters because for enqueued public calls start > 0 while end === 0
24
25
  max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber());
25
26
  } else {
26
- max = Math.max(max, sideEffect.counter.toNumber());
27
+ const counter = typeof sideEffect.counter === 'number' ? sideEffect.counter : sideEffect.counter.toNumber();
28
+ max = Math.max(max, counter);
27
29
  }
28
30
  }
29
31
 
package/src/test/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/circuit-types';
2
2
  import { type AztecAddress, EthAddress, type Fr } from '@aztec/circuits.js';
3
- import { computeMessageSecretHash } from '@aztec/circuits.js/hash';
3
+ import { computeSecretHash } from '@aztec/circuits.js/hash';
4
4
  import { sha256ToField } from '@aztec/foundation/crypto';
5
5
 
6
6
  /**
@@ -21,9 +21,7 @@ export const buildL1ToL2Message = (
21
21
  const selectorBuf = Buffer.from(selector, 'hex');
22
22
 
23
23
  const content = sha256ToField([selectorBuf, ...contentPreimage]);
24
- const secretHash = computeMessageSecretHash(secret);
24
+ const secretHash = computeSecretHash(secret);
25
25
 
26
- // Eventually the kernel will need to prove the kernel portal pair exists within the contract tree,
27
- // EthAddress.random() will need to be replaced when this happens
28
26
  return new L1ToL2Message(new L1Actor(EthAddress.random(), 1), new L2Actor(targetContract, 1), content, secretHash);
29
27
  };