fix: allow negative gas refund propagation#333
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates EVM gas refund accounting to correctly propagate negative refund deltas (e.g., refund cancellations from net SSTORE accounting and subcall refund adjustments), avoiding incorrect unsigned wrap/ignoring negative values.
Changes:
- Switch
EVMInstance::GasRefundand related APIs fromuint64_ttoint64_t. - Update interpreter frame refund snapshots to
int64_tto preserve correct rollback semantics. - Always propagate
Result.gas_refundfrom subcalls (CREATE/CALL paths), including negative values.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/runtime/evm_instance.h | Make gas refund storage and accessors signed (int64_t) to support negative refund deltas. |
| src/evm/opcode_handlers.cpp | Clarify that subcall refund deltas may be negative when accumulating at instance level. |
| src/evm/interpreter.h | Store gas refund snapshots as int64_t for correct restore behavior. |
| src/compiler/evm_frontend/evm_imported.cpp | Propagate subcall gas_refund unconditionally (including negative values) in JIT-imported call/create helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Instance->addGasRefund(Result.gas_refund); | ||
| } | ||
| // Track subcall refund (may be negative) | ||
| Instance->addGasRefund(Result.gas_refund); |
There was a problem hiding this comment.
when will the gas refund negative
There was a problem hiding this comment.
It becomes negative under EIP-2200 net SSTORE accounting when a later storage change cancels a previously accrued refund.
EVMC allows per-call gas_refund to be negative; we just accumulate deltas and the tx-level cap is applied later.
7c5d98e to
c5e66ab
Compare
c5e66ab to
8a6cb69
Compare
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
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