Skip to content
Business logic Audit finding Beginner

Period calculation does not use provided timestamp in periodattimestamp

The periodAtTimestamp function ignores the timestamp argument and instead subtracts the epoch from the current block time, so querying a future timestamp can revert with an underflow or return a period number that changes as real time passes. An attacker or integrator relying on this view gets wrong period information, though no funds are lost.

sahuang Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#59559 [SC-Low] period calculation does not use provided timestamp in periodattimestamp

Submitted on Nov 13th 2025 at 14:42:17 UTC by @sahuang for Audit Comp | Firelight

Description

Summary

The periodAtTimestamp() function contains a logic error where it uses the current block timestamp instead of the provided timestamp parameter when calculating period numbers. This causes two potential failure modes:

  1. Underflow Reverts: When querying future timestamps before the epoch is reached, the function reverts with an arithmetic underflow
  2. Silent Incorrect Returns: When querying future timestamps after the epoch is reached, the function returns an incorrect period number based on current time instead of the requested timestamp

Both failures break the contract's ability to provide accurate period information, and this falls in the "Contract fails to deliver promised returns, but doesn't lose value" low-severity impact.

Finding Description

The vulnerability exists in the interaction between two functions:

  1. periodAtTimestamp(uint48 timestamp):
Solidity
function periodAtTimestamp(uint48 timestamp) public view returns (uint256) {
    PeriodConfiguration memory periodConfiguration = periodConfigurationAtTimestamp(timestamp);
    return periodConfiguration.startingPeriod + _sinceEpoch(periodConfiguration.epoch) / periodConfiguration.duration;
}
  1. _sinceEpoch(uint48 epoch):
Solidity
function _sinceEpoch(uint48 epoch) private view returns (uint48) {
    return Time.timestamp() - epoch;  // @audit: Uses current time, not the timestamp parameter
}

The _sinceEpoch() function ignores the caller-supplied timestamp parameter and always uses Time.timestamp() (current block time). This creates an incorrect calculation path.

Impact

As discussed above, the function returns incorrect value and satisfies the low severity criteria.

Recommendation

Modify _sinceEpoch() to accept and use the actual timestamp parameter:

Solidity
function _sinceEpoch(uint48 epoch, uint48 timestamp) private pure returns (uint48) {
    return timestamp - epoch;
}

Then update respective callers.

Proof of Concept

Proof of Concept

We update period_update.js and add another test under describe('Period update test', function() section:

JavaScript
it("periodAtTimestamp should map to the same period", async () => {
    // choose a timestamp ahead of the current block time
    const t0 = await time.latest();
    const ts = t0 + 2 * PERIOD_CONFIGURATION_DURATION;

    const duration = await current_period_duration();
    expect(duration).to.equal(PERIOD_CONFIGURATION_DURATION);

    // snapshot the computed period before time movement
    const initial = await firelight_vault.periodAtTimestamp(ts);
    // move forward exactly one period
    await time.increase(PERIOD_CONFIGURATION_DURATION);
    // query again after the time jump
    const shifted = await firelight_vault.periodAtTimestamp(ts);

    expect(shifted).to.equal(initial);
});

Running the test would fail. This demonstrates a different return value is from expected value.

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

Likely the helper that computes time since the epoch reads the live block timestamp rather than accepting the timestamp passed by the caller.

Impact

The view returns an incorrect period number that shifts with real time, and can revert with an arithmetic underflow for future timestamps before the epoch, so the contract fails to deliver promised returns without losing value.

What the attacker needed

None

The fix

The helper should take the timestamp as an argument and compute the difference from it, with callers updated accordingly.

How it was found

  1. Pick a timestamp ahead of the current block time.
  2. Call periodAtTimestamp with that timestamp and record the result.
  3. Advance chain time by one period duration.
  4. Call periodAtTimestamp with the same timestamp again and compare the two results.

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 read-only function that is supposed to tell you which period a given moment in time belongs to. Internally it subtracts the start of the schedule from the current clock instead of from the moment you asked about, so the answer is wrong and can even crash the call. Nothing is stolen, but anything that trusts the answer gets bad data.

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.