Skip to content
Smart contracts Audit finding Advanced

Incorrect `LienToken.changeInSlope` calculation can lead to vault insolvency

The changeInSlope function calculates a new slope without accounting for interest and the interest denominator, making the value inflated and causing an underflow when subtracting from the old slope. This can lead to reverts and vault insolvency because users cannot determine the implicit value of vaults.

0xRajeev Follow with hansfriese

Originally disclosed on Sherlock

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

Found by

0xRajeev, hansfriese

Summary

The calculation of newSlope in changeInSlope() is incorrect which can lead to vault insolvency.

Vulnerability Detail

Contrary to the changeInSlope function, the calculateSlope function uses the _getOwed function to calculate the owed amount (incl. the interest). The interest is calculated with the _getInterest function. This function takes care of the lien.last and also if a lien is expired already. This logic is completely missing in the changeInSlope for the newSlope calculation which makes it incorrect. Also, very importantly, in the changeInSlope function, the INTEREST_DENOMINATOR is missing which makes the value inflated causing an underflow error in the last line of changeInSlope function: slope = oldSlope - newSlope;. oldslope, which accounts for the INTEREST_DENOMINATOR, is less than newSlope.

Impact

The incorrect changeInSlope() calculation can lead to reverts and vault insolvency because users cannot determine the implicit value of vaults while interacting with it as borrowers or lenders.

Code Snippet

  1. https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L453-L469
  2. https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L440-L445

Tool used

Manual Review

Recommendation

Make changeInSlope() consistent with calculateSlope() by implementing a separate helper function to calculate the interest accounting for all the parameters and reusing it in both places.

The original report as published on Sherlock, by 0xRajeev. 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

Likely the changeInSlope function omits the interest calculation and the INTEREST_DENOMINATOR scaling factor that are present in calculateSlope, leading to an inflated newSlope and an underflow.

Impact

The incorrect calculation can cause reverts and vault insolvency because users cannot determine the implicit value of vaults while interacting as borrowers or lenders.

What the attacker needed

None

The fix

changeInSlope should be made consistent with calculateSlope by implementing a separate helper function to calculate interest accounting for all parameters and reusing it in both places.

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 calculates interest on a loan using a slope value. One function that updates this slope forgets to include the interest and a scaling factor, so the new slope becomes too large. When the contract tries to subtract it from the old slope, the number goes negative and the transaction fails, which can break the vault and make it insolvent.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by 0xRajeev

View all

61 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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.