Skip to content
Business logic Audit finding Intermediate

isValidRefinance will approve invalid refinances and reject valid refinances due to buggy math

The isValidRefinance function incorrectly checks whether the new interest rate is greater than a minimum rate, rather than less than a maximum rate, so it approves refinances with higher rates and rejects those with lower rates. This allows invalid refinances and blocks valid ones.

hansfriese Follow with obront and 0xRajeev

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/21

Found by

hansfriese, obront, 0xRajeev

Summary

The math in isValidRefinance() checks whether the rate increased rather than decreased, resulting in invalid refinances being approved and valid refinances being rejected.

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.

Solidity
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 current implementation of the function does the opposite. It calculates a minNewRate (which should be maxNewRate) and then checks whether the new rate is greater than that value.

Solidity
uint256 minNewRate = uint256(lien.rate) - minInterestBPS;
return (newLien.rate >= minNewRate ...

The result is that if the new rate has increased (or decreased by less than 0.5%), it will be considered valid, but if it has decreased by more than 0.5% (the ideal behavior) it will be rejected as invalid.

Impact

  • Users can perform invalid refinances with the wrong parameters.
  • Users who should be able to perform refinances at better rates will not be able to.

Code Snippet

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/AstariaRouter.sol#L482-L491

Tool used

Manual Review

Recommendation

Flip the logic used to check the rate to the following:

Solidity
uint256 maxNewRate = uint256(lien.rate) - minInterestBPS;
return (newLien.rate <= maxNewRate...

Discussion

IAmTurnipBoy

Escalate for 1 USDC

Should be medium because no funds at risk

sherlock-admin

Escalate for 1 USDC

Should be medium because 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.

The original report as published on Sherlock, by hansfriese. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 comparison operator and variable naming are inverted: the code calculates a minimum rate and checks if the new rate is greater than or equal to it, when it should calculate a maximum rate and check if the new rate is less than or equal to it.

Impact

Users can perform invalid refinances with worse terms, and users who should be able to refinance at better rates are prevented from doing so.

What the attacker needed

None

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.

A smart contract function meant to check if a loan refinance is better for the borrower uses the wrong comparison. It should reject a new interest rate that is higher than the old one minus a small margin, but instead it rejects rates that are lower. This means borrowers can get stuck with worse rates and cannot take advantage of better ones.

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.

More by hansfriese

View all

65 more disclosed reports, best first.

More from Astaria

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.