fix(evm): apply capped gas refund and intrinsic gas once in CLI settlement - #608
Merged
Merged
Conversation
⚡ Performance Regression Check Results✅ Performance Check Passed (interpreter)Performance Benchmark Results (threshold: 25%)
Summary: 194 benchmarks, 0 regressions ✅ Performance Check Passed (multipass)Performance Benchmark Results (threshold: 25%)
Summary: 194 benchmarks, 0 regressions |
ys8888john
force-pushed
the
fix/588-gas-refund-settlement
branch
2 times, most recently
from
September 9, 2026 12:14
2f806e7 to
d52f88f
Compare
…ement Settle the execution refund counter with the EIP-3529 revision-specific cap and count intrinsic gas exactly once when charging the sender. This aligns CLI gas settlement with EVM spec behavior and adds regression tests for refund limits across revisions. Closes DTVMStack#588
Create the EVM instance after upfront gas deduction so interpreter and JIT start from the same Msg.gas value. Rename the fee helper for transaction generality, share settlement test setup, and document the utility contracts. Verified the issue DTVMStack#588 CLI repro and EVM interpreter regression tests.
Previously, loaded storage set current but left original as zero. A non-zero prestate slot cleared to zero was classified as a dirty clear, charging the wrong SSTORE gas and accruing an incorrect refund. Initialize original from the persisted current value unless an explicit original is provided, so loading state starts a new transaction from that boundary. Closes DTVMStack#589
ys8888john
force-pushed
the
fix/588-gas-refund-settlement
branch
from
September 10, 2026 13:12
ae81c54 to
acdf8e7
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.
…ement
The CLI transaction settlement only refunded unused gas computed from gas_left; it never consumed the refund counter produced during execution, so refunds earned by SSTORE clearing (EIP-2200/EIP-3529) were discarded and the sender was overcharged.
Additionally, intrinsic gas was deducted from Msg.gas before execution and added again to GasUsed at settlement, double counting 21000 gas.
Settlement now caps the accumulated refund counter at gas_used / 5, subtracts it from gas_used before charging the sender, and no longer re-adds the already-deducted intrinsic gas, mirroring the settlement in tests/evm_test_host.hpp which passes the upstream EVM state tests.
For the issue #588 repro (SSTORE set 5 then clear, Cancun), the sender now pays 34570 gas (21000 + 22212 - 8642) instead of 64212, matching evmone/geth/besu/ethrex/revm/py-evm.
Closes #588
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
N
Y
e.g.
fix DTVM EVM Bug: SSTORE refund is never credited to the sender at transaction settlement #588
2. What is the scope of this PR (e.g. component or file name):
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:
6. Release note