President Elector

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

Vulnerability in `RankedChoice::selectPresident` function in block.timestamp Usage for Time-based Voting Control

Summary

The RankedChoice::selectPresident() function relies on block.timestamp to determine when voting can occur. While this approach works in most cases, it introduces potential risks due to the manipulability of block.timestamp by miners. Although the manipulation window is relatively small, it can still lead to premature or delayed voting. To improve robustness, a time buffer should be implemented to mitigate risks related to timestamp inaccuracies.

Vulnerability Details

Vulnerability: Inaccurate Time-based Voting with block.timestamp

The current implementation uses block.timestamp to calculate whether the presidential voting duration has passed:

if (block.timestamp - s_previousVoteEndTimeStamp <= i_presidentalDuration) {
revert RankedChoice__NotTimeToVote();
}

While convenient, block.timestamp is susceptible to manipulation by miners, who can adjust it slightly within a few seconds. This could lead to:

  1. Premature voting, where miners manipulate timestamps to allow voting earlier than intended.

  2. Delayed voting, where congestion or delays in the network cause inaccuracies in the expected voting times.

Impact

Although the manipulation window is small (up to 15 minutes), it can still impact time-sensitive operations in the contract, such as voting intervals. Premature or delayed voting might result in an unexpected outcome in the presidential election, especially if certain voters rely on precise timing to participate.

Consequences:

Election Manipulation: A malicious miner could exploit the timestamp to allow voting slightly earlier or delay the voting process, which could undermine the fairness of the election process.
Reduced Reliability: Overreliance on block.timestamp makes the system prone to network latency, miner strategies, and inconsistencies in election timing.

Tools Used

Manual review

Recommendations

  1. Implement a Time Buffer: Add a buffer period to account for possible timestamp manipulation. This buffer ensures that minor changes to block.timestamp won't affect the eligibility window for voting.

+ uint256 private constant TIME_BUFFER = 1 hours;
function selectPresident() external {
+ if (block.timestamp - s_previousVoteEndTimeStamp <= i_presidentalDuration + TIME_BUFFER) {
- if (block.timestamp - s_previousVoteEndTimeStamp <= i_presidentalDuration) {
revert RankedChoice__NotTimeToVote();
}
// Proceed with president selection logic...
}
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.