AOSSIE-Org / AOSSIE-Org/Agora-Blockchain

BUG:The RankedBallot.sol contract allows a single voter to assign multiple ranks

Aperta
#228 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
97
Fork
199
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Issue Description ✍️

📌 Describe the Bug
The RankedBallot.sol contract allows a single voter to assign multiple ranks to the same candidate within a single transaction. This bypasses the intended "one rank per candidate" logic of ranked-choice voting.

🚨 Actual Behavior
In the vote function, the contract iterates through the provided voteArr and adds points to the candidateVotes mapping based on the index. Because there is no validation to ensure each candidateID in the array is unique, a user can submit an array like [0, 0, 0]. This results in Candidate 0 receiving the points intended for 1st, 2nd, and 3rd place combined, effectively triple-counting the user's influence on that specific candidate.

🎯 Expected Behavior
The vote function should validate that the voteArr contains a unique list of candidate IDs. Each candidate should only be ranked once per ballot to maintain the integrity of the weighted voting system.

📷 Screenshot
(Not applicable for smart contract logic bugs)

💡 Suggestions
Add a uniqueness check inside the vote function. This can be achieved by using a temporary boolean array or a bitmask to track which candidates have already been processed in the current loop.

```
function vote(uint[] memory voteArr) external onlyOwner {
uint totalCandidates = candidateVotes.length;
if (voteArr.length != totalCandidates) revert VoteInputLength();

bool[] memory seen = new bool[](totalCandidates); // Track unique IDs

for (uint i = 0; i < totalCandidates; i++) {
uint candidateId = voteArr[i];
if (candidateId >= totalCandidates) revert InvalidCandidateID();
if (seen[candidateId]) revert DuplicateCandidateID(); // Revert on duplicates

seen[candidateId] = true;
candidateVotes[candidateId] += totalCandidates - i;
}
}
```

### Record

- [x] I have synced all my node versions as mentioned in the project
- [x] I am using the same version of npm as is the project
- [x] My current branch is in sync with the development branch
- [x] I want to work on this issue

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.