Share Commitments
Each share is committed to in the bitcoin coinbase, which is committed to in the bitcoin header through the merkle root. This bitcoin header is embedded in the share header. The commitment serves two goals:
-
Each bitcoin proof of work can build only one share.
-
Each sharechain coinbase is unique, even among shares mined on the same bitcoin block template.
The share commitment is a SHA256 hash of the shareblock header’s fields and of the share witness root. The share witness root is the the BIP141 witness root of the share’s non-coinbase sharechain transactions.
The diagram below shows the committed fields. The commitment sits in the last output of the bitcoin coinbase, the coinbase txid feeds into the bitcoin header’s merkle root, and the miner hashes that header. The shareblock header’s fields therefore commit to the bitcoin block hash, and one proof of work can stand behind only one shareblock, which meets the first goal.
The sharechain coinbase’s scriptSig carries the bitcoin block hash. Each proof of work has its own nonce and so its own block hash, which makes each sharechain coinbase unique and meets the second goal.
The share coinbase cannot be in the commitment, because the block hash exists only once the work is done. The commitment binds the miner’s sharechain address and the share witness root instead, and with those fixed, the header alone determines the share coinbase.
Checking the Commitment From the Header
P2Poolv2 uses the commitment trick of the original P2Pool to tie the share header to the bitcoin coinbase. A node checks that tie from the header alone, before it has the shareblock body and without reading PPLNS data from its store.
The miner splits the serialized bitcoin coinbase into a prefix and a tail. The prefix holds the version, the input with its scriptSig, the payout outputs, the witness commitment, and a padding output. The tail holds the share commitment output and the locktime. The padding brings the prefix to a whole number of 64-byte SHA256 blocks, so SHA256 can hash the prefix and pause. The state it pauses in, the midstate, stands in for the whole prefix. The miner puts the midstate and the prefix length in the share header’s coinbase proof, beside the share witness root.
A node rebuilds the tail from the header: the commitment output from the share commitment, and the locktime from the bitcoin height. It checks the proof in three steps:
-
Rebuild the share commitment from the header fields and the share witness root.
-
Resume SHA256 from the midstate over the commitment output and the locktime, then hash again to get the coinbase txid.
-
Fold the coinbase merkle branch into the txid, and require the result to equal the bitcoin header’s merkle root.
The proof of work fixes the merkle root, so a forged proof needs a SHA256 collision, and one bitcoin header can stand behind only one shareblock. The share commitment is checked as part of the share validation scheme.