Skip to content

Commit 1365401

Browse files
chore!: l2 gas maximum is per-TX-public-portion. AVM startup gas is now 20k. (#10214)
Resolves #10030 Bump of AVM startup gas to 20k is mostly arbitrary, but considering some individual opcodes cost more than its previous value of 512, it certainly needed to be much higher. I thought 20k is at least _more_ reasonable to account for the constraint cost of verifying an AVM proof. The l2 gas maximum per-tx-public-portion ensures that there is some hard limit on execution per AVM proof. For now, we use that limit to ensure that you cannot overflow the AVM trace. --------- Co-authored-by: IlyasRidhuan <ilyasridhuan@gmail.com>
1 parent e7686f1 commit 1365401

File tree

14 files changed

+72
-91
lines changed

14 files changed

+72
-91
lines changed

barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp

-21
Original file line numberDiff line numberDiff line change
@@ -1739,27 +1739,6 @@ TEST_F(AvmExecutionTests, daGasLeft)
17391739
validate_trace(std::move(trace), public_inputs);
17401740
}
17411741

1742-
TEST_F(AvmExecutionTests, ExecutorThrowsWithTooMuchGasAllocated)
1743-
{
1744-
GTEST_SKIP();
1745-
std::string bytecode_hex = to_hex(OpCode::GETENVVAR_16) + // opcode GETENVVAR_16(sender)
1746-
"00" // Indirect flag
1747-
+ "0007" + to_hex(static_cast<uint8_t>(EnvironmentVariable::SENDER)); // addr 7
1748-
1749-
std::vector<FF> calldata = {};
1750-
std::vector<FF> returndata = {};
1751-
public_inputs.gas_settings.gas_limits.l2_gas = MAX_L2_GAS_PER_ENQUEUED_CALL;
1752-
1753-
auto bytecode = hex_to_bytes(bytecode_hex);
1754-
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
1755-
ASSERT_TRUE(is_ok(error));
1756-
1757-
ExecutionHints execution_hints;
1758-
EXPECT_THROW_WITH_MESSAGE(gen_trace(bytecode, calldata, public_inputs, returndata, execution_hints),
1759-
"Cannot allocate more than MAX_L2_GAS_PER_ENQUEUED_CALL to the AVM for "
1760-
"execution of an enqueued call");
1761-
}
1762-
17631742
// Should throw whenever the wrong number of public inputs are provided
17641743
// TEST_F(AvmExecutionTests, ExecutorThrowsWithIncorrectNumberOfPublicInputs)
17651744
// {

barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.hpp

-15
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ template <typename FF_> VmPublicInputs_<FF_> convert_public_inputs(std::vector<F
3838
throw_or_abort("Public inputs vector is not of PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH");
3939
}
4040

41-
// WARNING: this must be constrained by the kernel!
42-
// Here this is just a sanity check to prevent generation of proofs that
43-
// will be thrown out by the kernel anyway.
44-
if constexpr (IsAnyOf<FF_, bb::fr>) {
45-
if (public_inputs_vec[L2_START_GAS_LEFT_PCPI_OFFSET] > MAX_L2_GAS_PER_ENQUEUED_CALL) {
46-
throw_or_abort(
47-
"Cannot allocate more than MAX_L2_GAS_PER_ENQUEUED_CALL to the AVM for execution of an enqueued call");
48-
}
49-
} else {
50-
if (public_inputs_vec[L2_START_GAS_LEFT_PCPI_OFFSET].get_value() > MAX_L2_GAS_PER_ENQUEUED_CALL) {
51-
throw_or_abort(
52-
"Cannot allocate more than MAX_L2_GAS_PER_ENQUEUED_CALL to the AVM for execution of an enqueued call");
53-
}
54-
}
55-
5641
std::array<FF_, KERNEL_INPUTS_LENGTH>& kernel_inputs = std::get<KERNEL_INPUTS>(public_inputs);
5742

5843
// Copy items from PublicCircuitPublicInputs vector to public input columns

barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,16 @@ AvmTraceBuilder::AvmTraceBuilder(AvmPublicInputs public_inputs,
401401
, bytecode_trace_builder(execution_hints.all_contract_bytecode)
402402
, merkle_tree_trace_builder(public_inputs.start_tree_snapshots)
403403
{
404+
// Only allocate up to the maximum L2 gas for execution
405+
// TODO: constrain this!
406+
auto const l2_gas_left_after_private =
407+
public_inputs.gas_settings.gas_limits.l2_gas - public_inputs.start_gas_used.l2_gas;
408+
// TODO: think about cast
409+
auto const allocated_l2_gas =
410+
std::min(l2_gas_left_after_private, static_cast<uint32_t>(MAX_L2_GAS_PER_TX_PUBLIC_PORTION));
404411
// TODO: think about cast
405412
gas_trace_builder.set_initial_gas(
406-
static_cast<uint32_t>(public_inputs.gas_settings.gas_limits.l2_gas - public_inputs.start_gas_used.l2_gas),
413+
static_cast<uint32_t>(allocated_l2_gas),
407414
static_cast<uint32_t>(public_inputs.gas_settings.gas_limits.da_gas - public_inputs.start_gas_used.da_gas));
408415
}
409416

barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define MAX_L2_TO_L1_MSGS_PER_TX 8
2020
#define MAX_UNENCRYPTED_LOGS_PER_TX 8
2121
#define MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS 3000
22-
#define MAX_L2_GAS_PER_ENQUEUED_CALL 12000000
22+
#define MAX_L2_GAS_PER_TX_PUBLIC_PORTION 12000000
2323
#define CANONICAL_AUTH_REGISTRY_ADDRESS 1
2424
#define DEPLOYER_CONTRACT_ADDRESS 2
2525
#define REGISTERER_CONTRACT_ADDRESS 3

docs/docs/migration_notes.md

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Further changes are planned, so that:
4444

4545
## 0.66
4646

47+
### L2 Gas limit of 12M enforced for public portion of TX
48+
49+
This limit was previously enforced per-enqueued-public-call. The protocol now enforces a stricter limit that the entire public portion of a transaction consumes at most 12,000,000 L2 gas.
50+
4751
### DEBUG env var is removed
4852

4953
The `DEBUG` variable is no longer used. Use `LOG_LEVEL` with one of `silent`, `fatal`, `error`, `warn`, `info`, `verbose`, `debug`, or `trace`. To tweak log levels per module, add a list of module prefixes with their overridden level. For example, LOG_LEVEL="info; verbose: aztec:sequencer, aztec:archiver; debug: aztec:kv-store" sets `info` as the default log level, `verbose` for the sequencer and archiver, and `debug` for the kv-store. Module name match is done by prefix.

l1-contracts/src/core/libraries/ConstantsGen.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ library Constants {
112112
14061769416655647708490531650437236735160113654556896985372298487345;
113113
uint256 internal constant DEFAULT_GAS_LIMIT = 1000000000;
114114
uint256 internal constant DEFAULT_TEARDOWN_GAS_LIMIT = 12000000;
115-
uint256 internal constant MAX_L2_GAS_PER_ENQUEUED_CALL = 12000000;
115+
uint256 internal constant MAX_L2_GAS_PER_TX_PUBLIC_PORTION = 12000000;
116116
uint256 internal constant DA_BYTES_PER_FIELD = 32;
117117
uint256 internal constant DA_GAS_PER_BYTE = 16;
118118
uint256 internal constant FIXED_DA_GAS = 512;
119119
uint256 internal constant FIXED_L2_GAS = 512;
120-
uint256 internal constant FIXED_AVM_STARTUP_L2_GAS = 1024;
120+
uint256 internal constant FIXED_AVM_STARTUP_L2_GAS = 20000;
121121
uint256 internal constant L2_GAS_DISTRIBUTED_STORAGE_PREMIUM = 1024;
122122
uint256 internal constant L2_GAS_PER_READ_MERKLE_HASH = 30;
123123
uint256 internal constant L2_GAS_PER_WRITE_MERKLE_HASH = 40;

noir-projects/noir-protocol-circuits/crates/types/src/constants.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ pub global DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE: Field =
171171
// GAS DEFAULTS
172172
pub global DEFAULT_GAS_LIMIT: u32 = 1_000_000_000;
173173
pub global DEFAULT_TEARDOWN_GAS_LIMIT: u32 = 12_000_000;
174-
pub global MAX_L2_GAS_PER_ENQUEUED_CALL: u32 = 12_000_000;
174+
pub global MAX_L2_GAS_PER_TX_PUBLIC_PORTION: u32 = 12_000_000;
175175
pub global DA_BYTES_PER_FIELD: u32 = 32;
176176
pub global DA_GAS_PER_BYTE: u32 = 16;
177177
// pays for preamble information in TX Effects
178178
pub global FIXED_DA_GAS: u32 = 512;
179179
// pays for fixed tx costs like validation, and updating state roots
180180
pub global FIXED_L2_GAS: u32 = 512;
181181
// base cost for a single public call
182-
pub global FIXED_AVM_STARTUP_L2_GAS: u32 = 1024;
182+
pub global FIXED_AVM_STARTUP_L2_GAS: u32 = 20_000;
183183

184184
// Some tree insertions incur an additional cost associated with
185185
// the new database entry to be stored by all network participants.

yarn-project/circuits.js/src/constants.gen.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE =
9898
14061769416655647708490531650437236735160113654556896985372298487345n;
9999
export const DEFAULT_GAS_LIMIT = 1000000000;
100100
export const DEFAULT_TEARDOWN_GAS_LIMIT = 12000000;
101-
export const MAX_L2_GAS_PER_ENQUEUED_CALL = 12000000;
101+
export const MAX_L2_GAS_PER_TX_PUBLIC_PORTION = 12000000;
102102
export const DA_BYTES_PER_FIELD = 32;
103103
export const DA_GAS_PER_BYTE = 16;
104104
export const FIXED_DA_GAS = 512;
105105
export const FIXED_L2_GAS = 512;
106-
export const FIXED_AVM_STARTUP_L2_GAS = 1024;
106+
export const FIXED_AVM_STARTUP_L2_GAS = 20000;
107107
export const L2_GAS_DISTRIBUTED_STORAGE_PREMIUM = 1024;
108108
export const L2_GAS_PER_READ_MERKLE_HASH = 30;
109109
export const L2_GAS_PER_WRITE_MERKLE_HASH = 40;

yarn-project/circuits.js/src/scripts/constants.in.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const CPP_CONSTANTS = [
8282
'MEM_TAG_U64',
8383
'MEM_TAG_U128',
8484
'MEM_TAG_FF',
85-
'MAX_L2_GAS_PER_ENQUEUED_CALL',
85+
'MAX_L2_GAS_PER_TX_PUBLIC_PORTION',
8686
'MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS',
8787
'CANONICAL_AUTH_REGISTRY_ADDRESS',
8888
'DEPLOYER_CONTRACT_ADDRESS',

yarn-project/simulator/src/avm/avm_simulator.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type AztecAddress, Fr, type GlobalVariables, MAX_L2_GAS_PER_ENQUEUED_CALL } from '@aztec/circuits.js';
1+
import { type AztecAddress, Fr, type GlobalVariables, MAX_L2_GAS_PER_TX_PUBLIC_PORTION } from '@aztec/circuits.js';
22
import { type Logger, createLogger } from '@aztec/foundation/log';
33

44
import { strict as assert } from 'assert';
@@ -47,8 +47,8 @@ export class AvmSimulator {
4747
// only. Otherwise, use build() below.
4848
constructor(private context: AvmContext, private instructionSet: InstructionSet = INSTRUCTION_SET()) {
4949
assert(
50-
context.machineState.gasLeft.l2Gas <= MAX_L2_GAS_PER_ENQUEUED_CALL,
51-
`Cannot allocate more than ${MAX_L2_GAS_PER_ENQUEUED_CALL} to the AVM for execution of an enqueued call`,
50+
context.machineState.gasLeft.l2Gas <= MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
51+
`Cannot allocate more than ${MAX_L2_GAS_PER_TX_PUBLIC_PORTION} to the AVM for execution.`,
5252
);
5353
this.log = createLogger(`simulator:avm(calldata[0]: ${context.environment.calldata[0]})`);
5454
// TODO(palla/log): Should tallies be printed on debug, or only on trace?

yarn-project/simulator/src/avm/fixtures/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isNoirCallStackUnresolved } from '@aztec/circuit-types';
2-
import { GasFees, GlobalVariables, MAX_L2_GAS_PER_ENQUEUED_CALL } from '@aztec/circuits.js';
2+
import { GasFees, GlobalVariables, MAX_L2_GAS_PER_TX_PUBLIC_PORTION } from '@aztec/circuits.js';
33
import { type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
44
import { AztecAddress } from '@aztec/foundation/aztec-address';
55
import { EthAddress } from '@aztec/foundation/eth-address';
@@ -93,7 +93,7 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
9393
*/
9494
export function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachineState {
9595
return AvmMachineState.fromState({
96-
l2GasLeft: overrides?.l2GasLeft ?? MAX_L2_GAS_PER_ENQUEUED_CALL,
96+
l2GasLeft: overrides?.l2GasLeft ?? MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
9797
daGasLeft: overrides?.daGasLeft ?? 1e8,
9898
});
9999
}

yarn-project/simulator/src/public/fixtures/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
GasFees,
1313
GasSettings,
1414
GlobalVariables,
15-
MAX_L2_GAS_PER_ENQUEUED_CALL,
15+
MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
1616
PartialPrivateTailPublicInputsForPublic,
1717
PrivateKernelTailCircuitPublicInputs,
1818
type PublicFunction,
@@ -113,7 +113,7 @@ export function createTxForPublicCall(
113113
): Tx {
114114
const callRequest = executionRequest.toCallRequest();
115115
// use max limits
116-
const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_ENQUEUED_CALL);
116+
const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
117117

118118
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
119119
// TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.

yarn-project/simulator/src/public/public_tx_context.ts

+41-22
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Gas,
1818
type GasSettings,
1919
type GlobalVariables,
20+
MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
2021
type PrivateToPublicAccumulatedData,
2122
type PublicCallRequest,
2223
PublicCircuitPublicInputs,
@@ -43,7 +44,7 @@ export class PublicTxContext {
4344
private log: Logger;
4445

4546
/* Gas used including private, teardown gas _limit_, setup and app logic */
46-
private gasUsed: Gas;
47+
private gasUsedByPublic: Gas = Gas.empty();
4748
/* Gas actually used during teardown (different from limit) */
4849
public teardownGasUsed: Gas = Gas.empty();
4950

@@ -60,8 +61,9 @@ export class PublicTxContext {
6061
public readonly state: PhaseStateManager,
6162
private readonly globalVariables: GlobalVariables,
6263
private readonly startStateReference: StateReference,
63-
private readonly startGasUsed: Gas,
6464
private readonly gasSettings: GasSettings,
65+
private readonly gasUsedByPrivate: Gas,
66+
private readonly gasAllocatedToPublic: Gas,
6567
private readonly setupCallRequests: PublicCallRequest[],
6668
private readonly appLogicCallRequests: PublicCallRequest[],
6769
private readonly teardownCallRequests: PublicCallRequest[],
@@ -73,7 +75,6 @@ export class PublicTxContext {
7375
public trace: PublicEnqueuedCallSideEffectTrace, // FIXME(dbanks12): should be private
7476
) {
7577
this.log = createLogger(`simulator:public_tx_context`);
76-
this.gasUsed = startGasUsed;
7778
}
7879

7980
public static async create(
@@ -100,12 +101,18 @@ export class PublicTxContext {
100101
// Transaction level state manager that will be forked for revertible phases.
101102
const txStateManager = await AvmPersistableStateManager.create(worldStateDB, enqueuedCallTrace, doMerkleOperations);
102103

104+
const gasSettings = tx.data.constants.txContext.gasSettings;
105+
const gasUsedByPrivate = tx.data.gasUsed;
106+
// Gas allocated to public is "whatever's left" after private, but with some max applied.
107+
const gasAllocatedToPublic = applyMaxToAvailableGas(gasSettings.gasLimits.sub(gasUsedByPrivate));
108+
103109
return new PublicTxContext(
104110
new PhaseStateManager(txStateManager),
105111
globalVariables,
106112
await db.getStateReference(),
107-
tx.data.gasUsed,
108-
tx.data.constants.txContext.gasSettings,
113+
gasSettings,
114+
gasUsedByPrivate,
115+
gasAllocatedToPublic,
109116
getCallRequestsByPhase(tx, TxExecutionPhase.SETUP),
110117
getCallRequestsByPhase(tx, TxExecutionPhase.APP_LOGIC),
111118
getCallRequestsByPhase(tx, TxExecutionPhase.TEARDOWN),
@@ -226,13 +233,14 @@ export class PublicTxContext {
226233
}
227234

228235
/**
229-
* How much gas is left for the specified phase?
236+
* How much gas is left as of the specified phase?
230237
*/
231-
getGasLeftForPhase(phase: TxExecutionPhase): Gas {
238+
getGasLeftAtPhase(phase: TxExecutionPhase): Gas {
232239
if (phase === TxExecutionPhase.TEARDOWN) {
233-
return this.gasSettings.teardownGasLimits;
240+
return applyMaxToAvailableGas(this.gasSettings.teardownGasLimits);
234241
} else {
235-
return this.gasSettings.gasLimits.sub(this.gasUsed);
242+
const gasLeftForPublic = this.gasAllocatedToPublic.sub(this.gasUsedByPublic);
243+
return gasLeftForPublic;
236244
}
237245
}
238246

@@ -243,10 +251,18 @@ export class PublicTxContext {
243251
if (phase === TxExecutionPhase.TEARDOWN) {
244252
this.teardownGasUsed = this.teardownGasUsed.add(gas);
245253
} else {
246-
this.gasUsed = this.gasUsed.add(gas);
254+
this.gasUsedByPublic = this.gasUsedByPublic.add(gas);
247255
}
248256
}
249257

258+
/**
259+
* The gasUsed by public and private,
260+
* as if the entire teardown gas limit was consumed.
261+
*/
262+
getTotalGasUsed(): Gas {
263+
return this.gasUsedByPrivate.add(this.gasUsedByPublic);
264+
}
265+
250266
/**
251267
* Compute the gas used using the actual gas used during teardown instead
252268
* of the teardown gas limit.
@@ -257,14 +273,7 @@ export class PublicTxContext {
257273
assert(this.halted, 'Can only compute actual gas used after tx execution ends');
258274
const requireTeardown = this.teardownCallRequests.length > 0;
259275
const teardownGasLimits = requireTeardown ? this.gasSettings.teardownGasLimits : Gas.empty();
260-
return this.gasUsed.sub(teardownGasLimits).add(this.teardownGasUsed);
261-
}
262-
263-
/**
264-
* The gasUsed as if the entire teardown gas limit was consumed.
265-
*/
266-
getGasUsedForFee(): Gas {
267-
return this.gasUsed;
276+
return this.getTotalGasUsed().sub(teardownGasLimits).add(this.teardownGasUsed);
268277
}
269278

270279
/**
@@ -284,10 +293,10 @@ export class PublicTxContext {
284293
* Should only be called during or after teardown.
285294
*/
286295
private getTransactionFeeUnsafe(): Fr {
287-
const txFee = this.gasUsed.computeFee(this.globalVariables.gasFees);
296+
const txFee = this.getTotalGasUsed().computeFee(this.globalVariables.gasFees);
288297
this.log.debug(`Computed tx fee`, {
289298
txFee,
290-
gasUsed: inspect(this.gasUsed),
299+
gasUsed: inspect(this.getTotalGasUsed()),
291300
gasFees: inspect(this.globalVariables.gasFees),
292301
});
293302
return txFee;
@@ -320,15 +329,15 @@ export class PublicTxContext {
320329
this.trace,
321330
this.globalVariables,
322331
this.startStateReference,
323-
this.startGasUsed,
332+
/*startGasUsed=*/ this.gasUsedByPrivate,
324333
this.gasSettings,
325334
this.setupCallRequests,
326335
this.appLogicCallRequests,
327336
this.teardownCallRequests,
328337
this.nonRevertibleAccumulatedDataFromPrivate,
329338
this.revertibleAccumulatedDataFromPrivate,
330339
endTreeSnapshots,
331-
/*endGasUsed=*/ this.gasUsed,
340+
/*endGasUsed=*/ this.getTotalGasUsed(),
332341
this.getTransactionFeeUnsafe(),
333342
this.revertCode,
334343
);
@@ -401,3 +410,13 @@ class PhaseStateManager {
401410
this.currentlyActiveStateManager = undefined;
402411
}
403412
}
413+
414+
/**
415+
* Apply L2 gas maximum.
416+
*/
417+
function applyMaxToAvailableGas(availableGas: Gas) {
418+
return new Gas(
419+
/*daGas=*/ availableGas.daGas,
420+
/*l2Gas=*/ Math.min(availableGas.l2Gas, MAX_L2_GAS_PER_TX_PUBLIC_PORTION),
421+
);
422+
}

yarn-project/simulator/src/public/public_tx_simulator.ts

+4-17
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ import {
1010
UnencryptedFunctionL2Logs,
1111
} from '@aztec/circuit-types';
1212
import { type AvmSimulationStats } from '@aztec/circuit-types/stats';
13-
import {
14-
type Fr,
15-
Gas,
16-
type GlobalVariables,
17-
MAX_L2_GAS_PER_ENQUEUED_CALL,
18-
type PublicCallRequest,
19-
type RevertCode,
20-
} from '@aztec/circuits.js';
13+
import { type Fr, type Gas, type GlobalVariables, type PublicCallRequest, type RevertCode } from '@aztec/circuits.js';
2114
import { type Logger, createLogger } from '@aztec/foundation/log';
2215
import { Timer } from '@aztec/foundation/timer';
2316
import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';
@@ -266,23 +259,17 @@ export class PublicTxSimulator {
266259
const address = executionRequest.callContext.contractAddress;
267260
const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, executionRequest.args);
268261

269-
const availableGas = context.getGasLeftForPhase(phase);
270-
// Gas allocated to an enqueued call can be different from the available gas
271-
// if there is more gas available than the max allocation per enqueued call.
272-
const allocatedGas = new Gas(
273-
/*daGas=*/ availableGas.daGas,
274-
/*l2Gas=*/ Math.min(availableGas.l2Gas, MAX_L2_GAS_PER_ENQUEUED_CALL),
275-
);
262+
const allocatedGas = context.getGasLeftAtPhase(phase);
276263

277264
const result = await this.simulateEnqueuedCallInternal(
278265
context.state.getActiveStateManager(),
279266
executionRequest,
280267
allocatedGas,
281-
context.getTransactionFee(phase),
268+
/*transactionFee=*/ context.getTransactionFee(phase),
282269
fnName,
283270
);
284271

285-
const gasUsed = allocatedGas.sub(result.gasLeft);
272+
const gasUsed = allocatedGas.sub(result.gasLeft); // by enqueued call
286273
context.consumeGas(phase, gasUsed);
287274
this.log.verbose(
288275
`[AVM] Enqueued public call consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`,

0 commit comments

Comments
 (0)