Skip to content
Business logic Audit finding Intermediate

_getInterest() function uses block.timestamp instead of the inputted timestamp

The _getInterest() function uses block.timestamp instead of the provided timestamp in a condition, causing it to return incorrect interest values. This can lead to miscalculations in several protocol functions that rely on accurate interest amounts.

obront Follow with sorrynotsorry

Originally disclosed on Sherlock

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

Found by

obront, sorrynotsorry

Summary

The _getInterest() function takes a timestamp as input. However, in a crucial check in the function, it uses block.timestamp instead. The result is that other functions expecting accurate interest amounts will receive incorrect values.

Vulnerability Detail

The _getInterest() function takes a lien and a timestamp as input. The intention is for it to calculate the amount of time that has passed in the lien (delta_t) and multiply this value by the rate and the amount to get the interest generated by this timestamp.

However, the function uses the following check regarding the timestamp:

Solidity
if (block.timestamp >= lien.start + lien.duration) {
  delta_t = uint256(lien.start + lien.duration - lien.last);
} 

Because this check uses block.timestamp before returning the maximum interest payment, the function will incorrectly determine which path to take, and return an incorrect interest value.

Impact

There are two negative consequences that can come from this miscalculation:

  • if the function is called when the lien is over (block.timestamp >= lien.start + lien.duration) to check an interest amount from a timestamp during the lien, it will incorrectly return the maximum interest value
  • If the function is called when the lien is active for a timestamp long after the lien is over, it will skip the check to return maximum value and return the value that would have been generated if interest kept accruing indefinitely (using delta_t = uint256(timestamp.safeCastTo32() - lien.last);)

This _getInterest() function is used in many crucial protocol functions (_getOwed(), calculateSlope(), changeInSlope(), getTotalDebtForCollateralToken()), so these incorrect values can have surprising and unexpected negative impacts on the protocol.

Code Snippet

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L177-L196

Tool used

Manual Review

Recommendation

Change block.timestamp to timestamp so that the if statement checks correctly.

The original report as published on Sherlock, by obront. 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 function mistakenly used block.timestamp instead of the input timestamp in a conditional check, leading to incorrect branching.

Impact

This miscalculation can cause incorrect interest values to be returned, potentially leading to unexpected negative impacts on the protocol's functions that rely on accurate interest amounts.

What the attacker needed

None

The fix

The function should be fixed by changing block.timestamp to the input timestamp in the conditional check.

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 that calculates interest uses the current time instead of the time it was given. This makes it return wrong interest amounts, which can affect other parts of the system that depend on those numbers.

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 obront

View all

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