BigInt fixes corresponding to algebra#372

Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This commit is contained in:
Marcin
2022-01-10 20:03:40 +01:00
committed by GitHub
parent d1ced15cc2
commit 6a5cf1d84a
32 changed files with 315 additions and 307 deletions

View File

@@ -1,4 +1,8 @@
use ark_ff::{biginteger::BigInteger256 as BigInteger, field_new, fields::*};
use ark_ff::{
biginteger::{BigInt, BigInteger256 as BigInteger},
field_new,
fields::*,
};
pub type Fq = Fp256<FqParameters>;
@@ -11,7 +15,7 @@ impl FftParameters for FqParameters {
const TWO_ADICITY: u32 = 1;
#[rustfmt::skip]
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
0x68c3488912edefaa,
0x8d087f6872aabf4f,
0x51e1a24709081231,
@@ -21,7 +25,7 @@ impl FftParameters for FqParameters {
impl FpParameters for FqParameters {
/// MODULUS = 21888242871839275222246405745257275088696311157297823662689037894645226208583
#[rustfmt::skip]
const MODULUS: BigInteger = BigInteger([
const MODULUS: BigInteger = BigInt::new([
0x3c208c16d87cfd47,
0x97816a916871ca8d,
0xb85045b68181585d,
@@ -35,7 +39,7 @@ impl FpParameters for FqParameters {
const REPR_SHAVE_BITS: u32 = 2;
#[rustfmt::skip]
const R: BigInteger = BigInteger([
const R: BigInteger = BigInt::new([
0xd35d438dc58f0d9d,
0x0a78eb28f5c70b3d,
0x666ea36f7879462c,
@@ -43,7 +47,7 @@ impl FpParameters for FqParameters {
]);
#[rustfmt::skip]
const R2: BigInteger = BigInteger([
const R2: BigInteger = BigInt::new([
0xf32cfc5b538afa89,
0xb5e71911d44501fb,
0x47ab1eff0a417ff6,
@@ -54,7 +58,7 @@ impl FpParameters for FqParameters {
// GENERATOR = 3
#[rustfmt::skip]
const GENERATOR: BigInteger = BigInteger([
const GENERATOR: BigInteger = BigInt::new([
0x7a17caa950ad28d7,
0x1f6ac17ae15521b9,
0x334bea4e696bd284,
@@ -62,7 +66,7 @@ impl FpParameters for FqParameters {
]);
#[rustfmt::skip]
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
0x9e10460b6c3e7ea3,
0xcbc0b548b438e546,
0xdc2822db40c0ac2e,
@@ -74,7 +78,7 @@ impl FpParameters for FqParameters {
// T = (MODULUS - 1) // 2^S =
// 10944121435919637611123202872628637544348155578648911831344518947322613104291
#[rustfmt::skip]
const T: BigInteger = BigInteger([
const T: BigInteger = BigInt::new([
0x9e10460b6c3e7ea3,
0xcbc0b548b438e546,
0xdc2822db40c0ac2e,
@@ -84,7 +88,7 @@ impl FpParameters for FqParameters {
// (T - 1) // 2 =
// 5472060717959818805561601436314318772174077789324455915672259473661306552145
#[rustfmt::skip]
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
0x4f082305b61f3f51,
0x65e05aa45a1c72a3,
0x6e14116da0605617,

View File

@@ -1,4 +1,7 @@
use ark_ff::{biginteger::BigInteger256 as BigInteger, fields::*};
use ark_ff::{
biginteger::{BigInt, BigInteger256 as BigInteger},
fields::*,
};
pub type Fr = Fp256<FrParameters>;
@@ -11,7 +14,7 @@ impl FftParameters for FrParameters {
const TWO_ADICITY: u32 = 28;
#[rustfmt::skip]
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
7164790868263648668u64,
11685701338293206998u64,
6216421865291908056u64,
@@ -21,7 +24,7 @@ impl FftParameters for FrParameters {
impl FpParameters for FrParameters {
/// MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617
#[rustfmt::skip]
const MODULUS: BigInteger = BigInteger([
const MODULUS: BigInteger = BigInt::new([
4891460686036598785u64,
2896914383306846353u64,
13281191951274694749u64,
@@ -37,7 +40,7 @@ impl FpParameters for FrParameters {
/// R = pow(2, 256) % MODULUS
/// = 6350874878119819312338956282401532410528162663560392320966563075034087161851
#[rustfmt::skip]
const R: BigInteger = BigInteger([
const R: BigInteger = BigInt::new([
12436184717236109307u64,
3962172157175319849u64,
7381016538464732718u64,
@@ -47,7 +50,7 @@ impl FpParameters for FrParameters {
/// R2 = R * R % MODULUS
/// = 944936681149208446651664254269745548490766851729442924617792859073125903783
#[rustfmt::skip]
const R2: BigInteger = BigInteger([
const R2: BigInteger = BigInt::new([
1997599621687373223u64,
6052339484930628067u64,
10108755138030829701u64,
@@ -59,7 +62,7 @@ impl FpParameters for FrParameters {
/// GENERATOR = 5
#[rustfmt::skip]
const GENERATOR: BigInteger = BigInteger([
const GENERATOR: BigInteger = BigInt::new([
1949230679015292902u64,
16913946402569752895u64,
5177146667339417225u64,
@@ -69,7 +72,7 @@ impl FpParameters for FrParameters {
/// (MODULUS - 1)/2 =
/// 10944121435919637611123202872628637544274182200208017171849102093287904247808
#[rustfmt::skip]
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
0xa1f0fac9f8000000,
0x9419f4243cdcb848,
0xdc2822db40c0ac2e,
@@ -81,7 +84,7 @@ impl FpParameters for FrParameters {
/// T = (MODULUS - 1) / 2^s =
/// 81540058820840996586704275553141814055101440848469862132140264610111
#[rustfmt::skip]
const T: BigInteger = BigInteger([
const T: BigInteger = BigInt::new([
0x9b9709143e1f593f,
0x181585d2833e8487,
0x131a029b85045b68,
@@ -91,7 +94,7 @@ impl FpParameters for FrParameters {
/// (T - 1) / 2 =
/// 40770029410420498293352137776570907027550720424234931066070132305055
#[rustfmt::skip]
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
0xcdcb848a1f0fac9f,
0x0c0ac2e9419f4243,
0x098d014dc2822db4,

View File

@@ -1,5 +1,5 @@
use ark_ff::{
biginteger::{BigInteger, BigInteger256},
biginteger::{BigInt, BigInteger, BigInteger256},
fields::{
fp6_3over2::Fp6Parameters, FftField, FftParameters, Field, FpParameters, PrimeField,
SquareRootField,
@@ -23,7 +23,7 @@ generate_field_serialization_test!(bn254; fq2; fq6; fq12;);
#[test]
fn test_fq_repr_from() {
assert_eq!(BigInteger256::from(100), BigInteger256([100, 0, 0, 0]));
assert_eq!(BigInteger256::from(100u64), BigInt::new([100, 0, 0, 0]));
}
#[test]
@@ -40,9 +40,9 @@ fn test_fq_repr_is_odd() {
#[test]
fn test_fq_repr_is_zero() {
assert!(BigInteger256::from(0).is_zero());
assert!(!BigInteger256::from(1).is_zero());
assert!(!BigInteger256([0, 0, 1, 0]).is_zero());
assert!(BigInteger256::from(0u64).is_zero());
assert!(!BigInteger256::from(1u64).is_zero());
assert!(!BigInt::new([0, 0, 1, 0]).is_zero());
}
#[test]