we have a contract given below which allows the attacker to know the winnerIndex before calling selectWinner(). This allows the attacker to choose the winner and steal the prize. Similarly, the attacker can also know the rarity before calling selectWinner().
this line uint256 winnerIndex = uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp, block.difficulty))) % players.length; allows the caller to know the winnerIndex after entering in block and before calling selectWinner().
The attacker first calls setPlayerSize() to set the player size and his index. Then he calls _attack() to get the winnerIndex and call selectWinner().
We have to call _attack() multiple times if it reverts Attack__NotsuccessFull().
After the metamask popup, we have to confirm the transaction immediately. Otherwise, block.timestamp will change and the winnerIndex will be different.
this is an example transaction: tx you can found in internal transaction section
Similarly, we can also know the rarity before calling selectWinner().
The attacker can choose the winner and steal the prize.
Manual Review
Remix
We can use Chainlink VRF to generate random numbers for WinnerIndex as well as rarity.
Root cause: bad RNG Impact: manipulate winner
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.