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.
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:
// 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:
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:
// 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
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.