Skip to content
Business logic Audit finding Intermediate

PeriodAtTimestamp() uses current time instead of input timestamp, returning wrong period numbers

The periodAtTimestamp function ignores its timestamp argument and uses the current block time to compute the period number. This returns incorrect period numbers for historical queries, potentially mis-scheduling accounting and causing unfairness between users.

IronsideSec Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#59937 [SC-Low] periodattimestamp uses current time instead of inputtimestamp returning wrong period

Submitted on Nov 17th 2025 at 03:42:51 UTC by @IronsideSec for Audit Comp | Firelight

Description

Brief/Intro

The vault’s periodAtTimestamp(timestamp) ignores its input timestamp argument and computes using the current block time. This yields incorrect period numbers for historicalqueries, can mis-schedule accounting tied to periods, and enables unfairness between users whose actions are recorded in different periods than intended.

Vulnerability Details

  • Concrete math with the PoC’s numbers:
    • Initial config: epoch = 100, duration = 10
    • Later config: at epoch = 160, duration becomes 20 (unrelated to the bug but present in the PoC)
    • Now = current time: 150
    • Query: periodAtTimestamp( t = 115)
    • Returned (buggy): starting + (now − epoch)/duration = 0 + (150 − 100)/10 = 5 period
    • Correct: starting + (t − epoch)/duration = 0 + (115 − 100)/10 = 1 period
  • Buggy code (uses now timestamp, not input):
function periodAtTimestamp(uint48 timestamp) public view returns (uint256) {
    PeriodConfiguration memory periodConfiguration = periodConfigurationAtTimestamp(timestamp);
    // solhint-disable-next-line max-line-length
    return periodConfiguration.startingPeriod + _sinceEpoch(periodConfiguration.epoch) / periodConfiguration.duration;
}

/**
 * ...
 */
function _sinceEpoch(uint48 epoch) private view returns (uint48) {
    return Time.timestamp() - epoch;
}
  • PoC in tests (exact lines):
function test_PeriodAtTimestamp_DependsOnNow_NotInput() public {
    // Force epoch = 100 (days) by warping before initialize of a fresh vault
    vm.warp(100 days);

    FirelightVault v = new FirelightVault();
    FirelightVault.InitParams memory params = FirelightVault.InitParams({
        defaultAdmin: address(this),
        limitUpdater: address(this),
        blocklister: address(0),
        pauser: address(0),
        periodConfigurationUpdater: address(this),
        depositLimit: LIMIT,
        periodConfigurationDuration: 10 days // duration = 10
    });

    // Initialize fresh vault with 10-day periods starting at epoch=100 days
    bytes memory initCalldata = abi.encodeWithSelector(
        v.initialize.selector,
        address(token),
        "Vault",
        "VLT",
        abi.encode(params)
    );
    (bool ok, ) = address(v).call(initCalldata);
    require(ok, "init failed");

    // "after a while it is 20": change duration to 20 starting at epoch = 160 days
    v.addPeriodConfiguration(uint48(160 days), uint48(20 days));

    // Now = 150
    vm.warp(150 days);

    // Query period at t = 115
    uint48 t = uint48(115 days);
    uint256 actual = v.periodAtTimestamp(t);

    // Buggy function uses now: starting(0) + (150-100)/10 = 5
    assertEq(actual, 5, "bug: returns period 5 at now=150");

    // Correct: starting(0) + (115-100)/10 = 1
    uint256 expected = (uint256(115 days) - uint256(100 days)) / uint256(10 days);
    assertEq(expected, 1, "sanity: expected period 1");

    // Prove mismatch
    assertTrue(actual != expected, "function should have used input timestamp");
}

Impact Details

  • Incorrect period classification for historical timestamps used by other logic (e.g., scheduling, accounting, limits) can:
    • Allocate or settle amounts in wrong periods.
    • Create unfairness between users whose actions are bucketed into unintended periods.
    • Break assumptions around period-based configuration changes.

References

  • Affected function: periodAtTimestamp in contracts/FirelightVault.sol lines 194–210 (see snippet above).
  • Reproducer: test/X.t.sol lines 87–134 (see snippet above).

Link to Proof of Concept

https://gist.github.com/IronsideSec/7a44ccd02d3a87d17a19cc9b3e1edf2f

Proof of Concept

Proof of Concept

  1. run forge init --force
  2. Delete test/Counter.t.sol and script/Counter.s.sol
  3. Create test/POC.t.sol and paste the code copied from https://gist.github.com/IronsideSec/7a44ccd02d3a87d17a19cc9b3e1edf2f
  4. then run forge t --mt test_PeriodAtTimestamp_DependsOnNow_NotInput -vvvv

The original report as published on Immunefi, by IronsideSec. 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 calls _sinceEpoch with the configuration's epoch but _sinceEpoch uses Time.timestamp() (current time) instead of the input timestamp.

Impact

Incorrect period classification for historical timestamps could allocate or settle amounts in wrong periods, create unfairness between users, and break assumptions around period-based configuration changes.

What the attacker needed

None

The fix

The function should use the input timestamp instead of the current time when computing the period.

How it was found

  1. Set up a fresh vault with epoch 100 days and duration 10 days.
  2. Add a new period configuration at epoch 160 days with duration 20 days.
  3. Warp time to 150 days.
  4. Call periodAtTimestamp with t = 115 days.
  5. Observe it returns 5 instead of the correct 1.

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 which period a given time belongs to instead uses the current time. So if you ask about a past time, it gives you the period for now, not for that past time. This can mess up calculations that depend on periods.

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 by IronsideSec

View all

28 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.

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.