-
-
Save xiaojay/3d475d8f4c2dbadcad87f606281deec1 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