Skip to content
DoS Audit finding Intermediate

Timestamp Ignored, Current Block Time Used

The periodAtTimestamp function ignores the caller-supplied timestamp and instead uses the current block time, causing incorrect results for past or future queries and a revert when a future configuration's epoch is ahead of the current time. An attacker could cause a denial of service on this view function or obtain wrong period information, potentially leading to temporary freezing of funds or NFTs.

jesse03 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#59385 [SC-Low] timestamp ignored current block time used

Submitted on Nov 11th 2025 at 18:22:24 UTC by @jesse03 for Audit Comp | Firelight

Description

periodAtTimestamp() calls periodConfigurationAtTimestamp(timestamp) (good), but then ignores the caller‑supplied timestamp and computes with the current block time via _sinceEpoch(periodConfiguration.epoch), which internally does Time.timestamp() - epoch.

This creates two wrong/unsafe behaviors that are directly tied to what periodConfigurationAtTimestamp may return:

  1. Wrong result for past/future lookups.
    For any timestamp != block.timestamp, the returned period number is computed using now instead of the provided timestamp. So the function returns the current period, not the period at the given time.
  2. Underflow & revert for future timestamps (DoS on view).
    periodConfigurationAtTimestamp can legitimately return a configuration whose epoch is in the future (e.g., you query a time after a scheduled future configuration). When epoch > block.timestamp, _sinceEpoch(epoch) does block.timestamp - epoch and underflows, causing a revert.

Minimal repro:

  • Assume current time t=105, first config: epoch=100, duration=10.
  • An admin schedules a new config at epoch=110 (the next period boundary) with duration=20.
  • Call periodAtTimestamp(115) now (i.e., while block.timestamp is still 105).

Flow:

  • periodConfigurationAtTimestamp(115) ⇒ returns the future config {epoch:110, duration:20}.
  • _sinceEpoch(110) ⇒ 105 - 110 ⇒ underflow → revert.

Even without the underflow, for any past timestamp (e.g., timestamp=101) the function wrongly calculates using block.timestamp rather than 101, so the answer is incorrect.


Root cause:

Solidity
function periodAtTimestamp(uint48 timestamp) public view returns (uint256) {
    PeriodConfiguration memory periodConfiguration = periodConfigurationAtTimestamp(timestamp);
    // BUG: uses current time instead of the input timestamp
    return periodConfiguration.startingPeriod
        + _sinceEpoch(periodConfiguration.epoch) / periodConfiguration.duration;
}

function _sinceEpoch(uint48 epoch) private view returns (uint48) {
    return Time.timestamp() - epoch; // underflows if epoch > now
}

Because periodConfigurationAtTimestamp can return a config with epoch > now when you ask about the future, the subsequent subtraction against now is unsafe and logically wrong.


Correct fix:

Use the provided timestamp in the arithmetic; do not derive from current time.

Solidity
function periodAtTimestamp(uint48 timestamp) public view returns (uint256) {
    PeriodConfiguration memory pc = periodConfigurationAtTimestamp(timestamp);
    // safe: pc.epoch <= timestamp by construction of periodConfigurationAtTimestamp
    return pc.startingPeriod + (timestamp - pc.epoch) / pc.duration;
}

You can then delete _sinceEpoch, or (if you prefer keeping a helper) make it take the reference timestamp explicitly:

Solidity
function _sinceEpoch(uint48 ref, uint48 epoch) private pure returns (uint48) {
    // ref is the timestamp you're evaluating at
    return ref - epoch;
}

and call:

Solidity
return pc.startingPeriod + _sinceEpoch(timestamp, pc.epoch) / pc.duration;

Proof of Concept

const { loadFixture, time } = require('@nomicfoundation/hardhat-network-helpers')
const { deployVault } = require('./setup/fixtures.js')
const { expect } = require('chai')

describe('periodAtTimestamp POC (bug reproduction)', function () {
  let firelight_vault, period_configuration_updater

  const DECIMALS = 6,
        INITIAL_DEPOSIT_LIMIT =  '20000000000', // 20k tokens (with 6 decimals)
        PERIOD_CONFIGURATION_DURATION = 172800   // 2 days

  before(async () => {
    ({ firelight_vault, period_configuration_updater } = await loadFixture(
      deployVault.bind(null, {
        decimals: DECIMALS,
        initial_deposit_limit: INITIAL_DEPOSIT_LIMIT,
        period_configuration_duration: PERIOD_CONFIGURATION_DURATION
      })
    ))
  })

  it('BUG: returns current period for a past timestamp (ignores input timestamp)', async () => {
    // Move forward one full period to ensure there is a "past" period to query
    const currentPeriodDuration = Number(
      (await firelight_vault.currentPeriodEnd()) - (await firelight_vault.currentPeriodStart())
    )
    await time.increase(currentPeriodDuration)

    const currentPeriod = await firelight_vault.currentPeriod()
    const currentStart = Number(await firelight_vault.currentPeriodStart())

    // Choose a timestamp strictly in the past, inside the previous period
    const pastTs = currentStart - 1

    // BUG: The function under test uses block.timestamp internally, so this returns the current period
    const periodAtPast = await firelight_vault.periodAtTimestamp(pastTs)
    expect(periodAtPast).to.equal(currentPeriod) // demonstrates the bug
  })

  it('BUG: reverts for future timestamp when future epoch > now (underflow)', async () => {
    // Schedule a new period configuration in the future (at the end of the next period)
    const currentEnd = Number(await firelight_vault.currentPeriodEnd())
    const currentPeriodDuration = Number(
      (await firelight_vault.currentPeriodEnd()) - (await firelight_vault.currentPeriodStart())
    )

    const newEpoch = currentEnd + currentPeriodDuration
    const newDuration = 3 * 24 * 60 * 60 // 3 days, divisible by 1 day

    await firelight_vault.connect(period_configuration_updater).addPeriodConfiguration(newEpoch, newDuration)

    // Query a timestamp after the scheduled future configuration starts, while block.timestamp is still before it
    const queryTs = newEpoch + 1

    // BUG: Internally computes Time.timestamp() - epoch, which underflows and reverts
    await expect(firelight_vault.periodAtTimestamp(queryTs)).to.be.reverted
  })
})

The original report as published on Immunefi, by jesse03. 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

Root cause

The function periodAtTimestamp uses the current block timestamp instead of the provided timestamp when calculating the period, and the helper _sinceEpoch subtracts the epoch from the current time, which underflows if the epoch is in the future.

Impact

The function returns incorrect period numbers for past or future timestamps and reverts for future timestamps when a future configuration's epoch is ahead of the current block time, potentially causing a denial of service on this view function and temporary freezing of funds or NFTs.

What the attacker needed

A future period configuration is scheduled; Caller queries a timestamp after that future epoch

The fix

The function should use the provided timestamp in the arithmetic instead of the current block time, and the helper should take the reference timestamp explicitly to avoid underflow.

How it was found

  1. Assume current time is 105, first config epoch=100, duration=10.
  2. Admin schedules a new config at epoch=110 with duration=20.
  3. Call periodAtTimestamp(115) while block.timestamp is still 105.
  4. periodConfigurationAtTimestamp(115) returns the future config {epoch:110, duration:20}.
  5. _sinceEpoch(110) computes 105 - 110, causing an underflow and revert.

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 is supposed to tell you the period number for a given time actually uses the current time instead. This means if you ask about a past or future time, you get the wrong answer, and if you ask about a future time when a new configuration is scheduled, the function crashes. This could stop other parts of the system from working correctly.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by jesse03

View all

5 more disclosed reports, best first.

More from Firelight

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.