Implemented full TapTree Merkle logic & Enhanced ControlBlockFactory #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements end-to-end Taproot script‐path support in
bp-derive, including:Full stack-based Merkle-tree logic in
TapTree::merkle_rootandTapTree::merkle_pathIntegration of the new
TapCodeop-codes from PR #120 to build leaf scriptsEnhanced ControlBlockFactory to track and pop a vector of Merkle paths per leaf
Comprehensive unit tests (
taptree_tests,negative_tests,control_block_factory_tests) covering:Dependency upgrades:
bitcoin = "0.29",secp256k1 = "0.30.0"(withrand), plus matchingsecp256k1-sysbp-coreand related crates to specific Git commits for reproducible buildsKey Changes
TapTree Merkle Logic
Replaced
todo!()with a generic stack‐merge algorithm that:(depth, hash)merkle_path(index)uses a stack of(depth, hash, path_vec, is_target)to collect only the sibling branch hashes for the chosen leaf.TapCode Leaf Construction
TapScript::push_opcode(op)on the newTapCodeenum, ensuring the PR #120 op-codes are actually used.ControlBlockFactory
merkle_paths: Vec<TapMerklePath>Iterator::next(), pops one leaf and its matching path, then constructsControlBlock::with(version, internal_pk, parity, path).Unit & Negative Tests
taptree_tests: validates correct roots/paths for various tree shapesnegative_tests:merkle_path(empty_tree)now deliberately panics with"unbalanced tap tree"on misuse—this is consistent with our policy to catch invalid tree use at development time rather than silently returning bogus data.control_block_factory_tests: ensures eachControlBlockcarries its correct Merkle branch and script version.Dependencies
bitcoin_hashes,bitcoin, andsecp256k1versions; pinnedbp-coreet al. to Git commit for consistency.randfeature forsecp256k1in workspace and derive crates.Behavioral & Compatibility Notes
merkle_pathonTapTree(vec![])) is intentional: an empty tap tree is invalid by spec, so a debug assertion and panic surface programming errors early.TapTree,ControlBlockFactory::with, etc.) retain their signatures.Testing
cargo test -p bp-derive(all 16 tests passing)libandbinbuilds including WASM targetscargo check& CII welcome any feedback—happy to iterate on panic-vs-error behavior or naming refinements at your direction!