Liquidation condition should not factor the liquidation reward into the premiums
The liquidation condition in Particle LAMM subtracts the liquidation reward from the premiums before checking whether the premiums are sufficient to cover the owed tokens. This can cause a lien to be considered underwater and liquidated even when it would otherwise be healthy.
The premiums used to determine the liquidation condition have the liquidation reward already discounted, potentially causing a lien to be considered underwater while technically it is not.
Impact
Positions in Particle LAMM can be liquidated if the owed tokens exceed the available premiums in the lien. Liquidators are incentivized with a reward to keep the protocol sane. This can be found in the implementation of liquidatePosition():
The liquidation rewards are calculated as a portion of the premiums, and discounted from these to keep them reserved from any further calculation that may involve tokenFromPremium or tokenToPremium. However, these are discounted before checking the liquidation condition.
The values used to check the conditions at lines 362 and 363 already incorporate the discounted rewards. This implies that the borrower might still maintain a healthy position if it weren’t for the subtracted amounts. The lien could be liquidated even if it’s not technically underwater.
Recommendation
Subtract the liquidation rewards from premiums after checking the liquidation condition.
If we get the liquidation reward after checking the condition, then it means after deducting the liquidation reward from tokenFromPremium and tokenToPremium, there isn’t enough left to pay for tokenFromOwed and tokenToOwed.
So yeah, I think it’s by design that some amount is going to liquidator, and then the left should be enough to meet the LP requirement (liquidation condition).
If we get the liquidation reward after checking the condition, then it means after deducting the liquidation reward from tokenFromPremium and tokenToPremium, there isn’t enough left to pay for tokenFromOwed and tokenToOwed.
You are right about the cap. Just want to follow up with the reward before/after liquidation condition —
If it’s after, then we always pay LP an amount less than the tokenOwed. This is because at the very beginning of liquidation condition being met, amount to LP is already deducted from 100% tokenOwed. Hence we designed it to do the liquidation reward before the condition check.
It should also consider the argument inside the duplicate issue #14, that the LIQUIDATION_REWARD_FACTOR can be changed by the admin, which can immediately affect the health condition of users’ positions.
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
The liquidation reward is deducted from the premiums before the liquidation condition is evaluated, so the condition uses reduced premium values.
Impact
A lien could be liquidated even if it is not technically underwater, as the reward deduction may push the premiums below the owed amount.
What the attacker needed
None
The fix
The liquidation rewards should be subtracted from premiums after checking the liquidation condition.
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, a position can be liquidated if the collateral or premiums are not enough to cover what is owed. Here, the code first takes out a reward for the liquidator from the premiums, and only then checks if the remaining premiums are enough. This means a position that was actually fine could be liquidated just because the reward was subtracted too early.
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.