The _getWinnerShares function iterates over an unbound array of all participants. As the vault gains users, the gas cost of this loop will exceed the block gas limit making the setWinner function not callable and permanently locking all funds in the contract.
Normal Behavior: When the owner calls setWinner, the contract is supposed to calculate the total number of shares held by all winners which is held by the totalWinnerShares variable. This value is critical for the final payout calculation.
The Problem: The _getWinnerShares function performs this calculation by looping over the usersAddress array, which grows by one every time a new user calls joinEvent. Once this array becomes large enough like thousands of users, the gas cost of the for loop will be higher than the block's gas limit, causing the transaction to revert. This will permanently break the setWinner function.
Likelihood: High
Reason 1: This is a guaranteed failure of the contract as it becomes more popular.
Reason 2: The vulnerability is triggered by the intended, normal use of the protocol which is users joining the event.
Impact: High
Impact 1: Severe disruption of protocol functionality. The setWinner function will become uncallable.
Impact 2: Total and permanent loss of all user funds. The withdraw function requires the winnerSet modifier, which relies on setWinner successfully executing. If setWinner fails, no one can ever withdraw their funds.
This test can be added to briVault.t.sol. It simulates thousands of users depositing and joining. The logic is self-evident, but a test case would be structured as follows:
Do not iterate over an unbounded array but instead, track the total shares for each team in a new mapping and update it in joinEvent.
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.