-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong calculation of elapsed days #492
Comments
range.end - 1 is in terms of seconds whereas Days Elapsed + 1 is in terms of days. uint256 elapsedDays = (currentTime - currentRange.start) / DAY; elapsedDays will have 1 day short but it's incremented here: _rpow(currentRange.dailyInterestRate, elapsedDays + 1, ONE), |
raymondfam marked the issue as low quality report |
raymondfam marked the issue as primary issue |
Agreed with @raymondfam that 1 is added to |
kirk-baird marked the issue as unsatisfactory: |
Lines of code
https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/rwaOracles/RWADynamicOracle.sol#L266
Vulnerability details
Impact
For a certain period of time, the dailyIr is compounded every day. However, when calculating
prevClosePrice
, the last day's addition is missed.The formula for calculating the current price is as follows:
(Range.dailyInterestRate ** (Days Elapsed + 1)) * Range.lastSetPrice.
Here, "Days Elapsed" refers to all the days that have passed during this time period.For example, if the period starts on July 31 at 8:00:00 PM UTC (timestamp = 1690833600) and ends on August 31 at 8:00:00 PM UTC (timestamp = 1693512000), a total of 31 days have passed.
In the
getPrice
function, whenrange.end <= block.timestamp
is true, the calculation ofprevClosePrice
callsderivePrice(range, range.end - 1);
. Subtracting 1 from range.end (for your example periodEnd = 1693512000), the elapsed days will be 30 due to precision errors in:uint256 elapsedDays = (currentTime - currentRange.start) / DAY;
A precision error causes the elapsed days to be 30 and the last
dailyIr
will not be compounded because the elapsed days will be one day less.PoC
Tools Used
Manual Review
Recommended Mitigation Steps
Do not substract 1 from
range.end
Assessed type
Math
The text was updated successfully, but these errors were encountered: