The getEpoch function is vulnerable to truncation when casting a uint256 value to uint16if the number exceeds 6,535, Since uint16 can only store values between 0 and 6,535
##Vulnerability Details
The function that is affected is getEpoch, here is the line of code:
The function calculates the number of epochs by dividing the difference between _timestamp and startTime by epochDuration.
This calculation results in a uint256 value. However, the function then casts this value to uint16.
Since uint16 can only store values between 0 and 6,535, any value larger than 6,535will be truncated, meaning only the lower 16 bits are kept, and the higher bits are discarded.
This can lead to the function returning an incorrect epoch number, especially as time progresses and more epochs pass.
Here is the relevant git-hub link:
This truncation can result in incorrect epoch numbers and can cause significant issues in any part of the contract that relies on accurate epoch calculations.
Manual
Use a higher value or if returning a uint16 is absolutely necessary, consider implementing a check before the cast to ensure the value does not exceed 6,535. If it does, the function should revert or handle the case appropriately to prevent incorrect values from being returned.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.