Open c4-bot-6 opened 8 months ago
0xRobocop marked the issue as sufficient quality report
0xRobocop marked the issue as primary issue
0xRobocop marked the issue as high quality report
enthusiastmartin (sponsor) disputed
This is by design, math cannot be precised enough. We deliberately implemented so using this function, users gets little bit less of shares to ensure that there is no impact for protocol.
Does not break any invariant.
What we would like to see instead is that using this function, users can get same amount if shares for less liquidity.
Similar to #38
Rounding difference in the order of magngitue of 10^-7 -> QA
OpenCoreCH changed the severity to QA (Quality Assurance)
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L512-L529 https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L475-L492 https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/math/src/stableswap/math.rs#L386-L392
Vulnerability details
Impact
This vulnerability will lead to loss of funds for liquidity providers , since the function
add_liquidity_shares
takes more assets than the functionadd_liquidity
takes for the same amount of shares . This will affect the liquidity providers who will try to provide_liquidity by usingadd_liquidity_shares
Proof of Concept
this vulnerability arises from the fact that
add_liquidity_shares
takes more assets than whatadd_liquidity
function takes for the same amount of shares , which is considered loss of funds for the liquidity providers .the function
calculate_add_one_asset
calculates the amount of assets to be taken from the user in order to receive a specific amount of shares , this function returns more assets than what it supposed to be .coded POC :
consider adding those two test to
add_liquidity.rs
test file here , and see the printed statements that resulted from the testthe logs
this POC demonstrates that the function
add_liquidity_shares
takes1423231920170
extra amount of assets from the liquidity provider thatadd_liquidity
function which is considered loss of funds for the users .Tools Used
vs code and manual review
Recommended Mitigation Steps
consider modify the
calculate_add_one_asset
function to calculate the right amount of assets to be taken from the user .the protocol may implement this change here :
Assessed type
Math