@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
@@ -9,7 +9,6 @@ import { OutOfGasError } from './errors.js';
9
9
  * A few fields of machine state are initialized from AVM session inputs or call instruction arguments
10
10
  */
11
11
  export type InitialAvmMachineState = {
12
- l1GasLeft: number;
13
12
  l2GasLeft: number;
14
13
  daGasLeft: number;
15
14
  };
@@ -18,7 +17,6 @@ export type InitialAvmMachineState = {
18
17
  * Avm state modified on an instruction-per-instruction basis.
19
18
  */
20
19
  export class AvmMachineState {
21
- public l1GasLeft: number;
22
20
  /** gas remaining of the gas allocated for a contract call */
23
21
  public l2GasLeft: number;
24
22
  public daGasLeft: number;
@@ -45,23 +43,22 @@ export class AvmMachineState {
45
43
  private output: Fr[] = [];
46
44
 
47
45
  constructor(gasLeft: Gas);
48
- constructor(l1GasLeft: number, l2GasLeft: number, daGasLeft: number);
49
- constructor(gasLeftOrL1GasLeft: Gas | number, l2GasLeft?: number, daGasLeft?: number) {
50
- if (typeof gasLeftOrL1GasLeft === 'object') {
51
- ({ l1Gas: this.l1GasLeft, l2Gas: this.l2GasLeft, daGas: this.daGasLeft } = gasLeftOrL1GasLeft);
46
+ constructor(l2GasLeft: number, daGasLeft: number);
47
+ constructor(gasLeftOrL2GasLeft: Gas | number, daGasLeft?: number) {
48
+ if (typeof gasLeftOrL2GasLeft === 'object') {
49
+ ({ l2Gas: this.l2GasLeft, daGas: this.daGasLeft } = gasLeftOrL2GasLeft);
52
50
  } else {
53
- this.l1GasLeft = gasLeftOrL1GasLeft;
54
- this.l2GasLeft = l2GasLeft!;
51
+ this.l2GasLeft = gasLeftOrL2GasLeft!;
55
52
  this.daGasLeft = daGasLeft!;
56
53
  }
57
54
  }
58
55
 
59
56
  public get gasLeft(): Gas {
60
- return { l1Gas: this.l1GasLeft, l2Gas: this.l2GasLeft, daGas: this.daGasLeft };
57
+ return { l2Gas: this.l2GasLeft, daGas: this.daGasLeft };
61
58
  }
62
59
 
63
60
  public static fromState(state: InitialAvmMachineState): AvmMachineState {
64
- return new AvmMachineState(state.l1GasLeft, state.l2GasLeft, state.daGasLeft);
61
+ return new AvmMachineState(state.l2GasLeft, state.daGasLeft);
65
62
  }
66
63
 
67
64
  /**
@@ -143,7 +140,7 @@ export class AvmMachineState {
143
140
  try {
144
141
  // Try to interpret the output as a text string.
145
142
  revertReason = new Error(
146
- 'Reverted with output: ' + String.fromCharCode(...this.output.map(fr => fr.toNumber())),
143
+ 'Reverted with output: ' + String.fromCharCode(...this.output.slice(1).map(fr => fr.toNumber())),
147
144
  );
148
145
  } catch (e) {
149
146
  revertReason = new Error('Reverted with non-string output');
@@ -61,7 +61,7 @@ export class AvmSimulator {
61
61
  'AVM attempted to execute non-existent instruction. This should never happen (invalid bytecode or AVM simulator bug)!',
62
62
  );
63
63
 
64
- const gasLeft = `l1=${machineState.l1GasLeft} l2=${machineState.l2GasLeft} da=${machineState.daGasLeft}`;
64
+ const gasLeft = `l2=${machineState.l2GasLeft} da=${machineState.daGasLeft}`;
65
65
  this.log.debug(`@${machineState.pc} ${instruction.toString()} (${gasLeft})`);
66
66
  // Execute the instruction.
67
67
  // Normal returns and reverts will return normally here.
@@ -1,5 +1,4 @@
1
- import { SiblingPath } from '@aztec/circuit-types';
2
- import { GasFees, GasSettings, GlobalVariables, Header, L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
1
+ import { GasFees, GasSettings, GlobalVariables, Header } from '@aztec/circuits.js';
3
2
  import { FunctionSelector } from '@aztec/foundation/abi';
4
3
  import { AztecAddress } from '@aztec/foundation/aztec-address';
5
4
  import { EthAddress } from '@aztec/foundation/eth-address';
@@ -8,12 +7,7 @@ import { Fr } from '@aztec/foundation/fields';
8
7
  import { mock } from 'jest-mock-extended';
9
8
  import merge from 'lodash.merge';
10
9
 
11
- import {
12
- type CommitmentsDB,
13
- MessageLoadOracleInputs,
14
- type PublicContractsDB,
15
- type PublicStateDB,
16
- } from '../../index.js';
10
+ import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from '../../index.js';
17
11
  import { AvmContext } from '../avm_context.js';
18
12
  import { AvmContextInputs, AvmExecutionEnvironment } from '../avm_execution_environment.js';
19
13
  import { AvmMachineState } from '../avm_machine_state.js';
@@ -61,10 +55,7 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
61
55
  return new AvmExecutionEnvironment(
62
56
  overrides?.address ?? AztecAddress.zero(),
63
57
  overrides?.storageAddress ?? AztecAddress.zero(),
64
- overrides?.origin ?? AztecAddress.zero(),
65
58
  overrides?.sender ?? AztecAddress.zero(),
66
- overrides?.portal ?? EthAddress.ZERO,
67
- overrides?.feePerL1Gas ?? Fr.zero(),
68
59
  overrides?.feePerL2Gas ?? Fr.zero(),
69
60
  overrides?.feePerDaGas ?? Fr.zero(),
70
61
  overrides?.contractCallDepth ?? Fr.zero(),
@@ -99,7 +90,6 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
99
90
  */
100
91
  export function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachineState {
101
92
  return AvmMachineState.fromState({
102
- l1GasLeft: overrides?.l1GasLeft ?? 100e6,
103
93
  l2GasLeft: overrides?.l2GasLeft ?? 100e6,
104
94
  daGasLeft: overrides?.daGasLeft ?? 100e6,
105
95
  });
@@ -112,18 +102,6 @@ export function allSameExcept(original: any, overrides: any): any {
112
102
  return merge({}, original, overrides);
113
103
  }
114
104
 
115
- /**
116
- * Create an empty L1ToL2Message oracle input
117
- */
118
- export function initL1ToL2MessageOracleInput(
119
- leafIndex?: bigint,
120
- ): MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT> {
121
- return new MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>(
122
- leafIndex ?? 0n,
123
- new SiblingPath(L1_TO_L2_MSG_TREE_HEIGHT, Array(L1_TO_L2_MSG_TREE_HEIGHT)),
124
- );
125
- }
126
-
127
105
  /**
128
106
  * Adjust the user index to account for the AvmContextInputs size.
129
107
  * This is a hack for testing, and should go away once AvmContextInputs themselves go away.
@@ -16,6 +16,7 @@ import {
16
16
  type TracedNullifierCheck,
17
17
  type TracedPublicStorageRead,
18
18
  type TracedPublicStorageWrite,
19
+ type TracedUnencryptedL2Log,
19
20
  } from './trace_types.js';
20
21
 
21
22
  /**
@@ -33,7 +34,7 @@ export type JournalData = {
33
34
 
34
35
  newL1Messages: L2ToL1Message[];
35
36
  newLogs: UnencryptedL2Log[];
36
-
37
+ newLogsHashes: TracedUnencryptedL2Log[];
37
38
  /** contract address -\> key -\> value */
38
39
  currentStorageValue: Map<bigint, Map<bigint, Fr>>;
39
40
  };
@@ -171,24 +172,11 @@ export class AvmPersistableStateManager {
171
172
  * @returns exists - whether the message exists in the L1 to L2 Messages tree
172
173
  */
173
174
  public async checkL1ToL2MessageExists(msgHash: Fr, msgLeafIndex: Fr): Promise<boolean> {
174
- let exists = false;
175
- try {
176
- // The following 2 values are used to compute a message nullifier. Given that here we do not care about getting
177
- // non-nullified messages we can just pass in random values and the nullifier check will effectively be ignored
178
- // (no nullifier will be found).
179
- const ignoredContractAddress = AztecAddress.random();
180
- const ignoredSecret = Fr.random();
181
- const gotMessage = await this.hostStorage.commitmentsDb.getL1ToL2MembershipWitness(
182
- ignoredContractAddress,
183
- msgHash,
184
- ignoredSecret,
185
- );
186
- exists = gotMessage !== undefined && gotMessage.index == msgLeafIndex.toBigInt();
187
- } catch {
188
- // error getting message - doesn't exist!
189
- exists = false;
190
- }
191
- this.log.debug(`l1ToL2Messages(${msgHash})@${msgLeafIndex} ?? exists: ${exists}.`);
175
+ const valueAtIndex = await this.hostStorage.commitmentsDb.getL1ToL2LeafValue(msgLeafIndex.toBigInt());
176
+ const exists = valueAtIndex?.equals(msgHash) ?? false;
177
+ this.log.debug(
178
+ `l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`,
179
+ );
192
180
  this.trace.traceL1ToL2MessageCheck(msgHash, msgLeafIndex, exists);
193
181
  return Promise.resolve(exists);
194
182
  }
@@ -206,13 +194,13 @@ export class AvmPersistableStateManager {
206
194
 
207
195
  public writeLog(contractAddress: Fr, event: Fr, log: Fr[]) {
208
196
  this.log.debug(`UnencryptedL2Log(${contractAddress}) += event ${event} with ${log.length} fields.`);
209
- this.newLogs.push(
210
- new UnencryptedL2Log(
211
- AztecAddress.fromField(contractAddress),
212
- EventSelector.fromField(event),
213
- Buffer.concat(log.map(f => f.toBuffer())),
214
- ),
197
+ const L2log = new UnencryptedL2Log(
198
+ AztecAddress.fromField(contractAddress),
199
+ EventSelector.fromField(event),
200
+ Buffer.concat(log.map(f => f.toBuffer())),
215
201
  );
202
+ this.newLogs.push(L2log);
203
+ this.trace.traceNewLog(Fr.fromBuffer(L2log.hash()));
216
204
  }
217
205
 
218
206
  /**
@@ -252,6 +240,7 @@ export class AvmPersistableStateManager {
252
240
  l1ToL2MessageChecks: this.trace.l1ToL2MessageChecks,
253
241
  newL1Messages: this.newL1Messages,
254
242
  newLogs: this.newLogs,
243
+ newLogsHashes: this.trace.newLogsHashes,
255
244
  currentStorageValue: this.publicStorage.getCache().cachePerContract,
256
245
  storageReads: this.trace.publicStorageReads,
257
246
  storageWrites: this.trace.publicStorageWrites,
@@ -8,6 +8,7 @@ import {
8
8
  type TracedNullifierCheck,
9
9
  type TracedPublicStorageRead,
10
10
  type TracedPublicStorageWrite,
11
+ type TracedUnencryptedL2Log,
11
12
  } from './trace_types.js';
12
13
 
13
14
  export class WorldStateAccessTrace {
@@ -21,6 +22,7 @@ export class WorldStateAccessTrace {
21
22
  public nullifierChecks: TracedNullifierCheck[] = [];
22
23
  public newNullifiers: TracedNullifier[] = [];
23
24
  public l1ToL2MessageChecks: TracedL1toL2MessageCheck[] = [];
25
+ public newLogsHashes: TracedUnencryptedL2Log[] = [];
24
26
 
25
27
  //public contractCalls: TracedContractCall[] = [];
26
28
  //public archiveChecks: TracedArchiveLeafCheck[] = [];
@@ -133,6 +135,15 @@ export class WorldStateAccessTrace {
133
135
  this.incrementAccessCounter();
134
136
  }
135
137
 
138
+ public traceNewLog(logHash: Fr) {
139
+ const traced: TracedUnencryptedL2Log = {
140
+ logHash,
141
+ counter: new Fr(this.accessCounter),
142
+ };
143
+ this.newLogsHashes.push(traced);
144
+ this.incrementAccessCounter();
145
+ }
146
+
136
147
  private incrementAccessCounter() {
137
148
  this.accessCounter++;
138
149
  }
@@ -155,6 +166,7 @@ export class WorldStateAccessTrace {
155
166
  this.nullifierChecks = this.nullifierChecks.concat(incomingTrace.nullifierChecks);
156
167
  this.newNullifiers = this.newNullifiers.concat(incomingTrace.newNullifiers);
157
168
  this.l1ToL2MessageChecks = this.l1ToL2MessageChecks.concat(incomingTrace.l1ToL2MessageChecks);
169
+ this.newLogsHashes = this.newLogsHashes.concat(incomingTrace.newLogsHashes);
158
170
  // it is assumed that the incoming trace was initialized with this as parent, so accept counter
159
171
  this.accessCounter = incomingTrace.accessCounter;
160
172
  }
@@ -73,6 +73,13 @@ export type TracedL1toL2MessageCheck = {
73
73
  //endLifetime: Fr;
74
74
  };
75
75
 
76
+ export type TracedUnencryptedL2Log = {
77
+ //callPointer: Fr;
78
+ logHash: Fr;
79
+ counter: Fr;
80
+ //endLifetime: Fr;
81
+ };
82
+
76
83
  //export type TracedArchiveLeafCheck = {
77
84
  // leafIndex: Fr;
78
85
  // leaf: Fr;
@@ -23,7 +23,7 @@ export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInst
23
23
  context.machineState.incrementPc();
24
24
  }
25
25
 
26
- protected gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>) {
26
+ protected override gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>) {
27
27
  const baseGasCost = getGasCostForTypeTag(this.inTag, getBaseGasCost(this.opcode));
28
28
  const memoryGasCost = getMemoryGasCost(memoryOps);
29
29
  return sumGas(baseGasCost, memoryGasCost);
@@ -102,7 +102,7 @@ export class FieldDiv extends Instruction {
102
102
  context.machineState.incrementPc();
103
103
  }
104
104
 
105
- protected gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>) {
105
+ protected override gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>) {
106
106
  const baseGasCost = getGasCostForTypeTag(TypeTag.FIELD, getBaseGasCost(this.opcode));
107
107
  const memoryGasCost = getMemoryGasCost(memoryOps);
108
108
  return sumGas(baseGasCost, memoryGasCost);
@@ -13,15 +13,6 @@ export class L2GasLeft extends GetterInstruction {
13
13
  }
14
14
  }
15
15
 
16
- export class L1GasLeft extends GetterInstruction {
17
- static type: string = 'L1GASLEFT';
18
- static readonly opcode: Opcode = Opcode.L1GASLEFT;
19
-
20
- protected getValue(context: AvmContext): MemoryValue {
21
- return new Field(context.machineState.l1GasLeft);
22
- }
23
- }
24
-
25
16
  export class DAGasLeft extends GetterInstruction {
26
17
  static type: string = 'DAGASLEFT';
27
18
  static readonly opcode: Opcode = Opcode.DAGASLEFT;
@@ -39,7 +39,6 @@ export class GetContractInstance extends Instruction {
39
39
  new Field(0),
40
40
  new Field(0),
41
41
  new Field(0),
42
- new Field(0),
43
42
  ]
44
43
  : [
45
44
  new Fr(1), // found
@@ -47,7 +46,6 @@ export class GetContractInstance extends Instruction {
47
46
  instance.deployer.toField(),
48
47
  instance.contractClassId,
49
48
  instance.initializationHash,
50
- instance.portalContractAddress.toField(),
51
49
  instance.publicKeysHash,
52
50
  ].map(f => new Field(f));
53
51
 
@@ -41,24 +41,6 @@ export class Sender extends EnvironmentGetterInstruction {
41
41
  }
42
42
  }
43
43
 
44
- export class Origin extends EnvironmentGetterInstruction {
45
- static type: string = 'ORIGIN';
46
- static readonly opcode: Opcode = Opcode.ORIGIN;
47
-
48
- protected getEnvironmentValue(env: AvmExecutionEnvironment) {
49
- return env.origin;
50
- }
51
- }
52
-
53
- export class FeePerL1Gas extends EnvironmentGetterInstruction {
54
- static type: string = 'FEEPERL1GAS';
55
- static readonly opcode: Opcode = Opcode.FEEPERL1GAS;
56
-
57
- protected getEnvironmentValue(env: AvmExecutionEnvironment) {
58
- return env.feePerL1Gas;
59
- }
60
- }
61
-
62
44
  export class FeePerL2Gas extends EnvironmentGetterInstruction {
63
45
  static type: string = 'FEEPERL2GAS';
64
46
  static readonly opcode: Opcode = Opcode.FEEPERL2GAS;
@@ -77,15 +59,6 @@ export class FeePerDAGas extends EnvironmentGetterInstruction {
77
59
  }
78
60
  }
79
61
 
80
- export class Portal extends EnvironmentGetterInstruction {
81
- static type: string = 'PORTAL';
82
- static readonly opcode: Opcode = Opcode.PORTAL;
83
-
84
- protected getEnvironmentValue(env: AvmExecutionEnvironment) {
85
- return env.portal.toField();
86
- }
87
- }
88
-
89
62
  export class ChainId extends EnvironmentGetterInstruction {
90
63
  static type: string = 'CHAINID';
91
64
  static readonly opcode: Opcode = Opcode.CHAINID;
@@ -139,24 +112,6 @@ export class Timestamp extends EnvironmentGetterInstruction {
139
112
  // }
140
113
  // }
141
114
 
142
- // // TODO: are these even needed within the block? (both block gas limit variables - why does the execution env care?)
143
- // export class BlockL1GasLimit extends EnvironmentGetterInstruction {
144
- // static type: string = 'BLOCKL1GASLIMIT';
145
- // static numberOfOperands = 1;
146
-
147
- // constructor(private destOffset: number) {
148
- // super();
149
- // }
150
-
151
- // async execute(machineState: AvmMachineState, _journal: AvmJournal): Promise<void> {
152
- // const {blockL1GasLimit} = machineState.executionEnvironment.globals;
153
-
154
- // machineState.memory.set(this.destOffset, blockL1GasLimit);
155
-
156
- // this.incrementPc(machineState);
157
- // }
158
- // }
159
-
160
115
  // export class BlockL2GasLimit extends EnvironmentGetterInstruction {
161
116
  // static type: string = 'BLOCKL2GASLIMIT';
162
117
  // static numberOfOperands = 1;
@@ -60,13 +60,12 @@ abstract class ExternalCall extends Instruction {
60
60
  const callAddress = memory.getAs<Field>(addrOffset);
61
61
  const calldataSize = memory.get(argsSizeOffset).toNumber();
62
62
  const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
63
- const l1Gas = memory.get(gasOffset).toNumber();
64
- const l2Gas = memory.getAs<Field>(gasOffset + 1).toNumber();
65
- const daGas = memory.getAs<Field>(gasOffset + 2).toNumber();
63
+ const l2Gas = memory.get(gasOffset).toNumber();
64
+ const daGas = memory.getAs<Field>(gasOffset + 1).toNumber();
66
65
  const functionSelector = memory.getAs<Field>(this.temporaryFunctionSelectorOffset).toFr();
67
66
 
68
- const allocatedGas = { l1Gas, l2Gas, daGas };
69
- const memoryOperations = { reads: calldataSize + 6, writes: 1 + this.retSize, indirect: this.indirect };
67
+ const allocatedGas = { l2Gas, daGas };
68
+ const memoryOperations = { reads: calldataSize + 5, writes: 1 + this.retSize, indirect: this.indirect };
70
69
  const totalGas = sumGas(this.gasCost(memoryOperations), allocatedGas);
71
70
  context.machineState.consumeGas(totalGas);
72
71
 
@@ -122,7 +121,7 @@ abstract class ExternalCall extends Instruction {
122
121
  context.machineState.incrementPc();
123
122
  }
124
123
 
125
- public abstract get type(): 'CALL' | 'STATICCALL';
124
+ public abstract override get type(): 'CALL' | 'STATICCALL';
126
125
  }
127
126
 
128
127
  export class Call extends ExternalCall {
@@ -1,5 +1,5 @@
1
1
  import type { AvmContext } from '../avm_context.js';
2
- import { getBaseGasCost, getMemoryGasCost, mulGas, sumGas } from '../avm_gas.js';
2
+ import { getBaseGasCost, getMemoryGasCost, sumGas } from '../avm_gas.js';
3
3
  import { Field, type MemoryOperations, TaggedMemory, TypeTag } from '../avm_memory_types.js';
4
4
  import { InstructionExecutionError } from '../errors.js';
5
5
  import { BufferCursor } from '../serialization/buffer_cursor.js';
@@ -46,7 +46,7 @@ export class Set extends Instruction {
46
46
  }
47
47
 
48
48
  /** We need to use a custom serialize function because of the variable length of the value. */
49
- public serialize(): Buffer {
49
+ public override serialize(): Buffer {
50
50
  const format: OperandType[] = [
51
51
  ...Set.wireFormatBeforeConst,
52
52
  getOperandTypeFromInTag(this.inTag),
@@ -56,7 +56,7 @@ export class Set extends Instruction {
56
56
  }
57
57
 
58
58
  /** We need to use a custom deserialize function because of the variable length of the value. */
59
- public static deserialize(this: typeof Set, buf: BufferCursor | Buffer): Set {
59
+ public static override deserialize(this: typeof Set, buf: BufferCursor | Buffer): Set {
60
60
  if (buf instanceof Buffer) {
61
61
  buf = new BufferCursor(buf);
62
62
  }
@@ -217,8 +217,8 @@ export class CalldataCopy extends Instruction {
217
217
  context.machineState.incrementPc();
218
218
  }
219
219
 
220
- protected gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }> = {}) {
221
- const baseGasCost = mulGas(getBaseGasCost(this.opcode), this.copySize);
220
+ protected override gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }> = {}) {
221
+ const baseGasCost = getBaseGasCost(this.opcode);
222
222
  const memoryGasCost = getMemoryGasCost(memoryOps);
223
223
  return sumGas(baseGasCost, memoryGasCost);
224
224
  }
@@ -27,7 +27,7 @@ abstract class BaseStorageInstruction extends Instruction {
27
27
  super();
28
28
  }
29
29
 
30
- protected gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>): Gas {
30
+ protected override gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>): Gas {
31
31
  const baseGasCost = mulGas(getBaseGasCost(this.opcode), this.size);
32
32
  const memoryGasCost = getMemoryGasCost(memoryOps);
33
33
  return sumGas(baseGasCost, memoryGasCost);
@@ -1,5 +1,6 @@
1
- import { DAGasLeft, L1GasLeft, L2GasLeft } from '../opcodes/context_getters.js';
1
+ import { DAGasLeft, L2GasLeft } from '../opcodes/context_getters.js';
2
2
  import { Keccak, Pedersen, Poseidon2, Sha256 } from '../opcodes/hashing.js';
3
+ import type { Instruction } from '../opcodes/index.js';
3
4
  import {
4
5
  Add,
5
6
  Address,
@@ -16,7 +17,6 @@ import {
16
17
  EmitUnencryptedLog,
17
18
  Eq,
18
19
  FeePerDAGas,
19
- FeePerL1Gas,
20
20
  FeePerL2Gas,
21
21
  FieldDiv,
22
22
  GetContractInstance,
@@ -33,8 +33,6 @@ import {
33
33
  NoteHashExists,
34
34
  NullifierExists,
35
35
  Or,
36
- Origin,
37
- Portal,
38
36
  Return,
39
37
  Revert,
40
38
  SLoad,
@@ -51,7 +49,6 @@ import {
51
49
  Version,
52
50
  Xor,
53
51
  } from '../opcodes/index.js';
54
- import type { Instruction } from '../opcodes/index.js';
55
52
  import { BufferCursor } from './buffer_cursor.js';
56
53
  import { Opcode } from './instruction_serialization.js';
57
54
 
@@ -82,10 +79,7 @@ const INSTRUCTION_SET = () =>
82
79
  [Cast.opcode, Cast],
83
80
  [Address.opcode, Address],
84
81
  [StorageAddress.opcode, StorageAddress],
85
- [Origin.opcode, Origin],
86
82
  [Sender.opcode, Sender],
87
- [Portal.opcode, Portal],
88
- [FeePerL1Gas.opcode, FeePerL1Gas],
89
83
  [FeePerL2Gas.opcode, FeePerL2Gas],
90
84
  [FeePerDAGas.opcode, FeePerDAGas],
91
85
  //[Contractcalldepth.opcode, Contractcalldepth],
@@ -95,7 +89,6 @@ const INSTRUCTION_SET = () =>
95
89
  [BlockNumber.opcode, BlockNumber],
96
90
  [Timestamp.opcode, Timestamp],
97
91
  //[Coinbase.opcode, Coinbase],
98
- //[Blockl1gaslimit.opcode, Blockl1gaslimit],
99
92
  //[Blockl2gaslimit.opcode, Blockl2gaslimit],
100
93
  //[Blockdagaslimit.opcode, Blockdagaslimit],
101
94
  // Execution Environment - Calldata
@@ -103,7 +96,6 @@ const INSTRUCTION_SET = () =>
103
96
 
104
97
  // Machine State
105
98
  // Machine State - Gas
106
- [L1GasLeft.opcode, L1GasLeft],
107
99
  [L2GasLeft.opcode, L2GasLeft],
108
100
  [DAGasLeft.opcode, DAGasLeft],
109
101
  // Machine State - Internal Control Flow
@@ -3,7 +3,7 @@ import { strict as assert } from 'assert';
3
3
  import { BufferCursor } from './buffer_cursor.js';
4
4
 
5
5
  /**
6
- * All AVM opcodes. (Keep in sync with cpp counterpart code avm_opcode.hpp).
6
+ * All AVM opcodes. (Keep in sync with cpp counterpart code avm_opcode.hpp and rs in opcodes.rs).
7
7
  * Source: https://yp-aztec.netlify.app/docs/public-vm/instruction-set
8
8
  */
9
9
  export enum Opcode {
@@ -26,10 +26,7 @@ export enum Opcode {
26
26
  // Execution environment
27
27
  ADDRESS,
28
28
  STORAGEADDRESS,
29
- ORIGIN,
30
29
  SENDER,
31
- PORTAL,
32
- FEEPERL1GAS,
33
30
  FEEPERL2GAS,
34
31
  FEEPERDAGAS,
35
32
  CONTRACTCALLDEPTH,
@@ -38,12 +35,10 @@ export enum Opcode {
38
35
  BLOCKNUMBER,
39
36
  TIMESTAMP,
40
37
  COINBASE,
41
- BLOCKL1GASLIMIT,
42
38
  BLOCKL2GASLIMIT,
43
39
  BLOCKDAGASLIMIT,
44
40
  CALLDATACOPY,
45
41
  // Gas
46
- L1GASLEFT,
47
42
  L2GASLEFT,
48
43
  DAGASLEFT,
49
44
  // Control flow