50632 sc insight critical timestamp parsing bug in getyear of datetime contract
Description
Brief/Intro
Vulnerability Details
function getYear(
uint256 timestamp
) public pure returns (uint16) {
uint256 secondsAccountedFor = 0;
uint16 year;
uint256 numLeapYears;
// Rough approximation
year = uint16(ORIGIN_YEAR + timestamp / YEAR_IN_SECONDS);
numLeapYears = leapYearsBefore(year) - leapYearsBefore(ORIGIN_YEAR);
secondsAccountedFor += LEAP_YEAR_IN_SECONDS * numLeapYears;
secondsAccountedFor += YEAR_IN_SECONDS * (year - ORIGIN_YEAR - numLeapYears);
while (secondsAccountedFor > timestamp) {
if (isLeapYear(uint16(year - 1))) {
secondsAccountedFor -= LEAP_YEAR_IN_SECONDS;
} else {
secondsAccountedFor -= YEAR_IN_SECONDS;
}
year -= 1;
}
return year;
}Recommendation
Impact Details
References
Proof of Concept
Previous51456 sc high token creator can revoke the upgrader role from the factory in order to avoid upgradesNext50951 sc high inconsistent streak count usage between jackpot and raffle ticket calculations
Was this helpful?