diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index b00e258da..7ea77f17d 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -16,14 +16,14 @@ jobs: fail-fast: false matrix: fuzz_target: [ -roundtrip_semantic, +compile_descriptor, parse_descriptor, parse_descriptor_secret, +roundtrip_concrete, +roundtrip_descriptor, roundtrip_miniscript_script, roundtrip_miniscript_str, -roundtrip_descriptor, -roundtrip_concrete, -compile_descriptor, +roundtrip_semantic, ] steps: - name: Install test dependencies diff --git a/Cargo.toml b/Cargo.toml index f57dc899d..d8eadcdee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miniscript" -version = "11.2.0" +version = "11.2.1" authors = ["Andrew Poelstra , Sanket Kanjalkar "] license = "CC0-1.0" homepage = "https://github.com/rust-bitcoin/rust-miniscript/" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index c4b76a35d..8fb077cf1 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -15,8 +15,8 @@ miniscript = { path = "..", features = [ "compiler" ] } regex = "1.0" [[bin]] -name = "roundtrip_semantic" -path = "fuzz_targets/roundtrip_semantic.rs" +name = "compile_descriptor" +path = "fuzz_targets/compile_descriptor.rs" [[bin]] name = "parse_descriptor" @@ -27,21 +27,21 @@ name = "parse_descriptor_secret" path = "fuzz_targets/parse_descriptor_secret.rs" [[bin]] -name = "roundtrip_miniscript_script" -path = "fuzz_targets/roundtrip_miniscript_script.rs" - -[[bin]] -name = "roundtrip_miniscript_str" -path = "fuzz_targets/roundtrip_miniscript_str.rs" +name = "roundtrip_concrete" +path = "fuzz_targets/roundtrip_concrete.rs" [[bin]] name = "roundtrip_descriptor" path = "fuzz_targets/roundtrip_descriptor.rs" [[bin]] -name = "roundtrip_concrete" -path = "fuzz_targets/roundtrip_concrete.rs" +name = "roundtrip_miniscript_script" +path = "fuzz_targets/roundtrip_miniscript_script.rs" [[bin]] -name = "compile_descriptor" -path = "fuzz_targets/compile_descriptor.rs" +name = "roundtrip_miniscript_str" +path = "fuzz_targets/roundtrip_miniscript_str.rs" + +[[bin]] +name = "roundtrip_semantic" +path = "fuzz_targets/roundtrip_semantic.rs" diff --git a/fuzz/fuzz-util.sh b/fuzz/fuzz-util.sh index 804e0da92..dcce45256 100755 --- a/fuzz/fuzz-util.sh +++ b/fuzz/fuzz-util.sh @@ -2,9 +2,13 @@ REPO_DIR=$(git rev-parse --show-toplevel) +# Sort order is effected by locale. See `man sort`. +# > Set LC_ALL=C to get the traditional sort order that uses native byte values. +export LC_ALL=C + listTargetFiles() { pushd "$REPO_DIR/fuzz" > /dev/null || exit 1 - find fuzz_targets/ -type f -name "*.rs" + find fuzz_targets/ -type f -name "*.rs" | sort popd > /dev/null || exit 1 } diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index a81a2786e..feea99161 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -725,12 +725,9 @@ impl Descriptor { } let descriptor = Descriptor::::from_str(s)?; - let descriptor = descriptor.translate_pk(&mut keymap_pk).map_err(|e| { - Error::Unexpected( - e.expect_translator_err("No Outer context errors") - .to_string(), - ) - })?; + let descriptor = descriptor + .translate_pk(&mut keymap_pk) + .map_err(TranslateErr::flatten)?; Ok((descriptor, keymap_pk.0)) } @@ -2053,4 +2050,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))"; Desc::from_str(&format!("tr({},pk({}))", x_only_key, uncomp_key)).unwrap_err(); Desc::from_str(&format!("tr({},pk({}))", x_only_key, x_only_key)).unwrap(); } + + #[test] + fn regression_806() { + let secp = secp256k1::Secp256k1::signing_only(); + type Desc = Descriptor; + // OK + Desc::from_str("pkh(111111111111111111111111111111110000008375319363688624584A111111)") + .unwrap_err(); + // ERR: crashes in translate_pk + Desc::parse_descriptor( + &secp, + "pkh(111111111111111111111111111111110000008375319363688624584A111111)", + ) + .unwrap_err(); + } } diff --git a/src/lib.rs b/src/lib.rs index f62406902..0f2fec080 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,9 +82,6 @@ #![deny(non_camel_case_types)] #![deny(non_snake_case)] #![deny(unused_mut)] -#![deny(dead_code)] -#![deny(unused_imports)] -#![deny(missing_docs)] // Clippy lints that we have disabled #![allow(clippy::iter_kv_map)] // https://github.com/rust-lang/rust-clippy/issues/11752 @@ -343,10 +340,22 @@ impl TranslateErr { /// /// This function will panic if the Error is OutError. pub fn expect_translator_err(self, msg: &str) -> E { - if let Self::TranslatorErr(v) = self { - v - } else { - panic!("{}", msg) + match self { + Self::TranslatorErr(v) => v, + Self::OuterError(ref e) => { + panic!("Unexpected Miniscript error when translating: {}\nMessage: {}", e, msg) + } + } + } +} + +impl TranslateErr { + /// If we are doing a translation where our "outer error" is the generic + /// Miniscript error, eliminate the `TranslateErr` type which is just noise. + pub fn flatten(self) -> Error { + match self { + Self::TranslatorErr(e) => e, + Self::OuterError(e) => e, } } }