The RankedChoice
contract does not emit events when significant state changes occur, such as when a new president is selected or when votes are submitted. Emitting events is a best practice in Solidity to ensure that off-chain systems and users can track and react to important changes.
In Solidity, emitting events is essential for providing off-chain monitoring tools (e.g., front-end applications, analytics platforms, or wallets) with information about the internal state changes in the contract. This contract lacks events for important actions like the selection of a new president or the ranking of candidates. Without events, external parties cannot easily detect or monitor these actions without repeatedly querying the blockchain, which is inefficient and costly in terms of gas usage.
Events could be emitted in the following instances:
When a new president is selected in the selectPresident()
function.
When a voter ranks candidates, which occurs in the rankCandidates()
and rankCandidatesBySig()
functions.
Lack of Transparency: Users, dApps, or off-chain systems cannot be easily notified when a key event like a presidential election takes place, leading to reduced transparency.
Difficult to Track Changes: Off-chain systems need to rely on manual or gas-intensive methods like polling the blockchain to detect state changes.
Reduced Efficiency: Failing to emit events increases the load on systems that need to continuously query the blockchain, which could be optimized by simply emitting events when important changes happen.
Emit Events for Key Actions: It is recommended to emit events in key functions such as:
NewPresidentSelected: Emit an event when a new president is selected in the selectPresident()
function.
VotesRanked: Emit an event when a voter ranks candidates.
Implement Events for Significant State Changes: Events should be emitted for other significant changes to improve off-chain monitoring and transparency.
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.