isValidRefinance checks both conditions instead of one, leading to rejection of valid refinances
The isValidRefinance function incorrectly required both a rate decrease and a duration increase to be true, instead of either condition, causing valid refinances to be rejected. An attacker could not directly exploit this, but it would prevent legitimate refinance attempts.
Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/22
Found by
obront
Summary
isValidRefinance() is intended to check whether either (a) the loan interest rate decreased sufficiently or (b) the loan duration increased sufficiently. Instead, it requires both of these to be true, leading to the rejection of valid refinances.
Vulnerability Detail
When trying to buy out a lien from LienToken.sol:buyoutLien(), the function calls AstariaRouter.sol:isValidRefinance() to check whether the refi terms are valid.
if (!ASTARIA_ROUTER.isValidRefinance(lienData[lienId], ld)) {
revert InvalidRefinance();
}
One of the roles of this function is to check whether the rate decreased by more than 0.5%. From the docs:
An improvement in terms is considered if either of these conditions is met:
- The loan interest rate decrease by more than 0.5%.
- The loan duration increases by more than 14 days.
The currently implementation of the code requires both of these conditions to be met:
return (
newLien.rate >= minNewRate &&
((block.timestamp + newLien.duration - lien.start - lien.duration) >= minDurationIncrease)
);
Impact
Valid refinances that meet one of the two criteria will be rejected.
Code Snippet
https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/AstariaRouter.sol#L488-L490
Tool used
Manual Review
Recommendation
Change the AND in the return statement to an OR:
return (
newLien.rate >= minNewRate ||
((block.timestamp + newLien.duration - lien.start - lien.duration) >= minDurationIncrease)
);
Discussion
SantiagoGregory
Independently fixed during our own review so there's no PR specifically for this, but this is now updated to an or.
IAmTurnipBoy
Escalate for 1 USDC
Should be medium because there are no funds at risk
sherlock-admin
Escalate for 1 USDC
Should be medium because there are no funds at risk
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.
Not a major loss of funds but definitely a severe flaw that will hurt the protocol.
sherlock-admin
Escalation rejected.
Not a major loss of funds but definitely a severe flaw that will hurt the protocol.
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.
How it worked
Root cause
The return statement used a logical AND (&&) instead of OR (||) when combining the two refinance conditions.
Impact
Valid refinances that meet only one of the two criteria are rejected, which could hurt the protocol by preventing legitimate refinancing.
What the attacker needed
None
The fix
The condition was fixed by changing the AND to an OR, as confirmed in the discussion.
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.
This is a smart contract bug where a check for loan refinancing used 'AND' instead of 'OR'. That meant a refinance was only allowed if both the interest rate went down and the loan duration went up, but the rules said either one should be enough. So some valid refinances were wrongly blocked.
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.