Skip to content

refactor(tests): tx_gas and cold_gas for gas_test generator#2083

Merged
LouisTsai-Csie merged 2 commits intoethereum:forks/amsterdamfrom
monad-developers:fix/gas-test
May 7, 2026
Merged

refactor(tests): tx_gas and cold_gas for gas_test generator#2083
LouisTsai-Csie merged 2 commits intoethereum:forks/amsterdamfrom
monad-developers:fix/gas-test

Conversation

@pdobacz
Copy link
Copy Markdown
Contributor

@pdobacz pdobacz commented Jan 27, 2026

🗒️ Description

gas_test generator had some gas values hardcoded and wasn't immune to gas repricings. This PR should provide tx_gas based on forks gas_cost values.

Also, it allows to specify cold_gas=0 to test opcodes like REVERT, and unlocks some standard gas cost tests

🔗 Related Issues or PRs

N/A.

✅ Checklist

  • All: Ran fast tox checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    uvx tox -e static
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Set appropriate labels for the changes (only maintainers can apply labels).

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.62%. Comparing base (6333758) to head (5c46d04).
⚠️ Report is 8 commits behind head on forks/amsterdam.

Additional details and impacted files
@@                 Coverage Diff                 @@
##           forks/amsterdam    #2083      +/-   ##
===================================================
+ Coverage            88.17%   88.62%   +0.45%     
===================================================
  Files                  577      577              
  Lines                35659    35659              
  Branches              3490     3490              
===================================================
+ Hits                 31442    31604     +162     
+ Misses                3654     3492     -162     
  Partials               563      563              
Flag Coverage Δ
unittests 88.62% <ø> (+0.45%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marioevz marioevz self-requested a review February 18, 2026 22:08
@marioevz marioevz self-assigned this Feb 18, 2026
@marioevz marioevz requested review from spencer-tb and removed request for marioevz February 18, 2026 22:17
@marioevz marioevz assigned spencer-tb and unassigned marioevz Feb 18, 2026
@marioevz
Copy link
Copy Markdown
Member

@spencer-tb I think this is going to be affected by EIP-8037, could you take a look pls?

@LouisTsai-Csie
Copy link
Copy Markdown
Collaborator

I think we could use bytecode.gas_cost(fork) for this helper, as i notice these values are calculated manually:

gas_costs = fork.gas_costs()
    opcode_gas_cost = gas_costs.GAS_BASE
    opcode_pop_cost = gas_costs.GAS_BASE
    opcode_push_cost = gas_costs.GAS_VERY_LOW
    gas_single_gas_run = (
        2 * opcode_gas_cost
        + opcode_pop_cost
        + gas_costs.GAS_WARM_ACCOUNT_ACCESS
        + 6 * opcode_push_cost
    )

Some example:

the code

sstore_loop = While(
body=(
Op.MSTORE(64, Op.MLOAD(32))
+ Op.POP(
Op.CALL(
address=erc20_address,
value=0,
args_offset=28,
args_size=68,
ret_offset=0,
ret_size=0,
# gas accounting
address_warm=True,
)
)
+ Op.MSTORE(32, Op.ADD(Op.MLOAD(32), 1))
),
condition=DECREMENT_COUNTER_CONDITION,
)

the gas accounting

# Gas Accounting
setup_cost = setup.gas_cost(fork)
sload_loop_cost = sload_loop.gas_cost(fork)
transition_cost = transition.gas_cost(fork)
sstore_loop_cost = sstore_loop.gas_cost(fork)

@pdobacz
Copy link
Copy Markdown
Contributor Author

pdobacz commented Mar 4, 2026

Applied the suggestion about gas_single_gas_run, rebased, ready for review

@pdobacz
Copy link
Copy Markdown
Contributor Author

pdobacz commented Apr 29, 2026

@LouisTsai-Csie @spencer-tb @marioevz - gentle ping on this - should I try to get this rebased and mergeable or is there anything blocking this?

@LouisTsai-Csie
Copy link
Copy Markdown
Collaborator

@pdobacz I am sorry for late response, could you please rebase again, and let me know when it is ready for review again? I would keep track of this issue to merge, thank you

@pdobacz
Copy link
Copy Markdown
Contributor Author

pdobacz commented May 6, 2026

@LouisTsai-Csie np, done!

Copy link
Copy Markdown
Collaborator

@LouisTsai-Csie LouisTsai-Csie left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@LouisTsai-Csie LouisTsai-Csie changed the title fix(tests): tx_gas and cold_gas for gas_test generator fixed refactor(tests): tx_gas and cold_gas for gas_test generator May 7, 2026
@LouisTsai-Csie LouisTsai-Csie added A-tests Area: Consensus tests. C-refactor Category: refactor labels May 7, 2026
@LouisTsai-Csie LouisTsai-Csie merged commit 0c25df6 into ethereum:forks/amsterdam May 7, 2026
25 checks passed
@pdobacz pdobacz deleted the fix/gas-test branch May 7, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tests Area: Consensus tests. C-refactor Category: refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants