Unspent gas fees are always refunded to the FeePayer() which leads to incorrect refunds if the FeeGranter() paid for the fees
berndartmueller Follow with ABAIKUNANBAEV, abdulsamijay and 3 others
Originally disclosed on Code4rena
Submitted by berndartmueller, also found by ABAIKUNANBAEV, abdulsamijay, Bauchibred, Egis_Security, and OakSecurity
Finding description and impact
FeeMarketDeductDecorator.PostHandle() is called after the transaction is executed to refund the paid but unspent gas.
The issue is that the refund is always sent to the FeePayer(), which is not the address that paid for the gas if a fee granter (FeeGranter()) paid for the tx fees instead.
In this case, the fee granter will not receive the refund, the fee payer (i.e., the sender) will receive the refund instead. This would slowly drain the fee granter’s account if they are paying for tx fees on behalf of others. Or, if the fee granter assumes to receive the refund, only paying the actual consumed gas fees, and thus only charging the user for the consumed gas fees (afterwards, settled off-chain, e.g., via credit card), they would make a loss.
Proof of Concept
x/xfeemarket/post/fee.go#L123-L127
The feePayer is passed to BurnFeeAndRefund().
123: feePayer := feeTx.FeePayer()
124:
125: if err := dfd.BurnFeeAndRefund(ctx, payCoin, tip, feePayer, params.FeeDenom); err != nil {
126: return ctx, err
127: }
x/xfeemarket/post/fee.go#L164-L176
BurnFeeAndRefund() subsequently refunds the tip to the feePayer via SendCoinsFromModuleToAccount().
148: func (dfd FeeMarketDeductDecorator) BurnFeeAndRefund(ctx sdk.Context, fee, tip sdk.Coin, feePayer sdk.AccAddress, defaultFeeDenom string) error {
... // [...]
163:
164: // refund the tip if it is not nil and non zero
165: if !tip.IsNil() && !tip.IsZero() {
166: err := RefundTip(dfd.bankKeeper, ctx, feePayer, sdk.NewCoins(tip))
167: if err != nil {
168: return err
169: }
170:
171: events = append(events, sdk.NewEvent(
172: xfeemarkettypes.EventTypeTipRefund,
173: sdk.NewAttribute(feemarkettypes.AttributeKeyTip, tip.String()),
174: sdk.NewAttribute(feemarkettypes.AttributeKeyTipPayee, feePayer.String()),
175: ))
176: }
177:
178: ctx.EventManager().EmitEvents(events)
179: return nil
180: }
Recommended mitigation steps
Consider determining the actual fee payer, which is either the FeePayer() or the FeeGranter(), and refund the unused gas fees to the correct address.
For example, see Celestia’s solution: https://github.com/rootulp/celestia-app/blob/d10fdbd4e5507f8449747a2388c4657f593b691b/app/posthandler/refund_gas_remaining.go#L133-L138
Lance Lan (MANTRA) confirmed and commented:
Valid. Grantee can drain all granter’s granted funds; however, most of the granter grantee relationship are internal so the impact is relatively low.
Regarding S-203: yes, we have found this bug prior to it being reported and will be patched in next upgrade. This should be medium-high as all feegranter feegrantee relationships are mostly internal now.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity business logic bug in MANTRA Chain. Code4rena made it public on 31 March 2025. Found in the 2024-11-mantra-chain audit contest (finding H-02), also found by 5 other wardens.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.