Attackers can force the rewards to be stuck in the contract with malicious x/tokenfactory denoms
An attacker can create a tokenfactory denom, fund it as a reward, then use MsgForceTransfer to drain the contract's balance, causing reward claims to fail with insufficient funds. This also prevents the contract owner from closing the malicious farm, leaving legitimate rewards stuck.
peachtea Follow with Audinarey, carrotsmuggler and 2 others
Originally disclosed on Code4rena
Submitted by peachtea, also found by Audinarey, carrotsmuggler, Egis_Security, and p0wd3r
Attackers can fund rewards of LP tokens with tokens created from the x/tokenfactory module and abuse the MsgForceTransfer message to prevent the contract from successfully distributing rewards. This would also prevent the contract owner from closing the malicious farm. As a result, rewards that are accrued to the users will be stuck in the contract, causing a loss of rewards.
Proof of Concept
When a user claims pending rewards of their LP tokens, all of their rewards are aggregated together and sent within a BankMsg::Send message.
/contracts/farm-manager/src/farm/commands.rs#L102-L107
These rewards can be funded externally via the FarmAction::Fill message for a particular LP asset.
One thing to note is that the reward must be a Coin, which means it must be a native token recognized by the Cosmos SDK module.
The Mantra DEX contract will be deployed in the Mantra chain, which is running in parallel as another competition here. The Mantra chain implements a x/tokenfactory module to allow token creators to create native tokens.
https://github.com/MANTRA-Chain/mantrachain/blob/v1.0.2/x/tokenfactory/keeper/msg_server.go
One of the features in the x/tokenfactory module is that token creators can call the MsgForceTransfer to forcefully transfer funds from one account to another account, effectively reducing its balance.
https://github.com/MANTRA-Chain/mantrachain/blob/v1.0.2/x/tokenfactory/keeper/msg_server.go#L149
This allows an attacker to perform a denial of service of the rewards pending in the contract by supplying a tokenfactory denom, and then forcefully transfer funds from the contract in order to cause an “insufficient funds” error.
- The attacker creates an
x/tokenfactorydenom from the Mantra chain. - The attacker mints some of the tokens and supplies them to an LP token with
FarmAction::Fill. - The attacker calls
MsgForceTransferto transfer all the tokens forcefully from the contract. - When users want to claim their rewards, the transaction will fail due to an insufficient funds error. Since all the rewards are aggregated into a single
BankMsg::Send, other legitimate rewards that are accrued for the user will be stuck and cannot be withdrawn. - At this point, the contract owner notices it and sends the
FarmAction::Closemessages to close the farm created by the attacker. However, because theclose_farmsfunction will automatically refund the unclaimedfarm.farm_asset.amountto the attacker (see here), the transaction will fail due to an insufficient funds error.
Recommended mitigation steps
To mitigate this attack, consider modifying the close_farms function so the messages are dispatched as SubMsg::reply_on_error when refunding the rewards to the farm owner. Within the reply handler, simply return an Ok(Response::default()) if an error occurred during BankMsg::Send. This will prevent the attack because the contract owner will still have the power to close malicious farms even though the attacker reduced the contract’s balance.
https://docs.rs/cosmwasm-std/latest/cosmwasm_std/struct.SubMsg.html#method.reply_on_error
jvr0x (MANTRA) confirmed
Marking this one as primary, because it highlights the two impacts in this group:
- Malicious pools brick claiming of legitimate pools’ rewards.
- Malicious pools can’t be closed.
It is, however, recommended to take into consideration also the S-377 mitigation of letting users opt-out from malicious pools without requiring admin intervention
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
Likely the contract aggregates all rewards into a single bank send and does not handle the case where one reward token's balance has been forcibly removed, causing the entire send to fail.
Impact
Rewards accrued to users are stuck and cannot be claimed, and the malicious farm cannot be closed by the owner.
What the attacker needed
Attacker can create a tokenfactory denom; Attacker can fund a farm with that denom; Attacker can call MsgForceTransfer
The fix
The close_farms function should dispatch refund messages as SubMsg::reply_on_error and ignore errors in the reply handler, so the owner can still close malicious farms.
How it was found
- The attacker creates an x/tokenfactory denom from the Mantra chain.
- The attacker mints some of the tokens and supplies them to an LP token with FarmAction::Fill.
- The attacker calls MsgForceTransfer to transfer all the tokens forcefully from the contract.
- When users want to claim their rewards, the transaction will fail due to an insufficient funds error.
- The contract owner sends FarmAction::Close to close the farm, but the close_farms function fails due to insufficient funds when refunding the attacker.
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.
A token factory lets people create their own tokens on a blockchain. The attacker creates such a token, puts it into a rewards pool, then uses a special command to take all those tokens back out of the contract. When users try to claim their rewards, the contract tries to send all rewards at once but has no tokens left, so the whole claim fails and other rewards get stuck.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.