Logical error in validate_fees_are_paid can cause a DoS or allow users to bypass fees if denom_creation_fee includes multiple coins, including pool_creation_fee , and the user attempts to pay all fees using only pool_creation_fee
The fee validation logic in the pool creation function incorrectly handles cases where the pool creation fee and denom creation fee share the same denomination. An attacker could bypass paying one of the fees if the amounts are equal, or cause a denial of service if the amounts differ and they attempt to pay both together.
0xRajkumar Follow with 0xAlix2, carrotsmuggler and 8 others
Originally disclosed on Code4rena
Submitted by 0xRajkumar, also found by 0xAlix2, carrotsmuggler, Egis_Security, Egis_Security, jasonxiale, Lambda, oakcobalt, Tigerfrake, Tigerfrake, and Tigerfrake
/contracts/pool-manager/src/helpers.rs#L561-L592
Finding description and Impact
When a user creates a pool, they must pay both denom_creation_fee and pool_creation_fee.
The denom_creation_fee can be paid using multiple coins or a single coin and may also include the same coin as pool_creation_fee. If multiple denom_creation_fee coins options are available, and one of them matches the coin used for pool_creation_fee, it can lead to issues.
Problem Scenario
The issue arises when the user attempts to pay both fees using the same coin.
- Different Fee Amounts: If the user pays both fees in the same coin, with different amounts for
denom_creation_feeandpool_creation_fee, they might add both amounts and send the total. When validating thepool_creation_fee, the checkpaid_pool_fee_amount==pool_creation_fee.amount will fail, causing a DoS.
ensure!(
paid_pool_fee_amount == pool_creation_fee.amount,
ContractError::InvalidPoolCreationFee {
amount: paid_pool_fee_amount,
expected: pool_creation_fee.amount,
}
);
- Same Fee Amounts: If both fees have the same amount and the user pays only once, they can bypass one of the fees entirely, resulting in a fee payment bypass.
ensure!(
paid_pool_fee_amount == pool_creation_fee.amount, //-> HERE It will pass
ContractError::InvalidPoolCreationFee {
amount: paid_pool_fee_amount,
expected: pool_creation_fee.amount,
}
);
total_fees.push(Coin {
denom: pool_fee_denom.clone(),
amount: paid_pool_fee_amount,
});
// Check if the user paid the token factory fee in any other of the allowed denoms
let tf_fee_paid = denom_creation_fee.iter().any(|fee| {
let paid_fee_amount = info
.funds
.iter()
.filter(|fund| fund.denom == fee.denom)
.map(|fund| fund.amount)
.try_fold(Uint128::zero(), |acc, amount| acc.checked_add(amount))
.unwrap_or(Uint128::zero());
total_fees.push(Coin {
denom: fee.denom.clone(),
amount: paid_fee_amount,
});
paid_fee_amount == fee.amount //-> HERE It will pass
});
As both are equal, that’s why both checks will pass. The impact is High as it can cause a DoS and allow the bypass of one of the fees.
Proof of Concept
How it happens when amounts are different:
- The user sends a transaction to create a pool by combining both fee amounts into a single payment.
- The transaction reverts because the check
paid_pool_fee_amount == pool_creation_fee.amountevaluates to false. - If the user attempts to bypass this, the next check for
denom_creation_feewill also fail.
How it happens when amounts are the same:
- The attacker will send only one amount because both checks (for
pool_creation_feeanddenom_creation_fee) will pass, as both amounts are equal. This allows the attacker to pay only once.
Recommended mitigation steps
We can verify whether the user is paying with one coin or multiple coins. If the user is paying with one coin, we can combine both amounts and perform the validation. Similarly, if the user is paying with multiple coins, we can apply the same approach. This will effectively mitigate the issue.
jvr0x (MANTRA) confirmed and commented:
It is valid. However, considering the chain only supports 1 token to pay for the token factory at the moment, I wouldn’t deem it as high, but low.
I see your point, and while I would agree if this were a bug bounty program (funds are not at risk in live contracts), I consider this a High, because what counts is the code in-scope and not the live config, unless the in-scope code is hardcoded to have only one token and can’t be changed by config.
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 validation logic does not correctly handle the case where the same coin is used for both fees, leading to double-counting or under-counting of payments.
Impact
This could cause a denial of service when fee amounts differ, or allow users to bypass paying one fee when amounts are equal; the project confirmed the issue but noted the chain currently supports only one token for the token factory fee, which may limit the impact.
What the attacker needed
Denom_creation_fee includes pool_creation_fee coin; user attempts to pay both fees with same coin
The fix
The code should be modified to correctly handle cases where the same coin is used for both fees, by combining amounts or validating appropriately.
How it was found
- User sends a transaction to create a pool, combining both fee amounts into a single payment when amounts differ.
- Transaction reverts because the pool fee check fails.
- If amounts are the same, user sends only one amount, and both checks pass, bypassing one fee.
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.
When creating a pool, users must pay two fees: a pool creation fee and a denom creation fee. The code checks these fees separately but doesn't account for the possibility that both fees could be in the same coin. If the amounts are the same, paying once satisfies both checks, so the user pays only one fee instead of two. If the amounts differ and the user tries to pay both together, the check fails and the transaction is blocked, causing a denial of service.
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.