Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Update the documentation of BN254's field parameters (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
weikengchen authored May 6, 2021
1 parent 9d232a7 commit 8c795ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bn254/src/fields/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl FftParameters for FqParameters {
]);
}
impl FpParameters for FqParameters {
/// MODULUS = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
/// MODULUS = 21888242871839275222246405745257275088696311157297823662689037894645226208583
#[rustfmt::skip]
const MODULUS: BigInteger = BigInteger([
0x3c208c16d87cfd47,
Expand Down Expand Up @@ -82,7 +82,7 @@ impl FpParameters for FqParameters {
]);

// (T - 1) // 2 =
// 1837921289030710838195067919506396475074392872918698035817074744121558668640693829665401097909504529
// 5472060717959818805561601436314318772174077789324455915672259473661306552145
#[rustfmt::skip]
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
0x4f082305b61f3f51,
Expand Down
13 changes: 9 additions & 4 deletions bn254/src/fields/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ impl FpParameters for FrParameters {

const REPR_SHAVE_BITS: u32 = 2;

/// R = pow(2, 320) % MODULUS
/// = 6350874878119819312338956282401532410528162663560392320966563075034087161851
#[rustfmt::skip]
const R: BigInteger = BigInteger([
12436184717236109307u64,
Expand All @@ -42,6 +44,8 @@ impl FpParameters for FrParameters {
1011752739694698287u64,
]);

/// R2 = R * R % MODULUS
/// = 944936681149208446651664254269745548490766851729442924617792859073125903783
#[rustfmt::skip]
const R2: BigInteger = BigInteger([
1997599621687373223u64,
Expand All @@ -50,9 +54,10 @@ impl FpParameters for FrParameters {
150537098327114917u64,
]);

/// INV = (-MODULUS) ^ {-1} % pow(2, 64) = 14042775128853446655
const INV: u64 = 14042775128853446655u64;

// GENERATOR = 5
/// GENERATOR = 5
#[rustfmt::skip]
const GENERATOR: BigInteger = BigInteger([
1949230679015292902u64,
Expand All @@ -61,7 +66,7 @@ impl FpParameters for FrParameters {
1571765431670520771u64,
]);

/// (r - 1)/2 =
/// (MODULUS - 1)/2 =
/// 10944121435919637611123202872628637544274182200208017171849102093287904247808
#[rustfmt::skip]
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
Expand All @@ -73,7 +78,7 @@ impl FpParameters for FrParameters {

// T and T_MINUS_ONE_DIV_TWO, where r - 1 = 2^s * t

/// t = (r - 1) / 2^s =
/// T = (MODULUS - 1) / 2^s =
/// 81540058820840996586704275553141814055101440848469862132140264610111
#[rustfmt::skip]
const T: BigInteger = BigInteger([
Expand All @@ -83,7 +88,7 @@ impl FpParameters for FrParameters {
0x30644e72e,
]);

/// (t - 1) / 2 =
/// (T - 1) / 2 =
/// 40770029410420498293352137776570907027550720424234931066070132305055
#[rustfmt::skip]
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
Expand Down

0 comments on commit 8c795ec

Please sign in to comment.