circom_lsp_program_structure/utils/
constants.rs

1use num_bigint::BigInt;
2
3const P_BN128: &str =
4    "21888242871839275222246405745257275088548364400416034343698204186575808495617";
5const P_BLS12381: &str = 
6    "52435875175126190479447740508185965837690552500527637822603658699938581184513";
7const P_GOLDILOCKS: &str = 
8    "18446744069414584321";
9const P_GRUMPKIN: &str = "21888242871839275222246405745257275088696311157297823662689037894645226208583";
10const P_PALLAS: &str = "28948022309329048855892746252171976963363056481941560715954676764349967630337";
11const P_VESTA : &str = "28948022309329048855892746252171976963363056481941647379679742748393362948097";
12//const P_STR: &str = "21888242871839275222246405745257275088548364400416034343698204186575808495617";
13
14pub struct UsefulConstants {
15    p: BigInt,
16}
17
18impl Clone for UsefulConstants {
19    fn clone(&self) -> Self {
20        UsefulConstants { p: self.p.clone() }
21    }
22}
23
24impl UsefulConstants {
25    pub fn new(possible_prime: &String) -> UsefulConstants {
26        let prime_to_use = if possible_prime.eq("bn128") {P_BN128} 
27          else if possible_prime.eq("bls12381") { P_BLS12381} 
28          else if possible_prime.eq("goldilocks") { P_GOLDILOCKS} 
29          else if possible_prime.eq("grumpkin") { P_GRUMPKIN} 
30          else if possible_prime.eq("pallas") { P_PALLAS} 
31          else if possible_prime.eq("vesta") { P_VESTA} 
32          else {unreachable!()};
33
34        UsefulConstants { p: BigInt::parse_bytes(prime_to_use.as_bytes(), 10).expect("can not parse p") }
35    }
36    
37    pub fn get_p(&self) -> &BigInt {
38        &self.p
39    }
40}