Missing slippage on Stableswap add_Liquidity() #40
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-93
edited-by-warden
🤖_15_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/main/HydraDX-node/pallets/stableswap/src/lib.rs#L475
Vulnerability details
Bug Description
The stableswap AMM in the HydraDX protocol allows users to deposit liquidity to facilitate the market maker functionality. It is a well known issue that calls to add/withdraw liquidty on vaults/amm pools can be frontrun to reduce the users received shares. In the
add_liquidity_shares()
this is already accounted for as the user provides the amount of shares he wants to receive, and can control his slippage by setting themax_asset_amount
variable.Unfortunately, in the
add_liquidity()
function, where the user sets how many assets he wants to provide, he is not able to set the minimum amount of assets that he wants to receive. This way the user could have to endure up to 100% slippage, resulting in massive losses.Impact
This issue allows a malicious attacker to frontrun calls to
add_Liquidity()
so that users incur high slippage losses. The users can't protect themselves against this as they are not able to set a slippage parameter in the function.Proof of Concept
The issue can already be spotted when looking at
add_liquidty()
's function signature.An exemplary situation can be described as follows
add_liquidity()
functionTools Used
Manual Review
Recommended Mitigation Steps
The issue can be mitigated by allowing the user to pass a
minShares
parameter. At the end of the function, it should check if the user receives more shares than this parameter, and otherwise revert.Assessed type
MEV
The text was updated successfully, but these errors were encountered: