59168 sc low incorrect time semantics in periodattimestamp cause off chain miscalculations and data inconsistency
Submitted on Nov 9th 2025 at 14:33:19 UTC by @Arkindyo for Audit Comp | Firelight
Report ID: #59168
Report Type: Smart Contract
Report severity: Low
Target: https://github.com/firelight-protocol/firelight-core/blob/main/contracts/FirelightVault.sol
Impacts:
Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
Description
Brief/Intro
The periodAtTimestamp(uint48 timestamp) function in FirelightVault.sol returns the current period number based on the current block timestamp, not the period for the provided timestamp.
##Vulnerability Details
The periodAtTimestamp function is documented to return “the period number for the given timestamp”, but it computes with Time.timestamp() (current block time) instead of the provided timestamp. Although it correctly selects the period configuration applicable to the provided timestamp via periodConfigurationAtTimestamp(timestamp), the quotient uses the elapsed time since epoch based on “now” rather than the provided timestamp.
firelight-core/contracts/FirelightVault.sol::periodAtTimestamp#249
firelight-core/contracts/FirelightVault.sol::_sinceEpoch#796
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;
}
Impact Details
Incorrect historical/future queries: Any off-chain analytics, dashboards, or integrators using
periodAtTimestamp(pastOrFutureTs)will receive the period number for “now” (under the configuration that would apply totimestamp), not for the actualtimestamp.Mis-scheduling and mislabeling: Systems that plan actions or label data by period number may misassign entries, leading to misleading reports and operational errors (e.g., wrong “batch” attribution or period-based KPIs).
User confusion and governance optics: Period-based histories and charts may appear inconsistent, undermining trust and complicating audits.
Recommended Fix
Update the computation to use the provided timestamp:
The contract enforces left-closed, right-open intervals for period divisions. With the correct formula, when
timestamp == pc.epoch + k * pc.duration, the function should returnpc.startingPeriod + k.Period alignment and configuration transitions are already guarded by
_addPeriodConfigurationandperiodConfigurationAtTimestamp, so using(timestamp - pc.epoch)is safe (no underflow) becausetimestamp >= pc.epochfor the selected configuration.
References
Code: firelight-core/contracts/FirelightVault.sol, periodAtTimestamp(uint48 timestamp) and _sinceEpoch(uint48 epoch).
firelight-core/contracts/FirelightVault.sol::periodAtTimestamp#249
firelight-core/contracts/FirelightVault.sol::_sinceEpoch#796
Proof of Concept
Proof of Concept
The periodAtTimestamp function uses the current block time instead of the input timestamp, causing incorrect period numbers when querying past or future timestamps. This test test_PeriodAtTimestamp_UsesNowInsteadOfArg() publicconstructs a period configuration that has already started in the past, then queries with a "past timestamp" to assert that the returned value equals the period based on the current time rather than the correct one based on the query timestamp.
Was this helpful?