2

I'm writing my own proxy pool implementation. I have problem with share verification.

I received a job from upsteam mining pool:

 job={
  "blob": "0c0ccdb490f2053f393023bdc102f7bf4c63be5c64569dc0b57ab94e9881fd66157995b679adc700000000767cb11fc62b2bde9fb8eae21058d99ad317482bfdbcc1956d766888dd4d475709",
  "job_id": "333",
  "target": "dc460300",
  "seed_hash": "154eb7a21cd32a597f985644187297607bad491650091620550877239c4178e1",
  "next_seed_hash": "",
  "height": 2032062
}

Sent this work to the miner. And miner submitted work with following result:

share={
  'id': '1',
  'job_id': '333',
  'nonce': '38870000',
  'result': 'f54a858a87f0f5bc9f3e75fba670a11cfdaf87b650d4189f50601597c8650200'
}

I want verify if the solution is correct. I'm using python and pyrx. The steps that I take to complete the verification:

Insert share['nonce'] from miner into job['blob'] to 39...43 bytes:

0c0ccdb490f2053f393023bdc102f7bf4c63be5c64569dc0b57ab94e9881fd66157995b679adc7*00000000*767cb11fc62b2bde9fb8eae21058d99ad317482bfdbcc1956d766888dd4d475709

0c0ccdb490f2053f393023bdc102f7bf4c63be5c64569dc0b57ab94e9881fd66157995b679adc7*38870000*767cb11fc62b2bde9fb8eae21058d99ad317482bfdbcc1956d766888dd4d475709

Hash this blob:

In [24]: blob = '0c0ccdb490f2053f393023bdc102f7bf4c63be5c64569dc0b57ab94e9881fd66157995b679adc738870000767cb11fc62b2bde9fb8eae21058d99ad317482bfdbcc1956d766888dd4d475709'              

In [25]: hashing_blob = pyrx.get_rx_hash(blob, job['seed_hash'], job['height']).hex()                                                                                                         

But I got unequal results with share['result']. I am sure that the answer is correct. The original pool accepted this work. Where am i wrong?

In [37]: hashing_blob == share['result']                                                                                                                                                
Out[37]: False

In [38]: hashing_blob                                                                                                                                                                   
Out[38]: '4fa368b991c8320c9c2ad1b80566f67439e789b329e0c33119b072aa7f2782e9'

In [39]: share['result']                                                                                                                                                                
Out[39]: 'f54a858a87f0f5bc9f3e75fba670a11cfdaf87b650d4189f50601597c8650200'
Andrei
  • 367
  • 1
  • 9

1 Answers1

3

You are trying to hash a hex string not binary data.

Working example:

import pyrx
import binascii
import struct

def pack_nonce(blob, nonce):
    b = binascii.unhexlify(blob)
    bin = struct.pack('39B', *bytearray(b[:39]))
    bin += struct.pack('I', nonce)
    bin += struct.pack('{}B'.format(len(b)-43), *bytearray(b[43:]))
    return bin

seed = binascii.unhexlify('154eb7a21cd32a597f985644187297607bad491650091620550877239c4178e1');
nonce = struct.unpack('I',binascii.unhexlify('38870000'))[0]
blob = "0c0ccdb490f2053f393023bdc102f7bf4c63be5c64569dc0b57ab94e9881fd66157995b679adc700000000767cb11fc62b2bde9fb8eae21058d99ad317482bfdbcc1956d766888dd4d475709"
bin = pack_nonce(blob, nonce)
height = 2032062
hash = binascii.hexlify( pyrx.get_rx_hash(bin, seed, height) )
print(hash)

Which results in: f54a858a87f0f5bc9f3e75fba670a11cfdaf87b650d4189f50601597c8650200

jtgrassie
  • 19,601
  • 4
  • 17
  • 54