Post
Topic
Board Gambling
Re: Dice64 - Off Blockchain. Provably fair. Instantly verifiable. 0.9% Edge
by
dice64
on 10/08/2013, 23:58:58 UTC
Updated python verification code. Increased maximum bets again.

https://gist.github.com/Dice64/6151316
Code:
import hashlib
import requests
 
# Doesn't currently do signature checking, we'll implement that in soon.
URL = "https://dice64.com"
 
 
def dsha256(input):
    return hashlib.sha256(hashlib.sha256(input.decode('hex')).digest()).hexdigest()
 
 
def verify_bet(id):
    r = requests.get(URL + '/api/bets/'+str(id))
 
    if r.status_code != 200:
        print "Couldn't find bet"
        exit()
 
    secret = r.json()['secret']
    secret_hash = r.json()['secret_hash']
    nonce = r.json()['nonce']
    combined_hash = r.json()['combined_hash']
    result = r.json()['result']
    # Calculated results
    combined = int(secret, base=16) + nonce
    combined_hex = hex(combined)[2:].strip("L")
 
    # Add preceeding zeros to make it 64 bytes in length
    while len(combined_hex) < 64:
        combined_hex = "0"+combined_hex
 
    # Print output
    print "\nSecret Hash - dsha256(secret)"
    print "Calculated:", dsha256(secret)
    print "Server val:", secret_hash
 
    print "\nCombined Hash - dsha256(secret + nonce)"
    print "Calculated:", dsha256(combined_hex)
    print "Server val:", combined_hash
 
    print "\nResult - dsha256(secret + nonce) mod 64"
    print "Calculated:", long(combined_hash, base=16) % 64
    print "Server val:", result
 
 
if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('id', help='id of bet to check', type=int)
    args = parser.parse_args()
 
    verify_bet(args.id)