Browse Source

Update the documentation of BN254's field parameters (#59)

reduce-generics
Weikeng Chen 3 years ago
committed by GitHub
parent
commit
8c795ec0cf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions
  1. +2
    -2
      bn254/src/fields/fq.rs
  2. +9
    -4
      bn254/src/fields/fr.rs

+ 2
- 2
bn254/src/fields/fq.rs

@ -19,7 +19,7 @@ impl FftParameters for FqParameters {
]); ]);
} }
impl FpParameters for FqParameters { impl FpParameters for FqParameters {
/// MODULUS = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
/// MODULUS = 21888242871839275222246405745257275088696311157297823662689037894645226208583
#[rustfmt::skip] #[rustfmt::skip]
const MODULUS: BigInteger = BigInteger([ const MODULUS: BigInteger = BigInteger([
0x3c208c16d87cfd47, 0x3c208c16d87cfd47,
@ -82,7 +82,7 @@ impl FpParameters for FqParameters {
]); ]);
// (T - 1) // 2 = // (T - 1) // 2 =
// 1837921289030710838195067919506396475074392872918698035817074744121558668640693829665401097909504529
// 5472060717959818805561601436314318772174077789324455915672259473661306552145
#[rustfmt::skip] #[rustfmt::skip]
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([ const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
0x4f082305b61f3f51, 0x4f082305b61f3f51,

+ 9
- 4
bn254/src/fields/fr.rs

@ -34,6 +34,8 @@ impl FpParameters for FrParameters {
const REPR_SHAVE_BITS: u32 = 2; const REPR_SHAVE_BITS: u32 = 2;
/// R = pow(2, 320) % MODULUS
/// = 6350874878119819312338956282401532410528162663560392320966563075034087161851
#[rustfmt::skip] #[rustfmt::skip]
const R: BigInteger = BigInteger([ const R: BigInteger = BigInteger([
12436184717236109307u64, 12436184717236109307u64,
@ -42,6 +44,8 @@ impl FpParameters for FrParameters {
1011752739694698287u64, 1011752739694698287u64,
]); ]);
/// R2 = R * R % MODULUS
/// = 944936681149208446651664254269745548490766851729442924617792859073125903783
#[rustfmt::skip] #[rustfmt::skip]
const R2: BigInteger = BigInteger([ const R2: BigInteger = BigInteger([
1997599621687373223u64, 1997599621687373223u64,
@ -50,9 +54,10 @@ impl FpParameters for FrParameters {
150537098327114917u64, 150537098327114917u64,
]); ]);
/// INV = (-MODULUS) ^ {-1} % pow(2, 64) = 14042775128853446655
const INV: u64 = 14042775128853446655u64; const INV: u64 = 14042775128853446655u64;
// GENERATOR = 5
/// GENERATOR = 5
#[rustfmt::skip] #[rustfmt::skip]
const GENERATOR: BigInteger = BigInteger([ const GENERATOR: BigInteger = BigInteger([
1949230679015292902u64, 1949230679015292902u64,
@ -61,7 +66,7 @@ impl FpParameters for FrParameters {
1571765431670520771u64, 1571765431670520771u64,
]); ]);
/// (r - 1)/2 =
/// (MODULUS - 1)/2 =
/// 10944121435919637611123202872628637544274182200208017171849102093287904247808 /// 10944121435919637611123202872628637544274182200208017171849102093287904247808
#[rustfmt::skip] #[rustfmt::skip]
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([ const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
@ -73,7 +78,7 @@ impl FpParameters for FrParameters {
// T and T_MINUS_ONE_DIV_TWO, where r - 1 = 2^s * t // T and T_MINUS_ONE_DIV_TWO, where r - 1 = 2^s * t
/// t = (r - 1) / 2^s =
/// T = (MODULUS - 1) / 2^s =
/// 81540058820840996586704275553141814055101440848469862132140264610111 /// 81540058820840996586704275553141814055101440848469862132140264610111
#[rustfmt::skip] #[rustfmt::skip]
const T: BigInteger = BigInteger([ const T: BigInteger = BigInteger([
@ -83,7 +88,7 @@ impl FpParameters for FrParameters {
0x30644e72e, 0x30644e72e,
]); ]);
/// (t - 1) / 2 =
/// (T - 1) / 2 =
/// 40770029410420498293352137776570907027550720424234931066070132305055 /// 40770029410420498293352137776570907027550720424234931066070132305055
#[rustfmt::skip] #[rustfmt::skip]
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([ const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([

Loading…
Cancel
Save