Skip to content

[codex] add dynamic custom precompile gas meter#3644

Open
codchen wants to merge 1 commit into
codex/evmonly-staking-precompilefrom
codex/evmonly-staking-dynamic-gas
Open

[codex] add dynamic custom precompile gas meter#3644
codchen wants to merge 1 commit into
codex/evmonly-staking-precompilefrom
codex/evmonly-staking-dynamic-gas

Conversation

@codchen

@codchen codchen commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds dynamic gas accounting for evm-only custom precompiles, with the staking precompile using the shared meter through the existing store, balance-transfer, and log boundaries.

Changes

  • Add a reusable precompile gas meter for base gas, SLOAD/SSTORE-style storage costs, keccak slot derivation, native value transfers, and log emission.
  • Wrap storageBackedStore, nativeBalanceTransfer, and log emission in the custom precompile adapter so gas is charged based on the actual execution path.
  • Reduce staking RequiredGas to only base/input gas, avoiding double charging now that state access is dynamically metered.
  • Add executor coverage for dynamic store gas and update staking lifecycle tests to use realistic gas limits.

Validation

  • go test ./giga/evmonly/...
  • golangci-lint v2.8.0 run ./giga/evmonly/...

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.66851% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.09%. Comparing base (27e3acc) to head (56bf186).

Files with missing lines Patch % Lines
giga/evmonly/precompile_gas.go 68.46% 23 Missing and 18 partials ⚠️
giga/evmonly/precompile_adapter.go 34.69% 19 Missing and 13 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                         Coverage Diff                          @@
##           codex/evmonly-staking-precompile    #3644      +/-   ##
====================================================================
- Coverage                             58.09%   58.09%   -0.01%     
====================================================================
  Files                                  2186     2184       -2     
  Lines                                178307   178410     +103     
====================================================================
+ Hits                                 103588   103643      +55     
- Misses                                65443    65473      +30     
- Partials                               9276     9294      +18     
Flag Coverage Δ
sei-chain-pr 54.18% <59.66%> (-0.04%) ⬇️
sei-db 70.41% <ø> (ø)

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

Files with missing lines Coverage Δ
giga/evmonly/precompiles/staking/staking.go 23.91% <100.00%> (-0.40%) ⬇️
giga/evmonly/precompile_adapter.go 66.35% <34.69%> (-8.65%) ⬇️
giga/evmonly/precompile_gas.go 68.46% <68.46%> (ø)

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJun 26, 2026, 3:43 AM

@codchen codchen marked this pull request as ready for review June 26, 2026 03:42
@cursor

cursor Bot commented Jun 26, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes consensus-relevant gas for custom precompiles and staking calls; incorrect metering could allow cheap state writes or break existing txs that relied on the old flat gas schedule.

Overview
Introduces dynamic gas accounting for evm-only custom precompiles so execution cost reflects real work (storage, transfers, logs), not only a flat RequiredGas.

RunAndCalculateGas now drives a shared precompileGasMeter: it charges the contract’s base RequiredGas, then passes the meter into storageBackedStore, nativeBalanceTransfer, and meteredLogSink. Those paths charge EIP-2929/2200-style SLOAD/SSTORE, Keccak for store slot derivation, account access + value transfer costs, and LOG gas, with tracing hooks on each deduction.

The staking precompile drops separate read/write gas constants and uses baseGas + per-input-byte in RequiredGas only, avoiding double billing now that store and balance side effects are metered dynamically.

Tests assert store writes consume more than intrinsic gas, OOG on a tight gas limit leaves no storage changes, and staking flows use 8M gas limits.

Reviewed by Cursor Bugbot for commit 56bf186. Bugbot is set up for automated code reviews on this repo. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant