Skip to content

evm: Add Gas::charge() for the gas checks - #1789

Open
chfast wants to merge 1 commit into
evm/gas-strong-typefrom
evm/gas-charge-method
Open

chfast wants to merge 1 commit into
evm/gas-strong-typefrom
evm/gas-charge-method

Conversation

@chfast

@chfast chfast commented Oct 28, 2026

Copy link
Copy Markdown
Member

Replace the (gas_left -= cost) < 0 idiom with gas_left.charge(cost), so that the gas check is defined in one place. charge() asserts that neither the gas left nor the cost is negative: the execution starts with non-negative gas and stops at the first failed charge.

The benchmarks execute the same number of instructions as with #1564, with both GCC 16 and Clang 21.

Stacked on #1564.

Replace the (gas_left -= cost) < 0 idiom with gas_left.charge(cost), so
that the gas check is defined in one place. charge() subtracts the cost
and returns false when the gas left goes negative. It asserts that
neither the gas left nor the cost is negative: the execution starts with
non-negative gas and stops at the first failed charge.
@codspeed

codspeed Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 899 untouched benchmarks


Comparing evm/gas-charge-method (bd22809) with evm/gas-strong-type (b01afcf)

Open in CodSpeed

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.24%. Comparing base (b01afcf) to head (bd22809).

Additional details and impacted files
@@                 Coverage Diff                  @@
##           evm/gas-strong-type    #1789   +/-   ##
====================================================
  Coverage                98.24%   98.24%           
====================================================
  Files                      187      187           
  Lines                    17188    17188           
  Branches                  3921     3921           
====================================================
  Hits                     16886    16886           
  Misses                     233      233           
  Partials                    69       69           
Flag Coverage Δ
eest-develop-gmp 26.98% <84.21%> (-0.02%) ⬇️
eest-legacy 17.26% <23.68%> (ø)
eest-libsecp256k1 29.13% <84.21%> (-0.02%) ⬇️
eest-stable 84.22% <100.00%> (-0.02%) ⬇️
evmone-unittests 94.11% <81.57%> (ø)
riscv64 94.83% <78.94%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 96.63% <100.00%> (ø)
tooling 94.87% <ø> (ø)
tests 99.82% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone/advanced_execution.cpp 100.00% <100.00%> (ø)
lib/evmone/advanced_instructions.cpp 96.87% <100.00%> (ø)
lib/evmone/baseline_execution.cpp 97.63% <100.00%> (+0.01%) ⬆️
lib/evmone/gas.hpp 100.00% <100.00%> (ø)
lib/evmone/instructions.hpp 100.00% <100.00%> (ø)
lib/evmone/instructions_calls.cpp 100.00% <100.00%> (ø)
lib/evmone/instructions_storage.cpp 100.00% <100.00%> (ø)
test/state/host.cpp 100.00% <100.00%> (ø)
test/state/state.cpp 99.78% <100.00%> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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