From 4fb0adf1645349a9a9afe0314351266f889eff07 Mon Sep 17 00:00:00 2001 From: Weikeng Chen Date: Thu, 18 Jul 2024 17:42:24 +0800 Subject: [PATCH] Replace derivative with educe (#146) * replace derivative with educe * add check-cfg lint config to allow the ci variable * use the same target as algebra for no-std * std --- .github/workflows/ci.yml | 7 ------- Cargo.toml | 6 +++++- src/fields/cubic_extension.rs | 20 +++++++++---------- src/fields/quadratic_extension.rs | 20 +++++++++---------- .../curves/short_weierstrass/bls12/mod.rs | 12 ++++------- .../curves/short_weierstrass/mnt4/mod.rs | 17 ++++++++-------- .../curves/short_weierstrass/mnt6/mod.rs | 17 ++++++++-------- src/groups/curves/short_weierstrass/mod.rs | 13 ++++++------ .../short_weierstrass/non_zero_affine.rs | 6 +++--- src/groups/curves/twisted_edwards/mod.rs | 13 ++++++------ src/lib.rs | 4 ---- 11 files changed, 64 insertions(+), 71 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4f5893a..53b6f312 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,13 +109,6 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - id: toolchain-thumbv6m - with: - target: thumbv6m-none-eabi - - run: rustup override set ${{steps.toolchain-thumbv6m.outputs.name}} - - name: Install Rust ARM64 uses: dtolnay/rust-toolchain@stable id: toolchain-aarch64 diff --git a/Cargo.toml b/Cargo.toml index 6f69d8dc..7afc7d0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ ark-ec = { version = "0.4.0", default-features = false } ark-std = { version = "0.4.0", default-features = false } ark-relations = { version = "0.4.0", default-features = false } -derivative = { version = "2", features = ["use_core"] } +educe = "0.6.0" tracing = { version = "0.1", default-features = false, features = [ "attributes" ] } num-bigint = { version = "0.4", default-features = false } num-traits = { version = "0.2", default-features = false } @@ -73,6 +73,9 @@ incremental = true debug-assertions = true debug = true +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } + [patch.crates-io] ark-ff = { git = "https://github.com/arkworks-rs/algebra/" } ark-ec = { git = "https://github.com/arkworks-rs/algebra/" } @@ -87,3 +90,4 @@ ark-mnt4-753 = { git = "https://github.com/arkworks-rs/curves/" } ark-mnt6-298 = { git = "https://github.com/arkworks-rs/curves/" } ark-mnt6-753 = { git = "https://github.com/arkworks-rs/curves/" } ark-pallas = { git = "https://github.com/arkworks-rs/curves/" } +ark-std = { git = "https://github.com/arkworks-rs/std/" } \ No newline at end of file diff --git a/src/fields/cubic_extension.rs b/src/fields/cubic_extension.rs index d0b64a71..62105a2d 100644 --- a/src/fields/cubic_extension.rs +++ b/src/fields/cubic_extension.rs @@ -1,21 +1,21 @@ -use ark_ff::{ - fields::{CubicExtField, Field}, - CubicExtConfig, Zero, -}; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; -use core::{borrow::Borrow, marker::PhantomData}; - use crate::{ convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, fields::{fp::FpVar, FieldOpsBounds, FieldVar}, prelude::*, Vec, }; +use ark_ff::{ + fields::{CubicExtField, Field}, + CubicExtConfig, Zero, +}; +use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use core::{borrow::Borrow, marker::PhantomData}; +use educe::Educe; /// This struct is the `R1CS` equivalent of the cubic extension field type /// in `ark-ff`, i.e. `ark_ff::CubicExtField`. -#[derive(Derivative)] -#[derivative(Debug(bound = "BF: core::fmt::Debug"), Clone(bound = "BF: Clone"))] +#[derive(Educe)] +#[educe(Debug, Clone)] #[must_use] pub struct CubicExtVar, P: CubicExtVarConfig> where @@ -27,7 +27,7 @@ where pub c1: BF, /// The second coefficient of this field element. pub c2: BF, - #[derivative(Debug = "ignore")] + #[educe(Debug(ignore))] _params: PhantomData

, } diff --git a/src/fields/quadratic_extension.rs b/src/fields/quadratic_extension.rs index a38f47c1..d7419da3 100644 --- a/src/fields/quadratic_extension.rs +++ b/src/fields/quadratic_extension.rs @@ -1,21 +1,21 @@ -use ark_ff::{ - fields::{Field, QuadExtConfig, QuadExtField}, - Zero, -}; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; -use core::{borrow::Borrow, marker::PhantomData}; - use crate::{ convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, fields::{fp::FpVar, FieldOpsBounds, FieldVar}, prelude::*, Vec, }; +use ark_ff::{ + fields::{Field, QuadExtConfig, QuadExtField}, + Zero, +}; +use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use core::{borrow::Borrow, marker::PhantomData}; +use educe::Educe; /// This struct is the `R1CS` equivalent of the quadratic extension field type /// in `ark-ff`, i.e. `ark_ff::QuadExtField`. -#[derive(Derivative)] -#[derivative(Debug(bound = "BF: core::fmt::Debug"), Clone(bound = "BF: Clone"))] +#[derive(Educe)] +#[educe(Debug, Clone)] #[must_use] pub struct QuadExtVar, P: QuadExtVarConfig> where @@ -25,7 +25,7 @@ where pub c0: BF, /// The first coefficient of this field element. pub c1: BF, - #[derivative(Debug = "ignore")] + #[educe(Debug(ignore))] _params: PhantomData

