all files / contracts/ Blackjack.sol

71.43% Statements 5/7
16.67% Branches 1/6
60% Functions 3/5
77.78% Lines 7/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                                                           
pragma solidity 0.8.9;
 
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
 
contract Blackjack is Initializable, PausableUpgradeable, OwnableUpgradeable {
 
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }
 
    function initialize() Einitializer public {
        __Pausable_init();
        __Ownable_init();
        nonce = 0;
    }
 
    function pause() public onlyOwner {
        _pause();
    }
 
    function unpause() public onlyOwner {
        _unpause();
    }
 
    uint256 nonce;
    // this function is exploitable. we need to change this ASAP
    function random() public returns (uint256) {
        uint256 randomNumber = uint256(
            keccak256(
                abi.encodePacked(
                    nonce,
                    msg.sender,
                    gasleft(),
                    block.difficulty,
                    block.timestamp,
                    block.number,
                    blockhash(block.number - 1),
                    block.coinbase,
                    block.gaslimit,
                    block.basefee,
                    block.chainid,
                    address(this)
                )
            )
        );
        nonce++;
        return randomNumber;
    }
}