bitcoindevkit / bitcoindevkit/bdk-cli

Add taproot privacy optimisations in policy compiler

Open
#244 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
141
Forks
99
Avg merge
6d 14m
Merged PRs (30d)
1

Description

**Describe the enhancement**

`bdk-cli compile --type tr "$POL"` currently only calls `compile` and manually wraps the result into a single taproot leaf, instead of using `compile_tr` from rust-miniscript that splits disjunctions into separate leaves and Huffman-optimises the tree. Using `compile_tr` would be a good compromise, though `compile_tr_private_experimental` exists and goes one step further in privacy optimisation.

**Use case**

When compiling a disjunctive policy to a taproot descriptor, each spending condition should ideally be its own leaf so that only the used path is revealed on-chain. Currently all conditions are bundled into a single leaf, missing the privacy benefits of taproot's script tree.

**Additional context**

The following shows the output of all three rust-miniscript functions for reference:

**Example 1:** `or(pk(A),pk(B))`
```
compile:
or_b(pk(A),s:pk(B))
compile_tr:
internal key : B
tap tree leaves (1 total):
depth=0 script=pk(A)
compile_tr_private_experimental:
internal key : B
tap tree leaves (1 total):
depth=0 script=pk(A)
```

**Example 2:** `thresh(1,pk(A),pk(B),pk(C))`
```
compile:
multi_a(1,A,B,C)
compile_tr:
internal key : C
tap tree leaves (2 total):
depth=1 script=pk(B)
depth=1 script=pk(A)
compile_tr_private_experimental:
internal key : C
tap tree leaves (2 total):
depth=1 script=pk(B)
depth=1 script=pk(A)
```

**Example 3:** `thresh(2,pk(A),pk(B),pk(C))`
```
compile:
multi_a(2,A,B,C)
compile_tr:
internal key : UNSPENDABLE
tap tree leaves (1 total):
depth=0 script=multi_a(2,A,B,C)
compile_tr_private_experimental:
internal key : UNSPENDABLE
tap tree leaves (3 total):
depth=1 script=and_v(v:pk(A),pk(B))
depth=2 script=and_v(v:pk(B),pk(C))
depth=2 script=and_v(v:pk(A),pk(C))
```

Contributor guide

Open the contributing guide

Research direction

Trace the `bdk-cli compile --type tr` entry point and inspect its current `compile` call and manual single-leaf wrapping. Compare that path with rust-miniscript's `compile_tr` output for the disjunctive and threshold examples; done means taproot policies use separate leaves and the resulting tree receives the intended Huffman optimisation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.