Skip to content

Commit a832fda

Browse files
committed
Merge #50: Simplicity descriptors
2ff1a17 Bump MSRV to 1.58.0 (Christian Lewe) 8bb85e3 examples: Adapt to Simplicity (Christian Lewe) f85036a bitcoind-tests: Adapt to Simplicity (Christian Lewe) 029848c psbt: Add support for Simplicity (Christian Lewe) 0c62c05 tr: Weight calculations for Simplicity (Christian Lewe) 2a077f5 tr: Spend Simplicity descriptors (Christian Lewe) 3a8c495 tr: Implement Simplicity spending info (Christian Lewe) 4ffcc00 tr: FromStr for Simplicity policy inside Tr (Christian Lewe) 20073b1 tr: Todo sanity check for Simplicity descriptors (Christian Lewe) edd15f3 tr: implement ForEachKey for Simplicity descriptors (Christian Lewe) 24b5296 simplicity: Parse policy (Christian Lewe) 5e06478 tr: Add Simplicity leaf to TapTree (Christian Lewe) 3e7440d fixme: Add rust-simplicity dependency (Christian Lewe) Pull request description: Takes ideas from BlockstreamResearch/rust-simplicity#154 and implements Simplicity descriptors as a special kind of script-spend inside a Taproot descriptor. Simplicity and Miniscript can be mixed in the same tree. `TapLeafScript` is an interface that unifies both worlds. All methods use this interface to work as normal. ACKs for top commit: apoelstra: ACK 2ff1a17 Tree-SHA512: cb31e8221ab976e0ab505354a1c3267d62a0c9c98c239c30ceed486f04a0fd81ce962861ef3c945438df68be5ef4d5b1e9205878de63dbeca3a5d11fbf2a1575
2 parents 81a9692 + 2ff1a17 commit a832fda

File tree

15 files changed

+467
-53
lines changed

15 files changed

+467
-53
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
runs-on: ubuntu-latest
7070
strategy:
7171
matrix:
72-
rust: [stable, beta, nightly, 1.48.0]
72+
rust: [stable, beta, nightly, 1.58.0]
7373
steps:
7474
- name: Checkout Crate
7575
uses: actions/checkout@v2

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ base64 = ["bitcoin/base64"]
2222
bitcoin = "0.30.0"
2323
elements = "0.22.0"
2424
bitcoin-miniscript = { package = "miniscript", version = "10.0" }
25+
simplicity = { git = "https://github.com/uncomputable/rust-simplicity", branch = "policy-fixes" }
2526

