Page MenuHomePhabricator

Merge #13451: rpc: expose CBlockIndex::nTx in getblock(header)
ClosedPublic

Authored by nakihito on Dec 18 2019, 21:18.

Details

Summary

86edf4a2a502416ba8d6cebbce61030992f7ff6f expose CBlockIndex::nTx in getblock(header) (Gregory Sanders)

Pull request description:

Recent publication of a weakness in Bitcoin's merkle tree construction demonstrates many SPV applications vulnerable to an expensive to pull off yet still plausible attack: https://bitslog.wordpress.com/2018/06/09/leaf-node-weakness-in-bitcoin-merkle-tree-design/

Including the coinbase in the txoutproof seems the most effective fix, however results in a significant efficiency downgrade. Transactors will not even know a priori what the size of their proof will be within a couple orders of magnitude, unless they use the mid-state of SHA2 as detailed in the blog post.

Some applications, like Elements blockchain platform that take SPV-style proofs have optional access to a bitcoind to verify these proofs of inclusion and check depth in the chain. Returning `CBlockIndex::nTx` would allow an extremely easy and compact way of checking the depth of the tree, with no additional overhead to the codebase, and works with pruned nodes.

`getblockheader` is arguably not the place for it, but as mentioned before, is a natural workflow for us checking depth of a block in a possibly pruned node.

We should also ensure that `verifytxoutproof` ends up validating this depth fact as well, but left this for another PR.

Tree-SHA512: af4cf48e704c6088f8da06a477fda1aaa6f8770cee9b876c4465d1075966d6a95831a88817673fe5a0d6bbcdc1ffcbc1892e2be0d838c60fc6958d33eacdcc14

Backport of Core PR13451
https://github.com/bitcoin/bitcoin/pull/13451/

Test Plan
make check
test_runner.py
test_runner.py feature_pruning

./bitcoind
./bitcoin-cli help getblock
./bitcoin-cli help getblockheader

Verify changes to help text.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Owners added a reviewer: Restricted Owners Package.Dec 18 2019, 21:18
jasonbcox requested changes to this revision.Dec 18 2019, 22:46

The change looks good. Please include a comment in release notes as well.

This revision now requires changes to proceed.Dec 18 2019, 22:46
This revision is now accepted and ready to land.Dec 19 2019, 22:44