joinEvent function cannot prevent DOS caused by excessive participating usersWhen users call the joinEvent function to participate in an event, the protocol uses the usersAddress array to record participating users.
As the number of participants increases, the usersAddress array will grow larger and larger. When traversing this array (when calling setWinner), it will consume a huge amount of Gas.
Likelihood:
It will occur once the administrator calls the setWinner function when there are enough participating users.
Impact:
The administrator needs to pay a relatively high Gas fee when calling the setWinner function.
If the number of participants is large enough, the Gas amount may even reach "the Gas limit of a single block on Ethereum", which will render the protocol ineffective.
Add the following function to test/BriVaultTest.t.sol and run forge test --mt test__joinEvent_withHugeUsers -vv
Console output:
The above console output shows that the Gas amount is close to 20 million.
Method 1: Limit the number of participants to a safe amount.
Method 2: Refactor the contract, replace address[] public usersAddress; with mapping (uint256 => uint256) public stakedAsset_KeyIsCountryIdx;, and adjust the contract according to the original logic.
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.