2627
# Do NOT use this as a feature! Use the `serde` feature instead.
2728
actual-serde = { package = "serde", version = "1.0", optional = true }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Build](https://github.com/ElementsProject/elements-miniscript/workflows/Continuous%20integration/badge.svg)
22

3-
**Minimum Supported Rust Version:** 1.48.0
3+
**Minimum Supported Rust Version:** 1.58.0
44

55
*This crate uses "2018" edition
66

@@ -40,7 +40,7 @@ Enabling the `no-std` feature does not disable `std`. To disable the `std` featu
4040
To run the benchmarks run `RUSTFLAGS=--cfg=miniscript_bench cargo +nightly bench --all-features`.
4141

4242
## Minimum Supported Rust Version (MSRV)
43-
This library should always compile with any combination of features on **Rust 1.48.0**.
43+
This library should always compile with any combination of features on **Rust 1.58.0**.
4444

4545

4646
Some dependencies do not play nicely with our MSRV, if you are running the tests

bitcoind-tests/tests/test_arith.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use elements::pset::PartiallySignedTransaction as Psbt;
77
use elements::sighash::SigHashCache;
8-
use elements::taproot::{LeafVersion, TapLeafHash};
8+
use elements::taproot::TapLeafHash;
99
use elements::{
1010
confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint, Script, Sequence,
1111
TxIn, TxOut, Txid,
@@ -107,9 +107,9 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
107107
// ------------------ script spend -------------
108108
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
109109
.iter_scripts()
110-
.flat_map(|(_depth, ms)| {
111-
let leaf_hash = TapLeafHash::from_script(&ms.encode(), LeafVersion::default());
112-
ms.iter_pk().filter_map(move |pk| {
110+
.flat_map(|(_depth, script)| {
111+
let leaf_hash = TapLeafHash::from_script(&script.encode(), script.version());
112+
script.iter_pk().filter_map(move |pk| {
113113
let i = x_only_pks.iter().position(|&x| x.to_public_key() == pk);
114114
i.map(|idx| (xonly_keypairs[idx], leaf_hash))
115115
})

bitcoind-tests/tests/test_csfs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use elements::pset::PartiallySignedTransaction as Psbt;
77
use elements::sighash::SigHashCache;
8-
use elements::taproot::{LeafVersion, TapLeafHash};
8+
use elements::taproot::TapLeafHash;
99
use elements::{
1010
confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint, Script, Sequence,
1111
TxIn, TxOut, Txid,
@@ -108,9 +108,9 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
108108
// ------------------ script spend -------------
109109
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
110110
.iter_scripts()
111-
.flat_map(|(_depth, ms)| {
112-
let leaf_hash = TapLeafHash::from_script(&ms.encode(), LeafVersion::default());
113-
ms.iter_pk().filter_map(move |pk| {
111+
.flat_map(|(_depth, script)| {
112+
let leaf_hash = TapLeafHash::from_script(&script.encode(), script.version());
113+
script.iter_pk().filter_map(move |pk| {
114114
let i = x_only_pks.iter().position(|&x| x.to_public_key() == pk);
115115
i.map(|idx| (xonly_keypairs[idx], leaf_hash))
116116
})

bitcoind-tests/tests/test_desc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{error, fmt};
99
use elements::hashes::{sha256d, Hash};
1010
use elements::pset::PartiallySignedTransaction as Psbt;
1111
use elements::sighash::SigHashCache;
12-
use elements::taproot::{LeafVersion, TapLeafHash};
12+
use elements::taproot::TapLeafHash;
1313
use elements::{
1414
confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint, SchnorrSig, Script,
1515
Sequence, TxIn, TxOut, Txid,
@@ -178,9 +178,9 @@ pub fn test_desc_satisfy(
178178
// ------------------ script spend -------------
179179
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
180180
.iter_scripts()
181-
.flat_map(|(_depth, ms)| {
182-
let leaf_hash = TapLeafHash::from_script(&ms.encode(), LeafVersion::default());
183-
ms.iter_pk().filter_map(move |pk| {
181+
.flat_map(|(_depth, script)| {
182+
let leaf_hash = TapLeafHash::from_script(&script.encode(), script.version());
183+
script.iter_pk().filter_map(move |pk| {
184184
let i = x_only_pks.iter().position(|&x| x.to_public_key() == pk);
185185
i.map(|idx| (xonly_keypairs[idx], leaf_hash))
186186
})

bitcoind-tests/tests/test_introspect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use elements::pset::PartiallySignedTransaction as Psbt;
77
use elements::sighash::SigHashCache;
8-
use elements::taproot::{LeafVersion, TapLeafHash};
8+
use elements::taproot::TapLeafHash;
99
use elements::{
1010
confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint, Script, Sequence,
1111
TxIn, TxOut, Txid,
@@ -107,9 +107,9 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
107107
// ------------------ script spend -------------
108108
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
109109
.iter_scripts()
110-
.flat_map(|(_depth, ms)| {
111-
let leaf_hash = TapLeafHash::from_script(&ms.encode(), LeafVersion::default());
112-
ms.iter_pk().filter_map(move |pk| {
110+
.flat_map(|(_depth, script)| {
111+
let leaf_hash = TapLeafHash::from_script(&script.encode(), script.version());
112+
script.iter_pk().filter_map(move |pk| {
113113
let i = x_only_pks.iter().position(|&x| x.to_public_key() == pk);
114114
i.map(|idx| (xonly_keypairs[idx], leaf_hash))
115115
})

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.48.0"
1+
msrv = "1.58.0"

contrib/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ FEATURES="compiler serde rand base64"
77
cargo --version
88
rustc --version
99

10-
# Pin dependencies required to build with Rust 1.48
11-
if cargo --version | grep "1\.48"; then
10+
# Pin dependencies required to build with Rust 1.58
11+
if cargo --version | grep "1\.58"; then
1212
cargo update -p quote --precise 1.0.28
1313
cargo update -p proc-macro2 --precise 1.0.63
1414
cargo update -p serde_json --precise 1.0.99

examples/taproot.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use miniscript::policy::Concrete;
99
use miniscript::{
1010
translate_hash_fail, Descriptor, Miniscript, NoExt, Tap, TranslatePk, Translator,
1111
};
12+
use miniscript::descriptor::TapLeafScript;
1213
use secp256k1::{rand, KeyPair};
1314

1415
// Refer to https://github.com/sanket1729/adv_btc_workshop/blob/master/workshop.md#creating-a-taproot-descriptor
@@ -70,14 +71,14 @@ fn main() {
7071
iter.next().unwrap(),
7172
(
7273
1,
73-
&Miniscript::<String, Tap, NoExt>::from_str("and_v(vc:pk_k(In),older(9))").unwrap()
74+
TapLeafScript::Miniscript(&Miniscript::<String, Tap, NoExt>::from_str("and_v(vc:pk_k(In),older(9))").unwrap())
7475
)
7576
);
7677
assert_eq!(
7778
iter.next().unwrap(),
7879
(
7980
1,
80-
&Miniscript::<String, Tap, NoExt>::from_str("multi_a(2,hA,S)").unwrap()
81+
TapLeafScript::Miniscript(&Miniscript::<String, Tap, NoExt>::from_str("multi_a(2,hA,S)").unwrap())
8182
)
8283
);
8384
assert_eq!(iter.next(), None);

0 commit comments

Comments
 (0)