|
1 | 1 | #![allow(unexpected_cfgs)]
|
2 | 2 |
|
3 |
| -use std::fmt; |
4 |
| -use std::str::FromStr; |
5 | 3 | use std::sync::atomic::{AtomicUsize, Ordering};
|
6 | 4 |
|
| 5 | +use descriptor_fuzz::FuzzPk; |
7 | 6 | use honggfuzz::fuzz;
|
8 |
| -use miniscript::bitcoin::hashes::{hash160, ripemd160, sha256, Hash}; |
| 7 | +use miniscript::bitcoin::hashes::hash160; |
9 | 8 | use miniscript::bitcoin::locktime::{absolute, relative};
|
10 | 9 | use miniscript::bitcoin::taproot::Signature;
|
11 | 10 | use miniscript::bitcoin::{secp256k1, PublicKey, TapLeafHash, TapSighashType, XOnlyPublicKey};
|
12 |
| -use miniscript::{hash256, Miniscript, MiniscriptKey, Satisfier, Segwitv0, Tap, ToPublicKey}; |
13 |
| - |
14 |
| -// FIXME pull this out into a library used by all the fuzztests |
15 |
| -#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Hash)] |
16 |
| -struct FuzzPk { |
17 |
| - compressed: bool, |
18 |
| -} |
19 |
| - |
20 |
| -impl FuzzPk { |
21 |
| - pub fn new_from_control_byte(control: u8) -> Self { Self { compressed: control & 1 == 1 } } |
22 |
| -} |
23 |
| - |
24 |
| -impl FromStr for FuzzPk { |
25 |
| - type Err = std::num::ParseIntError; |
26 |
| - fn from_str(s: &str) -> Result<Self, Self::Err> { |
27 |
| - let byte = u8::from_str_radix(s, 16)?; |
28 |
| - Ok(Self::new_from_control_byte(byte)) |
29 |
| - } |
30 |
| -} |
31 |
| - |
32 |
| -impl fmt::Display for FuzzPk { |
33 |
| - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { "[fuzz pubkey]".fmt(f) } |
34 |
| -} |
35 |
| - |
36 |
| -impl MiniscriptKey for FuzzPk { |
37 |
| - type Sha256 = u8; |
38 |
| - type Ripemd160 = u8; |
39 |
| - type Hash160 = u8; |
40 |
| - type Hash256 = u8; |
41 |
| -} |
42 |
| - |
43 |
| -impl ToPublicKey for FuzzPk { |
44 |
| - fn to_public_key(&self) -> PublicKey { |
45 |
| - let secp_pk = secp256k1::PublicKey::from_slice(&[ |
46 |
| - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x78, |
47 |
| - 0xce, 0x56, 0x3f, 0x89, 0xa0, 0xed, 0x94, 0x14, 0xf5, 0xaa, 0x28, 0xad, 0x0d, 0x96, |
48 |
| - 0xd6, 0x79, 0x5f, 0x9c, 0x63, 0x3f, 0x39, 0x79, 0xbf, 0x72, 0xae, 0x82, 0x02, 0x98, |
49 |
| - 0x3d, 0xc9, 0x89, 0xae, 0xc7, 0xf2, 0xff, 0x2e, 0xd9, 0x1b, 0xdd, 0x69, 0xce, 0x02, |
50 |
| - 0xfc, 0x07, 0x00, 0xca, 0x10, 0x0e, 0x59, 0xdd, 0xf3, |
51 |
| - ]) |
52 |
| - .unwrap(); |
53 |
| - PublicKey { inner: secp_pk, compressed: self.compressed } |
54 |
| - } |
55 |
| - |
56 |
| - fn to_sha256(hash: &Self::Sha256) -> sha256::Hash { sha256::Hash::from_byte_array([*hash; 32]) } |
57 |
| - |
58 |
| - fn to_hash256(hash: &Self::Hash256) -> hash256::Hash { |
59 |
| - hash256::Hash::from_byte_array([*hash; 32]) |
60 |
| - } |
61 |
| - |
62 |
| - fn to_ripemd160(hash: &Self::Ripemd160) -> ripemd160::Hash { |
63 |
| - ripemd160::Hash::from_byte_array([*hash; 20]) |
64 |
| - } |
65 |
| - |
66 |
| - fn to_hash160(hash: &Self::Ripemd160) -> hash160::Hash { |
67 |
| - hash160::Hash::from_byte_array([*hash; 20]) |
68 |
| - } |
69 |
| -} |
| 11 | +use miniscript::{Miniscript, Satisfier, Segwitv0, Tap}; |
70 | 12 |
|
71 | 13 | struct FuzzSatisfier<'b> {
|
72 | 14 | idx: AtomicUsize,
|
@@ -198,14 +140,14 @@ fn do_test(data: &[u8]) {
|
198 | 140 |
|
199 | 141 | let s = String::from_utf8_lossy(s);
|
200 | 142 | if control & 1 == 1 {
|
201 |
| - let ms = match Miniscript::<FuzzPk, Segwitv0>::from_str(&s) { |
| 143 | + let ms = match s.parse::<Miniscript<FuzzPk, Segwitv0>>() { |
202 | 144 | Ok(d) => d,
|
203 | 145 | Err(_) => return,
|
204 | 146 | };
|
205 | 147 |
|
206 | 148 | let _ = ms.build_template(&fuzz_sat);
|
207 | 149 | } else {
|
208 |
| - let ms = match Miniscript::<FuzzPk, Tap>::from_str(&s) { |
| 150 | + let ms = match s.parse::<Miniscript<FuzzPk, Tap>>() { |
209 | 151 | Ok(d) => d,
|
210 | 152 | Err(_) => return,
|
211 | 153 | };
|
|
0 commit comments