Contract 0xD1CEeeef70c61da45800bd81BE3352160ad72F2a 2

 
Txn Hash Method
Block
From
To
Value
0x31bff77ea9b6fa3009775ae4a61217151a9fd6dee815748ce03dcbd6b1813205Kill59320032018-07-09 7:56:311177 days 1 hr ago0xd1ceeee271fd5a8b0e2bfc12ea5b5b2e5cedec95 IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00016449612
0x3a34d25d727b9f79ea282c1e7792a0d904b5be68790db98487e4cd3c39520eddPlace Bet59299352018-07-08 23:23:091177 days 10 hrs ago0xf508130fa49d60c3c6d21c03757c620cb093006d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0.02 Ether0.000114895
0x4d99038571dd24439f322d63812357b91f3e1b7c3ead41977471fbfa848c6997Place Bet59268522018-07-08 10:35:461177 days 23 hrs ago0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc8 IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0.1 Ether0.0002309410
0xa153c1e5bc29a957e213bf154a0133a48483267842eaf4f9211d0ef1e7117b28Refund Bet59222222018-07-07 15:07:421178 days 18 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00166644171
0xa1e7baad057bcfc2d9c3888ac15d03071c8dff6cf573302a26db5d4d8b5c1c64Withdraw Funds59209832018-07-07 10:08:191178 days 23 hrs ago0xd1ceeee271fd5a8b0e2bfc12ea5b5b2e5cedec95 IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00259252575
0x3e2f1cc63e8ed74836dea6df148ace97d9cb8f47fcede7ef8b30165f975a1c7cChange Max Bet C...59209682018-07-07 10:04:351178 days 23 hrs ago0xd1ceeee271fd5a8b0e2bfc12ea5b5b2e5cedec95 IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00097995273
0xf58e30d57287d268d39d8e72061a0cbcac61b3a081cd83b543324e63afc619cbChange Max Bet D...59209622018-07-07 10:02:371178 days 23 hrs ago0xd1ceeee271fd5a8b0e2bfc12ea5b5b2e5cedec95 IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00098798273
0xa7e3b11d36c745b0722eb4487ae946ade85bb76d947a328da9542ceaf937ea69Withdraw Funds59209562018-07-07 9:59:391178 days 23 hrs ago0xd1ceeee271fd5a8b0e2bfc12ea5b5b2e5cedec95 IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.0027551280
0xd66135e036443a788be978f1adb81edf6d6a7feedf0fb5535863a6c3b774e95fSettle Bet59049892018-07-04 16:08:141181 days 17 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.0022089270
0xb7d8153d8b67efa792975c531a76383f084687f0e3122eb0f962a579022a8635Place Bet59049842018-07-04 16:06:301181 days 17 hrs ago0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc8 IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0.08 Ether0.00287344251
0x01e2183682682da66ab2a7cfd91fc6a27eb4fce6c5b4c7f59efeb4db1427663fRefund Bet59042032018-07-04 12:53:411181 days 20 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.0021015470
0xdafe01cc656067778d0b4c2fd0874e084890894701e64b3cb4116bdd0e496b47Refund Bet59041942018-07-04 12:51:321181 days 20 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.0023492770
0x6e294e4bc15aa8cc00c093cc17bbfda81e188a8d3dd3806e06cc794378db0403Refund Bet59041492018-07-04 12:41:371181 days 21 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00166644171
0x1d439b2bb9c767430ff7db49239854529f3db14aa05489ac2696e1e1053e2b81Refund Bet59041492018-07-04 12:41:371181 days 21 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00166644171
0xa39590c476909dfc17f208d091b3bdb2e2dce4302aa50fc7b3477b2b013f98a4Refund Bet59041492018-07-04 12:41:371181 days 21 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00166644171
0x58ea1c87108edd8063e99a5dfda4c7cb1ff5ba5367933e8806e5aa01dfc60c8eRefund Bet59041492018-07-04 12:41:371181 days 21 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00166644171
0x3832a97aa8390d2e2efe8c8c327bb864bd404e5bae2d46c34d58a947a854d8e6Refund Bet59041462018-07-04 12:41:041181 days 21 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00166644171
0x8b6d3b1206966d1d0adfcb5dd1a8132efcd7fab9e044a9aeca610d434093803dRefund Bet59041452018-07-04 12:40:411181 days 21 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.00166644171
0x410918d50de10406efbae958f245fe4cf657121d776c2ddfae0b0b086296ac9bRefund Bet59041452018-07-04 12:40:411181 days 21 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.0021332570
0xf1ccca6cf5cd3551b76f64bb46c788e50b205bd314d3faa4976012c0ea4ba574Place Bet59031912018-07-04 8:39:381182 days 1 hr ago0x5409e9e2f6cc8340d307fa15e0728adad54d6e8c IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0.1 Ether0.00345792662
0x4516d388a547d9727bb04e42d9842ab10a4f04d61f02ab9154c62f36d69d3695Settle Bet59000032018-07-03 19:38:141182 days 14 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.0004818820
0x85c227faf789b9aed1e77f516d1b7e8c6fd20149c1ef64e260ed537cb782bb4bSettle Bet58997672018-07-03 18:39:011182 days 15 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.0004818820
0xa28d404df5270c3e7aef2e8f7af829d47f8d5bb143db57412f34abfc1c470f96Place Bet58995722018-07-03 17:51:241182 days 15 hrs ago0x9fb16f1669545c3db1667aba486046846d72addb IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0.05 Ether0.00304653651
0x8ab9e5f1123c9943231c7d710aba8fcad1d0f06280d77bf3c68f7403b3bab2a8Place Bet58991982018-07-03 16:17:291182 days 17 hrs ago0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc8 IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0.08 Ether0.002817150
0x990ed96d9d3b5407ad739328a3db1c8b2434aee5fc7311532fe3caf8bf5ff4b6Settle Bet58954932018-07-03 0:57:441183 days 8 hrs ago0x00000000c0293c8ca34dac9bcc0f953532d34e4d IN  0xd1ceeeef70c61da45800bd81be3352160ad72f2a0 Ether0.0006329620
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x31bff77ea9b6fa3009775ae4a61217151a9fd6dee815748ce03dcbd6b181320559320032018-07-09 7:56:311177 days 1 hr ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0xd1ceeee271fd5a8b0e2bfc12ea5b5b2e5cedec951.6885 Ether
0xa1e7baad057bcfc2d9c3888ac15d03071c8dff6cf573302a26db5d4d8b5c1c6459209832018-07-07 10:08:191178 days 23 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0xd1ceeee271fd5a8b0e2bfc12ea5b5b2e5cedec951.222108134880994853 Ether
0xa7e3b11d36c745b0722eb4487ae946ade85bb76d947a328da9542ceaf937ea6959209562018-07-07 9:59:391178 days 23 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0xd1ceeee271fd5a8b0e2bfc12ea5b5b2e5cedec951 Ether
0xd66135e036443a788be978f1adb81edf6d6a7feedf0fb5535863a6c3b774e95f59049892018-07-04 16:08:141181 days 17 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.1176 Ether
0x01e2183682682da66ab2a7cfd91fc6a27eb4fce6c5b4c7f59efeb4db1427663f59042032018-07-04 12:53:411181 days 20 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x5409e9e2f6cc8340d307fa15e0728adad54d6e8c0.1 Ether
0xdafe01cc656067778d0b4c2fd0874e084890894701e64b3cb4116bdd0e496b4759041942018-07-04 12:51:321181 days 20 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x9fb16f1669545c3db1667aba486046846d72addb0.05 Ether
0x410918d50de10406efbae958f245fe4cf657121d776c2ddfae0b0b086296ac9b59041452018-07-04 12:40:411181 days 21 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.08 Ether
0x990ed96d9d3b5407ad739328a3db1c8b2434aee5fc7311532fe3caf8bf5ff4b658954932018-07-03 0:57:441183 days 8 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x5138240e96360ad64010c27eb0c685a8b2ede4f20.147 Ether
0x2f05ea03a8f38280702cbb97fec0439efa50d7ab3a266af2548fae5465d7960558946212018-07-02 21:25:131183 days 12 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.1 Ether
0x29ad94e75e9f9591eb10b961c9bdd8fbe499e2a9228d6e5a31b41551168606c058885222018-07-01 20:43:321184 days 13 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x63b589264db751382409f1f692cf8be7912032a60.1 Ether
0x4f00806b56c187ee595a67ade068a50a35eb66313961ab3d6e0f9df20bd4b4d058875492018-07-01 16:56:071184 days 16 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.1176 Ether
0xc4fabf770cf4a88d9c223f15ff4b69cc45d04d9e8ad89e4ee611e65e4594db5658802252018-06-30 10:25:451185 days 23 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x63b589264db751382409f1f692cf8be7912032a60.196 Ether
0x00914cea2e19b21ebde1b57cb0a7141735255801ec0a04c93740fbe02ac0b83958802152018-06-30 10:23:141185 days 23 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.1176 Ether
0x22f5edd8bb1f91935ab58aa40f0f33f98e295392dfdf628fa58a1c746b13b16258801292018-06-30 10:02:551185 days 23 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.1176 Ether
0xcf3358839588f7035895377cd6a5259c8d48d2ea46118d712cadacc79e691b2f58800972018-06-30 9:56:371185 days 23 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.1176 Ether
0xc7de9f7cd13de51171b16788f9e13ae4b69341f73bdae2066952b5388b187e7558800722018-06-30 9:50:021185 days 23 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x63b589264db751382409f1f692cf8be7912032a61 wei
0xf2814d753e6578e23f7790c36320a001d1f731d100d56597f27b25876bd07f7a58800302018-06-30 9:39:421186 days 5 mins ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x63b589264db751382409f1f692cf8be7912032a61 wei
0xd1f89ee8d75e4a1fa6038e7a835131e33c96f62e2171eafb551d530a7c264e4c58799912018-06-30 9:27:311186 days 17 mins ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x63b589264db751382409f1f692cf8be7912032a61 wei
0xaa674676909c35ced03054ce25836b7332f5bec52263184e6c7420acb2d5d59658799602018-06-30 9:20:351186 days 24 mins ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x63b589264db751382409f1f692cf8be7912032a60.0392 Ether
0x8ba2a16a068c654bba95dcfc26eb41c011aca7fef6c53d93f6f3782ae11c17c758798192018-06-30 8:49:261186 days 55 mins ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x63b589264db751382409f1f692cf8be7912032a60.196 Ether
0x4361d7ec3737190816611a821a1d448b178e356d0eb3f409292d3658814b223458795922018-06-30 7:59:031186 days 1 hr ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.1176 Ether
0x77e69a2783fffbc6c72e0e119eeb65ce5263d813c581d6abf5882935a57c118758795702018-06-30 7:54:171186 days 1 hr ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x136d0159be4313a5bdd38c5c8b5cef8dcff15fc80.1176 Ether
0xaea0ef598efa798bbc499aff76495372b51f057288a2254c3b06de99c55aaae058791782018-06-30 6:19:471186 days 3 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x9fb16f1669545c3db1667aba486046846d72addb0.121655172413793102 Ether
0x24c2a520106438513f731a9c4b4b53ff68f67eb93fcc597f9091f85c56dc54df58791572018-06-30 6:14:141186 days 3 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x9fb16f1669545c3db1667aba486046846d72addb0.121655172413793102 Ether
0x5f2266db1ec282b9f9d06461f2128469657f62bddd355bcf3364544ba30a5ee258791362018-06-30 6:08:541186 days 3 hrs ago 0xd1ceeeef70c61da45800bd81be3352160ad72f2a0x63b589264db751382409f1f692cf8be7912032a61 wei
[ Download CSV Export 
Loading
Contract Self Destruct called at Txn Hash 0x31bff77ea9b6fa3009775ae4a61217151a9fd6dee815748ce03dcbd6b1813205


Contract Source Code Verified (Exact Match)

Contract Name:
Dice2Win

Compiler Version
v0.4.23+commit.124ca40d

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
/**
 *Submitted for verification at Etherscan.io on 2018-05-07
*/

pragma solidity ^0.4.23;

contract Dice2Win {

    /// Constants

    // Chance to win jackpot - currently 0.1%
    uint256 constant JACKPOT_MODULO = 1000;

    // Each bet is deducted 2% amount - 1% is house edge, 1% goes to jackpot fund.
    uint256 constant HOUSE_EDGE_PERCENT = 2;
    uint256 constant JACKPOT_FEE_PERCENT = 50;

    // Minimum supported bet is 0.02 ETH, made possible by optimizing gas costs
    // compared to our competitors.
    uint256 constant MIN_BET = 0.02 ether;

    // Only bets higher that 0.1 ETH have a chance to win jackpot.
    uint256 constant MIN_JACKPOT_BET = 0.1 ether;

    // Random number generation is provided by the hashes of future blocks.
    // Two blocks is a good compromise between responsive gameplay and safety from miner attacks.
    uint256 constant BLOCK_DELAY = 2;

    // Bets made more than 100 blocks ago are considered failed - this has to do
    // with EVM limitations on block hashes that are queryable. Settlement failure
    // is most probably due to croupier bot failure, if you ever end in this situation
    // ask dice2.win support for a refund!
    uint256 constant BET_EXPIRATION_BLOCKS = 100;

    /// Contract storage.

    // Changing ownership of the contract safely
    address public owner;
    address public nextOwner;

    // Max bet limits for coin toss/single dice and double dice respectively.
    // Setting these values to zero effectively disables the respective games.
    uint256 public maxBetCoinDice;
    uint256 public maxBetDoubleDice;

    // Current jackpot size.
    uint128 public jackpotSize;

    // Amount locked in ongoing bets - this is to be sure that we do not commit to bets
    // that we cannot fulfill in case of win.
    uint128 public lockedInBets;

    /// Enum representing games

    enum GameId {
        CoinFlip,
        SingleDice,
        DoubleDice,

        MaxGameId
    }

    uint256 constant MAX_BLOCK_NUMBER = 2 ** 56;
    uint256 constant MAX_BET_MASK = 2 ** 64;
    uint256 constant MAX_AMOUNT = 2 ** 128;

    // Struct is tightly packed into a single 256-bit by Solidity compiler.
    // This is made to reduce gas costs of placing & settlement transactions.
    struct ActiveBet {
        // A game that was played.
        GameId gameId;
        // Block number in which bet transaction was mined.
        uint56 placeBlockNumber;
        // A binary mask with 1 for each option.
        // For example, if you play dice, the mask ranges from 000001 in binary (betting on one)
        // to 111111 in binary (betting on all dice outcomes at once).
        uint64 mask;
        // Bet amount in wei.
        uint128 amount;
    }

    mapping (address => ActiveBet) activeBets;

    // Events that are issued to make statistic recovery easier.
    event FailedPayment(address indexed _beneficiary, uint256 amount);
    event Payment(address indexed _beneficiary, uint256 amount);
    event JackpotPayment(address indexed _beneficiary, uint256 amount);

    /// Contract governance.

    constructor () public {
        owner = msg.sender;
        // all fields are automatically initialized to zero, which is just what's needed.
    }

    modifier onlyOwner {
        require (msg.sender == owner);
        _;
    }

    // This is pretty standard ownership change routine.

    function approveNextOwner(address _nextOwner) public onlyOwner {
        require (_nextOwner != owner);
        nextOwner = _nextOwner;
    }

    function acceptNextOwner() public {
        require (msg.sender == nextOwner);
        owner = nextOwner;
    }

    // Contract may be destroyed only when there are no ongoing bets,
    // either settled or refunded. All funds are transferred to contract owner.

    function kill() public onlyOwner {
        require (lockedInBets == 0);
        selfdestruct(owner);
    }

    // Fallback function deliberately left empty. It's primary use case
    // is to top up the bank roll.
    function () public payable {
    }

    // Helper routines to alter the respective max bet limits.
    function changeMaxBetCoinDice(uint256 newMaxBetCoinDice) public onlyOwner {
        maxBetCoinDice = newMaxBetCoinDice;
    }

    function changeMaxBetDoubleDice(uint256 newMaxBetDoubleDice) public onlyOwner {
        maxBetDoubleDice = newMaxBetDoubleDice;
    }

    // Ability to top up jackpot faster than it's natural growth by house fees.
    function increaseJackpot(uint256 increaseAmount) public onlyOwner {
        require (increaseAmount <= address(this).balance);
        require (jackpotSize + lockedInBets + increaseAmount <= address(this).balance);
        jackpotSize += uint128(increaseAmount);
    }

    // Funds withdrawal to cover costs of dice2.win operation.
    function withdrawFunds(address beneficiary, uint256 withdrawAmount) public onlyOwner {
        require (withdrawAmount <= address(this).balance);
        require (jackpotSize + lockedInBets + withdrawAmount <= address(this).balance);
        sendFunds(beneficiary, withdrawAmount, withdrawAmount);
    }

    /// Betting logic

    // Bet transaction - issued by player. Contains the desired game id and betting options
    // mask. Wager is the value in ether attached to the transaction.
    function placeBet(GameId gameId, uint256 betMask) public payable {
        // Check that there is no ongoing bet already - we support one game at a time
        // from single address.
        ActiveBet storage bet = activeBets[msg.sender];
        require (bet.amount == 0);

        // Check that the values passed fit into respective limits.
        require (gameId < GameId.MaxGameId);
        require (msg.value >= MIN_BET && msg.value <= getMaxBet(gameId));
        require (betMask < MAX_BET_MASK);

        // Determine roll parameters.
        uint256 rollModulo = getRollModulo(gameId);
        uint256 rollUnder = getRollUnder(rollModulo, betMask);

        // Check whether contract has enough funds to process this bet.
        uint256 reservedAmount = getDiceWinAmount(msg.value, rollModulo, rollUnder);
        uint256 jackpotFee = getJackpotFee(msg.value);
        require (jackpotSize + lockedInBets + reservedAmount + jackpotFee <= address(this).balance);

        // Update reserved amounts.
        lockedInBets += uint128(reservedAmount);
        jackpotSize += uint128(jackpotFee);

        // Store the bet parameters on blockchain.
        bet.gameId = gameId;
        bet.placeBlockNumber = uint56(block.number);
        bet.mask = uint64(betMask);
        bet.amount = uint128(msg.value);
    }

    // Settlement transaction - can be issued by anyone, but is designed to be handled by the
    // dice2.win croupier bot. However nothing prevents you from issuing it yourself, or anyone
    // issuing the settlement transaction on your behalf - that does not affect the bet outcome and
    // is in fact encouraged in the case the croupier bot malfunctions.
    function settleBet(address gambler) public {
        // Check that there is already a bet for this gambler.
        ActiveBet storage bet = activeBets[gambler];
        require (bet.amount != 0);

        // Check that the bet is neither too early nor too late.
        require (block.number > bet.placeBlockNumber + BLOCK_DELAY);
        require (block.number <= bet.placeBlockNumber + BET_EXPIRATION_BLOCKS);

        // The RNG - use hash of the block that is unknown at the time of placing the bet,
        // SHA3 it with gambler address. The latter step is required to make the outcomes of
        // different settlement transactions mined into the same block different.
        bytes32 entropy = keccak256(gambler, blockhash(bet.placeBlockNumber + BLOCK_DELAY));

        uint256 diceWin = 0;
        uint256 jackpotWin = 0;

        // Determine roll parameters, do a roll by taking a modulo of entropy.
        uint256 rollModulo = getRollModulo(bet.gameId);
        uint256 dice = uint256(entropy) % rollModulo;

        uint256 rollUnder = getRollUnder(rollModulo, bet.mask);
        uint256 diceWinAmount = getDiceWinAmount(bet.amount, rollModulo, rollUnder);

        // Check the roll result against the bet bit mask.
        if ((2 ** dice) & bet.mask != 0) {
            diceWin = diceWinAmount;
        }

        // Unlock the bet amount, regardless of the outcome.
        lockedInBets -= uint128(diceWinAmount);

        // Roll for a jackpot (if eligible).
        if (bet.amount >= MIN_JACKPOT_BET) {
            // The second modulo, statistically independent from the "main" dice roll.
            // Effectively you are playing two games at once!
            uint256 jackpotRng = (uint256(entropy) / rollModulo) % JACKPOT_MODULO;

            // Bingo!
            if (jackpotRng == 0) {
                jackpotWin = jackpotSize;
                jackpotSize = 0;
            }
        }

        // Remove the processed bet from blockchain storage.
        delete activeBets[gambler];

        // Tally up the win.
        uint256 totalWin = diceWin + jackpotWin;

        if (totalWin == 0) {
            totalWin = 1 wei;
        }

        if (jackpotWin > 0) {
            emit JackpotPayment(gambler, jackpotWin);
        }

        // Send the funds to gambler.
        sendFunds(gambler, totalWin, diceWin);
    }

    // Refund transaction - return the bet amount of a roll that was not processed
    // in due timeframe (100 Ethereum blocks). Processing such bets is not possible,
    // because EVM does not have access to the hashes further than 256 blocks ago.
    //
    // Like settlement, this transaction may be issued by anyone, but if you ever
    // find yourself in situation like this, just contact the dice2.win support!
    function refundBet(address gambler) public {
        // Check that there is already a bet for this gambler.
        ActiveBet storage bet = activeBets[gambler];
        require (bet.amount != 0);

        // The bet should be indeed late.
        require (block.number > bet.placeBlockNumber + BET_EXPIRATION_BLOCKS);

        // Determine roll parameters to calculate correct amount of funds locked.
        uint256 rollModulo = getRollModulo(bet.gameId);
        uint256 rollUnder = getRollUnder(rollModulo, bet.mask);

        lockedInBets -= uint128(getDiceWinAmount(bet.amount, rollModulo, rollUnder));

        // Delete the bet from the blockchain.
        uint256 refundAmount = bet.amount;
        delete activeBets[gambler];

        // Refund the bet.
        sendFunds(gambler, refundAmount, refundAmount);
    }

    /// Helper routines.

    // Number of bet options for specific game.
    function getRollModulo(GameId gameId) pure private returns (uint256) {
        if (gameId == GameId.CoinFlip) {
            // Heads/tails
            return 2;

        } else if (gameId == GameId.SingleDice) {
            // One through six.
            return 6;

        } else if (gameId == GameId.DoubleDice) {
            // 6*6=36 possible outcomes.
            return 36;

        }
    }

    // Max bet amount for a specific game.
    function getMaxBet(GameId gameId) view private returns (uint256) {
        if (gameId == GameId.CoinFlip) {
            return maxBetCoinDice;

        } else if (gameId == GameId.SingleDice) {
            return maxBetCoinDice;

        } else if (gameId == GameId.DoubleDice) {
            return maxBetDoubleDice;

        }
    }

    // Count 1 bits in the bet bit mask to find the total number of bet options
    function getRollUnder(uint256 rollModulo, uint256 betMask) pure private returns (uint256) {
        uint256 rollUnder = 0;
        uint256 singleBitMask = 1;
        for (uint256 shift = 0; shift < rollModulo; shift++) {
            if (betMask & singleBitMask != 0) {
                rollUnder++;
            }

            singleBitMask *= 2;
        }

        return rollUnder;
    }

    // Get the expected win amount after house edge is subtracted.
    function getDiceWinAmount(uint256 amount, uint256 rollModulo, uint256 rollUnder) pure private
      returns (uint256) {
        require (0 < rollUnder && rollUnder <= rollModulo);
        return amount * rollModulo / rollUnder * (100 - HOUSE_EDGE_PERCENT) / 100;
    }

    // Get the portion of bet amount that is to be accumulated in the jackpot.
    function getJackpotFee(uint256 amount) pure private returns (uint256) {
        return amount * HOUSE_EDGE_PERCENT / 100 * JACKPOT_FEE_PERCENT / 100;
    }

    // Helper routine to process the payment.
    function sendFunds(address beneficiary, uint256 amount, uint256 successLogAmount) private {
        if (beneficiary.send(amount)) {
            emit Payment(beneficiary, successLogAmount);
        } else {
            emit FailedPayment(beneficiary, amount);
        }
    }

}

Contract Security Audit

Contract ABI

[{"constant":false,"inputs":[{"name":"newMaxBetCoinDice","type":"uint256"}],"name":"changeMaxBetCoinDice","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"maxBetCoinDice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"gambler","type":"address"}],"name":"refundBet","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"jackpotSize","outputs":[{"name":"","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"nextOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"gambler","type":"address"}],"name":"settleBet","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maxBetDoubleDice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"beneficiary","type":"address"},{"name":"withdrawAmount","type":"uint256"}],"name":"withdrawFunds","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newMaxBetDoubleDice","type":"uint256"}],"name":"changeMaxBetDoubleDice","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"acceptNextOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_nextOwner","type":"address"}],"name":"approveNextOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"increaseAmount","type":"uint256"}],"name":"increaseJackpot","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"gameId","type":"uint8"},{"name":"betMask","type":"uint256"}],"name":"placeBet","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"lockedInBets","outputs":[{"name":"","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_beneficiary","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"FailedPayment","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_beneficiary","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Payment","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_beneficiary","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"JackpotPayment","type":"event"}]

