59334 sc low periodattimestamp function uses current timestamp instead of input parameter causing incorrect period calculation for historical or future queries
#59334 [SC-Low] `periodAtTimestamp` function uses current timestamp instead of input parameter, causing incorrect period calculation for historical or future queries
Submitted on Nov 11th 2025 at 08:43:14 UTC by @perseverance for Audit Comp | Firelight
Report ID: #59334
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
Short summary
The periodAtTimestamp(uint48 timestamp) function in FirelightVault.sol accepts a timestamp parameter but internally uses Time.timestamp() (current block timestamp) instead of the provided timestamp when calculating the period number. This causes the function to return incorrect period numbers when querying historical or future timestamps, breaking the expected behavior of the function.
While this bug does not directly cause loss of funds, it violates the contract's intended functionality and can lead to incorrect period calculations for historical data queries, which may affect off-chain integrations, analytics, or any system relying on accurate period information for past timestamps.
Background Information
The FirelightVault contract implements a period-based withdrawal system where users can request withdrawals that become available in future periods. The contract maintains multiple period configurations, each with an epoch, duration, and starting period number.
The periodAtTimestamp function is designed to return the period number corresponding to a given timestamp. This is useful for:
Querying historical period information
Verifying period calculations for past events
Off-chain systems that need to determine which period a transaction occurred in
Code Analysis
The bug is located in the periodAtTimestamp function:
https://github.com/firelight-protocol/firelight-core/blob/main/contracts/FirelightVault.sol#L246-L250
The function correctly retrieves the appropriate periodConfiguration for the given timestamp using periodConfigurationAtTimestamp(timestamp). However, it then calls _sinceEpoch(periodConfiguration.epoch), which uses the current timestamp instead of the provided input parameter timestamp:
https://github.com/firelight-protocol/firelight-core/blob/main/contracts/FirelightVault.sol#L795-L797
Expected Behavior
The function should calculate the period number using the provided timestamp:
Actual Behavior
The function incorrectly calculates the period number using the current block timestamp:
This means:
When querying a past timestamp, the function returns the period number for the current time, not the past timestamp
When querying a future timestamp, the function returns the period number for the current time, not the future timestamp
The function only returns correct results when querying with the current timestamp
Impact on Other Functions
The bug affects any code that relies on periodAtTimestamp for historical or future queries. However, the currentPeriod() function works correctly because it calls periodAtTimestamp(Time.timestamp()), which happens to work due to the bug using the same current timestamp:
Severity Assessment
Bug Severity: Low
Impact:
Contract fails to deliver promised returns, but doesn't lose value
Function does not work as documented/intended
Likelihood:
High - The bug affects all historical/future timestamp queries
The function is public and can be called by anyone
However, the impact is limited to informational queries and does not affect core functionality like deposits, withdrawals, or claims
Justification for Low Severity:
No funds are at risk
Core vault functionality (deposits, withdrawals, claims) is unaffected
The bug only affects informational queries about historical periods
Recommendation
Fix the periodAtTimestamp function to use the provided timestamp parameter instead of Time.timestamp():
Link to Proof of Concept
https://gist.github.com/Perseverancesuccess2021/4390a2d10d541b5ffc2a76b03e233619#file-periodattimestamp_bug-js
Proof of Concept
Proof of Concept
The following test case demonstrates the bug:
Full Runnable POC: https://gist.github.com/Perseverancesuccess2021/4390a2d10d541b5ffc2a76b03e233619#file-periodattimestamp_bug-js
Running the Test
Full POC: https://gist.github.com/Perseverancesuccess2021/4390a2d10d541b5ffc2a76b03e233619#file-periodattimestamp_bug-js
Copy the full POC into firelight-core/test
The test will pass, confirming that the contract returns incorrect values for historical timestamp queries.
Test log
Explanation:
Query target timestamp = 1762933126
period duration = 172800 = 2 days
Time since epoch = 86401 = 1/2 period duration
=> The period of that timestamp should be equal starting_period = 0
But the contract returns 1 because it takes current timestamp in calculation.
Was this helpful?