Skip to content

Commit 6d64f37

Browse files
mmakerPratyush
andauthored
Fix with latest arkworks version. (#95)
Co-authored-by: Pratyush Mishra <[email protected]>
1 parent 4e1e8d0 commit 6d64f37

35 files changed

+448
-391
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ ark-std = { git = "https://github.com/arkworks-rs/std" }
5858
ark-ec = { git = "https://github.com/arkworks-rs/algebra" }
5959
ark-ff = { git = "https://github.com/arkworks-rs/algebra" }
6060
ark-poly = { git = "https://github.com/arkworks-rs/algebra" }
61-
ark-serialize = { git = "https://github.com/arkworks-rs/algebra" }
6261
ark-test-curves = { git = "https://github.com/arkworks-rs/algebra" }
6362
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves" }
6463
ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves" }

benches/bench.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use ark_ff::PrimeField;
2-
use ark_r1cs_std::fields::nonnative::NonNativeFieldVar;
3-
use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget, fields::FieldVar};
2+
use ark_r1cs_std::{
3+
alloc::AllocVar,
4+
eq::EqGadget,
5+
fields::{nonnative::NonNativeFieldVar, FieldVar},
6+
};
47
use ark_relations::{
58
ns,
69
r1cs::{ConstraintSystem, ConstraintSystemRef, OptimizationGoal},

src/bits/boolean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,8 @@ impl<F: Field> Boolean<F> {
608608
}
609609
}
610610

