Skip to content

Commit 37a7d72

Browse files
committed
Merge rust-bitcoin#4713: Update deserialize_witness fuzz target to use the Witness arbitrary impl
ca344e6 Update deserialize_witness fuzz target to use arbitrary impl (Shing Him Ng) 66f7a0a Rename `deserialize_amount` to `parse_amount` (Shing Him Ng) 180dcdc Update fuzz script to include `arbitrary` and `p2p` as a dependency (Shing Him Ng) Pull request description: The result should be that the roundtrip logic is tested more often due to `arbitrary` yielding more valid Witnesses versus the previous case, which attempted to deserialize random bytes into a witness. IIUC this should also allow the fuzzer to find edge cases more easily as well ACKs for top commit: apoelstra: ACK ca344e6; successfully ran local tests Tree-SHA512: dec81a2caaadcd11989da9153228a8ad027b365ad6d6a8811b3555df272edc50209d3769fd19df95e0ee5c8776307166cbf841f4c56f0046a2942e213d76f8f5
2 parents 7f3ae16 + ca344e6 commit 37a7d72

File tree

8 files changed

+36
-20
lines changed

8 files changed

+36
-20
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ jobs:
1818
# We only get 20 jobs at a time, we probably don't want to go
1919
# over that limit with fuzzing because of the hour run time.
2020
fuzz_target: [
21+
bitcoin_deser_net_msg,
2122
bitcoin_deserialize_address,
2223
bitcoin_deserialize_block,
2324
bitcoin_deserialize_prefilled_transaction,
2425
bitcoin_deserialize_psbt,
2526
bitcoin_deserialize_script,
2627
bitcoin_deserialize_transaction,
2728
bitcoin_deserialize_witness,
28-
bitcoin_deser_net_msg,
2929
bitcoin_outpoint_string,
3030
bitcoin_p2p_address_roundtrip,
3131
bitcoin_script_bytes_to_asm_fmt,
3232
hashes_json,
3333
hashes_ripemd160,
3434
hashes_sha1,
3535
hashes_sha256,
36-
hashes_sha512_256,
3736
hashes_sha512,
38-
units_deserialize_amount,
37+
hashes_sha512_256,
38+
units_parse_amount,
3939
]
4040
steps:
4141
- name: Install test dependencies

Cargo-minimal.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ version = "0.0.0"
7676
name = "bitcoin-fuzz"
7777
version = "0.0.1"
7878
dependencies = [
79+
"arbitrary",
7980
"bitcoin",
8081
"bitcoin-p2p-messages",
8182
"honggfuzz",

Cargo-recent.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ version = "0.0.0"
7575
name = "bitcoin-fuzz"
7676
version = "0.0.1"
7777
dependencies = [
78+
"arbitrary",
7879
"bitcoin",
7980
"bitcoin-p2p-messages",
8081
"honggfuzz",

fuzz/Cargo.toml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "bitcoin-fuzz"
33
edition = "2021"
4+
rust-version = "1.63.0"
45
version = "0.0.1"
56
authors = ["Generated by fuzz/generate-files.sh"]
67
publish = false
@@ -10,15 +11,20 @@ cargo-fuzz = true
1011

1112
[dependencies]
1213
honggfuzz = { version = "0.5.56", default-features = false }
13-
bitcoin = { path = "../bitcoin", features = [ "serde" ] }
14+
bitcoin = { path = "../bitcoin", features = [ "serde", "arbitrary" ] }
1415
p2p = { path = "../p2p", package = "bitcoin-p2p-messages" }
16+
arbitrary = { version = "1.4" }
1517

1618
serde = { version = "1.0.103", features = [ "derive" ] }
1719
serde_json = "1.0"
1820

1921
[lints.rust]
2022
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(fuzzing)'] }
2123

24+
[[bin]]
25+
name = "bitcoin_deser_net_msg"
26+
path = "fuzz_targets/bitcoin/deser_net_msg.rs"
27+
2228
[[bin]]
2329
name = "bitcoin_deserialize_address"
2430
path = "fuzz_targets/bitcoin/deserialize_address.rs"
@@ -47,14 +53,14 @@ path = "fuzz_targets/bitcoin/deserialize_transaction.rs"
4753
name = "bitcoin_deserialize_witness"
4854
path = "fuzz_targets/bitcoin/deserialize_witness.rs"
4955

50-
[[bin]]
51-
name = "bitcoin_deser_net_msg"
52-
path = "fuzz_targets/bitcoin/deser_net_msg.rs"
53-
5456
[[bin]]
5557
name = "bitcoin_outpoint_string"
5658
path = "fuzz_targets/bitcoin/outpoint_string.rs"
5759

60+
[[bin]]
61+
name = "bitcoin_p2p_address_roundtrip"
62+
path = "fuzz_targets/bitcoin/p2p_address_roundtrip.rs"
63+
5864
[[bin]]
5965
name = "bitcoin_script_bytes_to_asm_fmt"
6066
path = "fuzz_targets/bitcoin/script_bytes_to_asm_fmt.rs"
@@ -75,18 +81,14 @@ path = "fuzz_targets/hashes/sha1.rs"
7581
name = "hashes_sha256"
7682
path = "fuzz_targets/hashes/sha256.rs"
7783

78-
[[bin]]
79-
name = "hashes_sha512_256"
80-
path = "fuzz_targets/hashes/sha512_256.rs"
81-
8284
[[bin]]
8385
name = "hashes_sha512"
8486
path = "fuzz_targets/hashes/sha512.rs"
8587

8688
[[bin]]
87-
name = "units_deserialize_amount"
88-
path = "fuzz_targets/units/deserialize_amount.rs"
89+
name = "hashes_sha512_256"
90+
path = "fuzz_targets/hashes/sha512_256.rs"
8991

9092
[[bin]]
91-
name = "bitcoin_p2p_address_roundtrip"
92-
path = "fuzz_targets/bitcoin/p2p_address_roundtrip.rs"
93+
name = "units_parse_amount"
94+
path = "fuzz_targets/units/parse_amount.rs"

fuzz/fuzz-util.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env bash
22

3+
# Sort order is affected by locale. See `man sort`.
4+
# > Set LC_ALL=C to get the traditional sort order that uses native byte values.
5+
export LC_ALL=C
6+
37
REPO_DIR=$(git rev-parse --show-toplevel)
48

59
listTargetFiles() {

fuzz/fuzz_targets/bitcoin/deserialize_witness.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
use bitcoin::consensus::{deserialize, serialize};
22
use bitcoin::witness::Witness;
33
use honggfuzz::fuzz;
4+
use arbitrary::{Arbitrary, Unstructured};
45

56
fn do_test(data: &[u8]) {
6-
let w: Result<Witness, _> = deserialize(data);
7+
let mut u = Unstructured::new(data);
8+
9+
let w = Witness::arbitrary(&mut u);
710
if let Ok(witness) = w {
811
let serialized = serialize(&witness);
9-
assert_eq!(data, &serialized[..]);
12+
let deserialized: Result<Witness, _> = deserialize(serialized.as_slice());
13+
14+
assert!(deserialized.is_ok());
15+
assert_eq!(deserialized.unwrap(), witness);
1016
}
1117
}
1218

File renamed without changes.

fuzz/generate-files.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ publish = false
2222
cargo-fuzz = true
2323
2424
[dependencies]
25-
honggfuzz = { version = "0.5.55", default-features = false }
26-
bitcoin = { path = "../bitcoin", features = [ "serde" ] }
25+
honggfuzz = { version = "0.5.56", default-features = false }
26+
bitcoin = { path = "../bitcoin", features = [ "serde", "arbitrary" ] }
27+
p2p = { path = "../p2p", package = "bitcoin-p2p-messages" }
28+
arbitrary = { version = "1.4" }
2729
2830
serde = { version = "1.0.103", features = [ "derive" ] }
2931
serde_json = "1.0"

0 commit comments

Comments
 (0)