`The setWinner()` function iterates over all participants to calculate total winner shares
When the number of participants is very large, this loop consumes a high amount of gas. This can cause the transaction to run out of gas, effectively preventing the owner from setting the winner and finalizing the vault.
Impact:
For a large number of participants, `setWinner()` may revert due to gas limits, creating a Denial-of-Service (DoS) scenario.
No direct theft of funds occurs, but participants may be blocked from withdrawing their rewards until the issue is resolved.
Risk is higher in events with thousands of participants, while small events are unaffected.
1. Create 5,000 fake participants and have each deposit + join the event.
2. Warp time to after the event ends.
3. Owner calls setWinner().
4. Transaction reverts due to gas limit.
Add the following to `briVault.t.sol`
Avoid iterating over unbounded arrays on-chain and consider batch processing, mapping-based aggregation, or off-chain computation to calculate winner shares.
The _getWinnerShares() function is intended to iterate through all users and sum their shares for the winning country, returning the total.
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.