Incorrect margin calculation in liquidationType2
In liquidation type 2, the contract calculates the margin as amount times ETH price divided by 100, but the Synthetix exchange charges a fee, so the actual sUSD received is less than the calculated margin. This causes the transferMargin call to revert due to insufficient sUSD, blocking liquidation type 2.
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/451
Found by
0x37, Audinarey
Summary
In liquidation type2, we will calculate the margin via amount * EthPrice. We don't consider the exchange fee in synthetix.
Root Cause
In borrowLiquidation.sol:350, we will exchange the sETH to sUSD. The sUSD will be taken as the margin in the synthetix.
In liquidationType2() function, we will exchange amount sETH to sUSD, and then these sUSD as the margin. The margin amount is calculated via (amount * currentEthPrice) / 100. The problem is that there is exchange fee in synthetix's exchange() function. This will cause that the sUSD from synthetix.exchange() may be less than calculated margin. This will cause reverted because there is not enough sUSD.
synthetix.exchange(
// sETH
0x7345544800000000000000000000000000000000000000000000000000000000,
amount,
// sUSD
0x7355534400000000000000000000000000000000000000000000000000000000
);
int256 margin = int256((amount * currentEthPrice) / 100);
synthetixPerpsV2.transferMargin(margin);
Internal pre-conditions
N/A
External pre-conditions
N/A
Attack Path
N/A
Impact
The liquidation transaction will be reverted for liquidation type2. We need to make sure the liquidation should work well considering that liquidation type 1 may not work if there is not enough cds owners who opt in the liquidation process.
PoC
N/A
Mitigation
Get the output sUSD amount via exchange() function. Take sUSD as the margin.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The margin is calculated from the input amount and price without accounting for the exchange fee, so the actual sUSD received is less than the margin required.
Impact
Liquidation type 2 transactions will revert, potentially leaving positions unliquidated if type 1 is unavailable.
What the attacker needed
Liquidation type 2 is triggered
The fix
The fix should use the actual sUSD amount returned by the exchange function as the margin.
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.
When a liquidation happens, the contract swaps one token for another and then uses the result as a margin. The code assumes the swap gives exactly the calculated amount, but the exchange takes a fee, so the actual amount is smaller. The margin transfer then fails because there isn't enough of the swapped token.
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.