Skip to content
Business logic Audit finding Beginner

PeriodAtTimestamp function is incorrectly implemented and always returns period at current timestamp.

The periodAtTimestamp function is meant to return the period number for a supplied timestamp, but it ignores that timestamp and uses the current block time instead. Anyone querying the period for a past or future timestamp receives the current period rather than the correct one.

Tadev Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

59115 sc low periodattimestamp function is incorrectly implemented and always returns period at current timestamp

Submitted on Nov 8th 2025 at 21:28:28 UTC by @Tadev for Audit Comp | Firelight

Description

Brief/Intro

As per the documentation, the periodAtTimestamp function is supposed to return the period number for the timestamp given. This function is defined as follows:

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

The problem is that the current implementation is incorrect, always returning the period at the current timestamp.

Vulnerability Details

The periodAtTimestamp function fetches the periodConfiguration of the provided timestamp. After that, it computes:

periodConfiguration.startingPeriod + _sinceEpoch(periodConfiguration.epoch) / periodConfiguration.duration

The problem lies in _sinceEpoch internal function, which doesn't use the provided timestamp but block.timestamp instead:

    function _sinceEpoch(uint48 epoch) private view returns (uint48) {
        return Time.timestamp() - epoch;
    }

This means the periodAtTimestamp function will return current period instead of period at given timestamp.

Impact Details

The impact of this issue is low as it consists of a logical error in periodAtTimestamp function. Anyone querying this function to know the period of a given timestamp will get a wrong result.

The impact is limited in the protocol itself because periodAtTimestamp function is used internally only in currentPeriod function, and the timestamp provided is the current block timestamp.

Proof of Concept

Proof of Concept

Please create a poc.js file in the test folder and copy paste the following code:

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

describe('POC LOW', function() {
  const DECIMALS = 18,
        INITIAL_DEPOSIT_LIMIT = ethers.parseUnits('100000', DECIMALS)

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

  it('demonstrates periodAtTimestamp ignores the timestamp parameter', async () => {
    const currentTime = await time.latest()
    const periodDuration = config.period_configuration_duration
    
    console.log(`\n  Current block timestamp: ${currentTime}`)
    console.log(`  Period duration: ${periodDuration} seconds`)
    
    // Get current period
    const currentPeriod = await firelight_vault.currentPeriod()
    console.log(`  Current period: ${currentPeriod}`)
    
    // Try to query period at current timestamp
    const periodAtNow = await firelight_vault.periodAtTimestamp(currentTime)
    console.log(`\n  periodAtTimestamp(${currentTime}) = ${periodAtNow}`)
    console.log(`  ✓ Correct: matches current period`)
    
    // Try to query period 3 periods in the future
    const futureTimestamp = currentTime + (periodDuration * 3)
    const periodAtFuture = await firelight_vault.periodAtTimestamp(futureTimestamp)
    const expectedPeriod = currentPeriod + 3n
    
    console.log(`\n  Query period at future timestamp:`)
    console.log(`  Future timestamp: ${futureTimestamp} (3 periods ahead)`)
    console.log(`  Expected period: ${expectedPeriod}`)
    console.log(`  periodAtTimestamp(${futureTimestamp}) = ${periodAtFuture}`)
    console.log(`  ✗ BUG: Returns ${periodAtFuture} instead of ${expectedPeriod}`)
  })
})

The output of this test is:

POC LOW

  Current block timestamp: 1766690171
  Period duration: 172800 seconds
  Current period: 0

  periodAtTimestamp(1766690171) = 0
  ✓ Correct: matches current period

  Query period at future timestamp:
  Future timestamp: 1767208571 (3 periods ahead)
  Expected period: 3
  periodAtTimestamp(1767208571) = 0
  ✗ BUG: Returns 0 instead of 3

This tests highlights that when querying the period at a given timestamp in the future, the function doesn't return the correct result. This issue is the same when querying with a timestamp that is in the past.

The original report as published on Immunefi, by Tadev. 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 internal helper _sinceEpoch uses the current block timestamp rather than the timestamp passed into periodAtTimestamp.

Impact

The impact is low: the function returns a wrong period for any timestamp other than the current one, but internally it is only called with the current block timestamp, so protocol behaviour is not otherwise affected.

What the attacker needed

None

The fix

The helper should compute the elapsed time from the supplied timestamp rather than the current block time, so the function honours its argument.

How it was found

  1. Deploy the vault using the test fixture.
  2. Read the current block time and the configured period duration.
  3. Query periodAtTimestamp with the current time and note it matches the current period.
  4. Query periodAtTimestamp with a time three periods in the future and observe it still returns the current period.

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 helper function that is supposed to answer 'which numbered time period does this date fall into?'. Internally it calls another helper that reads the clock of the blockchain right now instead of the date it was given, so every answer is the current period. The mistake only affects the answer to that question, not money held by the contract.

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 Tadev

View all

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