Submitted by berndartmueller
The EVM GASLIMIT opcode (https://www.ethervm.io/#45) is supposed to return the block gas limit.
However, when building the BlockContext in buildBlockContext(), GasLimit is set to the current transactions remaining gas, which is calculated as sdkCtx.GasMeter().Limit() - sdkCtx.GasMeter().GasConsumedToLimit(). This results in incompatibility with the EVM and potential issues with Solidity contracts.
For comparison, Evmos correctly uses the block gas meter.
minievm:x/evm/keeper/context.go#L70
GasLimit is determined by calling computeGasLimit().
computeGasLimit() returns the transactions remaining gas, calculated via the gas meter. For simulations, it even returns a fixed value of k.config.ContractSimulationGasLimit (i.e., DefaultContractSimulationGasLimit = uint64(3_000_000)).
The GASLIMIT EVM opcode uses this GasLimit value to return the block gas limit:
core/vm/instructions.go#L501-L504
Consider setting GasLimit to the block gas limit instead of the transactions gas.
leojin (Initia) confirmed and commented:
Initia mitigated:
Status: Mitigation confirmed. Full details in reports from 0xAlix2, berndartmueller and Franfran.
