Open c4-bot-1 opened 8 months ago
0xRobocop marked the issue as primary issue
0xRobocop marked the issue as sufficient quality report
enthusiastmartin (sponsor) disputed
withdraw_protocol_liquidity can be performed only by AuthorityOrigin.
This function is used to withdraw previously scarified positions, and only those known positions which had a price and shares amount. So the price is used to withdraw the same amount of shares. It cannot be abused by "bad price".
Centralization issue / abuse of privilege
OpenCoreCH changed the severity to QA (Quality Assurance)
OpenCoreCH marked the issue as grade-a
I would argue that since withdraw_protocol_liquidity
function does not have any slippage protection, a malicious user can trigger an LRNA minting by changing the price frontrunning the withdraw_protocol_liquidity
call.
Say the protocol does not want to remove any LRNA tokens. So they will call withdraw_protocol_liquidity
with the price
parameter equal to the actual price of the pool. This will ensure that the maximum amount of liquidity tokens are taken out, while not minting any LRNA tokens. However, a malicious user can do a swap right before this call, dropping the actual price of the pool. The system will see this as liquidity removal at lower prices, and mint the admins extra LRNA tokens. Thus LRNA tokens will get devaulted and minted, even if the admins don't want them.
So I would ask the judge to reconsider whether this an abuse of privilege, since it can be triggered by outsiders as well.
The abuse of privilege was related to passing invalid prices for the historical position (which would be passing in wrong values, as this is the intended value).
Under the assumption that the correct price is passed in, I do not see an issue with the function (and the sponsor seems to agree with that). The logic should then be the same as a normal liquidity removal.
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/omnipool/src/lib.rs#L1442-L1525
Vulnerability details
Impact
When a token's value has gone up between the addition and removal of liquidity, there are less tokens to give out to the liquidity providers. So the protocol closes this gap by minting to the liquidity provider some LRNA tokens to compensate the shortfall. This is done in the
process_hub_amount
function.Users can donate LP shares to the protocol by sacrificing them. The admin can then call
withdraw_protocol_liquidity
redeem these protocol owned shares. The issue is that since the price during liquidity addition is not recorded, the caller actually passes in aprice
parameter to this function. Thisprice
parameter can be used to steal tokens from the pool.If the caller passes in a lower
price
than the current price, the protocol thinks that there is a shortfall of the liquidity token and thus mints the caller extra LRNA tokens. Thus callers can callwithdraw_protocol_liquidity
function with a bad price to extract not just the liquidity token, but also LRNA tokens which they can then swap for the other tokens in the pool. This is more important during theremove_token
function call, since at that time it is assumed the protocol owns all the LP share tokens of a certain asset.The POC below highlights this issue.
In the POC, the price of the pool is changed with a
buy
call, and thenwithdraw_protocol_liquidity
is called. This is equivalent to callingwithdraw_protocol_liquidity
with a wrong price. Then theLRNA
token count and thetokenA
token count is checked at the destination address. The result is shown below.This test shows that not only does the destination receive the liquidity tokenA, but also extra LRNA tokens. These tokens cant hen be swapped to the other constituent tokens of the liquidity pool and thus allow stealing of tokens. This requires admin access so the likelihood is low, but the impact is high and thus a medium severity issue.
Proof of Concept
Tools Used
Substrate
Recommended Mitigation Steps
Don't mint out LRNA tokens for
withdraw_protocol_liquidity
calls.Assessed type
Invalid Validation