Skip to content

feat: transient per-block limit for zero gas tx per block#2519

Open
matthiasmatt wants to merge 10 commits intomainfrom
mat/rate-limit
Open

feat: transient per-block limit for zero gas tx per block#2519
matthiasmatt wants to merge 10 commits intomainfrom
mat/rate-limit

Conversation

@matthiasmatt
Copy link
Contributor

What

Adds a per-block quota for zero-gas EVM transactions to limit free blockspace consumption.

Why

Zero-gas EVM calls bypass fee deduction and mempool min-gas-price checks. A deterministic per-block cap provides a protocol-level
backstop against spam/DoS targeting ZeroGasActors.always_zero_gas_contracts.

How

  • Introduces a transient (per-block) counter EvmState.BlockZeroGasTxCount stored under a new transient namespace. (x/evm/const.go,
    x/evm/evmstate/evm_state.go)
  • Adds a new EVM ante step AnteStepZeroGasBlockQuota that runs immediately after AnteStepDetectZeroGas and:
    • applies DeliverTx-only
    • increments the counter when evm.IsZeroGasEthTx(ctx)
    • rejects once the block quota is exceeded with evm.ErrZeroGasBlockQuotaExceeded. (x/evm/evmante/evmante_zero_gas_quota.go, x/
      evm/errors.go, x/evm/evmante/all_evmante.go)
  • Quota is currently a consensus-critical constant maxZeroGasTxsPerBlock (set to 0 to disable). (x/evm/evmante/
    evmante_zero_gas_quota.go)

Testing

  • Added TestAnteStepZeroGasBlockQuota_PerBlockTxCount verifying the first maxZeroGasTxsPerBlock zero-gas txs pass and the next one
    fails in the same block. (x/evm/evmante/evmante_zero_gas_quota_test.go)
  • go test ./x/evm/...

Follow-ups

  • Consider making the quota governance-controlled (params/state) instead of a hardcoded constant.
  • If we want mempool-level protection too, add a separate CheckTx/local policy (this change intentionally enforces DeliverTx
    only).

Ensures EvmKeeper depends on SudoKeeper via depinject for zero-gas ante handling and tracks PaidWei in ZeroGasMeta with tests covering the ABCI EthereumTx path.
Introduces a new test case for the AmountsToUndoCredit method in ZeroGasMeta, covering various scenarios including crediting, paying, and refunding gas amounts. This enhances the test coverage for zero-gas transaction handling.
…s as bech32/hex, AlwaysZeroGasContracts as EIP55
…rop redundant nil/ok checks; failed or nil assertion already yields nil.
@matthiasmatt matthiasmatt requested a review from a team as a code owner February 8, 2026 10:32
@matthiasmatt matthiasmatt changed the base branch from main to ud/zero-gas-evm February 8, 2026 10:32
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a per-block quota for zero-gas EVM transactions to mitigate spam and DoS risks. The implementation is solid, adding new ante handler steps for detection and quota enforcement, and correctly modifying existing ante handlers to bypass fee-related logic for these transactions. The changes are well-tested, covering various scenarios including normal transactions, zero-gas transactions, and edge cases like new accounts and reverted executions. My main concern is the inclusion of hardcoded testnet private keys and mnemonic phrases in the repository, which poses a significant security risk and should be addressed immediately.

I am having trouble creating individual review comments. Click here to see my feedback.

evm-e2e/.passkey-testnet2-privkey.txt (1)

security-critical critical

Committing a private key to the repository, even for a testnet, is a significant security risk. This key should be removed from the repository's history. It's recommended to use environment variables or a secure secret management system to handle such credentials, or generate them on the fly for tests.

evm-e2e/.passkey-testnet2-wallet.json (1)

security-critical critical

Committing a wallet mnemonic phrase to the repository is a critical security vulnerability. This allows anyone with access to the repository to control the associated funds. This file should be removed from the repository and its history. For testing, consider generating wallets dynamically or using environment variables to supply credentials securely.

x/evm/evmante/evmante_gas_consume.go (119-121)

medium

The removal of debugging fmt.Printf and log.Printf statements is a good cleanup. However, there are more instances of such logging in the all_evmante.go file that should also be removed before merging to keep the codebase clean.

x/evm/evmstate/msg_server.go (76)

medium

This log.Printf statement appears to be for debugging and should be removed before merging to avoid polluting logs in production environments.

@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.07%. Comparing base (f89059d) to head (eb0387e).

Files with missing lines Patch % Lines
x/evm/evmante/evmante_zero_gas_quota.go 73.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           ud/zero-gas-evm    #2519      +/-   ##
===================================================
+ Coverage            58.98%   59.07%   +0.09%     
===================================================
  Files                  361      362       +1     
  Lines                24415    24436      +21     
===================================================
+ Hits                 14401    14436      +35     
+ Misses                8777     8758      -19     
- Partials              1237     1242       +5     
Files with missing lines Coverage Δ
x/evm/const.go 43.39% <ø> (ø)
x/evm/errors.go 0.00% <ø> (ø)
x/evm/evmante/all_evmante.go 64.86% <100.00%> (+0.31%) ⬆️
x/evm/evmstate/evm_state.go 92.94% <100.00%> (+0.44%) ⬆️
x/evm/evmante/evmante_zero_gas_quota.go 73.33% <73.33%> (ø)

... and 1 file 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.

Base automatically changed from ud/zero-gas-evm to main February 9, 2026 10:16
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.

2 participants