From de8c915815479fc96e210a91f6f55ba281256cde Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Mon, 7 Aug 2023 17:17:55 +0200 Subject: [PATCH] SFT-UNKN: Add foundation-psbt fuzz tests. Signed-off-by: Jean-Pierre De Jesus DIAZ --- Cargo.toml | 2 + psbt/fuzz/Cargo.toml | 40 +++++++++++++++++++ psbt/fuzz/fuzz_targets/compact_size.rs | 10 +++++ psbt/fuzz/fuzz_targets/global_key.rs | 10 +++++ psbt/fuzz/fuzz_targets/global_key_pair.rs | 10 +++++ .../partially_signed_bitcoin_transaction.rs | 10 +++++ 6 files changed, 82 insertions(+) create mode 100644 psbt/fuzz/Cargo.toml create mode 100644 psbt/fuzz/fuzz_targets/compact_size.rs create mode 100644 psbt/fuzz/fuzz_targets/global_key.rs create mode 100644 psbt/fuzz/fuzz_targets/global_key_pair.rs create mode 100644 psbt/fuzz/fuzz_targets/partially_signed_bitcoin_transaction.rs diff --git a/Cargo.toml b/Cargo.toml index 04b253f..0022ef7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "codecs", "ffi", "psbt", + "psbt/fuzz", "test-vectors", "ur", "urtypes", @@ -30,6 +31,7 @@ either = { version = "1", default-features = false } foundation-arena = { path = "arena" } foundation-bip32 = { path = "bip32" } foundation-codecs = { path = "codecs" } +foundation-psbt = { path = "psbt" } foundation-test-vectors = { path = "test-vectors" } foundation-urtypes = { path = "urtypes" } heapless = { version = "0.8", git = "https://github.com/japaric/heapless", default-features = false } diff --git a/psbt/fuzz/Cargo.toml b/psbt/fuzz/Cargo.toml new file mode 100644 index 0000000..4ec96d7 --- /dev/null +++ b/psbt/fuzz/Cargo.toml @@ -0,0 +1,40 @@ +# SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. +# SPDX-License-Identifier: GPL-3.0-or-later + +[package] +name = "foundation-psbt-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +foundation-psbt = { workspace = true } +libfuzzer-sys = { workspace = true } +nom = { workspace = true } + +[[bin]] +name = "compact_size" +path = "fuzz_targets/compact_size.rs" +test = false +doc = false + +[[bin]] +name = "global_key" +path = "fuzz_targets/global_key.rs" +test = false +doc = false + +[[bin]] +name = "global_key_pair" +path = "fuzz_targets/global_key_pair.rs" +test = false +doc = false + +[[bin]] +name = "partially_signed_bitcoin_transaction" +path = "fuzz_targets/partially_signed_bitcoin_transaction.rs" +test = false +doc = false diff --git a/psbt/fuzz/fuzz_targets/compact_size.rs b/psbt/fuzz/fuzz_targets/compact_size.rs new file mode 100644 index 0000000..ee5ac70 --- /dev/null +++ b/psbt/fuzz/fuzz_targets/compact_size.rs @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. +// SPDX-License-Identifier: GPL-3.0-or-later + +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + foundation_psbt::parser::global_key::>(data).ok(); +}); diff --git a/psbt/fuzz/fuzz_targets/global_key.rs b/psbt/fuzz/fuzz_targets/global_key.rs new file mode 100644 index 0000000..ee5ac70 --- /dev/null +++ b/psbt/fuzz/fuzz_targets/global_key.rs @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. +// SPDX-License-Identifier: GPL-3.0-or-later + +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + foundation_psbt::parser::global_key::>(data).ok(); +}); diff --git a/psbt/fuzz/fuzz_targets/global_key_pair.rs b/psbt/fuzz/fuzz_targets/global_key_pair.rs new file mode 100644 index 0000000..6ea79e0 --- /dev/null +++ b/psbt/fuzz/fuzz_targets/global_key_pair.rs @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. +// SPDX-License-Identifier: GPL-3.0-or-later + +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + foundation_psbt::parser::global_key_pair::>(data).ok(); +}); diff --git a/psbt/fuzz/fuzz_targets/partially_signed_bitcoin_transaction.rs b/psbt/fuzz/fuzz_targets/partially_signed_bitcoin_transaction.rs new file mode 100644 index 0000000..c32d283 --- /dev/null +++ b/psbt/fuzz/fuzz_targets/partially_signed_bitcoin_transaction.rs @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. +// SPDX-License-Identifier: GPL-3.0-or-later + +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + foundation_psbt::parser::partially_signed_bitcoin_transaction::>(data).ok(); +});