Skip to content
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

Add cuda support for all crates, allow for better test coverage #40

Merged
merged 1 commit into from
Nov 13, 2024
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
3 changes: 3 additions & 0 deletions ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ categories.workspace = true

[features]
parallel = ["plonky2_maybe_rayon/parallel", "plonky2/parallel"]
cuda = ["cryptography_cuda/cuda", "plonky2/cuda"]
no_cuda = ["cryptography_cuda/no_cuda", "plonky2/no_cuda"]

[dependencies]
anyhow = { version = "1.0.40" }
Expand All @@ -20,6 +22,7 @@ num = { version = "0.4.0" }
plonky2 = { path = "../plonky2" }
plonky2_u32 = { path = "../u32" }
serde = { version = "1.0", features = ["derive"] }
cryptography_cuda = { workspace = true, optional = true }

[dev-dependencies]
rand = { version = "0.8.4", features = ["getrandom"] }
Expand Down
14 changes: 14 additions & 0 deletions ecdsa/src/gadgets/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,13 @@ mod tests {
use rand::{rngs::OsRng, Rng};

use crate::gadgets::biguint::{CircuitBuilderBiguint, WitnessBigUint};
#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

#[test]
fn test_biguint_add() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -407,6 +411,8 @@ mod tests {

#[test]
fn test_biguint_sub() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -437,6 +443,8 @@ mod tests {

#[test]
fn test_biguint_mul() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -467,6 +475,8 @@ mod tests {

#[test]
fn test_biguint_cmp() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand All @@ -493,6 +503,8 @@ mod tests {

#[test]
fn test_biguint_div_rem() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -526,6 +538,8 @@ mod tests {

#[test]
fn test_is_zero_biguint() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down
17 changes: 17 additions & 0 deletions ecdsa/src/gadgets/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,13 @@ mod tests {
gadgets::{curve::CircuitBuilderCurve, nonnative::CircuitBuilderNonNative},
};

#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

#[test]
fn test_curve_point_is_valid() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand All @@ -305,6 +310,8 @@ mod tests {
#[test]
#[should_panic]
fn test_curve_point_is_not_valid() {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand All @@ -328,6 +335,8 @@ mod tests {

#[test]
fn test_curve_double() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -365,6 +374,8 @@ mod tests {

#[test]
fn test_curve_add() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -395,6 +406,8 @@ mod tests {

#[test]
fn test_curve_conditional_add() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -428,6 +441,8 @@ mod tests {
#[test]
#[ignore]
fn test_curve_mul() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -461,6 +476,8 @@ mod tests {
#[test]
#[ignore]
fn test_curve_random() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down
5 changes: 5 additions & 0 deletions ecdsa/src/gadgets/curve_fixed_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@ mod tests {
},
};

#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

#[test]
#[ignore]
fn test_fixed_base() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down
5 changes: 5 additions & 0 deletions ecdsa/src/gadgets/curve_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ mod tests {
},
};

#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

#[test]
#[ignore]
fn test_curve_msm() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down
7 changes: 7 additions & 0 deletions ecdsa/src/gadgets/curve_windowed_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ mod tests {
use super::*;
use crate::curve::secp256k1::Secp256K1;

#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

#[test]
fn test_random_access_curve_points() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down Expand Up @@ -220,6 +225,8 @@ mod tests {
#[test]
#[ignore]
fn test_curve_windowed_mul() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down
5 changes: 5 additions & 0 deletions ecdsa/src/gadgets/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ mod tests {
ecdsa::{sign_message, ECDSAPublicKey, ECDSASecretKey, ECDSASignature},
};

#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

fn test_ecdsa_circuit_with_config(config: CircuitConfig) -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down
5 changes: 5 additions & 0 deletions ecdsa/src/gadgets/glv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ mod tests {
},
};

#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

#[test]
#[ignore]
fn test_glv_gadget() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
Expand Down
19 changes: 19 additions & 0 deletions ecdsa/src/gadgets/nonnative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,13 @@ mod tests {

use crate::gadgets::nonnative::{CircuitBuilderNonNative, PartialWitnessNonNative};

#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

#[test]
fn test_nonnative_add() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Base;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand Down Expand Up @@ -776,6 +781,8 @@ mod tests {

#[test]
fn test_nonnative_many_adds() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Base;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand Down Expand Up @@ -816,6 +823,8 @@ mod tests {

#[test]
fn test_nonnative_sub() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Base;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand Down Expand Up @@ -846,6 +855,8 @@ mod tests {

#[test]
fn test_nonnative_mul() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Base;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand All @@ -872,6 +883,8 @@ mod tests {

#[test]
fn test_nonnative_neg() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Base;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand All @@ -896,6 +909,8 @@ mod tests {

#[test]
fn test_nonnative_inv() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Base;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand All @@ -920,6 +935,8 @@ mod tests {

#[test]
fn test_witness() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Base;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand Down Expand Up @@ -949,6 +966,8 @@ mod tests {

#[test]
fn test_assert_greater_nonnative() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Base;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand Down
5 changes: 5 additions & 0 deletions ecdsa/src/gadgets/split_nonnative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ mod tests {
use super::*;
use crate::gadgets::nonnative::{CircuitBuilderNonNative, NonNativeTarget};

#[cfg(feature = "cuda")]
use plonky2::util::test_utils::init_cuda;

#[test]
fn test_split_nonnative() -> Result<()> {
#[cfg(feature = "cuda")]
init_cuda();
type FF = Secp256K1Scalar;
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
Expand Down
5 changes: 5 additions & 0 deletions ecgfp5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ itertools = "0.10"
serde = "1"
rand = { version = "0.8.5", default-features = false, features = ["getrandom"] }
hex = "0.4.3"
cryptography_cuda = { workspace = true, optional = true }

[dev-dependencies]
rand = { version = "0.8.5", features = ["min_const_gen"] }
Expand All @@ -45,3 +46,7 @@ harness = false
[[bench]]
name = "schnorr"
harness = false

[features]
cuda = ["cryptography_cuda/cuda", "plonky2/cuda"]
no_cuda = ["cryptography_cuda/no_cuda", "plonky2/no_cuda"]
Loading