Skip to content

Instantly share code, notes, and snippets.

@hrkrshnn

hrkrshnn/bad.sol Secret

Created May 24, 2022
Embed
What would you like to do?
A contract with a bad design
struct Bet {
address user;
uint bet;
bool won;
}
contract Lottery {
address immutable owner = msg.sender;
Bet[] bets;
// store how much each user
uint winnings;
function deposit(uint bet) payable external {
require(msg.value == 1 ether);
bets.push(Bet(msg.sender, bet, false));
}
function pickWinner() external {
require(owner == msg.sender);
uint winning_number = 0;
uint winners = 0;
// Imagine some magic code for generating randomness
// and assigning to the variable winning_number
for (uint i = 0; i < bets.length; i++) {
if (bets[i].bet == winning_number) {
bets[i].won = true;
winners++;
}
}
winnings = address(this).balance / winners;
}
function claim() external {
// function that allows people to claim
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment