0

From this link What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?, to get the block hash I use the obfuscation key and xor it with the result I get from the db. So I look up the block hash I got on blockchain.com, but the block hash doesn't exist. So I check if I'm xoring right by using the website http://xor.pw/#. My xored value matched the website.

Then I look back to the example on How does Bitcoin read from/write to LevelDB and xored their example 26c326d7353661dc7005d274976f458691f24f0f05d141335f4ad5927e41 and 27c78118b731610527c78118b731610527c78118b731610527c78118b731 on http://xor.pw/# and I got 104a7cf820700d957c2536c205e2483b635ce17b2e02036788d548ac970 not 01028820010b2a00367244680f6da18acd861a08f0a89cb3b49ab50e.

Me and and the website can't get the same result and be wrong right? What am I missing?

import plyvel

def get_xor_key(o_key, result):
    xor_key = ''
    while len(xor_key) < len(result):
        if len(xor_key) + len(o_key) <= len(result): xor_key += o_key
        else: xor_key += o_key[:len(result)-len(xor_key)]
    return xor_key
def xor_two_str(s, t): return hex(int(s, 16) ^ int(t, 16))

db = plyvel.DB('/home/chris/.bitcoin/chainstate')
o_key = db.get(b'\x0e\x00obfuscate_key')
print('o_key', o_key.encode('hex')) # my o_key is 0899b9c2314a85c9b6

result = db.get(b'B')
result_hex = result.encode('hex')
print('result_hex', result_hex) # b6c9854a31c2b999b6da5ee266a8047f3c8c5fc82479ab03af9272a3a57372a2
xor_key = get_xor_key(o_key, result)
xored = xor_two_str(xor_key.encode('hex'), result_hex)
block_hash = xored[2:-1].decode('hex')[::-1].encode('hex')
print(block_hash) # 870b3cd33974701cfceb9c5bffa0b2b6b9c66e0a9de0a3b56617389267caebaa
  • Can you explain to me why in the answer for bitcoin.stackexchange.com/questions/51387/… it says 26c326d7353661dc7005d274976f458691f24f0f05d141335f4ad5927e41 xor 27c78118b731610527c78118b731610527c78118b731610527c78118b731 is equal to 104a7cf820700d957c2536c205e2483b635ce17b2e02036788d548ac970 and not 01028820010b2a00367244680f6da18acd861a08f0a89cb3b49ab50e? – guest1234312 Jun 14 at 1:01
  • Oh, I see what's going on. Your answer is mathematically right, but you have dropped a leading zero so it is harder to see. It's more clear if written as 0104a7cf820700d957c2536c205e2483b635ce17b2e02036788d548ac970. However, I don't understand either where the 010288... answer comes from. It's not even the right number of bytes. – Nate Eldredge Jun 14 at 1:57
  • The author of bitcoin.stackexchange.com/questions/51387/… has acknowledged that their result seems to be in error. – Nate Eldredge Jun 14 at 19:16
  • Hmm. Then I wonder what I'm doing wrong. – guest1234312 Jun 15 at 7:33
  • What information you trying to get from blockchain that you need to work with 'leveldb'? – Denis Leonov Jun 15 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.