The setWinner() function orders validation checks inefficiently, checking expensive storage reads before cheaper ones, wasting gas on early failures.
Normal behavior for gas-optimized validation expects checking the cheapest conditions first to fail fast and save gas when early checks don't pass.
The current implementation checks eventEndDate (SLOAD ~2100 gas) and array bounds before checking _setWinner flag (SLOAD ~2100 gas), when the latter should be checked first since it's the most likely to fail on repeated calls.
Likelihood:
Owner may accidentally call setWinner() multiple times
Testing environments frequently trigger this
Early failure case should be optimized
Impact:
Wasted ~2100 gas checking timestamp when winner already set
Wasted ~3 gas checking array bounds when winner already set
Total waste: ~2103 gas per failed duplicate call
Compounds during testing and development
Poor gas efficiency for common failure case
Optimization principles applied:
Fail fast: Check most likely failure first
Cheap first: Check cheaper operations before expensive ones
State before computation: Check state flags before complex calculations
Order of operations (cheapest to most expensive):
State variable read (warm): ~100 gas
State variable read (cold): ~2100 gas
External calls: ~2600+ gas
Loop operations: Variable (potentially unlimited)
Estimated Gas Savings: ~2,100 gas per failed duplicate call (common during testing/operations)
Gas optimizations are invalid according to the CodeHawks documentation.
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.