Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush authored Oct 17, 2024
2 parents f1640df + f742abd commit 309e2b4
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 187 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
- Add `UInt::rotate_{left,right}_in_place`.
- Add `{Boolean,UInt}::not_in_place`.
- Add `UInt::{from_bytes_le, from_bytes_be, to_bytes_be}`.
- [\#143](https://github.com/arkworks-rs/r1cs-std/pull/143)
- Add `AllocVar::new_variable_with_inferred_mode`.
- [\#143](https://github.com/arkworks-rs/r1cs-std/pull/143) Add `AllocVar::new_variable_with_inferred_mode`.
- [\#144](https://github.com/arkworks-rs/r1cs-std/pull/144) Add `ToConstraintFieldGadget` bounds to `CurveVar` and `FieldVar`

### Improvements

### Bug Fixes

- [\#145](https://github.com/arkworks-rs/r1cs-std/pull/145)
- Avoid deeply nested `LinearCombinations` in `EvaluationsVar::interpolate_and_evaluate` to fix the stack overflow issue when calling `.value()` on the evaluation result.
- [\#148](https://github.com/arkworks-rs/r1cs-std/pull/148)
- Fix panic issues during in-circuit polynomial interpolation.

## 0.4.0

- [\#117](https://github.com/arkworks-rs/r1cs-std/pull/117) Fix result of `precomputed_base_scalar_mul_le` to not discard previous value.
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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/" }
Expand All @@ -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/" }
20 changes: 10 additions & 10 deletions src/fields/cubic_extension.rs
Original file line number Diff line number Diff line change
@@ -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<BF: FieldVar<P::BaseField, P::BasePrimeField>, P: CubicExtVarConfig<BF>>
where
Expand All @@ -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<P>,
}

Expand Down
3 changes: 2 additions & 1 deletion src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::{
ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign},
};

use crate::convert::{ToBitsGadget, ToBytesGadget};
use crate::convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget};
use crate::prelude::*;

/// This module contains a generic implementation of cubic extension field
Expand Down Expand Up @@ -76,6 +76,7 @@ pub trait FieldVar<F: Field, ConstraintF: PrimeField>:
+ AllocVar<F, ConstraintF>
+ ToBytesGadget<ConstraintF>
+ CondSelectGadget<ConstraintF>
+ ToConstraintFieldGadget<ConstraintF>
+ for<'a> FieldOpsBounds<'a, F, Self>
+ for<'a> AddAssign<&'a Self>
+ for<'a> SubAssign<&'a Self>
Expand Down
20 changes: 10 additions & 10 deletions src/fields/quadratic_extension.rs
Original file line number Diff line number Diff line change
@@ -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<BF: FieldVar<P::BaseField, P::BasePrimeField>, P: QuadExtVarConfig<BF>>
where
Expand All @@ -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<P>,
}

Expand Down
12 changes: 4 additions & 8 deletions src/groups/curves/short_weierstrass/bls12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
groups::curves::short_weierstrass::*,
Vec,
};
use core::fmt::Debug;

/// Represents a projective point in G1.
pub type G1Var<P> = ProjectiveVar<<P as Bls12Config>::G1Config, FpVar<<P as Bls12Config>::Fp>>;
Expand All @@ -29,8 +28,8 @@ pub type G2AffineVar<P> = AffineVar<<P as Bls12Config>::G2Config, Fp2G<P>>;

/// Represents the cached precomputation that can be performed on a G1 element
/// which enables speeding up pairing computation.
#[derive(Derivative)]
#[derivative(Clone(bound = "G1Var<P>: Clone"), Debug(bound = "G1Var<P>: Debug"))]
#[derive(Educe)]
#[educe(Clone, Debug)]
pub struct G1PreparedVar<P: Bls12Config>(pub AffineVar<P::G1Config, FpVar<P::Fp>>);

impl<P: Bls12Config> G1PreparedVar<P> {
Expand Down Expand Up @@ -103,11 +102,8 @@ type Fp2G<P> = Fp2Var<<P as Bls12Config>::Fp2Config>;
type LCoeff<P> = (Fp2G<P>, Fp2G<P>);
/// Represents the cached precomputation that can be performed on a G2 element
/// which enables speeding up pairing computation.
#[derive(Derivative)]
#[derivative(
Clone(bound = "Fp2Var<P::Fp2Config>: Clone"),
Debug(bound = "Fp2Var<P::Fp2Config>: Debug")
)]
#[derive(Educe)]
#[educe(Clone, Debug)]
pub struct G2PreparedVar<P: Bls12Config> {
#[doc(hidden)]
pub ell_coeffs: Vec<LCoeff<P>>,
Expand Down
17 changes: 9 additions & 8 deletions src/groups/curves/short_weierstrass/mnt4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
Vec,
};
use core::borrow::Borrow;
use educe::Educe;

/// Represents a projective point in G1.
pub type G1Var<P> = ProjectiveVar<<P as MNT4Config>::G1Config, FpVar<<P as MNT4Config>::Fp>>;
Expand All @@ -23,8 +24,8 @@ pub type G2Var<P> = ProjectiveVar<<P as MNT4Config>::G2Config, Fp2G<P>>;

/// 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<P: MNT4Config> {
#[doc(hidden)]
pub x: FpVar<P::Fp>,
Expand Down Expand Up @@ -135,8 +136,8 @@ type Fp2G<P> = Fp2Var<<P as MNT4Config>::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<P: MNT4Config> {
#[doc(hidden)]
pub x: Fp2Var<P::Fp2Config>,
Expand Down Expand Up @@ -340,8 +341,8 @@ impl<P: MNT4Config> G2PreparedVar<P> {
}

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

#[doc(hidden)]
#[derive(Derivative)]
#[derivative(Clone(bound = "P: MNT4Config"), Debug(bound = "P: MNT4Config"))]
#[derive(Educe)]
#[educe(Clone, Debug)]
pub struct AteAdditionCoefficientsVar<P: MNT4Config> {
pub c_l1: Fp2Var<P::Fp2Config>,
pub c_rz: Fp2Var<P::Fp2Config>,
Expand Down
17 changes: 9 additions & 8 deletions src/groups/curves/short_weierstrass/mnt6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
Vec,
};
use core::borrow::Borrow;
use educe::Educe;

/// Represents a projective point in G1.
pub type G1Var<P> = ProjectiveVar<<P as MNT6Config>::G1Config, FpVar<<P as MNT6Config>::Fp>>;
Expand All @@ -23,8 +24,8 @@ pub type G2Var<P> = ProjectiveVar<<P as MNT6Config>::G2Config, Fp3G<P>>;

/// 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<P: MNT6Config> {
#[doc(hidden)]
pub x: FpVar<P::Fp>,
Expand Down Expand Up @@ -135,8 +136,8 @@ type Fp3G<P> = Fp3Var<<P as MNT6Config>::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<P: MNT6Config> {
#[doc(hidden)]
pub x: Fp3Var<P::Fp3Config>,
Expand Down Expand Up @@ -340,8 +341,8 @@ impl<P: MNT6Config> G2PreparedVar<P> {
}

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

#[doc(hidden)]
#[derive(Derivative)]
#[derivative(Clone(bound = "P: MNT6Config"), Debug(bound = "P: MNT6Config"))]
#[derive(Educe)]
#[educe(Clone, Debug)]
pub struct AteAdditionCoefficientsVar<P: MNT6Config> {
pub c_l1: Fp3Var<P::Fp3Config>,
pub c_rz: Fp3Var<P::Fp3Config>,
Expand Down
13 changes: 7 additions & 6 deletions src/groups/curves/short_weierstrass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -42,8 +43,8 @@ type BasePrimeField<P> = <<P as CurveConfig>::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]](<https://eprint.iacr.org/2015/1060>).
#[derive(Derivative)]
#[derivative(Debug, Clone)]
#[derive(Educe)]
#[educe(Debug, Clone)]
#[must_use]
pub struct ProjectiveVar<P: SWCurveConfig, F: FieldVar<P::BaseField, BasePrimeField<P>>>
where
Expand All @@ -55,13 +56,13 @@ where
pub y: F,
/// The z-coordinate.
pub z: F,
#[derivative(Debug = "ignore")]
#[educe(Debug(ignore))]
_params: PhantomData<P>,
}

/// 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<P: SWCurveConfig, F: FieldVar<P::BaseField, BasePrimeField<P>>>
where
Expand All @@ -73,7 +74,7 @@ where
pub y: F,
/// Is `self` the point at infinity.
pub infinity: Boolean<BasePrimeField<P>>,
#[derivative(Debug = "ignore")]
#[educe(Debug(ignore))]
_params: PhantomData<P>,
}

Expand Down
6 changes: 3 additions & 3 deletions src/groups/curves/short_weierstrass/non_zero_affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,7 +17,7 @@ pub struct NonZeroAffineVar<
pub x: F,
/// The y-coordinate.
pub y: F,
#[derivative(Debug = "ignore")]
#[educe(Debug(ignore))]
_params: PhantomData<P>,
}

Expand Down
Loading

0 comments on commit 309e2b4

Please sign in to comment.