Incorrect amount of Collateral moves for Auction
The auction calculation incorrectly moves the entire collateral and debt when the proportional amount falls below the minimum debt, instead of only increasing to the minimum. An attacker could cause a vault's full collateral to be auctioned when only a portion should be, potentially leading to loss of collateral for the user.
Originally disclosed on Code4rena
Submitted by csanuragjain
It was observed that the debt and collateral which moves for Auction is calculated incorrectly. In case where line.proportion is set to small value, chances are art will become lower than min debt. This causes whole collateral to go for auction, which was not expected.
Proof of Concept
- Assume
line.proportionis set to 10% which is a valid value - Auction is started on Vault associated with collateral & base representing line from Step 1
- Now debt and collateral to be sold are calculated in _calcAuction
uint128 art = uint256(balances.art).wmul(line.proportion).u128();
if (art < debt.min * (10**debt.dec)) art = balances.art;
uint128 ink = (art == balances.art)
? balances.ink
: uint256(balances.ink).wmul(line.proportion).u128();
- Now lets say debt (art) on this vault was amount 10, collateral (ink) was amount 9, debt.min * (10**debt.dec) was amount 2
- Below calculation occurs
uint128 art = uint256(balances.art).wmul(line.proportion).u128(); // which makes art = 10*10% =1
if (art < debt.min * (10**debt.dec)) art = balances.art; // since 1<2 so art=10
uint128 ink = (art == balances.art) // Since art is 10 so ink=9
? balances.ink
: uint256(balances.ink).wmul(line.proportion).u128();
- So full collateral and full debt are placed for Auction even though only 10% was meant for Auction. Even if it was lower than min debt, auction amount should have only increased up to the point where minimum debt limit is reached
Recommended Mitigation Steps
Revise the calculation like below
uint128 art = uint256(balances.art).wmul(line.proportion).u128();
uint128 ink=0;
if (art < debt.min * (10**debt.dec))
{
art = debt.min * (10**debt.dec);
(balances.ink<art) ? (ink=balances.ink) : (ink=art)
} else {
ink=uint256(balances.ink).wmul(line.proportion).u128();
}
debt.min * (10**debt.dec) was amount 2
Only way for this to happen is for the token’s decimals to be 0, which is an edge case.
Anyway, the issue is invalid because it is intended for the full collateral to be offered if it is below the minimum debt amount, ie. vault proportion is to be disregarded:
// We store the proportion of the vault to auction, which is the whole vault if the debt would be below dust.
alcueca (Yield) confirmed and commented:
The finding is valid, but it is a bit complicated.
The behaviour should be:
- If the part of the vault for auction is below
dust, increase todust.- If the remaining part of the vault is below
dust, increase to 100%.
This is the second most critical vulnerability found during the audit. This issue is less critical than H-01 (#116) since the protocol would not take on bad debts but users may lose their entire collateral when only part of their collateral should have been put to auction.
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
Likely the code sets the auctioned debt to the full debt when the proportional amount is below the minimum debt, and then also sets the collateral to the full collateral, instead of only increasing the debt to the minimum and adjusting collateral accordingly.
Impact
Users may lose their entire collateral when only part of it should have been auctioned, although the protocol would not take on bad debts.
What the attacker needed
Line.proportion set to a small value; a vault with debt and collateral
The fix
The calculation should be revised so that if the proportional debt is below the minimum, the debt is increased to the minimum and the collateral is set to the minimum of the proportional collateral and the increased debt, rather than using the full balances.
How it was found
- Set line.proportion to a small value such as 10%.
- Start an auction on a vault with that line.
- The calculation in _calcAuction computes art as 10% of the debt, which is below the minimum debt, so it sets art to the full debt and ink to the full collateral.
- As a result, the entire collateral and debt are put up for auction instead of just 10%.
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.
In a lending protocol, when a borrower's debt becomes risky, part of their collateral can be sold at auction to repay the debt. The code is supposed to sell only a percentage of the collateral, but if that percentage is very small, it mistakenly sells all of it. This means a borrower could lose all their collateral even when only a small part should have been sold.
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.