Repository navigation
Conversation
axic
reviewed
Aug 1, 2026
| evmone::advanced::AdvancedExecutionState st; | ||
| st.gas_left = 1; | ||
| st.gas_left = evmone::Gas{1}; | ||
| st.gas_refund = 2; |
The execution gas counter is a bare int64_t, so it mixes silently with stack values, sizes and the int64 fields of EVMC. Wrap it in Gas: the conversions from and to int64_t are explicit, and the arithmetic and comparison operators take raw int64_t costs, so the instruction bodies and the cost tables stay unchanged. Gas is converted to int64_t only at the EVMC boundary, for the GAS instruction and for tracing. Gas is an enum class, not a class: with a class GCC makes different inlining and register allocation decisions in the dispatch loops. With the enum the generated code of both GCC and Clang is the same as before except for the order of a few instructions in cold paths. The StateGas charge() and refill() become templates because the test state transition still uses them with raw int64_t gas.
Use Gas also for the execution gas of the top-level message: for the authorization list costs and the recipient account creation of EIP-7702/EIP-2780 and for the code deposit cost. The message gas is set from it right before the call. The StateGas charge() and refill() then take Gas and are no longer templates.
chfast
force-pushed
the
evm/gas-strong-type
branch
from
October 23, 2026 16:51
d436cff to
6687d11
Compare
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1564 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 185 186 +1
Lines 17131 17143 +12
Branches 3912 3912
=======================================
+ Hits 16829 16841 +12
Misses 233 233
Partials 69 69
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
Static review supports that the type migration preserves existing gas arithmetic and boundary conversions, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Introduces a strong Gas type for execution gas counters, preventing implicit mixing with unrelated integers and preparing gas checks for centralized changes.
Changes:
- Adds an
int64_t-backed enum with arithmetic and comparison operators. - Migrates interpreter and transaction execution counters while retaining raw integer costs.
- Makes conversions explicit at EVMC, stack, and tracing boundaries.
| File | Description |
|---|---|
| test/unittests/execution_state_test.cpp | Updates gas initialization in the reset test. |
| test/state/state.cpp | Uses Gas for transaction preparation charges. |
| test/state/host.cpp | Uses Gas during contract code deployment. |
| lib/evmone/state_gas.hpp | Accepts Gas counters for charges and refills. |
| lib/evmone/instructions.hpp | Migrates instruction signatures and results to Gas. |
| lib/evmone/instructions_storage.cpp | Updates storage instruction signatures. |
| lib/evmone/instructions_calls.cpp | Migrates call/create gas handling and EVMC conversions. |
| lib/evmone/gas.hpp | Defines the strong gas type and operators. |
| lib/evmone/execution_state.hpp | Converts typed gas when constructing execution results. |
| lib/evmone/baseline_execution.cpp | Migrates baseline dispatch and tracing conversions. |
| lib/evmone/advanced_instructions.cpp | Updates advanced instruction adapters and stack conversion. |
| lib/evmone/advanced_analysis.hpp | Stores and initializes advanced execution gas as Gas. |
Review effort: Balanced
This branch has not been deployed
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.
Wrap the execution gas counter in the Gas type so it no longer mixes
silently with other int64_t values (stack items, sizes, EVMC fields).
Conversions are explicit; the operators take raw int64_t costs, so
instruction implementations and cost tables are unchanged. The second
commit uses Gas also in the transaction execution of test/state.
Gas is an enum class rather than a class to keep the generated code
identical: the disassembly of libevmone (GCC 16, Clang 21, Release)
differs from master only by the order of a few instructions in cold
paths.
This prepares for changing the gas check implementation in one place.