The rankCandidates function in the RankedChoice contract allows a voter to submit the same vote multiple times without restriction. This leads to a replay attack vulnerability, where a malicious voter can submit duplicate votes to influence the outcome of the election.
In the current implementation, there is no mechanism to track or prevent a voter from submitting the same ranking of candidates multiple times during a voting session. The lack of validation allows a single voter to submit their ranking repeatedly, effectively bypassing the voting restrictions.
The attacker first votes for their preferred candidates by calling the rankCandidates
function.
After the vote is recorded, the attacker simply calls the same rankCandidates
function again with the same candidate ranking.
Since there is no mechanism to prevent this, the contract records the vote a second time, allowing the attacker to effectively vote multiple times in the same session.
Add the following test to RankedChoiceTest.t.sol
, it should pass due to no duplicate checks.
The replay attack enables a malicious voter to vote multiple times within a single voting session, leading to an unfair advantage and compromising the integrity of the election process. The lack of tracking or nonce protection in the contract allows repeated submissions of the same vote, resulting in potential manipulation of election results.
Foundry: Used to run unit tests and simulate the replay attack by voting twice with the same voter.
To mitigate this vulnerability, implement a check in the _rankCandidates
function to ensure that a voter cannot submit their vote more than once in the same voting session. This can be done by tracking whether a voter has already cast their vote and reverting if a duplicate vote is detected.
This mitigation will prevent voters from submitting multiple votes in the same voting session, thus protecting the system against replay attacks.
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.