Skip to content
Business logic Audit finding Intermediate

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

The refund mechanism sends transaction fees back to the fee payer instead of the fee granter, so when a granter pays fees on behalf of a user, the refund goes to the wrong party. This causes a loss of funds for the fee granter.

0xeix Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-12-babylon-judging/issues/20

Found by

0xeix

Summary

There is currently a refund logic that transfers the funds to a fee payer.

Root Cause

The root cause lies in the fact that the transaction fees can be paid by other enitities and the funds are returned to a fee payer and not a granter.

Internal Pre-conditions

External Pre-conditions

Fee granter has to pay for the fees.

Attack Path

Fee grantor paid for the fees but the funds are returned to a fee payer.

Impact

Loss of funds for a fee granter.

PoC

Consider the current refund mechanism:

https://github.com/sherlock-audit/2024-12-babylon/blob/main/babylon/x/incentive/keeper/refundable_msg_index.go#L10-23

Go

// 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)
}

The problem is that the fees are refunded to the feePayer (the sender of the message) without taking into account the fact that the actual payer can be feeGranter resulting in a loss of funds for the granter:

Go
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)
}

Mitigation

Check out the Celestia solution for this issue:

https://github.com/rootulp/celestia-app/blob/d10fdbd4e5507f8449747a2388c4657f593b691b/app/posthandler/refund_gas_remaining.go#L133-L138

Go
// 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()
}

Here the funds are actually sent to the right entity.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/babylonlabs-io/babylon/pull/594

The original report as published on Sherlock, by 0xeix. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The refund function only considers the fee payer and ignores the fee granter, who may have actually paid the fees.

Impact

A fee granter loses funds because the refund is sent to the fee payer instead.

What the attacker needed

Fee granter pays fees for a transaction

The fix

The refund logic should check if a fee granter is set and send the refund to the granter instead of the fee payer; the protocol team fixed this issue.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In some blockchain systems, one account can pay transaction fees for another. Here, when fees are refunded, the code sends the money back to the account that sent the transaction, not the account that actually paid the fees. This means the person who paid loses their money.

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.

More by 0xeix

View all

10 more disclosed reports, best first.

More from Babylon Chain Launch (Phase-2)

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.