Skip to content

rpc: add gettxproof and verifytxproof for transactions with witness #116

Open
Sjors wants to merge 8 commits into
masterfrom
2026/06/wtxid-merkle
Open

rpc: add gettxproof and verifytxproof for transactions with witness #116
Sjors wants to merge 8 commits into
masterfrom
2026/06/wtxid-merkle

Conversation

@Sjors

@Sjors Sjors commented Jun 12, 2026

Copy link
Copy Markdown
Owner

The gettxproof and verifytxproof only proof Txid inclusion, not the witness. This PR adds that.

This PR introduces two new methods (gettxproof and verifytxproof), rather than expanding the originals, since those were designed around BIP37 bloom filters. The new methods require Wtxid instead of Txid. Clients that have the full serialized transaction can calculate both. Clients that only know the Txid have no need for the witness inclusion proof and can just keep using the old RPC methods.

Note that there is no -wtxindex (see #117) so we can't infer the block even when -txindex is enabled. If that's required, then see #118.

Commits:

  • common: move merkle path helpers out of consensus: consensus/merkle.{h,cpp} already contains functions that are not actually used by consensus and are not needed for the kernel. Since PR introduces additional such functions, add common/merkle.{h,cpp}` for those.
  • Allow calling GetWitnessCommitmentIndex with just the coinbase tx: taken from RPC/txoutproof: Support including (and verifying) proofs of wtxid bitcoin/bitcoin#32844, but renaming "generation" to "coinbase".
  • common: add merkle branch verification helper
  • common: add witness merkle path helper
  • node: add transaction proof helpers: includes test fixtures of small and early blocks, which should probably be in a BIP too
  • rpc: add verifytxproof
  • `doc: add transaction proof RPC
  • doc: release note

Superseedes bitcoin#32844

This PR may still contain LLM hallucinations, so I'm holding off on opening it on bitcoin/bitcoin. Feedback and testing is welcome, but detailed code review is probably premature.

TODO:

@Sjors

Sjors commented Jun 13, 2026

Copy link
Copy Markdown
Owner Author

Based on some light investigation, my current impression is that with Electrs you don't need -wtxindex (it also doesn't need -txindex), but with ElectrumX you would either need -wtxindex #117 or the wallet client needs to provide both txid and wtxid, so it can use the former to find the block.

@Sjors Sjors force-pushed the 2026/06/wtxid-merkle branch from 3496580 to 2503d28 Compare June 13, 2026 10:47
@Sjors Sjors force-pushed the 2026/06/wtxid-merkle branch from 2503d28 to 406128e Compare June 13, 2026 10:54
@Sjors Sjors force-pushed the 2026/06/wtxid-merkle branch from 406128e to b629abf Compare June 13, 2026 11:28
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

Successfully merging this pull request may close these issues.

1 participant