Handsome Jetblack Swift
Medium
Summary The priority calculation logic in the getTxPriority function is inaccurate, which may lead to an underestimation of transaction priority.
Impact When the transaction fee consists of multiple tokens, the priority calculation may be dominated by the token with the lower fee, leading to an underestimation of the actual transaction priority 1. This inaccurate priority calculation may affect the execution order of transactions, especially in high-load networks, leading to transaction delays or failures. Code Snippet https://github.com/babylonlabs-io/babylon/blob/main/app/ante/fee_checker.go#L52 func getTxPriority(fee sdk.Coins, gas int64) int64 { if gas == 0 { return 0 }
var priority int64
for _, c := range fee {
p := c.Amount.Mul(sdkmath.NewInt(priorityScalingFactor)).QuoRaw(gas)
if !p.IsInt64() {
continue
}
if priority == 0 || p.Int64() < priority {
priority = p.Int64()
}
}
return priority
} Recommendation Optimize the priority calculation logic to consider the total fee of all tokens, rather than just taking the lowest priority. For example: func getTxPriority(fee sdk.Coins, gas int64) int64 { if gas <= 0 { return 0 }
var totalPriority int64
for _, c := range fee {
p := c.Amount.Mul(sdkmath.NewInt(priorityScalingFactor)).QuoRaw(gas)
if !p.IsInt64() {
continue
}
totalPriority += p.Int64()
}
return totalPriority
}
Proof of Concept (PoC) Create a transaction containing two tokens, where one token has a lower fee and the other has a higher fee. Call the getTxPriority function and observe the priority calculation result. The result will show that the priority is dominated by the token with the lower fee, leading to an underestimation of the actual priority. Conclusion This vulnerability may lead to inaccurate transaction priority calculations, affecting the execution order and success rate of transactions. It is recommended to optimize the priority calculation logic to ensure it accurately reflects the actual priority of the transaction.