Skip to content

Update multi_a to not include n wrapper #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 7.0.1 - March 8, 2023

- Fixed a typing rule in `multi_a` for taproot miniscript descriptors. Current typing rules
incorrectly tagged `multi_a` with the `n` property. Certain miniscripts of the form `j:multi_a` could
could not spent without the first key. We could not find any evidence of these scripts being used
in the wild. While this is technically a breaking change, any downstream users whose code would
break by this change are already vulnerable.

# 7.0.0 - April 20, 2022

- Fixed miniscript type system bug. This is a security vulnerability and users are strongly encouraged to upgrade.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miniscript"
version = "7.0.0"
version = "7.0.1"
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
repository = "https://github.com/apoelstra/miniscript"
description = "Miniscript: a subset of Bitcoin Script designed for analysis"
Expand Down
7 changes: 7 additions & 0 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ then
alias cargo="cargo +$TOOLCHAIN"
fi


# Pin dependencies as required if we are using MSRV toolchain.
if cargo --version | grep "1\.41"; then
# 1.0.108 uses `matches!` macro so does not work with Rust 1.41.1, bad `syn` no biscuit.
cargo update -p syn --precise 1.0.107
fi

# Lint if told to
if [ "$DO_LINT" = true ]
then
Expand Down
9 changes: 9 additions & 0 deletions src/miniscript/types/correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ impl Property for Correctness {
}
}

fn from_multi_a(_: usize, _: usize) -> Self {
Correctness {
base: Base::B,
input: Input::Any,
dissatisfiable: true,
unit: true,
}
}

fn from_hash() -> Self {
Correctness {
base: Base::B,
Expand Down
8 changes: 8 additions & 0 deletions src/miniscript/types/malleability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ impl Property for Malleability {
}
}

fn from_multi_a(_: usize, _: usize) -> Self {
Malleability {
dissat: Dissat::Unique,
safe: true,
non_malleable: true,
}
}

fn from_hash() -> Self {
Malleability {
dissat: Dissat::Unknown,
Expand Down
12 changes: 8 additions & 4 deletions src/miniscript/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ pub trait Property: Sized {
fn from_multi(k: usize, n: usize) -> Self;

/// Type property of a `MultiA` fragment
fn from_multi_a(k: usize, n: usize) -> Self {
// default impl same as multi
Self::from_multi(k, n)
}
fn from_multi_a(k: usize, n: usize) -> Self;

/// Type property of a hash fragment
fn from_hash() -> Self;
Expand Down Expand Up @@ -584,6 +581,13 @@ impl Property for Type {
}
}

fn from_multi_a(k: usize, n: usize) -> Self {
Type {
corr: Property::from_multi_a(k, n),
mall: Property::from_multi_a(k, n),
}
}

fn from_hash() -> Self {
Type {
corr: Property::from_hash(),
Expand Down
8 changes: 8 additions & 0 deletions src/policy/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ impl Property for CompilerExtData {
}
}

fn from_multi_a(k: usize, n: usize) -> Self {
CompilerExtData {
branch_prob: None,
sat_cost: 66.0 * k as f64 + (n - k) as f64,
dissat_cost: Some(n as f64), /* <w_n> ... <w_1> := 0x00 ... 0x00 (n times) */
}
}

fn from_hash() -> Self {
CompilerExtData {
branch_prob: None,
Expand Down