feat(evm): extend zero gas functionality to allow for any sender to call certain EVM contracts with zero gas#2517
feat(evm): extend zero gas functionality to allow for any sender to call certain EVM contracts with zero gas#2517Unique-Divine wants to merge 9 commits intomainfrom
Conversation
… to record payments
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.
… and sdb.Commit comments
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
…s as bech32/hex, AlwaysZeroGasContracts as EIP55
… O(1) ante lookup
…rop redundant nil/ok checks; failed or nil assertion already yields nil.
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-gaswithalways_zero_gas_contractsin the JSON payload).Key Changes
x/sudo — allowlist and CLI: New field
always_zero_gas_contractsonZeroGasActors(proto, state, generated code). Contracts in this list can be invoked with zero gas by any sender (no sender allowlist for this path). Existingsenders/contractsunchanged for non-EVM zero-gas. Validation and default inx/sudo/msgs.go;EditZeroGasActorsand CLI updated inx/sudo/keeper/msg_server.goandx/sudo/cli/cli.go;x/sudo/keeper/querier.goaddsGetZeroGasEvmContractsreturning EIP55 addresses for EVM ante.x/evm — context marker and SudoKeeper: New context key and helpers:
CtxKeyZeroGasMeta,ZeroGasMeta,GetZeroGasMeta,IsZeroGasEthTxinx/evm/const.goandx/evm/evm.go. SudoKeeper interface gainsGetZeroGasEvmContractsinx/evm/deps.go; EVM keeper is wired to SudoKeeper inx/evm/evmmodule/module.goand uses it for zero-gas detection. Keeper constructor and field inx/evm/evmstate/keeper.go.EVM ante — detection and conditional skips: New step
AnteStepDetectZeroGasinx/evm/evmante/evmante_zero_gas.go: eligibility =tx.Toinalways_zero_gas_contractsandtx.Value == 0; only sets marker, no state writes. Step order inx/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).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.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.goandx/evm/evmante/evmante_can_transfer_test.go; full ante (zero-gas with min gas price, first-time onboarding) inx/evm/evmante/all_evmante_test.go. Msg_server: RefundGas skipped for zero-gas, reverted execution inx/evm/evmstate/msg_ethereum_tx_test.go. Sudo: EditZeroGasActors and validation foralways_zero_gas_contractsinx/sudo/keeper/msg_server_test.go,x/sudo/cli/cli_test.go, andx/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 thesudo edit-zero-gasCLI + validation/deduping to manage this field.Implements a context-based zero-gas bypass in
x/evm: introducesZeroGasMeta+ helpers, addsAnteStepDetectZeroGas(runs early) to mark eligible txs (toallowlisted +value==0), and then skips fee-related checks/operations (mempool min gas price, balance-vs-cost, fee deduction, andRefundGas) while still creating the sender account if missing and still runningCanTransfer.Wires
x/evmto depend onx/sudovia a newSudoKeeper.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.