-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[M02] Complete liquidity removals fail from stableswap pools #86
Comments
0xRobocop marked the issue as sufficient quality report |
0xRobocop marked the issue as primary issue |
enthusiastmartin (sponsor) disputed |
It is not issue, and it is by design as we dont need the multi-token withdrawal functionality. |
The warden demonstrated that the initial liquidity cannot be removed from the system because of an overflow. This can lead to (temporary) locked funds in edge cases, so Medium is appropriate here. |
OpenCoreCH marked issue #198 as primary and marked this issue as a duplicate of 198 |
OpenCoreCH marked the issue as selected for report |
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L638
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L551
Vulnerability details
Impact
The contracts for stableswap has 2 functions dealing with removal of liquidity:
remove_liquidity_one_asset
andwithdraw_asset_amount
. However, both these functions allow redeeming LP tokens and pay out in only one token. Critically, this contract is missing Curve protocol'sremove_liquidity
function, which allows redeeming LP tokens for all the different tokens in the pool.The result of this decision is that when the complete liquidity of a pool is to be removed, the contract reverts with an arithmetic overflow. In curve protocol, when removing the complete liquidity, the composing tokens are removed from the pool. However here, they also need to be converted to a single token, using a liqudity which wont exist anymore. This leads to an issue somewhere in the mathematics of the curve liquidity calculation, and thus reverts.
Proof of Concept
A simple POC to remove the complete liquidity is coded up below. This POC reverts when the entire amount of shares is being redeemed.
Here ALICE adds liquidity, and is trying to redeem all her LP tokens. This reverts with the following:
This is because the internal math of the stableswap algorithm fails when there is no more liquidity.
Tools Used
Substrate
Recommended Mitigation Steps
Allow multi-token liquidity withdrawal, which would allow complete redeeming of all LP tokens.
Assessed type
Under/Overflow
The text was updated successfully, but these errors were encountered: