In May, following the Bitcoin Cash (BCH) network upgrade, developers began testing the use of OP_Codes, which had previously been absent from the network. The results have been both interesting and fun, and have shown the advanced versatility of the Bitcoin BCH blockchain that wasn’t seen in other networks. As the innovation continues, the trustless betting protocol, Chainbet, has been used in conjunction with the OP_Codes in the first-ever “atomic bet” on the blockchain.
Chainbet, an on-chain betting protocol, was designed by developer and Electron Cash wallet founder Jonald Fyookball. Well-known OpenBazaar developer Chris Pacia combined Chainbet with the OP_Codes to successfully test a trustless wager. Pacia said he opted for the BCH network for the test after learning of Fyookball’s protocol and indicated that trustless wagers are not possible on the SegWit BTC Core (BTC) network since it does not have OP_Code capability.
In a post on Yours.org about the atomic bet capability, Pacia said, “The way the scheme works from a high level is that Alice and Bob are going to generate secret random numbers and commit the hashes of those numbers to the bet’s output script. To determine the winner they will both reveal their random numbers and the script will add them together. If the sum is even, Alice wins—Otherwise, Bob wins.”
Pacia also pointed out that the BTC network wasn’t feasible for the operation due to its size limitations. Because arithmetic operations on the BTC network are limited to 32-bit signed integers, the process doesn’t work if, using the example, Bob and Alice commit to 32-bit random numbers. Using a hash of 256-bit random numbers and converting them into signed 32-bit integers is only possible on the BCH blockchain. The operation employs the use of the newly offered OP_SPLIT and OP_BIN2NUM codes, with the OP_MOD directive being called to determine if the result is odd or even.
Pacia further explains the operation, stating, “To make the scheme atomic, Alice first funds a special output with a redeem script of: OP_HASH160 <aliceCommitment> OP_EQUALVERIFY <alicePubkey> OP_CHECKSIG,” Pacia explains. “Alice and Bob then jointly build a transaction with two inputs―Alice’s special output and a normal output from Bob’s wallet [edit: this will need to be a 2-of-2 to prevent bob from double spending].
“Bob signs the transaction first and sends his signature to Alice. Alice then signs her input and broadcasts the transaction to the blockchain. By signing the transaction Alice is revealing her secret number to Bob who can then use that number to determine if he won or lost the bet. If he won, Bob can immediately claim his winnings. If Alice won, Bob cannot do anything but Alice can claim the funds after a timelock (6 blocks) expires.”
Many BCH supporters virtually applauded Pacia’s design, and indicated that it could help advance trustless wagers on sites such as Satoshi Dice. Fyookball responded as well, saying, “Looking forward to working with you and others to create a usable implementation soon. That’s pretty amusing that this scheme can’t be done on BTC.”