Skip to content

Commit 7b459e2

Browse files
committed
Merge #816: Backport #809 to 11.x
953e679 bump patch version of 11.2 (Andrew Poelstra) 3bf002c add regression test for #806 (Andrew Poelstra) 4f8b065 descriptor: fix key parsing error handling in parse_desc (Andrew Poelstra) 7c651f4 ci: update fuzz CI job to reorder tests (Andrew Poelstra) aaf276c lib: remove some deny lints (Andrew Poelstra) Pull request description: Backport of #809 to 11.x. Last backport for this PR. ACKs for top commit: sanket1729: utACK 953e679 Tree-SHA512: 8f9ee0b49f2d2e1e4560a950bd84dad2bef285e72466b3ccf19170157958e5749bc73194581b40c7dc977c6938627ccb444d58a2161934e148281891c6b319de
2 parents 2c9d2e7 + 953e679 commit 7b459e2

File tree

6 files changed

+56
-31
lines changed

6 files changed

+56
-31
lines changed

.github/workflows/fuzz.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
fuzz_target: [
19-
roundtrip_semantic,
19+
compile_descriptor,
2020
parse_descriptor,
2121
parse_descriptor_secret,
22+
roundtrip_concrete,
23+
roundtrip_descriptor,
2224
roundtrip_miniscript_script,
2325
roundtrip_miniscript_str,
24-
roundtrip_descriptor,
25-
roundtrip_concrete,
26-
compile_descriptor,
26+
roundtrip_semantic,
2727
]
2828
steps:
2929
- name: Install test dependencies

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "11.2.0"
3+
version = "11.2.1"
44
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"

fuzz/Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ miniscript = { path = "..", features = [ "compiler" ] }
1515
regex = "1.0"
1616

1717
[[bin]]
18-
name = "roundtrip_semantic"
19-
path = "fuzz_targets/roundtrip_semantic.rs"
18+
name = "compile_descriptor"
19+
path = "fuzz_targets/compile_descriptor.rs"
2020

2121
[[bin]]
2222
name = "parse_descriptor"
@@ -27,21 +27,21 @@ name = "parse_descriptor_secret"
2727
path = "fuzz_targets/parse_descriptor_secret.rs"
2828

2929
[[bin]]
30-
name = "roundtrip_miniscript_script"
31-
path = "fuzz_targets/roundtrip_miniscript_script.rs"
32-
33-
[[bin]]
34-
name = "roundtrip_miniscript_str"
35-
path = "fuzz_targets/roundtrip_miniscript_str.rs"
30+
name = "roundtrip_concrete"
31+
path = "fuzz_targets/roundtrip_concrete.rs"
3632

3733
[[bin]]
3834
name = "roundtrip_descriptor"
3935
path = "fuzz_targets/roundtrip_descriptor.rs"
4036

4137
[[bin]]
42-
name = "roundtrip_concrete"
43-
path = "fuzz_targets/roundtrip_concrete.rs"
38+
name = "roundtrip_miniscript_script"
39+
path = "fuzz_targets/roundtrip_miniscript_script.rs"
4440

4541
[[bin]]
46-
name = "compile_descriptor"
47-
path = "fuzz_targets/compile_descriptor.rs"
42+
name = "roundtrip_miniscript_str"
43+
path = "fuzz_targets/roundtrip_miniscript_str.rs"
44+
45+
[[bin]]
46+
name = "roundtrip_semantic"
47+
path = "fuzz_targets/roundtrip_semantic.rs"

fuzz/fuzz-util.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
REPO_DIR=$(git rev-parse --show-toplevel)
44

5+
# Sort order is effected by locale. See `man sort`.
6+
# > Set LC_ALL=C to get the traditional sort order that uses native byte values.
7+
export LC_ALL=C
8+
59
listTargetFiles() {
610
pushd "$REPO_DIR/fuzz" > /dev/null || exit 1
7-
find fuzz_targets/ -type f -name "*.rs"
11+
find fuzz_targets/ -type f -name "*.rs" | sort
812
popd > /dev/null || exit 1
913
}
1014

src/descriptor/mod.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,12 +725,9 @@ impl Descriptor<DescriptorPublicKey> {
725725
}
726726

727727
let descriptor = Descriptor::<String>::from_str(s)?;
728-
let descriptor = descriptor.translate_pk(&mut keymap_pk).map_err(|e| {
729-
Error::Unexpected(
730-
e.expect_translator_err("No Outer context errors")
731-
.to_string(),
732-
)
733-
})?;
728+
let descriptor = descriptor
729+
.translate_pk(&mut keymap_pk)
730+
.map_err(TranslateErr::flatten)?;
734731

735732
Ok((descriptor, keymap_pk.0))
736733
}
@@ -2053,4 +2050,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
20532050
Desc::from_str(&format!("tr({},pk({}))", x_only_key, uncomp_key)).unwrap_err();
20542051
Desc::from_str(&format!("tr({},pk({}))", x_only_key, x_only_key)).unwrap();
20552052
}
2053+
2054+
#[test]
2055+
fn regression_806() {
2056+
let secp = secp256k1::Secp256k1::signing_only();
2057+
type Desc = Descriptor<DescriptorPublicKey>;
2058+
// OK
2059+
Desc::from_str("pkh(111111111111111111111111111111110000008375319363688624584A111111)")
2060+
.unwrap_err();
2061+
// ERR: crashes in translate_pk
2062+
Desc::parse_descriptor(
2063+
&secp,
2064+
"pkh(111111111111111111111111111111110000008375319363688624584A111111)",
2065+
)
2066+
.unwrap_err();
2067+
}
20562068
}

src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@
8282
#![deny(non_camel_case_types)]
8383
#![deny(non_snake_case)]
8484
#![deny(unused_mut)]
85-
#![deny(dead_code)]
86-
#![deny(unused_imports)]
87-
#![deny(missing_docs)]
8885
// Clippy lints that we have disabled
8986
#![allow(clippy::iter_kv_map)] // https://github.com/rust-lang/rust-clippy/issues/11752
9087

@@ -343,10 +340,22 @@ impl<E> TranslateErr<E> {
343340
///
344341
/// This function will panic if the Error is OutError.
345342
pub fn expect_translator_err(self, msg: &str) -> E {
346-
if let Self::TranslatorErr(v) = self {
347-
v
348-
} else {
349-
panic!("{}", msg)
343+
match self {
344+
Self::TranslatorErr(v) => v,
345+
Self::OuterError(ref e) => {
346+
panic!("Unexpected Miniscript error when translating: {}\nMessage: {}", e, msg)
347+
}
348+
}
349+
}
350+
}
351+
352+
impl TranslateErr<Error> {
353+
/// If we are doing a translation where our "outer error" is the generic
354+
/// Miniscript error, eliminate the `TranslateErr` type which is just noise.
355+
pub fn flatten(self) -> Error {
356+
match self {
357+
Self::TranslatorErr(e) => e,
358+
Self::OuterError(e) => e,
350359
}
351360
}
352361
}

0 commit comments

Comments
 (0)