President Elector

First Flight #24
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Block.timestamp can be manipulated by miners, which causes mistakes in code logic.

Summary

RankedChoice.sol::selectPresident uses an If condition to make sure the function is called in the valid time for voting by checking this statement:

if (block.timestamp - s_previousVoteEndTimeStamp <= i_presidentalDuration)

However, using block.timestamp which is vulnerable, can be manipulated by a miner to increase their chances of profiting from a logic, here by calling the selectPresident at the wrong time to destroy the logic of the election.

Vulnerability Details

The timestamp vulnerability occurs when the smart contract operates based on the block timestamp's value. The timestamp is a property generated by the node on which the smart contract is deployed, which is highly manipulable by miners.
Based on the Neptune Mutual blog:

One of the most challenging issues with blockchain technology is synchronizing the precise time between nodes due to the distributed nature of the network. However, comprehending the present time is probably inevitable during the development of smart contracts, especially as most smart contract development languages are Turing complete.

Impact

By using timestamp in the logic of the selectPresident function which has the potential to be changed, anyone can call the selectPresedent at an inappropriate time (before four year ends).

Recommendations

  1. Avoid using block.timestamp

  2. Use external Time Oracle: These oracles fetch real-world time and provide it to your smart contract, minimizing the risk of manipulation.

  3. Thresholds and Confirmations: Implement thresholds and confirmation mechanisms for time-dependent actions. Require multiple blocks to confirm the passage of time before executing critical functions.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.