Skip to content

Commit

Permalink
Merge branch 'master' into plan_spend_example_branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshil-Jani committed Jul 31, 2023
2 parents b4b7d09 + 1f645ad commit 0f8550c
Show file tree
Hide file tree
Showing 47 changed files with 1,083 additions and 864 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ compile_descriptor,
key: cache-${{ matrix.target }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.58
toolchain: 1.64
override: true
profile: minimal
- name: fuzz
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ jobs:
- rust: stable
- rust: beta
- rust: nightly
- rust: 1.41.1
- rust: 1.47
- rust: 1.48
steps:
- name: Checkout Crate
uses: actions/checkout@v2
Expand Down
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ no-std = ["hashbrown", "bitcoin/no-std"]
compiler = []
trace = []

unstable = []
serde = ["actual-serde", "bitcoin/serde"]
rand = ["bitcoin/rand"]
base64 = ["bitcoin/base64"]
Expand All @@ -34,7 +33,6 @@ actual-serde = { package = "serde", version = "1.0.103", optional = true }
serde_test = "1.0.147"
bitcoin = { version = "0.30.0", features = ["base64"] }
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
actual-base64 = { package = "base64", version = "0.13.0" }

[[example]]
name = "htlc"
Expand All @@ -52,10 +50,6 @@ required-features = ["std"]
name = "verify_tx"
required-features = ["std"]

[[example]]
name = "psbt"
required-features = ["std"]

[[example]]
name = "xpub_descriptors"
required-features = ["std"]
Expand Down
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Build](https://github.com/rust-bitcoin/rust-miniscript/workflows/Continuous%20integration/badge.svg)

**Minimum Supported Rust Version:** 1.41.1
**Minimum Supported Rust Version:** 1.48.0

# Miniscript

Expand Down Expand Up @@ -40,18 +40,10 @@ The cargo feature `std` is enabled by default. At least one of the features `std
Enabling the `no-std` feature does not disable `std`. To disable the `std` feature you must disable default features. The `no-std` feature only enables additional features required for this crate to be usable without `std`. Both can be enabled without conflict.

## Minimum Supported Rust Version (MSRV)
This library should always compile with any combination of features (minus
`no-std`) on **Rust 1.41.1** or **Rust 1.47** with `no-std`.
This library should always compile with any combination of features on **Rust 1.48.0**.

Some dependencies do not play nicely with our MSRV, if you are running the tests
you may need to pin as follows:

```
cargo update --package url --precise 2.2.2
cargo update --package form_urlencoded --precise 1.0.1
cargo update -p once_cell --precise 1.13.1
cargo update -p bzip2 --precise 0.4.2
```
you may need to pin some dependencies. See `./contrib/test.sh` for current pinning.

## Contributing

Expand All @@ -61,6 +53,11 @@ architectural mismatches. If you have any questions or ideas you want to discuss
please join us in
[##miniscript](https://web.libera.chat/?channels=##miniscript) on Libera.

## Benchmarks

We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the
bench marks use: `RUSTFLAGS='--cfg=bench' cargo +nightly bench`.


## Release Notes

Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.41.1"
msrv = "1.48.0"
36 changes: 24 additions & 12 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ FEATURES="compiler serde rand base64"
cargo --version
rustc --version

# Cache the toolchain we are using.
NIGHTLY=false
if cargo --version | grep nightly; then
NIGHTLY=true
fi

# Format if told to
if [ "$DO_FMT" = true ]
then
rustup component add rustfmt
cargo fmt -- --check
fi

# Pin dependencies required to build with Rust 1.41.1
if cargo --version | grep "1\.41\.0"; then
cargo update -p once_cell --precise 1.13.1
cargo update -p serde --precise 1.0.156
fi

# Pin dependencies required to build with Rust 1.47.0
if cargo --version | grep "1\.47\.0"; then
# Pin dependencies required to build with Rust 1.48.0
if cargo --version | grep "1\.48\.0"; then
cargo update -p once_cell --precise 1.13.1
cargo update -p serde --precise 1.0.156
cargo update -p quote --precise 1.0.28
cargo update -p proc-macro2 --precise 1.0.63
cargo update -p serde_json --precise 1.0.99
cargo update -p serde --precise 1.0.152
cargo update -p log --precise 0.4.18
cargo update -p serde_test --precise 1.0.152
fi

# Test bitcoind integration tests if told to (this only works with the stable toolchain)
Expand Down Expand Up @@ -56,7 +61,6 @@ then
cargo run --example parse
cargo run --example sign_multisig
cargo run --example verify_tx > /dev/null
cargo run --example psbt
cargo run --example xpub_descriptors
cargo run --example taproot --features=compiler
cargo run --example psbt_sign_finalize --features=base64
Expand All @@ -80,10 +84,18 @@ then
done
fi

# Bench if told to (this only works with the nightly toolchain)
# Bench if told to, only works with non-stable toolchain (nightly, beta).
if [ "$DO_BENCH" = true ]
then
cargo bench --features="unstable compiler"
if [ "$NIGHTLY" = false ]; then
if [ -n "$RUSTUP_TOOLCHAIN" ]; then
echo "RUSTUP_TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain"
else
echo "DO_BENCH requires a nightly toolchain"
fi
exit 1
fi
RUSTFLAGS='--cfg=bench' cargo bench
fi

# Build the docs if told to (this only works with the nightly toolchain)
Expand Down
21 changes: 5 additions & 16 deletions examples/htlc.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
// Miniscript
// Written in 2019 by
// Thomas Eizinger <thomas@coblox.tech>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
// along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
//
// Written by Thomas Eizinger <thomas@coblox.tech>
// SPDX-License-Identifier: CC0-1.0

//! Example: Create an HTLC with miniscript using the policy compiler

use std::str::FromStr;

use bitcoin::Network;
use miniscript::bitcoin::Network;
use miniscript::descriptor::Wsh;
use miniscript::policy::{Concrete, Liftable};

Expand Down Expand Up @@ -51,7 +40,7 @@ fn main() {
"or(and(pk(022222222222222222222222222222222222222222222222222222222222222222),sha256(1111111111111111111111111111111111111111111111111111111111111111)),and(pk(020202020202020202020202020202020202020202020202020202020202020202),older(4444)))"
);

// Get the scriptPpubkey for this Wsh descriptor.
// Get the scriptPubkey for this Wsh descriptor.
assert_eq!(
format!("{:x}", htlc_descriptor.script_pubkey()),
"0020d853877af928a8d2a569c9c0ed14bd16f6a80ce9cccaf8a6150fd8f7f8867ae2"
Expand All @@ -63,7 +52,7 @@ fn main() {
"21022222222222222222222222222222222222222222222222222222222222222222ac6476a91451814f108670aced2d77c1805ddd6634bc9d473188ad025c11b26782012088a82011111111111111111111111111111111111111111111111111111111111111118768"
);

// Get the address for this Wsh descriptor.v
// Get the address for this Wsh descriptor.
assert_eq!(
format!("{}", htlc_descriptor.address(Network::Bitcoin)),
"bc1qmpfcw7he9z5d9ftfe8qw699azmm2sr8fen903fs4plv007yx0t3qxfmqv5"
Expand Down
14 changes: 1 addition & 13 deletions examples/parse.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Miniscript
// Written in 2019 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
// along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
//
// SPDX-License-Identifier: CC0-1.0

//! Example: Parsing a descriptor from a string.

Expand Down
11 changes: 6 additions & 5 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// SPDX-License-Identifier: CC0-1.0

use std::collections::BTreeMap;
use std::str::FromStr;

use actual_base64 as base64;
use bitcoin::sighash::SighashCache;
use bitcoin::PrivateKey;
use miniscript::bitcoin::consensus::encode::deserialize;
use miniscript::bitcoin::hashes::hex::FromHex;
use miniscript::bitcoin::psbt::PartiallySignedTransaction as Psbt;
use miniscript::bitcoin::psbt::{self, Psbt};
use miniscript::bitcoin::sighash::SighashCache;
use miniscript::bitcoin::{
self, psbt, secp256k1, Address, Network, OutPoint, Script, Sequence, Transaction, TxIn, TxOut,
self, base64, secp256k1, Address, Network, OutPoint, PrivateKey, Script, Sequence, Transaction,
TxIn, TxOut,
};
use miniscript::plan::Assets;
use miniscript::psbt::{PsbtExt, PsbtInputExt};
Expand Down
14 changes: 1 addition & 13 deletions examples/sign_multisig.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Miniscript
// Written in 2019 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
// along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
//
// SPDX-License-Identifier: CC0-1.0

//! Example: Signing a 2-of-3 multisignature.

Expand Down
30 changes: 16 additions & 14 deletions examples/taproot.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: CC0-1.0

use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::address::WitnessVersion;
use bitcoin::key::XOnlyPublicKey;
use bitcoin::secp256k1::{rand, KeyPair};
use bitcoin::Network;
use miniscript::bitcoin::address::WitnessVersion;
use miniscript::bitcoin::key::{KeyPair, XOnlyPublicKey};
use miniscript::bitcoin::secp256k1::rand;
use miniscript::bitcoin::Network;
use miniscript::descriptor::DescriptorType;
use miniscript::policy::Concrete;
use miniscript::{translate_hash_fail, Descriptor, Miniscript, Tap, TranslatePk, Translator};
Expand All @@ -21,9 +23,8 @@ impl Translator<String, XOnlyPublicKey, ()> for StrPkTranslator {
self.pk_map.get(pk).copied().ok_or(())
}

// We don't need to implement these methods as we are not using them in the policy
// Fail if we encounter any hash fragments.
// See also translate_hash_clone! macro
// We don't need to implement these methods as we are not using them in the policy.
// Fail if we encounter any hash fragments. See also translate_hash_clone! macro.
translate_hash_fail!(String, XOnlyPublicKey, ());
}

Expand All @@ -39,7 +40,7 @@ fn main() {
.replace(&[' ', '\n', '\t'][..], "");

let _ms = Miniscript::<String, Tap>::from_str("and_v(v:ripemd160(H),pk(A))").unwrap();
let pol: Concrete<String> = Concrete::from_str(&pol_str).unwrap();
let pol = Concrete::<String>::from_str(&pol_str).unwrap();
// In case we can't find an internal key for the given policy, we set the internal key to
// a random pubkey as specified by BIP341 (which are *unspendable* by any party :p)
let desc = pol.compile_tr(Some("UNSPENDABLE_KEY".to_string())).unwrap();
Expand All @@ -52,7 +53,7 @@ fn main() {
// Check whether the descriptors are safe.
assert!(desc.sanity_check().is_ok());

// Descriptor Type and Version should match respectively for Taproot
// Descriptor type and version should match respectively for taproot
let desc_type = desc.desc_type();
assert_eq!(desc_type, DescriptorType::Tr);
assert_eq!(desc_type.segwit_version().unwrap(), WitnessVersion::V1);
Expand Down Expand Up @@ -99,11 +100,12 @@ fn main() {

let real_desc = desc.translate_pk(&mut t).unwrap();

// Max Satisfaction Weight for compilation, corresponding to the script-path spend
// `multi_a(2,PUBKEY_1,PUBKEY_2) at taptree depth 1, having
// Max Witness Size = varint(control_block_size) + control_block size +
// varint(script_size) + script_size + max_satisfaction_size
// = 1 + 65 + 1 + 70 + 132 = 269
// Max satisfaction weight for compilation, corresponding to the script-path spend
// `multi_a(2,PUBKEY_1,PUBKEY_2) at taptree depth 1, having:
//
// max_witness_size = varint(control_block_size) + control_block size +
// varint(script_size) + script_size + max_satisfaction_size
// = 1 + 65 + 1 + 70 + 132 = 269
let max_sat_wt = real_desc.max_weight_to_satisfy().unwrap();
assert_eq!(max_sat_wt, 269);

Expand Down
20 changes: 4 additions & 16 deletions examples/verify_tx.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
// Miniscript
// Written in 2019 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
// along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
//
// SPDX-License-Identifier: CC0-1.0

//! Example: Verifying a signed transaction.

use std::str::FromStr;

use bitcoin::consensus::Decodable;
use bitcoin::secp256k1::{self, Secp256k1};
use bitcoin::{absolute, sighash, Sequence};
use miniscript::bitcoin::consensus::Decodable;
use miniscript::bitcoin::secp256k1::{self, Secp256k1};
use miniscript::bitcoin::{absolute, sighash, Sequence};
use miniscript::interpreter::KeySigPair;

fn main() {
Expand Down
14 changes: 1 addition & 13 deletions examples/xpub_descriptors.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Miniscript
// Written in 2019 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
// along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
//
// SPDX-License-Identifier: CC0-1.0

//! Example: Parsing a xpub and getting an address.

Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cargo-fuzz = true
honggfuzz = { version = "0.5.55", default-features = false }
miniscript = { path = "..", features = [ "compiler" ] }

regex = "1.4"
regex = "1.0"

[[bin]]
name = "roundtrip_miniscript_str"
Expand Down

0 comments on commit 0f8550c

Please sign in to comment.