Last active
April 1, 2021 00:18
-
-
Save bladedoyle/49dac1f6585474174f3c7aa2b5095e34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import bitarray | |
from hashlib import blake2b | |
# POW Constants | |
BASE_EDGE_BITS = 24 | |
PROOFSIZE = 42; | |
# https://github.com/mimblewimble/grin/blob/cccaf984936d4792f8b6c39e6b500ad2e3f08817/core/src/pow/types.rs#L314 | |
def hash_pow(proof, nonce_bits): | |
bitvec = (nonce_bits*PROOFSIZE) * [0] | |
for n, nonce in enumerate(proof): | |
for bit in range(0, nonce_bits): | |
if nonce & (1 << bit) != 0: | |
bitvec[n * nonce_bits + bit] = 1 | |
ba = bitarray.bitarray(bitvec, endian='little') | |
h = blake2b(digest_size=32) | |
h.update(ba) | |
return h.hexdigest() | |
if __name__ == "__main__": | |
# Example: Block 1149420 | |
pow = [86374760,154070018,222282246,242833237,438849293,619616595,699767524,824463679,960080314,1036405980,1089437639,1113708730,1148690094,1175329636,1286909702,1596013578,1636801188,1701402692,1723742869,1728061221,1747385321,1749092119,1831902087,1838767249,1960982891,2242937324,2335872672,2595968733,2622951640,2636225213,2827083503,2895620255,3058609249,3102998739,3165804021,3241357991,3390683027,3694396261,3737229546,3970590467,4038313798,4294675502] | |
edge_bits = 32 | |
h = hash_pow(pow, edge_bits) | |
print("Hash: {}".format(h)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ curl -s https://grinblocks.online/ipns/k51qzi5uqu5di6j7rwnp4b2bb98nh1dwypwaymemx044kwnap8d0p1qmghhjpf/114/1149420 | jq -c .header.cuckoo_solution
[86374760,154070018,222282246,242833237,438849293,619616595,699767524,824463679,960080314,1036405980,1089437639,1113708730,1148690094,1175329636,1286909702,1596013578,1636801188,1701402692,1723742869,1728061221,1747385321,1749092119,1831902087,1838767249,1960982891,2242937324,2335872672,2595968733,2622951640,2636225213,2827083503,2895620255,3058609249,3102998739,3165804021,3241357991,3390683027,3694396261,3737229546,3970590467,4038313798,4294675502]
$ curl -s https://grinblocks.online/ipns/k51qzi5uqu5di6j7rwnp4b2bb98nh1dwypwaymemx044kwnap8d0p1qmghhjpf/114/1149420 | jq -c .header.edge_bits
32
$ curl -s https://grinblocks.online/ipns/k51qzi5uqu5di6j7rwnp4b2bb98nh1dwypwaymemx044kwnap8d0p1qmghhjpf/114/1149420 | jq -c .header.hash
"0003fa754aaa5ea1a8ac5e30973ac470a508725ebd4e2bc7bc14175e9005673a"
$ python3 ./hash_grin_pow.py
Hash: 0003fa754aaa5ea1a8ac5e30973ac470a508725ebd4e2bc7bc14175e9005673a