Yes, thanks, Cricktor. Of all the source information I was able to find, this one (which I already knew about) came the closest to solving my troubles. It filled in a lot of holes, but still lacks a 100% completely worked example start to finish. I'll try the other source you mentioned since I haven't seen it yet. Thanks.
-gt-
Okay, I've been able to get a little further with this now. I found an example that had the coin base hash. Still missing this: coinbase = coinbase1 + extranonce1 + extranonce2 + coinbase2
However this SHOULD be one of the easiest parts to deal with. If I had the pieces to make coinbase, I could hash it twice and I'd get the double hash of coinbase. But I'm pretty close now, because the example I now found misses these pieces, but DOES include the double hash of coinbase.
I was able to use that to calculate the correct Merkle Root. So even though I STILL haven't managed to find a complete worked example end-to-end, the only missing link is extremely trivial - just concatenating four things and double hashing them.
Therefore, I'm assuming that my captured mining traffic will now work and generate a reasonable hash. Although it's not over yet, its pretty close.
I found so much misleading information. One source claimed that regardless of what kind of BTC operation it is (transmitting funds, or submitting shares) that you have to hash pairs linearly, not in a tree. Another source insisted that the concatenation of pieces from the merkle branches had to be paired in lexographic order, not in the order they appeared. Finally, an (apparently) correct source indicated NOT to lexographically order, but to build a binary tree hash the nodes as pairwise leaves moving them up a level after each completion until only the hashed root remains. THAT strategy allowed me to reproduce the example's final value from the coinbase and merkel branches.
I even tried using ChatGPT, but he kept changing his mind about which of the three strategies to use to hash the merkel tree. I can't believe there doesn't seem to be a complete, proper, end-to-end example out there on the net, and what's more surprising is all the posted code I've found which clearly uses completely different strategies to do the hashing. Every posting claims to be tested and correct and for BTC mining, but each one gives a different final hash for the same inputs.
-gt-
Well, I'm not out of the woods yet. Having taken data from
https://learnmeabitcoin.com/ I now realize that I can't tell how it relates to my captured mining data. For example, when I see the table of TX hashes in the table on the website example, does the endian-ness match how they look in the JSON strings from the miner/pool? There are still too many pieces and unknown details, and too many possible things to reverse or not to reverse, so without more details I STILL can't resolve this. I've decided to just post the pool/miner exchange that led to a accepted packet and hope that SOMEONE who sees this feels like seeing if they can put it all together in a way that gives a block header that hashes to a reasonable hash. I've removed all traffic except that relevant to the successfully mined share. However, the exchanges are probably not in order. Here's what I got:
The miner subscribes:
{"id": 3, "method": "mining.subscribe", "params": ["Antminer S19j Pro+/Fri Apr 14 21:39:16 CST 2023"]}
The pool responds:
{"id":3,"result":[[["mining.notify","00"],["mining.set_difficulty","00"]],"00",7],"error":null}
ExtraNonce1: '00',ExtraNonce2_size: 7,
The miner asks to authorize:
{"id": 5, "method": "mining.authorize", "params": ["1AGf9BSutC5ZAnMXi8rvE6nxoaVv4rYfNa.018", "x"]}
The pool responds:
{"id":5,"result":true,"error":null}
Pool offers job to miner:
{"id":null,"method":"mining.notify","params":["3782626","f29143edc62458e69f1a5661f85d2cdff4aeff9000008ac30000000000000000","01000000010000000000000000000000000000000000000000000000000000000000000000fffff
fff5a032f840d1d506f7765726564206279204c75786f72205465636868005f002a971a59fabe6d
6d648fad0e94f875d4783a1d2b146e0fa869052d181b79a88ebc54783aeda6018e1000000000000
00000010666","ffffffff05220200000000000017a914bf73ad4cf3a107812bad3deb310611bee49a3c79871a14c
1120000000017a914056adde53ebc396a1b3b678bb0d3a5c116ff430c870000000000000000266a
24aa21a9ed23ed3159409e966bff9642d36a658a385d5b655b0ba0bbba8d8b9317ce9a841500000
000000000002f6a2d434f524501a21cbd3caa4fe89bccd1d716c92ce4533e4d4733f459cc4ca322
d298304ff163b2a360d756c5db8400000000000000002b6a2952534b424c4f434b3a5033e57db45
8230515b003ad6b37755e76755337c12a9d8efd024916006f4f1500000000",["298563959d824c769c90df6880153ffe37ce692f40c86030f8da46072883ca98","713f3880adf3ec99241e10773c5994e0173631b23013be3a406423744523b5cb","d2cedcb2598099f5155c70f3964c8b9983d6bacdeae094a0c125eee2826332af","cd0308e9611464d808fc0cc7cd7a5220e7db837d27f8753ddf7ba1cf0e1004c7","43d98cfae83c979cb52376012ac6087c566b48e5b13c1e1fffbad82ab1ef429a","86c27c93418feac302f2fa49165314470c1c98fb989b7dd0712cba3c7ae515c9","fa5d9bd36f07cd05d7c38b37e5dcb18a4ff5a1c5f137c6c03f97acce091b4770","05b0ee676903b07295f97c2833348101368d5f0f0039fde81e35f3067df03278","4fe266926aab2d9e481aa79ab081b2953fb043c873f8111ec171673aafeb3981","96511215a92f1011bdfae46a4e2b86359571a72f1beaa5f795abb7493fbe4206"],"20000000","17028bb1","67c28154",false]}
Miner submits a share:
{"params": ["1AGf9BSutC5ZAnMXi8rvE6nxoaVv4rYfNa.018", "3782626", "ec100000000000", "67c28154", "16384721", "09b66000"], "id": 19, "method": "mining.submit"}
The pool responds:
{"id":19,"result":true,"error":null}
==========================================
{
"params": [
"1AGf9BSutC5ZAnMXi8rvE6nxoaVv4rYfNa.018", // Username (Bitcoin address + worker name)
"3782626", // Job ID
"ec100000000000", // Extranonce2
"67c28154", // Time
"16384721", // Nonce
"09b66000" // Extra nonce (optional, rarely used)
],
"id": 19, // Request ID
"method": "mining.submit" // Method name
}
pool offers job to miner
{
"id": null, // Identifier for the request (null means no specific ID)
"method": "mining.notify", // Method being called (notifies miners of a new block)
"params": [ // Parameters for the mining job
"3782626", // Job ID (unique identifier for this mining job)
"f29143edc62458e69f1a5661f85d2cdff4aeff9000008ac30000000000000000", // Previous block hash
"01000000010000000000000000000000000000000000000000000000000000000000000000fffff
fff5a032f840d1d506f7765726564206279204c75786f72205465636868005f002a971a59fabe6d
6d648fad0e94f875d4783a1d2b146e0fa869052d181b79a88ebc54783aeda6018e1000000000000
00000010666", // Coinbase transaction (block reward + fees)
"ffffffff05220200000000000017a914bf73ad4cf3a107812bad3deb310611bee49a3c79871a14c
1120000000017a914056adde53ebc396a1b3b678bb0d3a5c116ff430c870000000000000000266a
24aa21a9ed23ed3159409e966bff9642d36a658a385d5b655b0ba0bbba8d8b9317ce9a841500000
000000000002f6a2d434f524501a21cbd3caa4fe89bccd1d716c92ce4533e4d4733f459cc4ca322
d298304ff163b2a360d756c5db8400000000000000002b6a2952534b424c4f434b3a5033e57db45
8230515b003ad6b37755e76755337c12a9d8efd024916006f4f1500000000", // Merkle root (hash of all transactions)
[
"298563959d824c769c90df6880153ffe37ce692f40c86030f8da46072883ca98", // Transaction hash 1
"713f3880adf3ec99241e10773c5994e0173631b23013be3a406423744523b5cb", // Transaction hash 2
"d2cedcb2598099f5155c70f3964c8b9983d6bacdeae094a0c125eee2826332af", // Transaction hash 3
"cd0308e9611464d808fc0cc7cd7a5220e7db837d27f8753ddf7ba1cf0e1004c7", // Transaction hash 4
"43d98cfae83c979cb52376012ac6087c566b48e5b13c1e1fffbad82ab1ef429a", // Transaction hash 5
"86c27c93418feac302f2fa49165314470c1c98fb989b7dd0712cba3c7ae515c9", // Transaction hash 6
"fa5d9bd36f07cd05d7c38b37e5dcb18a4ff5a1c5f137c6c03f97acce091b4770", // Transaction hash 7
"05b0ee676903b07295f97c2833348101368d5f0f0039fde81e35f3067df03278", // Transaction hash 8
"4fe266926aab2d9e481aa79ab081b2953fb043c873f8111ec171673aafeb3981", // Transaction hash 9
"96511215a92f1011bdfae46a4e2b86359571a72f1beaa5f795abb7493fbe4206" // Transaction hash 10
],
"20000000", // Block version (format of the block)
"17028bb1", // Network difficulty target (how hard it is to mine)
"67c28154", // Current time (Unix timestamp)
false // Clean flag (false means the block may include unconfirmed transactions)
]
}
20000000 # Version
f29143edc62458e69f1a5661f85d2cdff4aeff9000008ac300000000000000000 # Previous Block Hash
[Merkle Root (computed from coinbase & merkle branches)] # Placeholder
67c28154 # Timestamp
17028bb1 # Bits (Difficulty Target)
16384721 # Nonce
Name Usage in Block Construction
Extranonce1 Used in coinbase transaction.
Extranonce2 Used in coinbase transaction.
Username Embedded in the coinbase transaction.
Job ID Included in the share submission.
Previous Block Hash Used in block header.
Coinbase1 Combined with extranonce1 and extranonce2.
Coinbase2 Combined with extranonce1 and extranonce2.
Merkle Branches List Used in block header.
Timestamp (time) Used in block header.
Bits Defines the maximum valid hash for the block.
Nonce Used in block header.
Extra Nonce Not always used in hashing, but included in submission.