Skip to content
Business logic Audit finding Beginner

Periodattimestamp returns incorrect period numbers for non current timestamps

The periodAtTimestamp function uses the current block time instead of the supplied timestamp when computing elapsed time, so it always returns the current period number rather than the period for the queried time. Any caller relying on it for historical analysis receives incorrect period data.

Falendar Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#59031 [SC-Low] periodattimestamp returns incorrect period numbers for non current timestamps

Submitted on Nov 7th 2025 at 21:37:11 UTC by @Falendar for Audit Comp | Firelight

Description

Brief/Intro

The periodAtTimestamp function doesn't return the correct period for the provided timestamp.

Vulnerability Details

The vulnerability exists in the interaction between two functions:

Solidity
function periodAtTimestamp(uint48 timestamp) public view returns (uint256) {
    PeriodConfiguration memory periodConfiguration = periodConfigurationAtTimestamp(timestamp);
    return periodConfiguration.startingPeriod + _sinceEpoch(periodConfiguration.epoch) / periodConfiguration.duration;
}
Solidity
function _sinceEpoch(uint48 epoch) private view returns (uint48) {
    return Time.timestamp() - epoch;
}

The bug occurs because:

  1. periodAtTimestamp(timestamp) accepts a timestamp parameter indicating which point in time to query
  2. It correctly uses this parameter to fetch the appropriate periodConfiguration via periodConfigurationAtTimestamp(timestamp)
  3. However, when calculating the period number, it calls _sinceEpoch(periodConfiguration.epoch) which ignores the input parameter and uses Time.timestamp() (current block time) instead
  4. This means the elapsed time calculation uses the wrong reference point: current time instead of the queried timestamp

Impact Details

Any external protocol, contract, user or future implementations that calls periodAtTimestamp for historical analysis will receive incorrect data.

References

https://github.com/firelight-protocol/firelight-core/blob/db36312f1fb24efc88c3fde15a760defbc3e6370/contracts/FirelightVault.sol#L246-L250

Proof of Concept

Proof of Concept

Example

periodConfigurations[0] = {epoch: 1000, duration: 100, startingPeriod: 0}

Period timeline:

Period 0: 1000-1100

Period 1: 1100-1200

Period 2: 1200-1300 (this is the period that needs to be retrieved)

...

Period 10: 2000-2100

Current blockchain timestamp: Time.timestamp() = 2000

Retrieving period at timestamp 1250: vault.periodAtTimestamp(1250);

elapsed = Time.timestamp() - 1000 = 2000 - 1000 = 1000

periodsElapsed = 1000 / 100 = 10

periodNumber = 0 + 10 = 10 (current value, WRONG)

Result: Returns Period 10 instead of Period 2 (always returns current period)

The original report as published on Immunefi, by Falendar. 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 helper that computes elapsed time reads the current block timestamp instead of the timestamp passed into periodAtTimestamp.

Impact

Callers using the function for historical analysis receive incorrect period numbers, though no funds are lost.

What the attacker needed

None

How it was found

  1. Configure a period schedule with a known epoch, duration and starting period.
  2. Note the current blockchain timestamp is later than the timestamp to query.
  3. Call periodAtTimestamp with a historical timestamp inside an earlier period.
  4. Observe the returned period number matches the current period, not the queried one.

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 has a function meant to tell you which time period a given moment falls into. It looks up the right settings for that moment, but then measures how much time has passed from the start of the schedule until now, not until the moment you asked about. So it always reports the current period, even when you ask about a past time.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Firelight

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.