Skip to content

Commit a9de593

Browse files
author
howardwu
committed
Fix BLS120377 generator and two-adic root of unity
1 parent 5b5acf3 commit a9de593

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

  • curves/src/bls12_377

curves/src/bls12_377/fr.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@
1717
use snarkvm_fields::{FftParameters, FieldParameters, Fp256, Fp256Parameters};
1818
use snarkvm_utilities::biginteger::BigInteger256 as BigInteger;
1919

20+
/// BLS12-377 scalar field.
21+
///
22+
/// Roots of unity computed from modulus and R using this sage code:
23+
///
24+
/// ```ignore
25+
/// q = 8444461749428370424248824938781546531375899335154063827935233455917409239041
26+
/// R = 6014086494747379908336260804527802945383293308637734276299549080986809532403 # Montgomery R
27+
/// s = 47
28+
/// o = q - 1
29+
/// F = GF(q)
30+
/// g = F.multiplicative_generator()
31+
/// g = F.multiplicative_generator()
32+
/// assert g.multiplicative_order() == o
33+
/// g2 = g ** (o/2**s)
34+
/// assert g2.multiplicative_order() == 2**s
35+
/// def into_chunks(val, width, n):
36+
/// return [int(int(val) // (2 ** (width * i)) % 2 ** width) for i in range(n)]
37+
/// print("Gen: ", g * R % q)
38+
/// print("Gen: ", into_chunks(g * R % q, 64, 4))
39+
/// print("2-adic gen: ", into_chunks(g2 * R % q, 64, 4))
40+
/// ```
2041
pub type Fr = Fp256<FrParameters>;
2142

2243
pub struct FrParameters;
@@ -30,23 +51,26 @@ impl FftParameters for FrParameters {
3051
const TWO_ADICITY: u32 = 47;
3152
#[rustfmt::skip]
3253
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
33-
0x3c3d3ca739381fb2,
34-
0x9a14cda3ec99772b,
35-
0xd7aacc7c59724826,
36-
0xd1ba211c5cc349c,
54+
12646347781564978760u64,
55+
6783048705277173164u64,
56+
268534165941069093u64,
57+
1121515446318641358u64,
3758
]);
3859
}
3960

4061
impl FieldParameters for FrParameters {
4162
#[rustfmt::skip]
4263
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
43-
/// GENERATOR = 11
64+
/// GENERATOR = 22
65+
/// Encoded in Montgomery form, so the value is
66+
/// (22 * R) % q = 5642976643016801619665363617888466827793962762719196659561577942948671127251
67+
#[rustfmt::skip]
4468
#[rustfmt::skip]
4569
const GENERATOR: BigInteger = BigInteger([
46-
1855201571499933546u64,
47-
8511318076631809892u64,
48-
6222514765367795509u64,
49-
1122129207579058019u64,
70+
2984901390528151251u64,
71+
10561528701063790279u64,
72+
5476750214495080041u64,
73+
898978044469942640u64,
5074
]);
5175
#[rustfmt::skip]
5276
const INV: u64 = 725501752471715839u64;

0 commit comments

Comments
 (0)