The PuppyRaffle::selectWinner()
function's logic, using a hash of on-chain data to generate:
the random number used to select the winner
the random number used to select the rarity of the NFT
is weak and can be used to predict the outcomes.
The function uses a widely known hashing algorithm (keccak256) and available to all data to generate numbers that will be used to pick the raffler winner withing the players
array aswell as the rarity of the NFT that is to be minted to him.
A hacker could anticipate and make sure to enter the raffle at the right time, in order for his slot i
in the players
array to be equal to the number that he could generate using his address
, a chosen block.timestamp
and the current or anticipated block.difficulty
. He then would make sure he is the winner of the raffle with and NFT of highest rarity.
If a hacker attacks the contract in this way, he would have the money directly sent to him since he would be the wiiner (even though he would have cheated).
Calculating and coordinating to reach this objective is quite technical: it's not a simple hack.
VScode
Slither
Remove the weak "not so random" generating code for winner selection and rarity selection:
Implement the use of an oracle to make sure that the numbers used to select the winner and the NFT's rarity are randomly generated off chain.
See: https://docs.chain.link/vrf
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.