From 1e490bd0019c17e0b4d332e867a2095aac78a4dc Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Thu, 8 Dec 2022 21:26:18 -0700 Subject: [PATCH] Fix `--no-default-features` test warnings; consolidate CI jobs (#461) Previously `cargo test --no-default-features` would succeed but with warnings. This commit fixes all of those warnings and tests `--no-default-features` in CI to ensure that in perpetuity. --- .github/workflows/rust.yml | 21 +++------------------ src/montgomery.rs | 1 + src/ristretto.rs | 24 ++++++++++++++---------- src/scalar.rs | 1 + 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 22e55a936..d294b3dec 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,6 +8,7 @@ on: env: CARGO_TERM_COLOR: always + RUSTFLAGS: '-D warnings' jobs: test: @@ -26,8 +27,10 @@ jobs: - uses: dtolnay/rust-toolchain@stable - run: rustup target add ${{ matrix.target }} - run: ${{ matrix.deps }} + - run: cargo test --target ${{ matrix.target }} --no-default-features - run: cargo test --target ${{ matrix.target }} - run: cargo test --target ${{ matrix.target }} --features fiat_backend + - run: cargo test --target ${{ matrix.target }} --features serde build-simd: name: Build simd backend (nightly) @@ -43,24 +46,6 @@ jobs: RUSTFLAGS: "-C target_feature=+avx512ifma" run: cargo build --target x86_64-unknown-linux-gnu --features simd_backend - test-defaults-serde: - name: Test default feature selection and serde - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - - run: cargo test --features "serde" - - test-alloc-u32: - name: Test no_std+alloc with u32 backend - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - - run: rustup target add i686-unknown-linux-gnu - - run: sudo apt update && sudo apt install gcc-multilib - - run: cargo test --lib --no-default-features --features alloc --target i686-unknown-linux-gnu - nightly: name: Test nightly compiler runs-on: ubuntu-latest diff --git a/src/montgomery.rs b/src/montgomery.rs index dc53a9d3f..2b54371b7 100644 --- a/src/montgomery.rs +++ b/src/montgomery.rs @@ -482,6 +482,7 @@ mod test { assert_eq!(result, expected.to_montgomery()) } + #[cfg(feature = "alloc")] const ELLIGATOR_CORRECT_OUTPUT: [u8; 32] = [ 0x5f, 0x35, 0x20, 0x00, 0x1c, 0x6c, 0x99, 0x36, 0xa3, 0x12, 0x06, 0xaf, 0xe7, 0xc7, 0xac, 0x22, 0x4e, 0x88, 0x61, 0x61, 0x9b, 0xf9, 0x88, 0x72, 0x44, 0x49, 0x15, 0x89, 0x9d, 0x95, diff --git a/src/ristretto.rs b/src/ristretto.rs index 12583d098..b520dde0a 100644 --- a/src/ristretto.rs +++ b/src/ristretto.rs @@ -179,6 +179,9 @@ use digest::Digest; use crate::constants; use crate::field::FieldElement; +#[cfg(feature = "alloc")] +use cfg_if::cfg_if; + use subtle::Choice; use subtle::ConditionallyNegatable; use subtle::ConditionallySelectable; @@ -196,16 +199,17 @@ use crate::traits::Identity; #[cfg(feature = "alloc")] use crate::traits::{MultiscalarMul, VartimeMultiscalarMul, VartimePrecomputedMultiscalarMul}; -#[cfg(not(all( - feature = "simd_backend", - any(target_feature = "avx2", target_feature = "avx512ifma") -)))] -use crate::backend::serial::scalar_mul; -#[cfg(all( - feature = "simd_backend", - any(target_feature = "avx2", target_feature = "avx512ifma") -))] -use crate::backend::vector::scalar_mul; +#[cfg(feature = "alloc")] +cfg_if! { + if #[cfg(all( + feature = "simd_backend", + any(target_feature = "avx2", target_feature = "avx512ifma") + ))] { + use crate::backend::vector::scalar_mul; + } else { + use crate::backend::serial::scalar_mul; + } +} // ------------------------------------------------------------------------ // Compressed points diff --git a/src/scalar.rs b/src/scalar.rs index 3cdf0e300..2a2ecdf0e 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -1025,6 +1025,7 @@ impl Scalar { /// Returns a size hint indicating how many entries of the return /// value of `to_radix_2w` are nonzero. + #[cfg(any(feature = "alloc", test))] pub(crate) fn to_radix_2w_size_hint(w: usize) -> usize { debug_assert!(w >= 4); debug_assert!(w <= 8);