Submitted by berndartmueller, also found by ABAIKUNANBAEV, abdulsamijay, Bauchibred, Egis_Security, and OakSecurity
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 granters 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.
x/xfeemarket/post/fee.go#L123-L127
The feePayer is passed to BurnFeeAndRefund().
x/xfeemarket/post/fee.go#L164-L176
BurnFeeAndRefund() subsequently refunds the tip to the feePayer via SendCoinsFromModuleToAccount().
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 Celestias solution: https://github.com/rootulp/celestia-app/blob/d10fdbd4e5507f8449747a2388c4657f593b691b/app/posthandler/refund_gas_remaining.go#L133-L138
Lance Lan (MANTRA) confirmed and commented:
Lance Lan (MANTRA) commented:
