The function periodattimestamp uses the current timestamp instead of provided timestamp causing incorrect period calculation
The function periodAtTimestamp is supposed to return the period number for a given timestamp, but it uses the current block timestamp instead of the provided timestamp when calculating elapsed periods. As a result, querying the same future timestamp at different times returns different, incorrect period numbers.
- Disclosed after under an hour
59369 sc low the function periodattimestamp uses the current timestamp instead of provided timestamp causing incorrect period calculation
Submitted on Nov 11th 2025 at 16:20:02 UTC by @Y4nhu1 for Audit Comp | Firelight
- Report ID: #59369
- 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
The function periodAtTimestamp uses the current timestamp for period number calculation, which leads to incorrect results when querying a timestamp other than the current one.
Vulnerability Details
The function periodAtTimestamp should return the period number for the timestamp given. The statement _sinceEpoch(periodConfiguration.epoch) / periodConfiguration.duration calculates the elapsed period based on the time elapsed since the start time of the current period configuration, i.e. periodConfiguration.epoch.
function periodAtTimestamp(uint48 timestamp) public view returns (uint256) {
// [...]
return periodConfiguration.startingPeriod + _sinceEpoch(periodConfiguration.epoch) / periodConfiguration.duration;
}
According to the function definition, the time elapsed from the periodConfiguration.epoch to the parameter timestamp should be used. However, the function _sinceEpoch calculates the time elapsed from the periodConfiguration.epoch to the current timestamp.
function _sinceEpoch(uint48 epoch) private view returns (uint48) {
return Time.timestamp() - epoch;
}
Impact Details
This leads to users or other contracts obtaining incorrect results when querying a timestamp other than the current one.
References
- https://github.com/firelight-protocol/firelight-core/blob/db36312f1fb24efc88c3fde15a760defbc3e6370/contracts/FirelightVault.sol#L249
- https://github.com/firelight-protocol/firelight-core/blob/db36312f1fb24efc88c3fde15a760defbc3e6370/contracts/FirelightVault.sol#L795-L797
Proof of Concept
Proof of Concept
Run the test using the command npx hardhat test --grep "periodAtTimestamp returns diffe rent values as time progresses".
Without adding a new period configuration, the period number for a future timestamp should not change. However, the test results show that over time, periodAtTimestamp() returns different results for the same timestamp, indicating a calculation error.
diff --git a/test/period_update.js b/test/period_update.js
index 97c4dee..1808848 100644
--- a/test/period_update.js
+++ b/test/period_update.js
@@ -33,6 +33,18 @@ describe('Period update test', function() {
withdraw_period_one = (await withdraw_request.wait()).logs[1].args[3]
})
+ it('periodAtTimestamp returns different values as time progresses', async () => {
+ let timestamp = (await time.latest()) + PERIOD_CONFIGURATION_DURATION * 5; // a future timestamp
+
+ expect(await current_period_duration()).to.equal(PERIOD_CONFIGURATION_DURATION);
+
+ const period_at_timestamp_before = await firelight_vault.periodAtTimestamp(timestamp);
+
+ await time.increase(PERIOD_CONFIGURATION_DURATION);
+
+ expect(await firelight_vault.periodAtTimestamp(timestamp)).to.equal(period_at_timestamp_before + 1n);
+ })
+
it('should validate initial period duration', async () => {
expect(await current_period_duration()).to.equal(PERIOD_CONFIGURATION_DURATION)
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 function _sinceEpoch ignores its epoch argument for the end time and subtracts from the current block timestamp instead of the timestamp passed to periodAtTimestamp.
Impact
Users or other contracts could receive incorrect period numbers when querying any timestamp other than the current one, which may lead to wrong decisions based on that data.
What the attacker needed
None
The fix
The function should be fixed to calculate elapsed time using the provided timestamp rather than the current block timestamp.
How it was found
- Call periodAtTimestamp with a future timestamp and record the result.
- Advance the blockchain time by one period duration.
- Call periodAtTimestamp again with the same future timestamp and observe the result has increased by one.
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 function that should tell you which 'period' (like a time slot) a particular date falls into. But instead of using the date you give it, the function secretly uses today's date, so the answer changes as time passes even though you asked about the same date. This makes the function unreliable for anything other than the current moment.
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.