diff --git a/eth2/state_processing/Cargo.toml b/eth2/state_processing/Cargo.toml index 1bc7a6c45..a2ae11aa8 100644 --- a/eth2/state_processing/Cargo.toml +++ b/eth2/state_processing/Cargo.toml @@ -30,3 +30,6 @@ tree_hash = { path = "../utils/tree_hash" } tree_hash_derive = { path = "../utils/tree_hash_derive" } types = { path = "../types" } rayon = "1.0" + +[features] +fake_crypto = ["bls/fake_crypto"] diff --git a/eth2/state_processing/build.rs b/eth2/state_processing/build.rs new file mode 120000 index 000000000..70d6c75b9 --- /dev/null +++ b/eth2/state_processing/build.rs @@ -0,0 +1 @@ +../utils/bls/build.rs \ No newline at end of file diff --git a/eth2/state_processing/tests/tests.rs b/eth2/state_processing/tests/tests.rs index 03401b2c7..6ea8863b8 100644 --- a/eth2/state_processing/tests/tests.rs +++ b/eth2/state_processing/tests/tests.rs @@ -47,31 +47,28 @@ fn run_state_transition_test(test_name: &str) { // Run Tests let mut ok = true; for (i, test_case) in doc.test_cases.iter().enumerate() { + let fake_crypto = cfg!(feature = "fake_crypto"); + if !test_case.verify_signatures == fake_crypto { + println!("Running {}", test_case.name); + } else { + println!( + "Skipping {} (fake_crypto: {}, need fake: {})", + test_case.name, fake_crypto, !test_case.verify_signatures + ); + continue; + } let mut state = test_case.initial_state.clone(); for (j, block) in test_case.blocks.iter().enumerate() { while block.slot > state.slot { let latest_block_header = state.latest_block_header.clone(); per_slot_processing(&mut state, &latest_block_header, &test_case.config).unwrap(); } - if test_case.verify_signatures { - let res = per_block_processing(&mut state, &block, &test_case.config); - if res.is_err() { - println!("Error in {} (#{}), on block {}", test_case.name, i, j); - println!("{:?}", res); - ok = false; - }; - } else { - let res = per_block_processing_without_verifying_block_signature( - &mut state, - &block, - &test_case.config, - ); - if res.is_err() { - println!("Error in {} (#{}), on block {}", test_case.name, i, j); - println!("{:?}", res); - ok = false; - } - } + let res = per_block_processing(&mut state, &block, &test_case.config); + if res.is_err() { + println!("Error in {} (#{}), on block {}", test_case.name, i, j); + println!("{:?}", res); + ok = false; + }; } } diff --git a/eth2/utils/bls/Cargo.toml b/eth2/utils/bls/Cargo.toml index 439debdcb..4ce499580 100644 --- a/eth2/utils/bls/Cargo.toml +++ b/eth2/utils/bls/Cargo.toml @@ -13,3 +13,6 @@ serde_derive = "1.0" serde_hex = { path = "../serde_hex" } ssz = { path = "../ssz" } tree_hash = { path = "../tree_hash" } + +[features] +fake_crypto = [] diff --git a/eth2/utils/bls/build.rs b/eth2/utils/bls/build.rs new file mode 100644 index 000000000..7f08a1ed5 --- /dev/null +++ b/eth2/utils/bls/build.rs @@ -0,0 +1,19 @@ +// This build script is symlinked from each project that requires BLS's "fake crypto", +// so that the `fake_crypto` feature of every sub-crate can be turned on by running +// with FAKE_CRYPTO=1 from the top-level workspace. +// At some point in the future it might be possible to do: +// $ cargo test --all --release --features fake_crypto +// but at the present time this doesn't work. +// Related: https://github.com/rust-lang/cargo/issues/5364 +fn main() { + if let Ok(fake_crypto) = std::env::var("FAKE_CRYPTO") { + if fake_crypto == "1" { + println!("cargo:rustc-cfg=feature=\"fake_crypto\""); + println!("cargo:rerun-if-env-changed=FAKE_CRYPTO"); + println!( + "cargo:warning=[{}]: Compiled with fake BLS cryptography. DO NOT USE, TESTING ONLY", + std::env::var("CARGO_PKG_NAME").unwrap() + ); + } + } +} diff --git a/eth2/utils/bls/src/lib.rs b/eth2/utils/bls/src/lib.rs index b9a4d5c1d..fae41aeed 100644 --- a/eth2/utils/bls/src/lib.rs +++ b/eth2/utils/bls/src/lib.rs @@ -6,22 +6,22 @@ mod keypair; mod public_key; mod secret_key; -#[cfg(not(debug_assertions))] +#[cfg(not(feature = "fake_crypto"))] mod aggregate_signature; -#[cfg(not(debug_assertions))] +#[cfg(not(feature = "fake_crypto"))] mod signature; -#[cfg(not(debug_assertions))] +#[cfg(not(feature = "fake_crypto"))] pub use crate::aggregate_signature::AggregateSignature; -#[cfg(not(debug_assertions))] +#[cfg(not(feature = "fake_crypto"))] pub use crate::signature::Signature; -#[cfg(debug_assertions)] +#[cfg(feature = "fake_crypto")] mod fake_aggregate_signature; -#[cfg(debug_assertions)] +#[cfg(feature = "fake_crypto")] mod fake_signature; -#[cfg(debug_assertions)] +#[cfg(feature = "fake_crypto")] pub use crate::fake_aggregate_signature::FakeAggregateSignature as AggregateSignature; -#[cfg(debug_assertions)] +#[cfg(feature = "fake_crypto")] pub use crate::fake_signature::FakeSignature as Signature; pub use crate::aggregate_public_key::AggregatePublicKey;