LienToken._payment function increases users debt
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/73
Found by
rvierdiiev
Summary
LienToken._payment function increases users debt by setting lien.amount = _getOwed(lien)
Vulnerability Detail
LienToken._payment is used by LienToken.makePayment function that allows borrower to repay part or all his debt.
Also this function can be called by AuctionHouse when the lien is liquidated.
https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L594-L649
function _payment(
uint256 collateralId,
uint8 position,
uint256 paymentAmount,
address payer
) internal returns (uint256) {
if (paymentAmount == uint256(0)) {
return uint256(0);
}
uint256 lienId = liens[collateralId][position];
Lien storage lien = lienData[lienId];
uint256 end = (lien.start + lien.duration);
require(
block.timestamp < end || address(msg.sender) == address(AUCTION_HOUSE),
"cannot pay off an expired lien"
);
address lienOwner = ownerOf(lienId);
bool isPublicVault = IPublicVault(lienOwner).supportsInterface(
type(IPublicVault).interfaceId
);
lien.amount = _getOwed(lien);
address payee = getPayee(lienId);
if (isPublicVault) {
IPublicVault(lienOwner).beforePayment(lienId, paymentAmount);
}
if (lien.amount > paymentAmount) {
lien.amount -= paymentAmount;
lien.last = block.timestamp.safeCastTo32();
// slope does not need to be updated if paying off the rest, since we neutralize slope in beforePayment()
if (isPublicVault) {
IPublicVault(lienOwner).afterPayment(lienId);
}
} else {
if (isPublicVault && !AUCTION_HOUSE.auctionExists(collateralId)) {
// since the openLiens count is only positive when there are liens that haven't been paid off
// that should be liquidated, this lien should not be counted anymore
IPublicVault(lienOwner).decreaseEpochLienCount(
IPublicVault(lienOwner).getLienEpoch(end)
);
}
//delete liens
_deleteLienPosition(collateralId, position);
delete lienData[lienId]; //full delete
_burn(lienId);
}
TRANSFER_PROXY.tokenTransferFrom(WETH, payer, payee, paymentAmount);
emit Payment(lienId, paymentAmount);
return paymentAmount;
}
The main problem is in line 617. lien.amount = _getOwed(lien);
https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L617
Here lien.amount becomes lien.amount + accrued interests, because _getOwed do that calculation.
lien.amount is the amount that user borrowed. So actually that line has just increased user's debt. And in case if he didn't pay all amount of lien, then next time he will pay more interests.
Example.
User borrows 1 eth. His lien.amount is 1eth.
Then he wants to repay some part(let's say 0.5 eth). Now his lien.amount becomes lien.amount + interests.
When he pays next time, he pays (lien.amount + interests) + new interests. So interests are acummulated on previous interests.
Impact
User borrowed amount increases and leads to lose of funds.
Code Snippet
Provided above
Tool used
Manual Review
Recommendation
Do not update lien.amount to _getOwed(lien).
Discussion
Evert0x
Downgrading to medium
IAmTurnipBoy
Escalate for 1 USDC
Invalid. All I see here is compounding interest. Nothing incorrect here, just a design choice. Plenty of loans use compounding interest.
sherlock-admin
Escalate for 1 USDC
Invalid. All I see here is compounding interest. Nothing incorrect here, just a design choice. Plenty of loans use compounding interest.
You've created a valid escalation for 1 USDC!
To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Evert0x
Escalation rejected
The impact of this is it'll cause a user in this situation to pay compound interest. Since loan is only 2 weeks, that will be very small impact. But the more often you make a payment the more interest you pay, a valid medium severity finding.
sherlock-admin
Escalation rejected
The impact of this is it'll cause a user in this situation to pay compound interest. Since loan is only 2 weeks, that will be very small impact. But the more often you make a payment the more interest you pay, a valid medium severity finding.
This issue's escalations have been rejected!
Watsons who escalated this issue will have their escalation amount deducted from their next payout.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Astaria. Sherlock made it public on 3 November 2022. Found in the 8 audit contest (finding M-16).
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.