Skip to content

feat(evm): extend zero gas functionality to allow for any sender to call certain EVM contracts with zero gas#2517

Open
Unique-Divine wants to merge 9 commits intomainfrom
ud/zero-gas-evm
Open

feat(evm): extend zero gas functionality to allow for any sender to call certain EVM contracts with zero gas#2517
Unique-Divine wants to merge 9 commits intomainfrom
ud/zero-gas-evm

Conversation

@Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Feb 7, 2026

EVM zero-balance gas (zero-gas) transactions

Allow EVM txs that call governance-allowlisted contracts to run without the
sender holding gas. Implementation uses a conditional bypass: detect
eligibility in ante, set a context marker, then skip only gas-related checks
(balance-vs-cost, fee deduction, mempool min gas price, RefundGas) while keeping
account verification and CanTransfer. Supports first-time onboarding (account
creation when sender has no prior chain interaction).

Specification: Protocol-level Gasless EVM Execution (Zero-Gas Actors)

Visit the above link for details on the design decisions, constraints, skip matrix, ante step order, test-to-claim mapping, and usage guidelines (e.g. nibid tx sudo edit-zero-gas with always_zero_gas_contracts in the JSON payload).

Key Changes

  1. x/sudo — allowlist and CLI: New field always_zero_gas_contracts on ZeroGasActors (proto, state, generated code). Contracts in this list can be invoked with zero gas by any sender (no sender allowlist for this path). Existing senders / contracts unchanged for non-EVM zero-gas. Validation and default in x/sudo/msgs.go; EditZeroGasActors and CLI updated in x/sudo/keeper/msg_server.go and x/sudo/cli/cli.go; x/sudo/keeper/querier.go adds GetZeroGasEvmContracts returning EIP55 addresses for EVM ante.

  2. x/evm — context marker and SudoKeeper: New context key and helpers: CtxKeyZeroGasMeta, ZeroGasMeta, GetZeroGasMeta, IsZeroGasEthTx in x/evm/const.go and x/evm/evm.go. SudoKeeper interface gains GetZeroGasEvmContracts in x/evm/deps.go; EVM keeper is wired to SudoKeeper in x/evm/evmmodule/module.go and uses it for zero-gas detection. Keeper constructor and field in x/evm/evmstate/keeper.go.

  3. EVM ante — detection and conditional skips: New step AnteStepDetectZeroGas in x/evm/evmante/evmante_zero_gas.go: eligibility = tx.To in always_zero_gas_contracts and tx.Value == 0; only sets marker, no state writes. Step order in x/evm/evmante/all_evmante.go: after ValidateBasic, before MempoolGasPrice. When marker set: MempoolGasPrice (x/evm/evmante/evmante_mempool_fees.go) and DeductGas (x/evm/evmante/evmante_gas_consume.go) skip; VerifyEthAcc (x/evm/evmante/evmante_can_transfer.go) runs validation and account creation but skips balance-vs-cost; CanTransfer runs always (per spec).

  4. Msg server — RefundGas skip: In x/evm/evmstate/msg_server.go, run RefundGas only when !evm.IsZeroGasEthTx(rootCtxGasless) so zero-gas txs are never charged or refunded.

  5. Tests: Unit: DetectZeroGas (eligible/ineligible, non-zero value, CheckTx), VerifyEthAcc zero-gas (account created when missing), DeductGas skip, CanTransfer still runs in x/evm/evmante/evmante_zero_gas_test.go and x/evm/evmante/evmante_can_transfer_test.go; full ante (zero-gas with min gas price, first-time onboarding) in x/evm/evmante/all_evmante_test.go. Msg_server: RefundGas skipped for zero-gas, reverted execution in x/evm/evmstate/msg_ethereum_tx_test.go. Sudo: EditZeroGasActors and validation for always_zero_gas_contracts in x/sudo/keeper/msg_server_test.go, x/sudo/cli/cli_test.go, and x/sudo/msgs_test.go.


Note

High Risk
Touches EVM ante handling and fee/refund logic; incorrect eligibility or bypass conditions could allow unintended free execution or disrupt fee accounting.

Overview
Adds a new governance-managed allowlist, ZeroGasActors.always_zero_gas_contracts, enabling any sender to call specific EVM contracts with zero gas, and updates the sudo edit-zero-gas CLI + validation/deduping to manage this field.

Implements a context-based zero-gas bypass in x/evm: introduces ZeroGasMeta + helpers, adds AnteStepDetectZeroGas (runs early) to mark eligible txs (to allowlisted + value==0), and then skips fee-related checks/operations (mempool min gas price, balance-vs-cost, fee deduction, and RefundGas) while still creating the sender account if missing and still running CanTransfer.

Wires x/evm to depend on x/sudo via a new SudoKeeper.GetZeroGasEvmContracts (EIP55-parsed) and includes extensive tests across sudo, ante flow, and msg server execution/refund behavior.

Written by Cursor Bugbot for commit 88e3452. Configure here.

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.
@Unique-Divine Unique-Divine requested a review from a team as a code owner February 7, 2026 23:51
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 zero-gas transaction feature for the EVM, allowing any sender to call specific governance-allowlisted contracts without holding gas. The implementation uses a conditional bypass in the ante handler, which is a clean approach. The changes are well-structured across the x/sudo and x/evm modules and are accompanied by a comprehensive set of tests. My review includes a couple of suggestions for minor code improvements related to conciseness and performance.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 71.62162% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.98%. Comparing base (90be562) to head (f89059d).

Files with missing lines Patch % Lines
x/sudo/keeper/querier.go 0.00% 9 Missing ⚠️
x/evm/evmante/evmante_zero_gas.go 66.66% 3 Missing and 3 partials ⚠️
x/sudo/msgs.go 57.14% 3 Missing ⚠️
x/evm/const.go 60.00% 2 Missing ⚠️
x/evm/evmstate/msg_update_params.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2517      +/-   ##
==========================================
- Coverage   59.02%   58.98%   -0.04%     
==========================================
  Files         360      361       +1     
  Lines       24360    24415      +55     
==========================================
+ Hits        14378    14401      +23     
- Misses       8743     8777      +34     
+ Partials     1239     1237       -2     
Files with missing lines Coverage Δ
x/evm/evm.go 50.00% <ø> (ø)
x/evm/evmante/all_evmante.go 64.54% <100.00%> (+0.32%) ⬆️
x/evm/evmante/evmante_can_transfer.go 76.36% <100.00%> (+0.89%) ⬆️
x/evm/evmante/evmante_gas_consume.go 82.55% <100.00%> (+4.14%) ⬆️
x/evm/evmante/evmante_mempool_fees.go 70.96% <100.00%> (+0.96%) ⬆️
x/evm/evmante/evmante_sigverify.go 90.47% <ø> (ø)
x/evm/evmmodule/module.go 84.15% <100.00%> (+1.74%) ⬆️
x/evm/evmstate/gas_fees.go 76.08% <ø> (ø)
x/evm/evmstate/keeper.go 75.40% <100.00%> (+0.40%) ⬆️
x/evm/evmstate/msg_server.go 85.78% <100.00%> (ø)
... and 7 more

... 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.

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