Skip to content

Commit

Permalink
Merge rust-bitcoin#792: fuzz: add target for tapscript parsing from s…
Browse files Browse the repository at this point in the history
…cript

f96bf24 fuzz: add target for tapscript parsing from script (Bruno Garcia)

Pull request description:

  This PR adds a new fuzz target to parse a miniscript from script hex for Tap. We currently have one target that does it for Segwitv0.

ACKs for top commit:
  apoelstra:
    ACK f96bf24; successfully ran local tests

Tree-SHA512: 97f61c52b5c582a278264a00df0c8cd7b871012f845f1b28dfd6d5fd3fceccef82b13b27bfed2357c67edf6181b53731eb71a244b73dc6599e839aab2ce78ccf
  • Loading branch information
apoelstra committed Mar 2, 2025
2 parents ee5e1f0 + f96bf24 commit 1101a79
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 @@ -27,6 +27,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 1101a79

Please sign in to comment.