Skip to content
Smart contracts Audit finding Intermediate

Critical Timestamp Parsing Bug in getYear() of DateTime contract

The getYear function in the DateTime contract returns an incorrect year for certain timestamps near year boundaries, especially around leap years. An attacker could exploit this to misclassify timestamps, potentially breaking time-sensitive smart contract logic.

ubl4nk Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

50632 sc insight critical timestamp parsing bug in getyear of datetime contract

Submitted on Jul 26th 2025 at 22:03:45 UTC by @ubl4nk for Attackathon | Plume Network

Impacts:

  • It may break core application logic in time-sensitive smart contracts.

Description

Brief/Intro

A critical miscalculation exists in the getYear(uint256 timestamp) function of the DateTime contract. Under certain conditions—particularly near the end of leap years—the function returns an incorrect year, misclassifying timestamps in late December as belonging to the next calendar year (e.g., returning 2028 instead of 2029 OR returning 2033 instead of the correct 2032).

Vulnerability Details

Problematic code:

Solidity
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;
}

Expected: timestamp = 1861910430 ⇒ Should return year 2029
Actual: Returns 2028 ❌

This timestamp (1861910430) corresponds to 2029-01-01 00:00:30 UTC, but the function misclassifies it as 2028.

Additional timestamps that fail:

  • 1861910460 → 2029-01-01 00:01:00 → returns 2028 ❌
  • 1861914000 → 2029-01-01 01:00:00 → returns 2028 ❌
  • 1991212000 → 2032-12-31 22:13:20 → returns 2033 ❌
  • 1991212199 → 2032-12-31 22:16:39 → returns 2033 ❌
  • 1991212500 → 2032-12-31 22:21:40 → returns 2033 ❌

These demonstrate a consistent off-by-one bug near year boundaries due to leap year misestimation.

Root cause:

  • The rough approximation line
Solidity
year = uint16(ORIGIN_YEAR + timestamp / YEAR_IN_SECONDS);

does not account for the variable duration introduced by leap years. The later correction loop

Solidity
while (secondsAccountedFor > timestamp) { ... }

fails to adjust the estimate correctly in some boundary conditions, producing incorrect year outputs.

Recommendation

Instead of approximating the year and correcting backwards, use a forward loop that counts exact seconds per year. Example suggested implementation:

Solidity
function getYearFixed(uint256 timestamp) public pure returns (uint16) {
    uint16 year = ORIGIN_YEAR;
    uint256 secondsInYear;

    while (true) {
        secondsInYear = isLeapYear(year) ? LEAP_YEAR_IN_SECONDS : YEAR_IN_SECONDS;
        if (timestamp < secondsInYear) {
            break;
        }
        timestamp -= secondsInYear;
        year++;
    }
    return year;
}

Impact Details

It may break core application logic in time-sensitive smart contracts.

References

https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/plume/src/spin/DateTime.sol#L111-L134

Proof of Concept

<details> <summary>Proof of Concept (expand)</summary>

The report lists concrete timestamps demonstrating the misclassification:

  • 1861910430 (2029-01-01 00:00:30 UTC) → function returns 2028 (incorrect)
  • 1861910460 (2029-01-01 00:01:00 UTC) → returns 2028 (incorrect)
  • 1861914000 (2029-01-01 01:00:00 UTC) → returns 2028 (incorrect)
  • 1991212000 (2032-12-31 22:13:20 UTC) → returns 2033 (incorrect)
  • 1991212199 (2032-12-31 22:16:39 UTC) → returns 2033 (incorrect)
  • 1991212500 (2032-12-31 22:21:40 UTC) → returns 2033 (incorrect)

These examples can be used to reproduce the issue by invoking getYear(timestamp) against the referenced DateTime.sol implementation.

</details>

The original report as published on Immunefi, by ubl4nk. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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

Impact

It may break core application logic in time-sensitive smart contracts.

What the attacker needed

None

The fix

The function should be fixed by using a forward loop that counts exact seconds per year instead of approximating and correcting backwards.

How it was found

  1. Call getYear with timestamp 1861910430 (2029-01-01 00:00:30 UTC).
  2. Observe that the function returns 2028 instead of 2029.
  3. Call getYear with timestamp 1991212000 (2032-12-31 22:13:20 UTC).
  4. Observe that the function returns 2033 instead of 2032.

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.

Smart contracts sometimes need to know the year for a given timestamp (a number representing a date and time). The function that calculates the year makes a rough guess and then tries to correct it, but the correction fails for some dates near the start or end of a year, especially around leap years. This means the contract might think a date is in the wrong year, which could cause problems if the contract relies on the year for decisions.

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 ubl4nk

View all

1 more disclosed report, best first.

More from Plume Network

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.