Skip to content

Commit a195c81

Browse files
committed
fuzz: add compile_taproot fuzztest
1 parent a6ca4ce commit a195c81

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

.github/workflows/cron-daily-fuzz.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
# over that limit with fuzzing because of the hour run time.
2020
fuzz_target: [
2121
compile_descriptor,
22+
compile_taproot,
2223
parse_descriptor,
2324
parse_descriptor_secret,
2425
roundtrip_concrete,

fuzz/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ regex = "1.0"
1919
name = "compile_descriptor"
2020
path = "fuzz_targets/compile_descriptor.rs"
2121

22+
[[bin]]
23+
name = "compile_taproot"
24+
path = "fuzz_targets/compile_taproot.rs"
25+
2226
[[bin]]
2327
name = "parse_descriptor"
2428
path = "fuzz_targets/parse_descriptor.rs"

fuzz/fuzz_targets/compile_taproot.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![allow(unexpected_cfgs)]
2+
3+
use std::str::FromStr;
4+
5+
use honggfuzz::fuzz;
6+
use miniscript::{policy, Miniscript, Tap};
7+
use policy::Liftable;
8+
9+
type Script = Miniscript<String, Tap>;
10+
type Policy = policy::Concrete<String>;
11+
12+
fn do_test(data: &[u8]) {
13+
let data_str = String::from_utf8_lossy(data);
14+
if let Ok(pol) = Policy::from_str(&data_str) {
15+
// Compile
16+
if let Ok(desc) = pol.compile::<Tap>() {
17+
// Lift
18+
assert_eq!(desc.lift().unwrap().sorted(), pol.lift().unwrap().sorted());
19+
// Try to roundtrip the output of the compiler
20+
let output = desc.to_string();
21+
if let Ok(desc) = Script::from_str(&output) {
22+
let rtt = desc.to_string();
23+
assert_eq!(output.to_lowercase(), rtt.to_lowercase());
24+
} else {
25+
panic!("compiler output something unparseable: {}", output)
26+
}
27+
}
28+
}
29+
}
30+
31+
fn main() {
32+
loop {
33+
fuzz!(|data| {
34+
do_test(data);
35+
});
36+
}
37+
}

fuzz/generate-files.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ publish = false
2222
cargo-fuzz = true
2323
2424
[dependencies]
25-
honggfuzz = { version = "0.5.55", default-features = false }
25+
honggfuzz = { version = "0.5.56", default-features = false }
2626
miniscript = { path = "..", features = [ "compiler" ] }
2727
2828
regex = "1.0"

0 commit comments

Comments
 (0)