There's no BIP for proving that a transaction is in a block by its wtxid. AJ 
asked for one, with test vectors, when reviewing the Core PR that adds those 
proofs to gettxoutproof [0]. Sjors picked that work up with a sketch [1] and 
said the vectors could become a BIP, preferably written by someone else [2]. I 
didn't see anyone take it up, so I wrote a draft:

https://github.com/jeanpablojp/bips/blob/witness-inclusion-proofs/bip-witness-inclusion-proofs.md

Knots, Sjors's sketch, the Electrum protocol draft [3] and an electrs PR [4] 
each have their own format, and the checks a verifier makes are in 
SomberNight's comment on the Core PR [5] and in each implementation's code. The 
draft writes those checks down and comes with a Python reference, 31 proofs 
that must verify and 62 that must be rejected. It reuses the five blocks of 
Sjors's fixtures, and its Merkle branches match the sketch's over nine blocks, 
except in block 481823.

Miners were adding the commitment output months before segwit activated. Of the 
mainnet coinbases I sampled, 12 of 51 between heights 436,000 and 481,000 have 
it, and all 42 between 481,700 and 481,823. None has a witness. I ran Sjors's 
sketch on block 481823: it builds each proof in the witness tree and then 
rejects all but the coinbase's. In the draft the verifier takes "segwit is 
active for this block" as an input. The coinbase witness can't settle that, 
because a prover can strip the witness without changing the txid.

A branch can also verify at a position past the last transaction. In block 
481823 the branch of position 1695 reaches the root at seven other positions, 
up to 2047. A node can check the position against the transaction count, which 
is what Sjors's sketch does. A client with only headers can't, so the draft 
rejects a right-hand node equal to its left sibling, as Core's partial Merkle 
tree does.

There are two formats and a JSON form. Format 1 is a plain branch per 
transaction, as in Sjors's sketch and Electrum. Format 2 is a BIP 37 partial 
tree with the same bytes as Core's CPartialMerkleTree, as in Knots and as AJ 
suggested [6]. Ten transactions of block 481823 take 4,523 bytes in format 1 
and 3,325 in format 2. I'm not sure two formats are worth it. I'm also unsure 
about requiring the padding bits of the last flag byte to be zero: BIP 37 
doesn't say what they are and Core doesn't check them.

Feedback welcome.

[0] https://github.com/bitcoin/bitcoin/pull/32844#pullrequestreview-3400680165
[1] https://github.com/Sjors/bitcoin/pull/116
[2] https://github.com/bitcoin/bitcoin/pull/32844#issuecomment-4690626677
[3] https://github.com/spesmilo/electrum-protocol/pull/16
[4] https://github.com/Blockstream/electrs/pull/235
[5] https://github.com/bitcoin/bitcoin/pull/32844#issuecomment-3021260691
[6] https://github.com/bitcoin/bitcoin/pull/32844#discussion_r2478855640

-- 
You received this message because you are subscribed to the Google Groups 
"Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/bitcoindev/C899B11E-4971-4AAF-8BA3-81EBAFBF7739%40jeanpablo.jp.

Reply via email to