The TempleGoldStaking
smart contract contains a potential vulnerability where the lastRewardNotificationTimestamp
is assigned the value of block.timestamp
cast to a uint32
data type. This could lead to an integer overflow after approximately 80 years, causing unexpected behavior in the contract.
In the distributeRewards
function, the contract assigns the current block timestamp to lastRewardNotificationTimestamp
by casting it to uint32
:
Since block.timestamp
returns a uint256
, and uint32
can only hold values up to 2^32 - 1 (approximately 4.29 billion seconds, or around 136 years), this assignment will result in an overflow once the blockchain's timestamp exceeds the maximum value a uint32
can hold.
The integer overflow could cause the lastRewardNotificationTimestamp
to reset to 0 after the overflow point, leading to potential issues such as:
Incorrect cooldown calculations for reward distribution, allowing or preventing distributions at incorrect times.
Possible exploitation by malicious actors who could manipulate reward distributions if they understand the overflow mechanics.
Given the approximately 80-year timeframe for this issue to manifest, it is a low-priority vulnerability in the short term but still a critical one in the long term.
Manual code review
To prevent the overflow, consider using a larger integer type for lastRewardNotificationTimestamp
, such as uint64
, which would delay the overflow far beyond any practical timeframe for the contract's operation.
Change the declaration of lastRewardNotificationTimestamp
and its usage to uint64
:
And update the assignment in the distributeRewards
function:
This modification will effectively mitigate the risk of overflow within any reasonable period of the contract's operation.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.