Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Invalid

Gas Guzzling Voters: Optimize Storage and Rewards for Streamlined Transactions

Summary

Storing voters in separate arrays and sending individual rewards might be gas-intensive. Using alternative data structures and multi-send functionality can optimize gas usage.

Vulnerability Details

The current implementation iterates through separate arrays (allowedVoters and votes) and sends individual rewards, incurring significant gas depending on the voter count.

Impact

Increased gas costs for voting and reward distribution, affecting user experience and contract efficiency.

Tools Used

  • Manual code review

Test Case and Logs:

  • Deploy the contract.

  • Simulate a voting process with many voters.

  • Monitor gas costs for voting and reward distribution.

  • Compare gas usage with alternative implementations using other data structures and multi-send functionality.

Expected Logs:

  • Higher gas costs with iterating separate arrays and sending individual rewards.

Recommendations

  • Consider using bitmaps or efficient data structures like Merkle trees to manage allowed voters.

  • Utilize multi-send functionality available in libraries like OpenZeppelin's MultiSend to send rewards efficiently in a single transaction.

// Use bitmaps to efficiently track allowed voters
BitMap public allowedVoters;
function _distributeRewards(uint256 totalRewards) internal {
// Use multi-send functionality to send rewards efficiently
MultiSend.sendEth(allowedVoters.getAddresses(), totalRewards / allowedVoters.size());
}
Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 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.