Skip to content

fix: allow negative gas refund propagation#333

Open
abmcar wants to merge 1 commit intoDTVMStack:mainfrom
abmcar:fix-sstore-refund
Open

fix: allow negative gas refund propagation#333
abmcar wants to merge 1 commit intoDTVMStack:mainfrom
abmcar:fix-sstore-refund

Conversation

@abmcar
Copy link
Contributor

@abmcar abmcar commented Feb 4, 2026

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

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):

  • Affects user behaviors
  • Contains CI/CD configuration changes
  • Contains documentation changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

6. Release note

None

Copilot AI review requested due to automatic review settings February 4, 2026 12:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::GasRefund and related APIs from uint64_t to int64_t.
  • Update interpreter frame refund snapshots to int64_t to preserve correct rollback semantics.
  • Always propagate Result.gas_refund from 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.

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.

1 participant