Skip to content

compile_tr: emit Or branches as separate Tapleaves instead of OP_IF/NOTIF #905

@kwsantiago

Description

@kwsantiago

The policy compiler's Taproot path currently compiles Or branches into single Tapleaves using OP_IF/NOTIF, carrying over the P2WSH pattern. In Tapscript, the Taptree itself provides a branching mechanism via separate leaves.

For simple policies, decomposing Or branches into separate leaves can improve privacy (only the spent leaf is revealed on-chain). For complex policies (e.g. large conjunctions of ors, or high-k thresholds), full decomposition is impractical due to combinatorial explosion, so a max_leaves cap is provided.

Proposed approach: add compile_tr_native() as an opt-in alternative that decomposes Or/Thresh at the policy level, compiles each branch to an IF-free leaf using the existing Tap compiler, then assembles an optimal Taptree via Huffman coding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions