From 8235d5ffb669b6dae035dd04ebc9191b7b55fcc2 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Fri, 30 Aug 2024 21:24:07 +0000 Subject: [PATCH] descriptor: add fuzz test comparing to published rust-miniscript 12 This bumps the local Cargo.toml version to 13, which will be the next release (since we've made many breaking changes), and in the fuzz test adds an explicit dependency on miniscript 12 from crates.io, as `old_miniscript`. Adds a single fuzztest which attempt to parse descriptors with both master and 12, to make sure they're the same. --- .github/workflows/cron-daily-fuzz.yml | 1 + Cargo-minimal.lock | 15 ++++++- Cargo-recent.lock | 15 ++++++- Cargo.toml | 2 +- fuzz/Cargo.toml | 5 +++ .../regression_descriptor_parse.rs | 43 +++++++++++++++++++ fuzz/generate-files.sh | 1 + 7 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 fuzz/fuzz_targets/regression_descriptor_parse.rs diff --git a/.github/workflows/cron-daily-fuzz.yml b/.github/workflows/cron-daily-fuzz.yml index 9c2f4e6fc..5c9f259be 100644 --- a/.github/workflows/cron-daily-fuzz.yml +++ b/.github/workflows/cron-daily-fuzz.yml @@ -22,6 +22,7 @@ compile_descriptor, compile_taproot, parse_descriptor, parse_descriptor_secret, +regression_descriptor_parse, roundtrip_concrete, roundtrip_descriptor, roundtrip_miniscript_script, diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index 4969b5a85..e5cf13fed 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -111,7 +111,8 @@ name = "descriptor-fuzz" version = "0.0.1" dependencies = [ "honggfuzz", - "miniscript", + "miniscript 12.3.0", + "miniscript 13.0.0", "regex", ] @@ -181,7 +182,17 @@ dependencies = [ [[package]] name = "miniscript" -version = "12.2.0" +version = "12.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bd3c9608217b0d6fa9c9c8ddd875b85ab72bd4311cfc8db35e1b5a08fc11f4d" +dependencies = [ + "bech32", + "bitcoin", +] + +[[package]] +name = "miniscript" +version = "13.0.0" dependencies = [ "bech32", "bitcoin", diff --git a/Cargo-recent.lock b/Cargo-recent.lock index 4969b5a85..e5cf13fed 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -111,7 +111,8 @@ name = "descriptor-fuzz" version = "0.0.1" dependencies = [ "honggfuzz", - "miniscript", + "miniscript 12.3.0", + "miniscript 13.0.0", "regex", ] @@ -181,7 +182,17 @@ dependencies = [ [[package]] name = "miniscript" -version = "12.2.0" +version = "12.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bd3c9608217b0d6fa9c9c8ddd875b85ab72bd4311cfc8db35e1b5a08fc11f4d" +dependencies = [ + "bech32", + "bitcoin", +] + +[[package]] +name = "miniscript" +version = "13.0.0" dependencies = [ "bech32", "bitcoin", diff --git a/Cargo.toml b/Cargo.toml index 88860af96..929b68e4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miniscript" -version = "12.2.0" +version = "13.0.0" 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 db5187266..36e56edf2 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -12,6 +12,7 @@ cargo-fuzz = true [dependencies] honggfuzz = { version = "0.5.56", default-features = false } miniscript = { path = "..", features = [ "compiler" ] } +old_miniscript = { package = "miniscript", version = "12.3" } regex = "1.0" @@ -31,6 +32,10 @@ path = "fuzz_targets/parse_descriptor.rs" name = "parse_descriptor_secret" path = "fuzz_targets/parse_descriptor_secret.rs" +[[bin]] +name = "regression_descriptor_parse" +path = "fuzz_targets/regression_descriptor_parse.rs" + [[bin]] name = "roundtrip_concrete" path = "fuzz_targets/roundtrip_concrete.rs" diff --git a/fuzz/fuzz_targets/regression_descriptor_parse.rs b/fuzz/fuzz_targets/regression_descriptor_parse.rs new file mode 100644 index 000000000..c25fd2c55 --- /dev/null +++ b/fuzz/fuzz_targets/regression_descriptor_parse.rs @@ -0,0 +1,43 @@ +use core::str::FromStr; + +use honggfuzz::fuzz; +use miniscript::{Descriptor, DescriptorPublicKey}; +use old_miniscript::{Descriptor as OldDescriptor, DescriptorPublicKey as OldDescriptorPublicKey}; + +type Desc = Descriptor; +type OldDesc = OldDescriptor; + +fn do_test(data: &[u8]) { + let data_str = String::from_utf8_lossy(data); + match (Desc::from_str(&data_str), OldDesc::from_str(&data_str)) { + (Err(_), Err(_)) => {} + (Ok(x), Err(e)) => panic!("new logic parses {} as {:?}, old fails with {}", data_str, x, e), + (Err(e), Ok(x)) => panic!("old logic parses {} as {:?}, new fails with {}", data_str, x, e), + (Ok(new), Ok(old)) => { + assert_eq!( + old.to_string(), + new.to_string(), + "input {} (left is old, right is new)", + data_str + ) + } + } +} + +fn main() { + loop { + fuzz!(|data| { + do_test(data); + }); + } +} + +#[cfg(test)] +mod tests { + #[test] + fn duplicate_crash() { + crate::do_test( + b"tr(02dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd,{1,unun:0})", + ) + } +} diff --git a/fuzz/generate-files.sh b/fuzz/generate-files.sh index 743f9066f..b2b40a5eb 100755 --- a/fuzz/generate-files.sh +++ b/fuzz/generate-files.sh @@ -24,6 +24,7 @@ cargo-fuzz = true [dependencies] honggfuzz = { version = "0.5.56", default-features = false } miniscript = { path = "..", features = [ "compiler" ] } +old_miniscript = { package = "miniscript", git = "https://github.com/apoelstra/rust-miniscript/", rev = "1259375d7b7c91053e09d1cbe3db983612fe301c" } regex = "1.0" EOF