611-
/// Convert a little-endian bitwise representation of a field element to `FpVar<F>`
611+
/// Convert a little-endian bitwise representation of a field element to
612+
/// `FpVar<F>`
612613
#[tracing::instrument(target = "r1cs", skip(bits))]
613614
pub fn le_bits_to_fp_var(bits: &[Self]) -> Result<FpVar<F>, SynthesisError>
614615
where
@@ -761,7 +762,6 @@ impl<F: Field> Boolean<F> {
761762
/// # Ok(())
762763
/// # }
763764
/// ```
764-
///
765765
#[tracing::instrument(target = "r1cs", skip(first, second))]
766766
pub fn select<T: CondSelectGadget<F>>(
767767
&self,

src/bits/uint.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ macro_rules! make_uint {
77
#[doc = " type."]
88
pub mod $mod_name {
99
use ark_ff::{Field, One, PrimeField, Zero};
10-
use core::borrow::Borrow;
11-
use core::convert::TryFrom;
10+
use core::{borrow::Borrow, convert::TryFrom};
1211
use num_bigint::BigUint;
1312
use num_traits::cast::ToPrimitive;
1413

@@ -87,7 +86,6 @@ macro_rules! make_uint {
8786
/// Construct `Self` from a slice of `Boolean`s.
8887
///
8988
/// # Panics
90-
///
9189
#[doc = "This method panics if `bits.len() != "]
9290
#[doc = $num_bits_doc]
9391
#[doc = "`."]
@@ -142,8 +140,8 @@ macro_rules! make_uint {
142140

143141
/// Outputs `self ^ other`.
144142
///
145-
/// If at least one of `self` and `other` are constants, then this method
146-
/// *does not* create any constraints or variables.
143+
/// If at least one of `self` and `other` are constants, then this
144+
/// method *does not* create any constraints or variables.
147145
#[tracing::instrument(target = "r1cs", skip(self, other))]
148146
pub fn xor(&self, other: &Self) -> Result<Self, SynthesisError> {
149147
let mut result = self.clone();
@@ -225,7 +223,8 @@ macro_rules! make_uint {
225223
Boolean::Not(ref bit) => {
226224
all_constants = false;
227225

228-
// Add coeff * (1 - bit_gadget) = coeff * ONE - coeff * bit_gadget
226+
// Add coeff * (1 - bit_gadget) = coeff * ONE - coeff *
227+
// bit_gadget
229228
lc = lc + (coeff, Variable::One) - (coeff, bit.variable());
230229
},
231230
Boolean::Constant(bit) => {

src/bits/uint8.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ use ark_ff::{Field, PrimeField, ToConstraintField};
22

33
use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError};
44

5-
use crate::fields::fp::{AllocatedFp, FpVar};
6-
use crate::{prelude::*, Assignment, ToConstraintFieldGadget, Vec};
5+
use crate::{
6+
fields::fp::{AllocatedFp, FpVar},
7+
prelude::*,
8+
Assignment, ToConstraintFieldGadget, Vec,
9+
};
710
use core::{borrow::Borrow, convert::TryFrom};
811

912
/// Represents an interpretation of 8 `Boolean` objects as an
@@ -335,9 +338,9 @@ impl<ConstraintF: Field> AllocVar<u8, ConstraintF> for UInt8<ConstraintF> {
335338
}
336339
}
337340

338-
/// Parses the `Vec<UInt8<ConstraintF>>` in fixed-sized `ConstraintF::MODULUS_BIT_SIZE - 1` chunks and
339-
/// converts each chunk, which is assumed to be little-endian, to its `FpVar<ConstraintF>`
340-
/// representation.
341+
/// Parses the `Vec<UInt8<ConstraintF>>` in fixed-sized
342+
/// `ConstraintF::MODULUS_BIT_SIZE - 1` chunks and converts each chunk, which is
343+
/// assumed to be little-endian, to its `FpVar<ConstraintF>` representation.
341344
/// This is the gadget counterpart to the `[u8]` implementation of
342345
/// [ToConstraintField](ark_ff::ToConstraintField).
343346
impl<ConstraintF: PrimeField> ToConstraintFieldGadget<ConstraintF> for [UInt8<ConstraintF>] {
@@ -360,13 +363,17 @@ impl<ConstraintF: PrimeField> ToConstraintFieldGadget<ConstraintF> for Vec<UInt8
360363
#[cfg(test)]
361364
mod test {
362365
use super::UInt8;
363-
use crate::fields::fp::FpVar;
364-
use crate::prelude::AllocationMode::{Constant, Input, Witness};
365-
use crate::{prelude::*, ToConstraintFieldGadget, Vec};
366+
use crate::{
367+
fields::fp::FpVar,
368+
prelude::{
369+
AllocationMode::{Constant, Input, Witness},
370+
*,
371+
},
372+
ToConstraintFieldGadget, Vec,
373+
};
366374
use ark_ff::{PrimeField, ToConstraintField};
367375
use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
368-
use ark_std::rand::distributions::Uniform;
369-
use ark_std::rand::Rng;
376+
use ark_std::rand::{distributions::Uniform, Rng};
370377
use ark_test_curves::bls12_381::Fr;
371378

372379
#[test]

src/fields/fp/cmp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ impl<F: PrimeField> FpVar<F> {
153153

154154
#[cfg(test)]
155155
mod test {
156-
use ark_std::cmp::Ordering;
157-
use ark_std::rand::Rng;
156+
use ark_std::{cmp::Ordering, rand::Rng};
158157

159158
use crate::{alloc::AllocVar, fields::fp::FpVar};
160159
use ark_ff::{PrimeField, UniformRand};

src/fields/fp/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ impl<F: PrimeField> AllocatedFp<F> {
127127

128128
/// Add many allocated Fp elements together.
129129
///
130-
/// This does not create any constraints and only creates one linear combination.
130+
/// This does not create any constraints and only creates one linear
131+
/// combination.
131132
pub fn addmany<'a, I: Iterator<Item = &'a Self>>(iter: I) -> Self {
132133
let mut cs = ConstraintSystemRef::None;
133134
let mut has_value = true;
@@ -918,15 +919,19 @@ impl<F: PrimeField> ToBytesGadget<F> for FpVar<F> {
918919
#[tracing::instrument(target = "r1cs")]
919920
fn to_bytes(&self) -> Result<Vec<UInt8<F>>, SynthesisError> {
920921
match self {
921-
Self::Constant(c) => Ok(UInt8::constant_vec(&ark_ff::to_bytes![c].unwrap())),
922+
Self::Constant(c) => Ok(UInt8::constant_vec(
923+
c.into_bigint().to_bytes_be().as_slice(),
924+
)),
922925
Self::Var(v) => v.to_bytes(),
923926
}
924927
}
925928

926929
#[tracing::instrument(target = "r1cs")]
927930
fn to_non_unique_bytes(&self) -> Result<Vec<UInt8<F>>, SynthesisError> {
928931
match self {
929-
Self::Constant(c) => Ok(UInt8::constant_vec(&ark_ff::to_bytes![c].unwrap())),
932+
Self::Constant(c) => Ok(UInt8::constant_vec(
933+
c.into_bigint().to_bytes_be().as_slice(),
934+
)),
930935
Self::Var(v) => v.to_non_unique_bytes(),
931936
}
932937
}
@@ -1060,10 +1065,12 @@ impl<'a, F: PrimeField> Sum<&'a FpVar<F>> for FpVar<F> {
10601065

10611066
#[cfg(test)]
10621067
mod test {
1063-
use crate::alloc::{AllocVar, AllocationMode};
1064-
use crate::eq::EqGadget;
1065-
use crate::fields::fp::FpVar;
1066-
use crate::R1CSVar;
1068+
use crate::{
1069+
alloc::{AllocVar, AllocationMode},
1070+
eq::EqGadget,
1071+
fields::fp::FpVar,
1072+
R1CSVar,
1073+
};
10671074
use ark_relations::r1cs::ConstraintSystem;
10681075
use ark_std::{UniformRand, Zero};
10691076
use ark_test_curves::bls12_381::Fr;

src/fields/fp12.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::fields::{fp2::Fp2Var, fp6_3over2::Fp6Var, quadratic_extension::*, FieldVar};
2-
use ark_ff::fields::{fp12_2over3over2::*, Field};
3-
use ark_ff::fp6_3over2::Fp6Config;
4-
use ark_ff::QuadExtConfig;
2+
use ark_ff::{
3+
fields::{fp12_2over3over2::*, Field},
4+
fp6_3over2::Fp6Config,
5+
QuadExtConfig,
6+
};
57
use ark_relations::r1cs::SynthesisError;
68

79
/// A degree-12 extension field constructed as the tower of a

src/fields/fp3.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::fields::{cubic_extension::*, fp::FpVar};
2-
use ark_ff::fields::{CubicExtConfig, Fp3ConfigWrapper};
3-
use ark_ff::Fp3Config;
2+
use ark_ff::{
3+
fields::{CubicExtConfig, Fp3ConfigWrapper},
4+
Fp3Config,
5+
};
46

57
/// A cubic extension field constructed over a prime field.
68
/// This is the R1CS equivalent of `ark_ff::Fp3<P>`.

src/fields/fp4.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::fields::{fp2::Fp2Var, quadratic_extension::*};
2-
use ark_ff::fields::{Fp4ConfigWrapper, QuadExtConfig};
3-
use ark_ff::Fp4Config;
2+
use ark_ff::{
3+
fields::{Fp4ConfigWrapper, QuadExtConfig},
4+
Fp4Config,
5+
};
46

57
/// A quartic extension field constructed as the tower of a
68
/// quadratic extension over a quadratic extension field.

0 commit comments

Comments
 (0)