Skip to content

tracer/vm: return out of gas in case available too small#18963

Merged
AskAlexSharov merged 4 commits intomainfrom
lupin012/fix_trace_gasCost_outOfGas
Feb 5, 2026
Merged

tracer/vm: return out of gas in case available too small#18963
AskAlexSharov merged 4 commits intomainfrom
lupin012/fix_trace_gasCost_outOfGas

Conversation

@lupin012
Copy link
Contributor

@lupin012 lupin012 commented Feb 4, 2026

closes #13870
In the Ethereum Virtual Machine (EVM), the total gas cost for an operation is composed of a static part and a dynamic part. For CALL opcodes, the engine processes various dynamic components (e.g., memory expansion, account access, value transfer) before invoking the callGas() function to determine the gas budget for the sub-context.

The current implementation performs the subtraction: availableGas - base. If availableGas is lower than the accumulated base cost, a uint64 underflow occurs.

This issue is currently present in Geth, while Nethermind correctly handles this scenario by returning the static cost.

This PR introduces a validation check prior to calling callGas(). By ensuring that availableGas is greater than or equal to the base cost, we prevent the underflow. If the gas is insufficient, an OutOfGas error is returned.

As a result, the tracer now correctly reports the gasCost of the static part (e.g., 700 for a CALL) instead of an underflowed value.

new rpc-test TAG is provided

@lupin012 lupin012 requested a review from canepat February 4, 2026 13:28
@lupin012 lupin012 marked this pull request as ready for review February 4, 2026 21:10
@AskAlexSharov AskAlexSharov merged commit 6621621 into main Feb 5, 2026
28 of 31 checks passed
@AskAlexSharov AskAlexSharov deleted the lupin012/fix_trace_gasCost_outOfGas branch February 5, 2026 01:39
Giulio2002 pushed a commit that referenced this pull request Feb 6, 2026
closes #13870
In the Ethereum Virtual Machine (EVM), the total gas cost for an
operation is composed of a static part and a dynamic part. For CALL
opcodes, the engine processes various dynamic components (e.g., memory
expansion, account access, value transfer) before invoking the callGas()
function to determine the gas budget for the sub-context.

The current implementation performs the subtraction: availableGas -
base. If availableGas is lower than the accumulated base cost, a uint64
underflow occurs.

This issue is currently present in Geth, while Nethermind correctly
handles this scenario by returning the static cost.

This PR introduces a validation check prior to calling callGas(). By
ensuring that availableGas is greater than or equal to the base cost, we
prevent the underflow. If the gas is insufficient, an OutOfGas error is
returned.

As a result, the tracer now correctly reports the gasCost of the static
part (e.g., 700 for a CALL) instead of an underflowed value.

new  rpc-test TAG is provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rpc: excessive gasCost value for CALL opcode

2 participants