Skip to content

Commit

Permalink
fuzz: add target for tapscript parsing from script
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoerg committed Feb 24, 2025
1 parent a17b34c commit 7c8b95c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 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 @@ -26,6 +26,7 @@ regression_descriptor_parse,
roundtrip_concrete,
roundtrip_descriptor,
roundtrip_miniscript_script,
roundtrip_miniscript_script_tap,
roundtrip_miniscript_str,
roundtrip_semantic,
]
Expand Down
4 changes: 4 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ path = "fuzz_targets/roundtrip_descriptor.rs"
name = "roundtrip_miniscript_script"
path = "fuzz_targets/roundtrip_miniscript_script.rs"

[[bin]]
name = "roundtrip_miniscript_script_tap"
path = "fuzz_targets/roundtrip_miniscript_script_tap.rs"

[[bin]]
name = "roundtrip_miniscript_str"
path = "fuzz_targets/roundtrip_miniscript_str.rs"
Expand Down
24 changes: 24 additions & 0 deletions fuzz/fuzz_targets/roundtrip_miniscript_script_tap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![allow(unexpected_cfgs)]

use honggfuzz::fuzz;
use miniscript::bitcoin::blockdata::script;
use miniscript::{Miniscript, Tap};

fn do_test(data: &[u8]) {
// Try round-tripping as a script
let script = script::Script::from_bytes(data);

if let Ok(pt) = Miniscript::<miniscript::bitcoin::key::XOnlyPublicKey, Tap>::parse(script) {
let output = pt.encode();
assert_eq!(pt.script_size(), output.len());
assert_eq!(&output, script);
}
}

fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}

0 comments on commit 7c8b95c

Please sign in to comment.