Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why blockheader+64 #514

Open
invpe opened this issue Oct 25, 2024 · 0 comments
Open

Why blockheader+64 #514

invpe opened this issue Oct 25, 2024 · 0 comments

Comments

@invpe
Copy link

invpe commented Oct 25, 2024

When looking through the sources, i noticed that the miner does double sha256 hash on blockheader+64.

But the only thing that changes during the iterations are nonce values, which is the last 4 bytes on the blockheader that is 80 bytes long.

According to BTC specifications:

| Offset | Size (bytes) | Component            |
|--------|--------------|-----------------------|
| 0      | 4            | Version                |
| 4      | 32           | Previous Block Hash    |
| 36     | 32           | Merkle Root            |
| 68     | 4            | Timestamp (ntime)      |
| 72     | 4            | Difficulty Target (nbits) |
| 76     | 4            | Nonce                  |
|--------|--------------|-----------------------|
| Total  | 80           | Block Header Size      |

So when the miner does (pointer arithmetic:)

header64 = mMiner.bytearray_blockheader + 64;
memcpy(mMiner.bytearray_blockheader + 76, &nonce, 4);

And you're moving the pointer forward by 64 bytes.
This means you move to the byte that is 64 bytes away from the start of the block header.
It will point you to the first byte of the ntime (offset 68), since you've already accounted for the first 64 bytes (4 bytes for Version, 32 bytes for Previous Block Hash, and 32 bytes for Merkle Root).

It will hash ntime nbits nonce

is16BitShare=nerd_sha256d(&nerdMidstate, header64, hash);

While only nonce is changing.
Not sure about the performance improvement, but here's pseudocode:

nerd_mids(&nerdMidstate, nonce);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant