Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: medium
Invalid

No way to determine the winner of the game

Summary
Assuming the winner of the game is the player that find the biggest number of eggs, there is no way to determine who won
There is no function to determine the winner

Vulnerability Details

If there is a prize, difficult to asses who gets it

Impact

Results in a winnless game, not an entertaining player experience

Tools Used

Forge Test, Remix, Manual Review

Recommendations

Add a function that returns the winner(s) with most eggs found and call it when game is ended.

address[] public players; // New array of players
/// @notice Tracks participating players. // New mapping
mapping(address => bool) private hasParticipated;
/// @notice Participants call this function to search for an egg.
/// A pseudo-random number is generated and, if below the threshold, an egg is found.
function searchForEgg() external returns (string memory searchStatus) {
require(gameActive, "Game not active");
require(block.timestamp >= startTime, "Game not started yet");
require(block.timestamp <= endTime, "Game ended");
/// @notice Checks if a player was already recorded and records new players
// New check
if (!hasParticipated[msg.sender]) {
hasParticipated[msg.sender] = true;
players.push(msg.sender);
}
// Pseudo-random number generation (for demonstration purposes only)
uint256 random =
uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender, eggCounter))) % 100;
if (random < eggFindThreshold) {
eggCounter++;
eggsFound[msg.sender] += 1;
eggNFT.mintEgg(msg.sender, eggCounter);
emit EggFound(msg.sender, eggCounter, eggsFound[msg.sender]);
}
}
/// @notice Returns the address(es) of the winner(s) who found the most eggs.
// New winner(s) picking function
function getWinners() external view returns (address[] memory winners, uint256 maxEggs) {
uint256 highest = 0;
uint256 playerCount = players.length;
uint256 winnerCount = 0;
// 1. Determine highest egg count
for (uint256 i = 0; i < playerCount; i++) {
uint256 count = eggsFound[players[i]];
if (count > highest) {
highest = count;
}
}
// 2. Count winners
for (uint256 i = 0; i < playerCount; i++) {
if (eggsFound[players[i]] == highest && highest > 0) {
winnerCount++;
}
}
// Generate winner array
address[] memory tempWinners = new address[](winnerCount);
uint256 index = 0;
for (uint256 i = 0; i < playerCount; i++) {
if (eggsFound[players[i]] == highest && highest > 0) {
tempWinners[index] = players[i];
index++;
}
}
return (tempWinners, highest); // Winner(s) and number of eggs found
}
Updates

Lead Judging Commences

m3dython Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.