fix: cosmwasm evm query path repeatable undercharged evm exec#18
fix: cosmwasm evm query path repeatable undercharged evm exec#18mattkii wants to merge 2 commits into
Conversation
|
Warning Review limit reached
More reviews will be available in 47 minutes and 52 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| // Bound the EVM gas limit by the caller-provided gasCap when set, falling | ||
| // back to DefaultGasCap. This prevents callers (e.g. CosmWasm query bindings) | ||
| // from triggering EVM execution larger than their remaining gas budget. | ||
| gasLimit := config.DefaultGasCap | ||
| if gasCap != nil && gasCap.IsUint64() { | ||
| if capped := gasCap.Uint64(); capped < gasLimit { | ||
| gasLimit = capped | ||
| } | ||
| } |
There was a problem hiding this comment.
Interesting to see that the gas cap was not being used after all.
They have changed this function to consider the gas cap in the recent version:
Interesting finding
| // Charge the SDK gas meter for the actual pre-refund EVM work (MaxUsedGas) | ||
| // rather than the post-refund GasUsed. Internal calls run with a full refund | ||
| // and no minimum-gas floor, so GasUsed can fall far below the real compute | ||
| // performed by validators; billing MaxUsedGas removes that undercharge. | ||
| // Precompile sub-calls keep their existing accounting. | ||
| chargedGas := res.GasUsed | ||
| if !callFromPrecompile && res.MaxUsedGas > chargedGas { | ||
| chargedGas = res.MaxUsedGas | ||
| } | ||
|
|
||
| ctx.GasMeter().ConsumeGas(chargedGas, "apply evm message") |
There was a problem hiding this comment.
Shouldn't we move this snipped to happen on the Kiichain side? Since it's related to Cosmos-SDK ctx gas handling instead of evm internal gas counters
Description
Hardens the internal EVM call helper
CallEVMWithData(x/vm/keeper/call_evm.go)against undercharged, repeatable internal EVM execution triggered from the SDK side
(e.g. the KiiChain CosmWasm→EVM ERC20 query bindings).
Two compounding problems were addressed:
gasCapwas ignored.CallEVMWithDataalways set the messageGasLimittoconfig.DefaultGasCap(25M), regardless of thegasCapargument or the caller'sremaining SDK gas budget. A caller passing a smaller cap (or relying on the
remaining budget) could not constrain the internal execution.
full gas refund (
refundQuotient = 1) and skip theminimumGasUsedfloor, sores.GasUsedcan fall far below the real pre-refund compute (res.MaxUsedGas).ConsumeGas(res.GasUsed)therefore billed validators for a fraction of the workactually performed, enabling a refund-maximizing contract to repeat the same heavy
workload while paying almost nothing.
Changes in
CallEVMWithData:GasLimitby the providedgasCapwhen set (min(gasCap, DefaultGasCap)),falling back to
DefaultGasCapwhen nil — so callers can cap execution to theirremaining budget.
res.MaxUsedGaswhenit exceeds
res.GasUsed, for non-precompile calls. Precompile sub-calls keep theirexisting accounting to avoid disturbing precompile gas costs.
Most critical file to review:
x/vm/keeper/call_evm.go.This is the EVM-fork half of the fix; the companion change lives in
KiiChain/kiichain(wasmbinding/evm/queries.go), which passes a realgasCapderived from the transaction's remaining SDK gas to these helpers.Author Checklist
I have...
report KCNL1DDA-89 (CosmWasm→EVM query path repeatable undercharged internal
EVM execution).
mainbranch — branchfix/wasm-repeatable-undercharged-internal-evm-execwas cut from and targetsmain.How to review
x/vm/keeper/call_evm.go— confirm thegasCapbounding and theMaxUsedGasvsGasUsedcharging logic (note the!callFromPrecompileguard).CallEVMandCallEVMWithDatasuites green).