Periodattimestamp will return different period for the same timestamp input
The view function periodAtTimestamp computes the period using the current block timestamp rather than the timestamp passed in, so querying the same historical timestamp returns a different period as time passes. An attacker or user could get incorrect period data from this view function, though no other accounting logic is affected.
- Disclosed after under an hour
#59715 [SC-Low] periodattimestamp will return different period for the same timestamp input
Submitted on Nov 15th 2025 at 03:54:46 UTC by @y4y for Audit Comp | Firelight
- Report ID: #59715
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/firelight-protocol/firelight-core/blob/main/contracts/FirelightVault.sol
- Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
In FirelightVault::periodAtTimestamp, the function returns the corresponding period at given timestamp. The view function should return the same period regardless how many other periods have passed, but in reality, periods passed can affect the returned value.
Vulnerability Details
The issue lies in the usage of _sinceEpoch:
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;
}
And in _sinceEpoch, it uses the current timestamp instead of the supplied one:
function _sinceEpoch(uint48 epoch) private view returns (uint48) {
return Time.timestamp() - epoch;
}
Since in periodAtTimestamp, the period to query is at the given timestamp variable, not the current one. The discrepancy here would make function return incorrect period for the same timestamp after some time has passed.
Impact Details
No other key accounting logic will be affected, only the view function periodAtTimestamp will return incorrect data.
References
Proof of Concept
Proof of Concept
Append the following test to period_update.js:
it('periodAtTimestamp returns different values for the same timestamp as time passes', async () => {
const period_start = await firelight_vault.currentPeriodStart()
const period_at_start_before = await firelight_vault.periodAtTimestamp(period_start)
const duration = await current_period_duration()
await time.increase(duration * 2)
const period_at_start_after = await firelight_vault.periodAtTimestamp(period_start)
expect(period_at_start_after).to.equal(period_at_start_before + 2n)
})
The PoC will get the period at T from periodAtTimestamp at timestamp of T0, then fast forward to time T1. Normally, it's expected that the result period would be the same, but the expect statement will verify the period fetched at T1 will be 2 more than the one fetched at T0.
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 the current block timestamp instead of the timestamp supplied to periodAtTimestamp, so the calculation drifts as time passes.
Impact
Only the view function periodAtTimestamp returns incorrect data; no other key accounting logic is affected.
What the attacker needed
None
The fix
The function should compute the elapsed time from the supplied timestamp rather than the current block timestamp.
How it was found
- Read the period for a fixed timestamp using periodAtTimestamp.
- Advance the chain time by two period durations.
- Read the period for the same fixed timestamp again.
- Observe the second result is two periods larger than the first.
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. Instead of using the moment you ask about, it secretly uses the current time, so the answer changes as the clock moves even though your question did not. This is a bug in a read-only helper, not in the money-handling code.
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.