608060405234801561001057600080fd5b5060008054600160a060020a033316600160a060020a0319909116179055610cae8061003d6000396000f3006080604052600436106100e55763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166309fb166881146100e75780632bec76fd146100ff5780632c69e64e1461012657806341c0e1b51461014757806357246d231461015c57806369f3331d1461018d5780636d5f3e15146101be5780638da5cb5b146101df57806397217085146101f4578063c107532914610209578063cf62d4e31461022d578063d06c54fb14610245578063d579fd441461025a578063d6d30a511461027b578063dcb3b30e14610293578063df88126f146102a4575b005b3480156100f357600080fd5b506100e56004356102b9565b34801561010b57600080fd5b506101146102d9565b60408051918252519081900360200190f35b34801561013257600080fd5b506100e5600160a060020a03600435166102df565b34801561015357600080fd5b506100e56103e8565b34801561016857600080fd5b5061017161042e565b604080516001608060020a039092168252519081900360200190f35b34801561019957600080fd5b506101a261043d565b60408051600160a060020a039092168252519081900360200190f35b3480156101ca57600080fd5b506100e5600160a060020a036004351661044c565b3480156101eb57600080fd5b506101a26106b8565b34801561020057600080fd5b506101146106c7565b34801561021557600080fd5b506100e5600160a060020a03600435166024356106cd565b34801561023957600080fd5b506100e5600435610745565b34801561025157600080fd5b506100e5610765565b34801561026657600080fd5b506100e5600160a060020a03600435166107b1565b34801561028757600080fd5b506100e5600435610816565b6100e560ff600435166024356108af565b3480156102b057600080fd5b50610171610a7d565b60005433600160a060020a039081169116146102d457600080fd5b600255565b60025481565b600160a060020a0381166000908152600560205260408120805490919081908190608060020a90046001608060020a0316151561031b57600080fd5b835466ffffffffffffff61010090910416606401431161033a57600080fd5b83546103489060ff16610a93565b845490935061036e90849068010000000000000000900467ffffffffffffffff16610ae9565b845490925061038e90608060020a90046001608060020a03168484610b20565b600480546001608060020a03808216608060020a9283900482169490940381168202939093179091558554600160a060020a038816600090815260056020526040812055041690506103e1858280610b62565b5050505050565b60005433600160a060020a0390811691161461040357600080fd5b600454608060020a90046001608060020a03161561042057600080fd5b600054600160a060020a0316ff5b6004546001608060020a031681565b600154600160a060020a031681565b600160a060020a0381166000908152600560205260408120805490919081908190819081908190819081908190608060020a90046001608060020a0316151561049457600080fd5b895466ffffffffffffff6101009091041660020143116104b357600080fd5b895466ffffffffffffff610100909104166064014311156104d357600080fd5b8954604080516c01000000000000000000000000600160a060020a038f1602815266ffffffffffffff610100840416600201406014820152905190819003603401902099506000985088975061052b9060ff16610a93565b9550858981151561053857fe5b8b54919006955061056090879068010000000000000000900467ffffffffffffffff16610ae9565b8a5490945061058090608060020a90046001608060020a03168786610b20565b8a54909350600286900a680100000000000000009091041667ffffffffffffffff16156105ab578297505b600480546001608060020a03808216608060020a92839004821687900382168302179092558b5467016345785d8a00009190049091161061062f576103e8868a8115156105f457fe5b048115156105fe57fe5b06915081151561062f57600480546fffffffffffffffffffffffffffffffff1981169091556001608060020a031696505b50600160a060020a038a16600090815260056020526040812055868601801515610657575060015b60008711156106a057604080518881529051600160a060020a038d16917fc388db0e8aa560a59633c094a0d0aa21322cd6234836fd5bac00fc5ae63b5783919081900360200190a25b6106ab8b828a610b62565b5050505050505050505050565b600054600160a060020a031681565b60035481565b60005433600160a060020a039081169116146106e857600080fd5b600160a060020a033016318111156106ff57600080fd5b600454600160a060020a033016316001608060020a03808316608060020a9093048116929092019091168201111561073657600080fd5b610741828283610b62565b5050565b60005433600160a060020a0390811691161461076057600080fd5b600355565b60015433600160a060020a0390811691161461078057600080fd5b6001546000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03909216919091179055565b60005433600160a060020a039081169116146107cc57600080fd5b600054600160a060020a03828116911614156107e757600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60005433600160a060020a0390811691161461083157600080fd5b600160a060020a0330163181111561084857600080fd5b600454600160a060020a033016316001608060020a03808316608060020a9093048116929092019091168201111561087f57600080fd5b600480546fffffffffffffffffffffffffffffffff1981166001608060020a039182169390930116919091179055565b33600160a060020a031660009081526005602052604081208054909190819081908190608060020a90046001608060020a0316156108ec57600080fd5b60038760038111156108fa57fe5b1061090457600080fd5b66470de4df8200003410158015610923575061091f87610c15565b3411155b151561092e57600080fd5b68010000000000000000861061094357600080fd5b61094c87610a93565b93506109588487610ae9565b9250610965348585610b20565b915061097034610c6d565b600454909150600160a060020a033016316001608060020a03808316608060020a9093048116929092019091168301820111156109ac57600080fd5b600480546001608060020a03608060020a808304821686018216029181169190911780821684019091166fffffffffffffffffffffffffffffffff199190911617905584548790869060ff19166001836003811115610a0757fe5b021790555050835467ffffffffffffff0019166101004366ffffffffffffff1602176fffffffffffffffff000000000000000019166801000000000000000067ffffffffffffffff9690961695909502949094176001608060020a03908116608060020a34909216919091021790925550505050565b600454608060020a90046001608060020a031681565b600080826003811115610aa257fe5b1415610ab057506002610ae4565b6001826003811115610abe57fe5b1415610acc57506006610ae4565b6002826003811115610ada57fe5b1415610ae4575060245b919050565b6000806001815b85811015610b165784821615610b07576001909201915b60029190910290600101610af0565b5090949350505050565b6000816000108015610b325750828211155b1515610b3d57600080fd5b6064606283868602811515610b4e57fe5b0402811515610b5957fe5b04949350505050565b604051600160a060020a0384169083156108fc029084906000818181858888f1935050505015610bd057604080518281529051600160a060020a038516917fd4f43975feb89f48dd30cabbb32011045be187d1e11c8ea9faa43efc35282519919081900360200190a2610c10565b604080518381529051600160a060020a038516917fac464fe4d3a86b9121261ac0a01dd981bfe0777c7c9d9c8f4473d31a9c0f9d2d919081900360200190a25b505050565b600080826003811115610c2457fe5b1415610c335750600254610ae4565b6001826003811115610c4157fe5b1415610c505750600254610ae4565b6002826003811115610c5e57fe5b1415610ae45750600354610ae4565b600060646002830281900460320204929150505600a165627a7a72305820cccff48377d74b829d668e2b08a7da222dc10521a27ae2d2cbb0f5dfe98362c50029

Swarm Source

bzzr://cccff48377d74b829d668e2b08a7da222dc10521a27ae2d2cbb0f5dfe98362c5
Block Transaction Difficulty Gas Used Reward
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.