Skip to content

Rename rust_secp_fuzz config flag to fuzzing #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secp256k1"
version = "0.20.0"
version = "0.20.1"
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
"Andrew Poelstra <[email protected]>" ]
license = "CC0-1.0"
Expand Down Expand Up @@ -56,4 +56,4 @@ required-features = ["rand"]

[workspace]
members = ["secp256k1-sys"]
exclude = ["no_std_test"]
exclude = ["no_std_test"]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ If you want to fuzz this library, or any library which depends on it, you will
probably want to disable the actual cryptography, since fuzzers are unable to
forge signatures and therefore won't test many interesting codepaths. To instead
use a trivially-broken but fuzzer-accessible signature scheme, compile with
`--cfg=rust_secp_fuzz` in your `RUSTFLAGS` variable.
`--cfg=fuzzing` in your `RUSTFLAGS` variable.

Note that `cargo hfuzz` sets this config flag automatically.

6 changes: 3 additions & 3 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
done

# Other combos
RUSTFLAGS='--cfg=rust_secp_fuzz' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all
RUSTFLAGS='--cfg=rust_secp_fuzz' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all --features="$FEATURES"
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all --features="$FEATURES"
cargo test --all --features="rand rand-std"
cargo test --all --features="rand serde"

if [ "$DO_BENCH" = true ]; then # proxy for us having a nightly compiler
cargo test --all --all-features
RUSTFLAGS='--cfg=rust_secp_fuzz' RUSTDOCFLAGS='--cfg=rust_secp_fuzz' cargo test --all --all-features
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS='--cfg=fuzzing' cargo test --all --all-features
fi

# Examples
Expand Down
8 changes: 4 additions & 4 deletions secp256k1-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#[cfg(any(test, feature = "std"))]
extern crate core;

#[cfg(rust_secp_fuzz)]
#[cfg(fuzzing)]
const THIS_UNUSED_CONSTANT_IS_YOUR_WARNING_THAT_ALL_THE_CRYPTO_IN_THIS_LIB_IS_DISABLED_FOR_FUZZING: usize = 0;

#[macro_use]
Expand Down Expand Up @@ -480,7 +480,7 @@ extern "C" {
) -> c_int;
}

#[cfg(not(rust_secp_fuzz))]
#[cfg(not(fuzzing))]
extern "C" {
// ECDSA
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_ecdsa_verify")]
Expand Down Expand Up @@ -666,7 +666,7 @@ impl<T> CPtr for [T] {
}
}

#[cfg(rust_secp_fuzz)]
#[cfg(fuzzing)]
mod fuzz_dummy {
use super::*;

Expand Down Expand Up @@ -755,7 +755,7 @@ mod fuzz_dummy {
}
}

#[cfg(rust_secp_fuzz)]
#[cfg(fuzzing)]
pub use self::fuzz_dummy::*;

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions secp256k1-sys/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern "C" {
-> c_int;
}

#[cfg(not(rust_secp_fuzz))]
#[cfg(not(fuzzing))]
extern "C" {
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_ecdsa_sign_recoverable")]
pub fn secp256k1_ecdsa_sign_recoverable(cx: *const Context,
Expand All @@ -72,7 +72,7 @@ extern "C" {
}


#[cfg(rust_secp_fuzz)]
#[cfg(fuzzing)]
mod fuzz_dummy {
use super::*;
use std::slice;
Expand Down Expand Up @@ -146,6 +146,6 @@ mod fuzz_dummy {
1
}
}
#[cfg(rust_secp_fuzz)]
#[cfg(fuzzing)]
pub use self::fuzz_dummy::*;

18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
//! 0xc9, 0x42, 0x8f, 0xca, 0x69, 0xc1, 0x32, 0xa2,
//! ]).expect("compact signatures are 64 bytes; DER signatures are 68-72 bytes");
//!
//! # #[cfg(not(rust_secp_fuzz))]
//! # #[cfg(not(fuzzing))]
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
//! ```
//!
Expand Down Expand Up @@ -744,7 +744,7 @@ impl<C: Signing> Secp256k1<C> {
entropy_p = extra_entropy.as_ptr() as *const ffi::types::c_void;

// When fuzzing, these checks will usually spinloop forever, so just short-circuit them.
#[cfg(rust_secp_fuzz)]
#[cfg(fuzzing)]
return Signature::from(ret);
}
}
Expand Down Expand Up @@ -1108,12 +1108,12 @@ mod tests {
if compact[0] < 0x80 {
assert_eq!(sig, low_r_sig);
} else {
#[cfg(not(rust_secp_fuzz))] // mocked sig generation doesn't produce low-R sigs
#[cfg(not(fuzzing))] // mocked sig generation doesn't produce low-R sigs
assert_ne!(sig, low_r_sig);
}
#[cfg(not(rust_secp_fuzz))] // mocked sig generation doesn't produce low-R sigs
#[cfg(not(fuzzing))] // mocked sig generation doesn't produce low-R sigs
assert!(super::compact_sig_has_zero_first_bit(&low_r_sig.0));
#[cfg(not(rust_secp_fuzz))] // mocked sig generation doesn't produce low-R sigs
#[cfg(not(fuzzing))] // mocked sig generation doesn't produce low-R sigs
assert!(super::der_length_check(&grind_r_sig.0, 70));
}
}
Expand Down Expand Up @@ -1186,7 +1186,7 @@ mod tests {
}

#[test]
#[cfg(not(rust_secp_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
fn test_low_s() {
// nb this is a transaction on testnet
// txid 8ccc87b72d766ab3128f03176bb1c98293f2d1f85ebfaf07b82cc81ea6891fa9
Expand All @@ -1208,7 +1208,7 @@ mod tests {
}

#[test]
#[cfg(not(rust_secp_fuzz))] // fuzz-sigs have fixed size/format
#[cfg(not(fuzzing))] // fuzz-sigs have fixed size/format
fn test_low_r() {
let secp = Secp256k1::new();
let msg = hex!("887d04bb1cf1b1554f1b268dfe62d13064ca67ae45348d50d1392ce2d13418ac");
Expand All @@ -1223,7 +1223,7 @@ mod tests {
}

#[test]
#[cfg(not(rust_secp_fuzz))] // fuzz-sigs have fixed size/format
#[cfg(not(fuzzing))] // fuzz-sigs have fixed size/format
fn test_grind_r() {
let secp = Secp256k1::new();
let msg = hex!("ef2d5b9a7c61865a95941d0f04285420560df7e9d76890ac1b8867b12ce43167");
Expand All @@ -1237,7 +1237,7 @@ mod tests {
}

#[cfg(feature = "serde")]
#[cfg(not(rust_secp_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
#[test]
fn test_signature_serde() {
use serde_test::{Configure, Token, assert_tokens};
Expand Down
2 changes: 1 addition & 1 deletion src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ mod tests {
}

#[test]
#[cfg(not(rust_secp_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
fn sign() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());
Expand Down
6 changes: 3 additions & 3 deletions src/schnorrsig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ mod tests {
}

#[test]
#[cfg(not(rust_secp_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
fn test_schnorrsig_sign() {
let secp = Secp256k1::new();

Expand All @@ -583,7 +583,7 @@ mod tests {
}

#[test]
#[cfg(not(rust_secp_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
fn test_schnorrsig_verify() {
let secp = Secp256k1::new();

Expand Down Expand Up @@ -722,7 +722,7 @@ mod tests {
}

#[cfg(feature = "serde")]
#[cfg(not(rust_secp_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
#[test]
fn test_signature_serde() {
use serde_test::{assert_tokens, Configure, Token};
Expand Down