, } diff --git a/src/groups/curves/short_weierstrass/bls12/mod.rs b/src/groups/curves/short_weierstrass/bls12/mod.rs index deb6b19a..1549f976 100644 --- a/src/groups/curves/short_weierstrass/bls12/mod.rs +++ b/src/groups/curves/short_weierstrass/bls12/mod.rs @@ -10,7 +10,6 @@ use crate::{ groups::curves::short_weierstrass::*, Vec, }; -use core::fmt::Debug; /// Represents a projective point in G1. pub type G1Var

= ProjectiveVar<

::G1Config, FpVar<

::Fp>>; @@ -29,8 +28,8 @@ pub type G2AffineVar

= AffineVar<

::G2Config, Fp2G

>; /// Represents the cached precomputation that can be performed on a G1 element /// which enables speeding up pairing computation. -#[derive(Derivative)] -#[derivative(Clone(bound = "G1Var

: Clone"), Debug(bound = "G1Var

: Debug"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct G1PreparedVar(pub AffineVar>); impl G1PreparedVar

{ @@ -103,11 +102,8 @@ type Fp2G

= Fp2Var<

::Fp2Config>; type LCoeff

= (Fp2G

, Fp2G

); /// Represents the cached precomputation that can be performed on a G2 element /// which enables speeding up pairing computation. -#[derive(Derivative)] -#[derivative( - Clone(bound = "Fp2Var: Clone"), - Debug(bound = "Fp2Var: Debug") -)] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct G2PreparedVar { #[doc(hidden)] pub ell_coeffs: Vec>, diff --git a/src/groups/curves/short_weierstrass/mnt4/mod.rs b/src/groups/curves/short_weierstrass/mnt4/mod.rs index 3b960c82..a5c6875d 100644 --- a/src/groups/curves/short_weierstrass/mnt4/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt4/mod.rs @@ -14,6 +14,7 @@ use crate::{ Vec, }; use core::borrow::Borrow; +use educe::Educe; /// Represents a projective point in G1. pub type G1Var

= ProjectiveVar<

::G1Config, FpVar<

::Fp>>; @@ -23,8 +24,8 @@ pub type G2Var

= ProjectiveVar<

::G2Config, Fp2G

>; /// Represents the cached precomputation that can be performed on a G1 element /// which enables speeding up pairing computation. -#[derive(Derivative)] -#[derivative(Clone(bound = "P: MNT4Config"), Debug(bound = "P: MNT4Config"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct G1PreparedVar { #[doc(hidden)] pub x: FpVar, @@ -135,8 +136,8 @@ type Fp2G

= Fp2Var<

::Fp2Config>; /// Represents the cached precomputation that can be performed on a G2 element /// which enables speeding up pairing computation. -#[derive(Derivative)] -#[derivative(Clone(bound = "P: MNT4Config"), Debug(bound = "P: MNT4Config"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct G2PreparedVar { #[doc(hidden)] pub x: Fp2Var, @@ -340,8 +341,8 @@ impl G2PreparedVar

{ } #[doc(hidden)] -#[derive(Derivative)] -#[derivative(Clone(bound = "P: MNT4Config"), Debug(bound = "P: MNT4Config"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct AteDoubleCoefficientsVar { pub c_h: Fp2Var, pub c_4c: Fp2Var, @@ -425,8 +426,8 @@ impl AteDoubleCoefficientsVar

{ } #[doc(hidden)] -#[derive(Derivative)] -#[derivative(Clone(bound = "P: MNT4Config"), Debug(bound = "P: MNT4Config"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct AteAdditionCoefficientsVar { pub c_l1: Fp2Var, pub c_rz: Fp2Var, diff --git a/src/groups/curves/short_weierstrass/mnt6/mod.rs b/src/groups/curves/short_weierstrass/mnt6/mod.rs index 3fdf923d..83f742f4 100644 --- a/src/groups/curves/short_weierstrass/mnt6/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt6/mod.rs @@ -14,6 +14,7 @@ use crate::{ Vec, }; use core::borrow::Borrow; +use educe::Educe; /// Represents a projective point in G1. pub type G1Var

= ProjectiveVar<

::G1Config, FpVar<

::Fp>>; @@ -23,8 +24,8 @@ pub type G2Var

= ProjectiveVar<

::G2Config, Fp3G

>; /// Represents the cached precomputation that can be performed on a G1 element /// which enables speeding up pairing computation. -#[derive(Derivative)] -#[derivative(Clone(bound = "P: MNT6Config"), Debug(bound = "P: MNT6Config"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct G1PreparedVar { #[doc(hidden)] pub x: FpVar, @@ -135,8 +136,8 @@ type Fp3G

= Fp3Var<

::Fp3Config>; /// Represents the cached precomputation that can be performed on a G2 element /// which enables speeding up pairing computation. -#[derive(Derivative)] -#[derivative(Clone(bound = "P: MNT6Config"), Debug(bound = "P: MNT6Config"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct G2PreparedVar { #[doc(hidden)] pub x: Fp3Var, @@ -340,8 +341,8 @@ impl G2PreparedVar

{ } #[doc(hidden)] -#[derive(Derivative)] -#[derivative(Clone(bound = "P: MNT6Config"), Debug(bound = "P: MNT6Config"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct AteDoubleCoefficientsVar { pub c_h: Fp3Var, pub c_4c: Fp3Var, @@ -423,8 +424,8 @@ impl AteDoubleCoefficientsVar

{ } #[doc(hidden)] -#[derive(Derivative)] -#[derivative(Clone(bound = "P: MNT6Config"), Debug(bound = "P: MNT6Config"))] +#[derive(Educe)] +#[educe(Clone, Debug)] pub struct AteAdditionCoefficientsVar { pub c_l1: Fp3Var, pub c_rz: Fp3Var, diff --git a/src/groups/curves/short_weierstrass/mod.rs b/src/groups/curves/short_weierstrass/mod.rs index d18f7209..8604c052 100644 --- a/src/groups/curves/short_weierstrass/mod.rs +++ b/src/groups/curves/short_weierstrass/mod.rs @@ -5,6 +5,7 @@ use ark_ec::{ use ark_ff::{AdditiveGroup, BitIteratorBE, Field, One, PrimeField, Zero}; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use ark_std::{borrow::Borrow, marker::PhantomData, ops::Mul}; +use educe::Educe; use non_zero_affine::NonZeroAffineVar; use crate::{ @@ -42,8 +43,8 @@ type BasePrimeField

= <

::BaseField as Field>::BasePrimeFiel /// An implementation of arithmetic for Short Weierstrass curves that relies on /// the complete formulae derived in the paper of /// [[Renes, Costello, Batina 2015]](). -#[derive(Derivative)] -#[derivative(Debug, Clone)] +#[derive(Educe)] +#[educe(Debug, Clone)] #[must_use] pub struct ProjectiveVar>> where @@ -55,13 +56,13 @@ where pub y: F, /// The z-coordinate. pub z: F, - #[derivative(Debug = "ignore")] + #[educe(Debug(ignore))] _params: PhantomData

, } /// An affine representation of a curve point. -#[derive(Derivative)] -#[derivative(Debug(bound = "F: ark_std::fmt::Debug"), Clone(bound = "F: Clone"))] +#[derive(Educe)] +#[educe(Debug, Clone)] #[must_use] pub struct AffineVar>> where @@ -73,7 +74,7 @@ where pub y: F, /// Is `self` the point at infinity. pub infinity: Boolean>, - #[derivative(Debug = "ignore")] + #[educe(Debug(ignore))] _params: PhantomData

