Refactor/opcodes self deduct gas#10081
Draft
daniellehrner wants to merge 6 commits intobesu-eth:mainfrom
Draft
Conversation
Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>
Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>
…ient When charge_state_gas fails (OutOfGasError), the spec modifies nothing: no reservoir drain, no stateGasUsed increment. Remove consumeStateGasForced which was incorrectly inflating stateGasUsed on failure, fixing short_one_gas reference tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>
accounting correctly reflects gas consumed on EIP-684 address collisions Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>
…irement EIP-8037 specifies that regular gas must be deducted before state gas so the reservoir/gasRemaining split is correct when state gas overflows. Also updates devnet reference tests to bal@v5.5.1. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move gas deduction from the EVM loop (post-execution) into each operation itself. This eliminates the decrement-then-increment pattern needed for EIP-8037 state gas ordering and makes gas accounting more explicit per-opcode. - EVM.java: remove post-switch gas deduction - AbstractFixedCostOperation: execute() checks gas only; staticOperation methods and non-delegating executeFixedCostOperation deduct gas - Variable-cost operations: use decrementRemainingGas as combined check+deduct - CALL/CREATE/SSTORE/SELFDESTRUCT: natural ordering without workarounds - Standardize GAS_COST constant and outOfGasResult naming across all ops Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fffb242 to
85aa68c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR description
Move gas deduction from EVM loop into individual opcodes
Problem
EIP-8037 (multidimensional gas metering) requires that regular gas is charged before state gas for opcodes like SSTORE, SELFDESTRUCT, and CREATE. However, the EVM loop deducts regular gas after an operation's
execute()returns while state gas is consumed duringexecute()via frame.consumeStateGas().This forces an ugly decrement-then-increment workaround: operations temporarily deduct regular gas before the state gas charge, then add it back so the EVM loop can re-deduct it:
Solution
Each opcode now deducts its own gas inside
execute()/staticOperation(). The EVM loop no longer performs gas deduction, it only checks for halt reasons.staticOperation()or executeFixedCostOperation() (non-delegating ops)decrementRemainingGas(cost) < 0replaces the separate check + deduction patternFixed Issue(s)
Thanks for sending a pull request! Have you done the following?
doc-change-requiredlabel to this PR if updates are required.Locally, you can run these tests to catch failures early:
./gradlew spotlessApply./gradlew build./gradlew acceptanceTest./gradlew integrationTest./gradlew ethereum:referenceTests:referenceTests