[H01] Share manipulation attack due to wrong check in withdraw_asset_amount
function
#83
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-154
🤖_42_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L677-L681
Vulnerability details
Impact
The stableswap pool allows users to send in any tokens to the pool, as confirmed by the dev on the discord channel. This opens it up to a potential attack vector, where initial user can deposit a small amount of tokens, and then "donate" a large amount of tokens such that the share ratio is set really high. This will lead to rounding losses and potentially block other users from making small sized deposits. The protocol prevents this attack vector by instituting a
T::MinPoolLiquidity
check, ensuring that the amount of LP shares minted is always either 0 or above this minimum threshold.This is reflected in the liquidity addition functions, where the minimum amount check is enforced.
This is also implemented in the function
remove_liquidity_one_asset
.Where
share_issuance
checks the total supply of the pool token. However, the check inwithdraw_asset_amount
is faulty.Instead of checking against the total issuance, here the contract checks against the user's balance. Thus, users are allowed to redeem all the LP tokens in their account, even if that leads to the situation where the total issuance is below the threshold, allowing an inflation attack. Users can just send 1 wei of LP token to some other account, and then the
current_share_balance == shares
will pass when redeeming the remaining balance, allowing LP removal and leaving 1 wei of LP still existing.Since inflation attacks and DOS attacks can be carried out due to this valid pool state, this is a high severity issue. The recent Wise lending hack was also due to such inflation attacks.
Proof of Concept
The user can trigger this situation by following these steps.
withdraw_asset_amount
function with all her LP token balance. Sincecurrent_share_balance == shares
check passes, all LP tokens are redeemed, except for the 1 wei in BOB's accountTools Used
Manual Review
Recommended Mitigation Steps
Check with
share_issuance
instead of the user's balance, just like inremove_liquidity_one_asset
function.Assessed type
Math
The text was updated successfully, but these errors were encountered: