Skip to content
Business logic Audit finding Intermediate

FirelightVault.sol#periodAtTimestamp() will return an incorrect period number due to flawed logic

The periodAtTimestamp function in FirelightVault.sol calculates the period number using the current block timestamp instead of the provided timestamp, so querying a past or future timestamp returns an incorrect period number. An attacker could rely on this wrong value, affecting operations that depend on it.

maggie Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

59533 sc low firelightvault sol periodattimestamp will return an incorrect period number due to flawed logic

Submitted on Nov 13th 2025 at 07:33:03 UTC by @maggie for Audit Comp | Firelight

Description

Brief/Intro

FirelightVault.sol#periodAtTimestamp() is used to get the period number for the given timestamp. In order to get the period number, we should get the period configuration for the give timestamp first, then add passed period number to startingPeriod of period configuration. However, the passed period number is calculated with current timestamp instead of the give timestamp, which will cause incorrect period number.

Vulnerability Details

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

periodConfiguration for the give timestamp is fetched, then add periodConfiguration.startingPeriod with passed period number. Passed period number = (time since epoch) /periodConfiguration.duration :

(timestamp - periodConfiguration.epoch) / periodConfiguration.duration.

In function periodAtTimestamp(uint48 timestamp), passed period number is calculated as following:

_sinceEpoch(periodConfiguration.epoch) / periodConfiguration.duration  

which is :

(Time.timestamp() - periodConfiguration.epoch) / periodConfiguration.duration.

If the give timestamp is not the current time, this function could return an incorrect period number.

We assume the following period configuration for the give time, 2025-11-03 10:00:00.

1, epoch: 2025-11-01 08:00,

2, duration: 1 days,

3, startingPeriod: 10

Now, user want to get period number for 2025-11-03 10:00:00, the expected period number should be:

startingPeriod + passed period number =

10 + (2025-11-03 10:00:00 - 2025-11-01 08:00) / 1days =

10 + 2 = 12

In fact, if users query the timestamp(2025-11-03 10:00:00) at 2025-11-06 10:00:00, user will get 10 + (2025-11-06 10:00:00 - 2025-11-01 08:00) / 1days = 10 + 5 = 15.

If users query the timestamp(2025-11-03 10:00:00) at 2025-11-07 10:00:00, user will get 10 + (2025-11-07 10:00:00 - 2025-11-01 08:00) / 1days = 10 + 6 = 16.

Impact Details

FirelightVault.sol#periodAtTimestamp() is a public function opened to all users, if the given timestamp is not the current timestamp, users could get an incorrect period number, which will affect following operations.

References

https://github.com/firelight-protocol/firelight-core/blob/main/contracts/FirelightVault.sol#L249

Proof of Concept

Proof of Concept

PoC steps:

1, add new period configurations.

2, set current time to new_epoch+7days, and query period number for (new_epoch + 2days)

3, set current time to new_epoch + 14days, and query period number for (new_epoch + 2days)

4, period number in step 2 and step 3 should be the same.

Please add the following code to period_update.js and run the test:

 it('test periodAtTimestamp', async () => {
 const current_period_end = await firelight_vault.currentPeriodEnd(),
      new_epoch = Number(current_period_end) + await current_period_duration()

await firelight_vault.connect(period_configuration_updater).addPeriodConfiguration(new_epoch, PERIOD_TARGET_DURATION)

const [period_epoch, period_duration, period_start] = await firelight_vault.periodConfigurations(1),
      current_period = await firelight_vault.currentPeriod()

expect(period_epoch).to.equal(new_epoch)
expect(period_duration).to.equal(PERIOD_TARGET_DURATION)
expect(period_start).to.equal(current_period + 2n)

await time.increaseTo(new_epoch + PERIOD_TARGET_DURATION);  //new epoch + 7 days
const period_number1 = await firelight_vault.periodAtTimestamp(new_epoch + 86400*2);
await time.increaseTo(new_epoch + PERIOD_TARGET_DURATION*2);  //new epoch + 14 days
const period_number2 = await firelight_vault.periodAtTimestamp(new_epoch + 86400*2);
await expect(period_number1).to.equal(period_number2)
 })

The original report as published on Immunefi, by maggie. 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 _sinceEpoch uses Time.timestamp() (the current time) rather than the timestamp argument passed to periodAtTimestamp.

Impact

Users could get an incorrect period number for any timestamp that is not the current time, which may affect operations that rely on this function.

What the attacker needed

None

The fix

The function should calculate the elapsed periods using the provided timestamp argument, not the current block timestamp.

How it was found

  1. Add new period configurations.
  2. Set the current time to new_epoch+7days and query the period number for new_epoch+2days.
  3. Set the current time to new_epoch+14days and query the period number for new_epoch+2days.
  4. Observe that the period numbers from steps 2 and 3 differ, though they should be the same.

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 is supposed to tell you which 'period' (a time slot) a given date falls into. It mistakenly uses today's date instead of the date you asked about, so the answer changes depending on when you ask. This can mislead other parts of the system that trust the result.

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 maggie

View all

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