# Refund mechanism doesn't make sure that there is a fee granter

Babylon's refund logic returns tx fees to the fee payer instead of the fee granter, so a granter who paid fees loses funds to the payer.

- Payout: Audit contest
- Severity: high
- Program: Babylon
- Found by: 0xeix
- Disclosed: 2024-12-09
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-12-babylon-judging/issues/20
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-babylon%3AH-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:go technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Cosmos SDK incentive module refund handler (RefundTx)
**Root cause:** RefundTx sends the fee back to tx.FeePayer() without checking tx.FeeGranter(), but when a fee granter sponsors the tx the granter actually paid the fee.
**Steps:**
1. Observe RefundTx in x/incentive/keeper/refundable_msg_index.go sends txFee to tx.FeePayer()
2. Note sdk.FeeTx exposes FeeGranter() which may differ from FeePayer()
3. Submit a tx where a fee granter pays fees on behalf of a payer
4. Refund is credited to the payer, not the granter
**How found:** Code reading of the refund handler against the sdk.FeeTx interface, noticing FeeGranter() is ignored while FeePayer() is used as recipient.
**Exploitation:** A fee granter sponsors a transaction's fees; on refund the fee collector module sends the coins to the fee payer, so the granter loses the funds while the payer gains them.
**Insight:** In Cosmos SDK fee-grant flows, any refund/rebate path must resolve the recipient via FeeGranter() first, falling back to FeePayer(); grep refund logic for FeePayer() usage.

## Proof of concept (copied exactly from the original report)

**RefundTx sends fee back to FeePayer only**

```
// RefundTx refunds the given tx by sending the fee back to the fee payer.
func (k Keeper) RefundTx(ctx context.Context, tx sdk.FeeTx) error {
	txFee := tx.GetFee()
	if txFee.IsZero() {
		// not possible with the global min gas price mechanism
		// but having this check for compatibility in the future
		return nil
	}
	txFeePayer := tx.FeePayer()

	return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, k.feeCollectorName, txFeePayer, txFee)
```

**FeeTx interface exposes FeeGranter**

```
type FeeTx interface {
	[Tx](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/types#Tx)
	GetGas() [uint64](https://pkg.go.dev/builtin#uint64)
	GetFee() [Coins](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/types#Coins)
	FeePayer() [][byte](https://pkg.go.dev/builtin#byte)
	FeeGranter() [][byte](https://pkg.go.dev/builtin#byte)
```

**Celestia getRecipient fix preferring feeGranter**

```
// getRecipient returns the address that should receive the refund.
func getRecipient(feeTx sdk.FeeTx) sdk.AccAddress {
	if feeGranter := feeTx.FeeGranter(); feeGranter != nil {
		return feeGranter
	}
	return feeTx.FeePayer()
```