, } diff --git a/src/groups/curves/short_weierstrass/non_zero_affine.rs b/src/groups/curves/short_weierstrass/non_zero_affine.rs index 7b894348..50448518 100644 --- a/src/groups/curves/short_weierstrass/non_zero_affine.rs +++ b/src/groups/curves/short_weierstrass/non_zero_affine.rs @@ -4,8 +4,8 @@ use ark_std::ops::Add; /// An affine representation of a prime order curve point that is guaranteed /// to *not* be the point at infinity. -#[derive(Derivative)] -#[derivative(Debug, Clone)] +#[derive(Educe)] +#[educe(Debug, Clone)] #[must_use] pub struct NonZeroAffineVar< P: SWCurveConfig, @@ -17,7 +17,7 @@ pub struct NonZeroAffineVar< pub x: F, /// The y-coordinate. pub y: F, - #[derivative(Debug = "ignore")] + #[educe(Debug(ignore))] _params: PhantomData

, } diff --git a/src/groups/curves/twisted_edwards/mod.rs b/src/groups/curves/twisted_edwards/mod.rs index 82095bfd..4ffcc644 100644 --- a/src/groups/curves/twisted_edwards/mod.rs +++ b/src/groups/curves/twisted_edwards/mod.rs @@ -17,6 +17,7 @@ use crate::{ use crate::fields::fp::FpVar; use ark_std::{borrow::Borrow, marker::PhantomData, ops::Mul}; +use educe::Educe; type BasePrimeField

= <

::BaseField as Field>::BasePrimeField; @@ -26,8 +27,8 @@ type BasePrimeField

= <

::BaseField as Field>::BasePrimeFiel /// /// This is intended for use primarily for implementing efficient /// multi-scalar-multiplication in the Bowe-Hopwood-Pedersen hash. -#[derive(Derivative)] -#[derivative(Debug, Clone)] +#[derive(Educe)] +#[educe(Debug, Clone)] #[must_use] pub struct MontgomeryAffineVar>> where @@ -37,7 +38,7 @@ where pub x: F, /// The y-coordinate. pub y: F, - #[derivative(Debug = "ignore")] + #[educe(Debug(ignore))] _params: PhantomData

, } @@ -233,8 +234,8 @@ mod montgomery_affine_impl { /// An implementation of arithmetic for Twisted Edwards curves that relies on /// the complete formulae for the affine model, as outlined in the /// [EFD](https://www.hyperelliptic.org/EFD/g1p/auto-twisted.html). -#[derive(Derivative)] -#[derivative(Debug, Clone)] +#[derive(Educe)] +#[educe(Debug, Clone)] #[must_use] pub struct AffineVar>> where @@ -244,7 +245,7 @@ where pub x: F, /// The y-coordinate. pub y: F, - #[derivative(Debug = "ignore")] + #[educe(Debug(ignore))] _params: PhantomData

, } diff --git a/src/lib.rs b/src/lib.rs index 7f3e5274..ed0b1621 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,10 +19,6 @@ extern crate ark_ff; #[macro_use] extern crate ark_relations; -#[doc(hidden)] -#[macro_use] -extern crate derivative; - /// Some utility macros for making downstream impls easier. #[macro_use] pub mod macros;