AOSSIE-Org / AOSSIE-Org/Agora-Blockchain

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

オープン
#228 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
97
フォーク
199
PR マージ指標
30日以内にマージされた PR はありません

説明

### 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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。