Skip to content

Commit

Permalink
descriptor: add fuzz test comparing to published rust-miniscript 12
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apoelstra committed Nov 27, 2024
1 parent ebae0ef commit 8235d5f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cron-daily-fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ compile_descriptor,
compile_taproot,
parse_descriptor,
parse_descriptor_secret,
regression_descriptor_parse,
roundtrip_concrete,
roundtrip_descriptor,
roundtrip_miniscript_script,
Expand Down
15 changes: 13 additions & 2 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ name = "descriptor-fuzz"
version = "0.0.1"
dependencies = [
"honggfuzz",
"miniscript",
"miniscript 12.3.0",
"miniscript 13.0.0",
"regex",
]

Expand Down Expand Up @@ -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",
Expand Down
15 changes: 13 additions & 2 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ name = "descriptor-fuzz"
version = "0.0.1"
dependencies = [
"honggfuzz",
"miniscript",
"miniscript 12.3.0",
"miniscript 13.0.0",
"regex",
]

Expand Down Expand Up @@ -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",
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 = "12.2.0"
version = "13.0.0"
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"
Expand Down
5 changes: 5 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand Down
43 changes: 43 additions & 0 deletions fuzz/fuzz_targets/regression_descriptor_parse.rs
Original file line number Diff line number Diff line change
@@ -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<DescriptorPublicKey>;
type OldDesc = OldDescriptor<OldDescriptorPublicKey>;

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})",
)
}
}
1 change: 1 addition & 0 deletions fuzz/generate-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8235d5f

Please sign in to comment.