From 6514f3775e2d7b40ff6525e7af6d30bd49f185cd Mon Sep 17 00:00:00 2001 From: d86leader Date: Wed, 20 Sep 2023 11:23:08 +0200 Subject: [PATCH 1/5] Update elliptic-curves version. Add stark-curve --- .gitignore | 1 + generic-ec-curves/Cargo.toml | 11 ++- generic-ec-curves/src/lib.rs | 3 + .../src/rust_crypto/affine_coords.rs | 18 ++--- .../src/rust_crypto/curve_name.rs | 5 ++ .../src/rust_crypto/hash_to_curve.rs | 8 +- generic-ec-curves/src/rust_crypto/mod.rs | 17 ++-- generic-ec-curves/src/rust_crypto/point.rs | 48 +++++------ generic-ec-curves/src/rust_crypto/scalar.rs | 80 ++++++++++--------- generic-ec-zkp/src/polynomial.rs | 2 + generic-ec/Cargo.toml | 5 +- generic-ec/src/lib.rs | 3 + generic-ec/src/point/mod.rs | 2 +- generic-ec/src/scalar.rs | 2 +- tests/tests/curves.rs | 8 +- 15 files changed, 122 insertions(+), 91 deletions(-) diff --git a/.gitignore b/.gitignore index 065616f..d4a80c0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ Cargo.lock /.idea .helix/ +.rstags diff --git a/generic-ec-curves/Cargo.toml b/generic-ec-curves/Cargo.toml index b70f1a0..d3a58c9 100644 --- a/generic-ec-curves/Cargo.toml +++ b/generic-ec-curves/Cargo.toml @@ -12,14 +12,17 @@ subtle = { version = "2.4", default-features = false } rand_core = { version = "0.6", default-features = false } zeroize = { version = "1", default-features = false } -elliptic-curve = { version = "0.12", features = ["sec1", "hash2curve"], optional = true } -k256 = { version = "0.12", optional = true, features = ["hash2curve"] } -p256 = { version = "0.12", optional = true, features = ["hash2curve"] } +crypto-bigint = { version = "0.5", optional = true } +elliptic-curve = { version = "0.13", features = ["sec1", "hash2curve"], optional = true } +k256 = { version = "0.13", optional = true, features = ["hash2curve"] } +p256 = { version = "0.13", optional = true, features = ["hash2curve"] } sha2 = { version = "0.10", optional = true } +stark-curve = { git = "https://github.com/dfns-labs/stark-curve", optional = true } [features] default = [] -rust-crypto = ["elliptic-curve"] +rust-crypto = ["elliptic-curve", "crypto-bigint"] secp256k1 = ["rust-crypto", "k256", "sha2"] secp256r1 = ["rust-crypto", "p256", "sha2"] +stark = ["rust-crypto", "stark-curve", "sha2"] diff --git a/generic-ec-curves/src/lib.rs b/generic-ec-curves/src/lib.rs index e859e77..93756da 100644 --- a/generic-ec-curves/src/lib.rs +++ b/generic-ec-curves/src/lib.rs @@ -8,3 +8,6 @@ pub use rust_crypto::Secp256k1; #[cfg(feature = "secp256r1")] pub use rust_crypto::Secp256r1; + +#[cfg(feature = "stark")] +pub use rust_crypto::Stark; diff --git a/generic-ec-curves/src/rust_crypto/affine_coords.rs b/generic-ec-curves/src/rust_crypto/affine_coords.rs index 2d73e63..4d6fa85 100644 --- a/generic-ec-curves/src/rust_crypto/affine_coords.rs +++ b/generic-ec-curves/src/rust_crypto/affine_coords.rs @@ -2,15 +2,15 @@ use elliptic_curve::generic_array::GenericArray; use elliptic_curve::sec1::{ CompressedPointSize, Coordinates, EncodedPoint, FromEncodedPoint, Tag, ToEncodedPoint, }; -use elliptic_curve::{AffineArithmetic, FieldSize, ProjectiveArithmetic}; +use elliptic_curve::{CurveArithmetic, FieldBytesSize}; use generic_ec_core::coords::{HasAffineX, HasAffineXAndParity, HasAffineXY, HasAffineY, Parity}; use super::{RustCryptoCurve, RustCryptoPoint}; impl HasAffineX for RustCryptoCurve where - C: ProjectiveArithmetic + AffineArithmetic, - FieldSize: elliptic_curve::sec1::ModulusSize, + C: CurveArithmetic, + FieldBytesSize: elliptic_curve::sec1::ModulusSize, C::AffinePoint: ToEncodedPoint + From, RustCryptoCurve: generic_ec_core::Curve< Point = RustCryptoPoint, @@ -33,8 +33,8 @@ where impl HasAffineXAndParity for RustCryptoCurve where - C: ProjectiveArithmetic + AffineArithmetic, - FieldSize: elliptic_curve::sec1::ModulusSize, + C: CurveArithmetic, + FieldBytesSize: elliptic_curve::sec1::ModulusSize, C::AffinePoint: ToEncodedPoint + FromEncodedPoint + From @@ -76,8 +76,8 @@ where impl HasAffineY for RustCryptoCurve where - C: ProjectiveArithmetic + AffineArithmetic, - FieldSize: elliptic_curve::sec1::ModulusSize, + C: CurveArithmetic, + FieldBytesSize: elliptic_curve::sec1::ModulusSize, C::AffinePoint: ToEncodedPoint + From, RustCryptoCurve: generic_ec_core::Curve< Point = RustCryptoPoint, @@ -100,8 +100,8 @@ where impl HasAffineXY for RustCryptoCurve where - C: ProjectiveArithmetic + AffineArithmetic, - FieldSize: elliptic_curve::sec1::ModulusSize, + C: CurveArithmetic, + FieldBytesSize: elliptic_curve::sec1::ModulusSize, C::AffinePoint: ToEncodedPoint + FromEncodedPoint + From diff --git a/generic-ec-curves/src/rust_crypto/curve_name.rs b/generic-ec-curves/src/rust_crypto/curve_name.rs index fc902ee..7c505bc 100644 --- a/generic-ec-curves/src/rust_crypto/curve_name.rs +++ b/generic-ec-curves/src/rust_crypto/curve_name.rs @@ -11,3 +11,8 @@ impl CurveName for p256::NistP256 { impl CurveName for k256::Secp256k1 { const CURVE_NAME: &'static str = "secp256k1"; } + +#[cfg(feature = "stark")] +impl CurveName for stark_curve::StarkCurve { + const CURVE_NAME: &'static str = "stark"; +} diff --git a/generic-ec-curves/src/rust_crypto/hash_to_curve.rs b/generic-ec-curves/src/rust_crypto/hash_to_curve.rs index e704c34..e671ff8 100644 --- a/generic-ec-curves/src/rust_crypto/hash_to_curve.rs +++ b/generic-ec-curves/src/rust_crypto/hash_to_curve.rs @@ -1,7 +1,7 @@ use elliptic_curve::{ group::cofactor::CofactorGroup, hash2curve::{ExpandMsg, FromOkm, GroupDigest}, - ProjectiveArithmetic, + CurveArithmetic, }; use generic_ec_core::hash_to_curve::{HashToCurve, Tag}; @@ -9,7 +9,7 @@ use super::{RustCryptoCurve, RustCryptoPoint, RustCryptoScalar}; impl HashToCurve for RustCryptoCurve where - C: ProjectiveArithmetic + GroupDigest, + C: CurveArithmetic + GroupDigest, C::ProjectivePoint: CofactorGroup, C::Scalar: FromOkm, for<'a> X: ExpandMsg<'a>, @@ -17,13 +17,13 @@ where generic_ec_core::Curve, Scalar = RustCryptoScalar>, { fn hash_to_curve(ctx: Tag, msgs: &[&[u8]]) -> Result { - let point = ::hash_from_bytes::(msgs, ctx.as_bytes()) + let point = ::hash_from_bytes::(msgs, &[ctx.as_bytes()]) .or(Err(generic_ec_core::Error))?; Ok(RustCryptoPoint(point)) } fn hash_to_scalar(ctx: Tag, msgs: &[&[u8]]) -> Result { - let scalar = ::hash_to_scalar::(msgs, ctx.as_bytes()) + let scalar = ::hash_to_scalar::(msgs, &[ctx.as_bytes()]) .or(Err(generic_ec_core::Error))?; Ok(RustCryptoScalar(scalar)) } diff --git a/generic-ec-curves/src/rust_crypto/mod.rs b/generic-ec-curves/src/rust_crypto/mod.rs index ab2097f..cceb689 100644 --- a/generic-ec-curves/src/rust_crypto/mod.rs +++ b/generic-ec-curves/src/rust_crypto/mod.rs @@ -7,14 +7,12 @@ use elliptic_curve::group::cofactor::CofactorGroup; use elliptic_curve::hash2curve::ExpandMsgXmd; use elliptic_curve::ops::Reduce; use elliptic_curve::sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint}; -use elliptic_curve::{ - AffineArithmetic, FieldSize, ProjectiveArithmetic, ScalarArithmetic, ScalarCore, -}; +use elliptic_curve::{CurveArithmetic, FieldBytesSize, ScalarPrimitive}; use generic_ec_core::{CompressedEncoding, Curve, IntegerEncoding, UncompressedEncoding}; use subtle::{ConditionallySelectable, ConstantTimeEq}; use zeroize::{DefaultIsZeroes, Zeroize}; -#[cfg(any(feature = "secp256k1", feature = "secp256r1"))] +#[cfg(any(feature = "secp256k1", feature = "secp256r1", feature = "stark"))] use sha2::Sha256; pub use self::{curve_name::CurveName, point::RustCryptoPoint, scalar::RustCryptoScalar}; @@ -40,9 +38,12 @@ pub type Secp256k1 = RustCryptoCurve>; #[cfg(feature = "secp256r1")] pub type Secp256r1 = RustCryptoCurve>; +#[cfg(feature = "stark")] +pub type Stark = RustCryptoCurve>; + impl Curve for RustCryptoCurve where - C: CurveName + ScalarArithmetic + ProjectiveArithmetic + AffineArithmetic, + C: CurveName + CurveArithmetic, C::ProjectivePoint: From + CofactorGroup + Copy @@ -55,9 +56,9 @@ where C::AffinePoint: From + ToEncodedPoint + FromEncodedPoint, for<'a> &'a C::ProjectivePoint: Mul<&'a C::Scalar, Output = C::ProjectivePoint>, C::Scalar: - Reduce + Eq + ConstantTimeEq + ConditionallySelectable + DefaultIsZeroes + Unpin, - for<'a> ScalarCore: From<&'a C::Scalar>, - FieldSize: ModulusSize, + Reduce + Eq + ConstantTimeEq + ConditionallySelectable + DefaultIsZeroes + Unpin, + for<'a> ScalarPrimitive: From<&'a C::Scalar>, + FieldBytesSize: ModulusSize, X: 'static, { const CURVE_NAME: &'static str = C::CURVE_NAME; diff --git a/generic-ec-curves/src/rust_crypto/point.rs b/generic-ec-curves/src/rust_crypto/point.rs index c100db2..5e4b8cc 100644 --- a/generic-ec-curves/src/rust_crypto/point.rs +++ b/generic-ec-curves/src/rust_crypto/point.rs @@ -4,15 +4,15 @@ use core::hash::{self, Hash}; use elliptic_curve::group::cofactor::CofactorGroup; use elliptic_curve::{ sec1::{EncodedPoint, FromEncodedPoint, ModulusSize, ToEncodedPoint}, - AffineArithmetic, FieldSize, Group, ProjectiveArithmetic, + CurveArithmetic, FieldBytesSize, Group, }; use generic_ec_core::*; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq}; use zeroize::Zeroize; -pub struct RustCryptoPoint(pub E::ProjectivePoint); +pub struct RustCryptoPoint(pub E::ProjectivePoint); -impl Additive for RustCryptoPoint { +impl Additive for RustCryptoPoint { #[inline] fn add(a: &Self, b: &Self) -> Self { RustCryptoPoint(a.0 + b.0) @@ -29,14 +29,14 @@ impl Additive for RustCryptoPoint { } } -impl From for RustCryptoPoint { +impl From for RustCryptoPoint { #[inline] fn from(_: CurveGenerator) -> Self { RustCryptoPoint(E::ProjectivePoint::generator()) } } -impl Zero for RustCryptoPoint { +impl Zero for RustCryptoPoint { #[inline] fn zero() -> Self { RustCryptoPoint(E::ProjectivePoint::identity()) @@ -48,7 +48,7 @@ impl Zero for RustCryptoPoint { } } -impl OnCurve for RustCryptoPoint { +impl OnCurve for RustCryptoPoint { #[inline] fn is_on_curve(&self) -> Choice { Choice::from(1) @@ -57,7 +57,7 @@ impl OnCurve for RustCryptoPoint { impl SmallFactor for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: CofactorGroup, { #[inline] @@ -68,7 +68,7 @@ where impl ConstantTimeEq for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: ConstantTimeEq, { #[inline] @@ -79,7 +79,7 @@ where impl ConditionallySelectable for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: ConditionallySelectable, { #[inline] @@ -100,9 +100,9 @@ where impl CompressedEncoding for RustCryptoPoint where - E: ProjectiveArithmetic + AffineArithmetic, + E: CurveArithmetic, E::AffinePoint: ToEncodedPoint + From, - FieldSize: ModulusSize, + FieldBytesSize: ModulusSize, { type Bytes = elliptic_curve::sec1::CompressedPoint; fn to_bytes_compressed(&self) -> Self::Bytes { @@ -117,9 +117,9 @@ where impl UncompressedEncoding for RustCryptoPoint where - E: ProjectiveArithmetic + AffineArithmetic, + E: CurveArithmetic, E::AffinePoint: ToEncodedPoint + From, - FieldSize: ModulusSize, + FieldBytesSize: ModulusSize, { type Bytes = elliptic_curve::sec1::UncompressedPoint; fn to_bytes_uncompressed(&self) -> Self::Bytes { @@ -134,9 +134,9 @@ where impl Decode for RustCryptoPoint where - E: ProjectiveArithmetic + AffineArithmetic, + E: CurveArithmetic, E::AffinePoint: FromEncodedPoint + Into, - FieldSize: ModulusSize, + FieldBytesSize: ModulusSize, { fn decode(bytes: &[u8]) -> Option { let encoded_point = EncodedPoint::::from_bytes(bytes).ok()?; @@ -147,7 +147,7 @@ where impl Clone for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, { fn clone(&self) -> Self { Self(self.0) @@ -156,14 +156,14 @@ where impl Copy for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: Copy, { } impl Zeroize for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: Zeroize, { fn zeroize(&mut self) { @@ -173,7 +173,7 @@ where impl PartialEq for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: PartialEq, { fn eq(&self, other: &Self) -> bool { @@ -183,14 +183,14 @@ where impl Eq for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: Eq, { } impl Hash for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: Hash, { fn hash(&self, state: &mut H) { @@ -200,7 +200,7 @@ where impl PartialOrd for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: PartialOrd, { fn partial_cmp(&self, other: &Self) -> Option { @@ -210,7 +210,7 @@ where impl Ord for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: Ord, { fn cmp(&self, other: &Self) -> cmp::Ordering { @@ -220,7 +220,7 @@ where impl Default for RustCryptoPoint where - E: ProjectiveArithmetic, + E: CurveArithmetic, E::ProjectivePoint: Default, { fn default() -> Self { diff --git a/generic-ec-curves/src/rust_crypto/scalar.rs b/generic-ec-curves/src/rust_crypto/scalar.rs index 70cb901..1dbb910 100644 --- a/generic-ec-curves/src/rust_crypto/scalar.rs +++ b/generic-ec-curves/src/rust_crypto/scalar.rs @@ -1,16 +1,18 @@ use core::ops::Mul; +use crypto_bigint::prelude::ArrayEncoding; +use crypto_bigint::ByteArray; use elliptic_curve::ops::Reduce; -use elliptic_curve::{ - Field, FieldBytes, Group, PrimeField, ProjectiveArithmetic, ScalarArithmetic, ScalarCore, +use elliptic_curve::{Curve, CurveArithmetic, Field, Group, PrimeField, ScalarPrimitive}; +use generic_ec_core::{ + Additive, CurveGenerator, IntegerEncoding, Invertible, Multiplicative, One, Samplable, Zero, }; -use generic_ec_core::*; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use zeroize::DefaultIsZeroes; -pub struct RustCryptoScalar(pub E::Scalar); +pub struct RustCryptoScalar(pub E::Scalar); -impl Additive for RustCryptoScalar { +impl Additive for RustCryptoScalar { fn add(a: &Self, b: &Self) -> Self { Self(a.0 + b.0) } @@ -24,7 +26,7 @@ impl Additive for RustCryptoScalar { } } -impl Multiplicative> for RustCryptoScalar { +impl Multiplicative> for RustCryptoScalar { type Output = RustCryptoScalar; fn mul(a: &Self, b: &RustCryptoScalar) -> Self::Output { @@ -34,7 +36,7 @@ impl Multiplicative> for RustCryptoScal impl Multiplicative> for RustCryptoScalar where - E: ProjectiveArithmetic + ScalarArithmetic, + E: CurveArithmetic, for<'a> &'a E::ProjectivePoint: Mul<&'a E::Scalar, Output = E::ProjectivePoint>, { type Output = super::RustCryptoPoint; @@ -46,7 +48,7 @@ where impl Multiplicative for RustCryptoScalar where - E: ProjectiveArithmetic + ScalarArithmetic, + E: CurveArithmetic, for<'a> &'a E::ProjectivePoint: Mul<&'a E::Scalar, Output = E::ProjectivePoint>, { type Output = super::RustCryptoPoint; @@ -56,15 +58,15 @@ where } } -impl Invertible for RustCryptoScalar { +impl Invertible for RustCryptoScalar { fn invert(x: &Self) -> CtOption { x.0.invert().map(Self) } } -impl Zero for RustCryptoScalar { +impl Zero for RustCryptoScalar { fn zero() -> Self { - Self(E::Scalar::zero()) + Self(E::Scalar::ZERO) } fn is_zero(x: &Self) -> subtle::Choice { @@ -72,17 +74,17 @@ impl Zero for RustCryptoScalar { } } -impl One for RustCryptoScalar { +impl One for RustCryptoScalar { fn one() -> Self { - Self(E::Scalar::one()) + Self(E::Scalar::ONE) } fn is_one(x: &Self) -> Choice { - x.0.ct_eq(&E::Scalar::one()) + x.0.ct_eq(&E::Scalar::ONE) } } -impl Samplable for RustCryptoScalar { +impl Samplable for RustCryptoScalar { fn random(rng: &mut R) -> Self { let mut bytes: ::Repr = Default::default(); @@ -96,30 +98,30 @@ impl Samplable for RustCryptoScalar { } } -impl Default for RustCryptoScalar { +impl Default for RustCryptoScalar { fn default() -> Self { Self(Default::default()) } } -impl Clone for RustCryptoScalar { +impl Clone for RustCryptoScalar { fn clone(&self) -> Self { Self(self.0) } } -impl Copy for RustCryptoScalar {} +impl Copy for RustCryptoScalar {} impl DefaultIsZeroes for RustCryptoScalar where - E: ScalarArithmetic, + E: CurveArithmetic, E::Scalar: DefaultIsZeroes, { } impl PartialEq for RustCryptoScalar where - E: ScalarArithmetic, + E: CurveArithmetic, E::Scalar: PartialEq, { fn eq(&self, other: &Self) -> bool { @@ -129,14 +131,14 @@ where impl Eq for RustCryptoScalar where - E: ScalarArithmetic, + E: CurveArithmetic, E::Scalar: Eq, { } impl ConstantTimeEq for RustCryptoScalar where - E: ScalarArithmetic, + E: CurveArithmetic, E::Scalar: ConstantTimeEq, { fn ct_eq(&self, other: &Self) -> Choice { @@ -146,7 +148,7 @@ where impl ConditionallySelectable for RustCryptoScalar where - E: ScalarArithmetic, + E: CurveArithmetic, E::Scalar: ConditionallySelectable, { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self { @@ -154,40 +156,44 @@ where } } -impl IntegerEncoding for RustCryptoScalar +impl IntegerEncoding for RustCryptoScalar where - for<'s> ScalarCore: From<&'s E::Scalar>, - E::Scalar: Reduce, + for<'s> ScalarPrimitive: From<&'s E::Scalar>, + E::Scalar: Reduce, { - type Bytes = FieldBytes; + type Bytes = ByteArray; fn to_be_bytes(&self) -> Self::Bytes { - let scalar_core = ScalarCore::::from(&self.0); - scalar_core.to_be_bytes() + let scalar_core = ScalarPrimitive::::from(&self.0); + let uint = scalar_core.as_uint(); + uint.to_be_byte_array() } fn to_le_bytes(&self) -> Self::Bytes { - let scalar_core = ScalarCore::::from(&self.0); - scalar_core.to_le_bytes() + let scalar_core = ScalarPrimitive::::from(&self.0); + let uint = scalar_core.as_uint(); + uint.to_le_byte_array() } fn from_be_bytes(bytes: &Self::Bytes) -> Self { - Self(E::Scalar::from_be_bytes_reduced(bytes.clone())) + let uint = E::Uint::from_be_byte_array(bytes.clone()); + Self(Reduce::reduce(uint)) } fn from_le_bytes(bytes: &Self::Bytes) -> Self { - Self(E::Scalar::from_le_bytes_reduced(bytes.clone())) + let uint = E::Uint::from_le_byte_array(bytes.clone()); + Self(Reduce::reduce(uint)) } fn from_be_bytes_exact(bytes: &Self::Bytes) -> Option { - let scalar_core: Option> = - ScalarCore::::from_be_bytes(bytes.clone()).into(); + let uint = E::Uint::from_be_byte_array(bytes.clone()); + let scalar_core: Option> = ScalarPrimitive::::new(uint).into(); Some(Self(E::Scalar::from(scalar_core?))) } fn from_le_bytes_exact(bytes: &Self::Bytes) -> Option { - let scalar_core: Option> = - ScalarCore::::from_le_bytes(bytes.clone()).into(); + let uint = E::Uint::from_le_byte_array(bytes.clone()); + let scalar_core: Option> = ScalarPrimitive::::new(uint).into(); Some(Self(E::Scalar::from(scalar_core?))) } } diff --git a/generic-ec-zkp/src/polynomial.rs b/generic-ec-zkp/src/polynomial.rs index 6fc9487..84326ff 100644 --- a/generic-ec-zkp/src/polynomial.rs +++ b/generic-ec-zkp/src/polynomial.rs @@ -485,4 +485,6 @@ mod tests { mod secp256k1 {} #[instantiate_tests()] mod secp256r1 {} + #[instantiate_tests()] + mod stark {} } diff --git a/generic-ec/Cargo.toml b/generic-ec/Cargo.toml index 1428171..5bb50b8 100644 --- a/generic-ec/Cargo.toml +++ b/generic-ec/Cargo.toml @@ -41,10 +41,11 @@ serde = ["dep:serde", "generic-ec-core/serde", "hex", "serde_with"] curves = ["generic-ec-curves"] curve-secp256k1 = ["curves", "generic-ec-curves/secp256k1"] curve-secp256r1 = ["curves", "generic-ec-curves/secp256r1"] -all-curves = ["curve-secp256k1", "curve-secp256r1"] +curve-stark = ["curves", "generic-ec-curves/stark"] +all-curves = ["curve-secp256k1", "curve-secp256r1", "curve-stark"] wasm = ["getrandom/js"] [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg", "docsrs"] \ No newline at end of file +rustdoc-args = ["--cfg", "docsrs"] diff --git a/generic-ec/src/lib.rs b/generic-ec/src/lib.rs index 4fd0149..c82e6d9 100644 --- a/generic-ec/src/lib.rs +++ b/generic-ec/src/lib.rs @@ -229,4 +229,7 @@ pub mod curves { #[cfg(feature = "curve-secp256r1")] #[cfg_attr(docsrs, doc(cfg(feature = "curve-secp256r1")))] pub use generic_ec_curves::Secp256r1; + #[cfg(feature = "curve-stark")] + #[cfg_attr(docsrs, doc(cfg(feature = "curve-stark")))] + pub use generic_ec_curves::Stark; } diff --git a/generic-ec/src/point/mod.rs b/generic-ec/src/point/mod.rs index b410e28..d44e3fb 100644 --- a/generic-ec/src/point/mod.rs +++ b/generic-ec/src/point/mod.rs @@ -164,7 +164,7 @@ impl fmt::Debug for Point { s.finish() } } -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] impl Hash for Point { fn hash(&self, state: &mut H) { state.write(self.to_bytes(true).as_bytes()) diff --git a/generic-ec/src/scalar.rs b/generic-ec/src/scalar.rs index 45fafb6..afeecc3 100644 --- a/generic-ec/src/scalar.rs +++ b/generic-ec/src/scalar.rs @@ -333,7 +333,7 @@ impl fmt::Debug for Scalar { } } -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] impl Hash for Scalar { fn hash(&self, state: &mut H) { state.write(self.to_be_bytes().as_bytes()) diff --git a/tests/tests/curves.rs b/tests/tests/curves.rs index 154ba71..04544d5 100644 --- a/tests/tests/curves.rs +++ b/tests/tests/curves.rs @@ -183,12 +183,15 @@ mod tests { #[instantiate_tests()] mod secp256r1 {} + + #[instantiate_tests()] + mod stark {} } #[generic_tests::define] mod coordinates { use generic_ec::coords::{HasAffineX, HasAffineXAndParity, HasAffineXY, HasAffineY}; - use generic_ec::curves::{Secp256k1, Secp256r1}; + use generic_ec::curves::{Secp256k1, Secp256r1, Stark}; use generic_ec::{Curve, Point, Scalar}; use rand_dev::DevRng; @@ -241,4 +244,7 @@ mod coordinates { #[instantiate_tests()] mod secp256r1 {} + + #[instantiate_tests()] + mod stark {} } From b069bb40b3e6bb724cca47e58eb0022dcea93110 Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Wed, 20 Sep 2023 11:41:43 +0000 Subject: [PATCH 2/5] Update readme.yml --- .github/workflows/readme.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml index 01f8411..e522c79 100644 --- a/.github/workflows/readme.yml +++ b/.github/workflows/readme.yml @@ -13,5 +13,8 @@ jobs: uses: baptiste0928/cargo-install@v1 with: crate: cargo-rdme + - uses: webfactory/ssh-agent@v0.7.0 + with: + ssh-private-key: ${{ secrets.STARK_CURVE_KEY }} - name: Check that readme matches lib.rs - run: cargo rdme -w generic-ec -r README.md --check \ No newline at end of file + run: cargo rdme -w generic-ec -r README.md --check From 48a7fd23e56b61766621c496219faccd6c839703 Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Wed, 20 Sep 2023 11:44:21 +0000 Subject: [PATCH 3/5] Update readme.yml --- .github/workflows/readme.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml index e522c79..1da05a3 100644 --- a/.github/workflows/readme.yml +++ b/.github/workflows/readme.yml @@ -3,6 +3,10 @@ name: Check README on: pull_request: branches: [ "*" ] + +env: + CARGO_TERM_COLOR: always + CARGO_NET_GIT_FETCH_WITH_CLI: true jobs: check_readme: From 8e8e1c4ec4f00cbbf02e0136499ceaeb9d534eeb Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Wed, 20 Sep 2023 11:46:08 +0000 Subject: [PATCH 4/5] Update rust.yml --- .github/workflows/rust.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6628993..c07ba1c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,17 +3,19 @@ name: Rust on: pull_request: branches: [ "*" ] - schedule: - - cron: '0 5 * * *' env: CARGO_TERM_COLOR: always + CARGO_NET_GIT_FETCH_WITH_CLI: true jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: webfactory/ssh-agent@v0.7.0 + with: + ssh-private-key: ${{ secrets.STARK_CURVE_KEY }} - uses: Swatinem/rust-cache@v2 with: cache-on-failure: "true" @@ -37,6 +39,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: webfactory/ssh-agent@v0.7.0 + with: + ssh-private-key: ${{ secrets.STARK_CURVE_KEY }} - uses: Swatinem/rust-cache@v2 with: cache-on-failure: "true" From 803c27570f9b3436698db70735d49a850d7bcdfc Mon Sep 17 00:00:00 2001 From: d86leader Date: Wed, 20 Sep 2023 14:01:42 +0200 Subject: [PATCH 5/5] Fix formatting and clippy with newer toolchain --- generic-ec-curves/src/rust_crypto/mod.rs | 2 +- generic-ec-curves/src/rust_crypto/point.rs | 2 +- generic-ec-curves/src/rust_crypto/scalar.rs | 2 +- generic-ec-zkp/src/polynomial.rs | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/generic-ec-curves/src/rust_crypto/mod.rs b/generic-ec-curves/src/rust_crypto/mod.rs index cceb689..040e262 100644 --- a/generic-ec-curves/src/rust_crypto/mod.rs +++ b/generic-ec-curves/src/rust_crypto/mod.rs @@ -84,7 +84,7 @@ impl fmt::Debug for RustCryptoCurve { impl Clone for RustCryptoCurve { fn clone(&self) -> Self { - Self { _ph: PhantomData } + *self } } diff --git a/generic-ec-curves/src/rust_crypto/point.rs b/generic-ec-curves/src/rust_crypto/point.rs index 5e4b8cc..377ec09 100644 --- a/generic-ec-curves/src/rust_crypto/point.rs +++ b/generic-ec-curves/src/rust_crypto/point.rs @@ -150,7 +150,7 @@ where E: CurveArithmetic, { fn clone(&self) -> Self { - Self(self.0) + *self } } diff --git a/generic-ec-curves/src/rust_crypto/scalar.rs b/generic-ec-curves/src/rust_crypto/scalar.rs index 1dbb910..fa11118 100644 --- a/generic-ec-curves/src/rust_crypto/scalar.rs +++ b/generic-ec-curves/src/rust_crypto/scalar.rs @@ -106,7 +106,7 @@ impl Default for RustCryptoScalar { impl Clone for RustCryptoScalar { fn clone(&self) -> Self { - Self(self.0) + *self } } diff --git a/generic-ec-zkp/src/polynomial.rs b/generic-ec-zkp/src/polynomial.rs index 84326ff..ef879c7 100644 --- a/generic-ec-zkp/src/polynomial.rs +++ b/generic-ec-zkp/src/polynomial.rs @@ -243,8 +243,8 @@ mod requires_alloc { { fn sum>>(mut iter: I) -> Self { let Some(mut sum) = iter.next().cloned() else { - return Self{ coefs: vec![] }; - }; + return Self { coefs: vec![] }; + }; for polynomial in iter { sum += polynomial; } @@ -258,8 +258,8 @@ mod requires_alloc { { fn sum>>(mut iter: I) -> Self { let Some(mut sum) = iter.next() else { - return Self{ coefs: vec![] }; - }; + return Self { coefs: vec![] }; + }; for polynomial in iter { sum += &polynomial }