Increase liquidity in close position may not cover original borrowed liquidity
The close position function does not verify that the liquidity added back to the LP covers the original borrowed liquidity. An attacker could potentially close a position with less liquidity returned, causing a loss to the LP.
When a position is closed, there is no check to ensure that the effective added liquidity covers the original borrowed liquidity from the LP.
Impact
Closing a position in the Particle LAMM protocol must ensure that the borrowed liquidity gets fully added back to the LP. Independently of the outcome of the trade, the LP should get its liquidity back. The implementation of _closePosition() calculates the required amounts and executes a call to LiquidityPosition.increaseLiquidity(), which ends up calling increaseLiquidity() in the Uniswap Position Manager.
As we can see in lines 424 and 432, the effective results of the liquidity increment are returned from the call to Uniswap NPM. Both amountToAdd and amountFromAdd are correctly overwritten with the actual amounts used by the addLiquidity() action, but liquidityAdded is simply assigned to the cache and never checked.
The effective added liquidity may fall short to cover the original borrowed liquidity, and if so the lien will be closed without returning the full amount to the LP.
Recommendation
Ensure the effective added liquidity covers the original borrowed amount.
where 1_000_000 is a buffer. But getting this 1_000_000 check is only just to satisfy the calculation..
Unless this opens some other attack angle — can someone somehow flash loan and change price dramatically to make this calculation off by a lot?
If not, we tend to skip this extra check. Thanks!
The original report as published on Code4rena, by adriro. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the code does not compare the actual liquidity added (liquidityAdded) with the original borrowed liquidity (lien.liquidity) after calling increaseLiquidity.
Impact
The LP may not get back the full borrowed liquidity, resulting in a loss.
What the attacker needed
A position is closed
The fix
The code should check that the effective added liquidity covers the original borrowed amount, for example by adding a require statement.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
In a lending protocol, when you close a position, you must return the borrowed liquidity. This report says the code doesn't check that the returned liquidity is enough, so the pool could lose funds.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.