2

I'm writing a Blackjack game in solidity. In the following function, the player ended up winning one time with a hand strength of 30 after doubling down even though they should have busted. Unfortunately I was just testing locally on testrpc and thus have no record of this.

    function _DoubleDown() public payable requireHandActive(true) requirePlayerActive(true) {
    require(msg.value == betAmount[msg.sender]);
    require(playerCards[msg.sender].length == 2);
    require(isSplit[msg.sender] == false);
    uint newCard = randgen();
    playerCards[msg.sender].push(newCard);
    betAmount[msg.sender] += msg.value;
    uint handPower1 = card2PowerConverter(playerCards[msg.sender]);
    if (handPower1 > 21) { //player busted
                processHandEnd(false);
            }
    else {
        isPlayerActive[msg.sender] = false;
        checkGameState();
        }
}

function processHandEnd(bool _win) internal { //hand is over and win is either true or false, now process it
    if (_win == false) {
        }
    else if (_win == true) {
        uint winAmount = betAmount[msg.sender] * 2;
        msg.sender.transfer(winAmount);
        payoutAmount[msg.sender]=winAmount;
    }
    gamestatus[msg.sender] = 5;
    isActive[msg.sender] = false;
    broadcastHand();
}

Until now however I've been unable to replicate the bug. Does anyone know what might have been wrong? I cannot release this app knowing this bug was present and observed, even though I cannot replicate it.

Full source code is here: https://ropsten.etherscan.io/address/0xcd9eba98aa4854246467248f8f814f3bc01e4c21#code

  • Please add more detail of bug. What was expected and what was wrong? – Aniket Nov 15 '18 at 7:05
  • card2PowerConverter() accepts an array of cards, calculates the strength of each card in the array, adds these strengths all together, and returns a single uint of the combined strength of all cards. This part is definitely functioning correctly. Se the code within _DoubleDown() at: "uint handPower1 = card2PowerConverter(playerCards[msg.sender]);" the returned strength when the bug occurred was "30". The subsequent "if" conditional should have returned true and triggered processHandEnd(false) which results in an immediate player loss. Instead, the player won, perhaps via triggering the "else" – Ectogold Nov 15 '18 at 8:47
  • @A.K. I tried replicating the issue since then but haven't been able to – Ectogold Nov 15 '18 at 8:48
  • Without more data I'd say that possible causes are debuger glitch (it showed 30 but it was 21 or less), ganache bug (try using to update), solc compiler issue (if you feed the same cards you should reproduce it). – Ismael Nov 18 '18 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.