-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* big_prime_constraints * prime field element place holder * fmt
- Loading branch information
Showing
6 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ edition="2021" | |
|
||
[dependencies] | ||
ark-ff="0.4.2" | ||
num-bigint="0.4.4" | ||
lazy_static="1.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod big_prime_constants; | ||
mod prime_field_element; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::str::FromStr; | ||
|
||
use lazy_static::lazy_static; | ||
use num_bigint::BigInt; | ||
|
||
pub trait BigPrimeConstants { | ||
const NBITS: u32; | ||
const INDEX: u32; | ||
type ValueType: Sized; | ||
|
||
// Define associated functions instead of constants for complex types | ||
fn modulus() -> Self::ValueType; | ||
fn montgomery_r() -> Self::ValueType; | ||
fn montgomery_r_squared() -> Self::ValueType; | ||
fn montgomery_r_cubed() -> Self::ValueType; | ||
fn factors() -> &'static [Self::ValueType]; | ||
fn montgomery_m_prime() -> Self::ValueType; | ||
fn generator() -> Self::ValueType; | ||
fn max_divisible() -> Self::ValueType; | ||
} | ||
|
||
struct BigPrimeConstants252_0; | ||
|
||
lazy_static! { | ||
static ref FACTORS_252_0: [BigInt; 5] = [ | ||
BigInt::from_str("3").unwrap(), | ||
BigInt::from_str("5").unwrap(), | ||
BigInt::from_str("7").unwrap(), | ||
BigInt::from_str("5e2430d").unwrap(), | ||
BigInt::from_str("9f1e667").unwrap(), | ||
]; | ||
} | ||
|
||
impl BigPrimeConstants for BigPrimeConstants252_0 { | ||
type ValueType = BigInt; | ||
|
||
const INDEX: u32 = 0; | ||
const NBITS: u32 = 252; | ||
|
||
fn modulus() -> Self::ValueType { | ||
BigInt::from_str("800000000000011000000000000000000000000000000000000000000000001").unwrap() | ||
} | ||
|
||
fn montgomery_r() -> Self::ValueType { | ||
BigInt::from_str("7fffffffffffdf0ffffffffffffffffffffffffffffffffffffffffffffffe1").unwrap() | ||
} | ||
|
||
fn montgomery_r_squared() -> Self::ValueType { | ||
BigInt::from_str("7ffd4ab5e008810ffffffffff6f800000000001330ffffffffffd737e000401").unwrap() | ||
} | ||
|
||
fn montgomery_r_cubed() -> Self::ValueType { | ||
BigInt::from_str("38e5f79873c0a6df47d84f8363000187545706677ffcc06cc7177d1406df18e").unwrap() | ||
} | ||
|
||
fn factors() -> &'static [Self::ValueType] { &*FACTORS_252_0 } | ||
|
||
fn montgomery_m_prime() -> Self::ValueType { | ||
BigInt::from(u64::MAX) // Equivalent to ~uint64_t(0) | ||
} | ||
|
||
fn generator() -> Self::ValueType { BigInt::from(3) } | ||
|
||
fn max_divisible() -> Self::ValueType { | ||
BigInt::from_str("f80000000000020f00000000000000000000000000000000000000000000001f").unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::marker::PhantomData; | ||
|
||
// use super::big_prime_constants::BigPrimeConstants; | ||
|
||
// Define a struct representing a prime field element. | ||
// The NBits and Index are generic parameters. | ||
// todo: probably get rid of this and use Arkworks PrimeFieldElement | ||
pub struct PrimeFieldElement<NBits, Index> { | ||
_nbits: PhantomData<NBits>, | ||
_index: PhantomData<Index>, | ||
} | ||
|
||
impl<NBits, Index> From<usize> for PrimeFieldElement<NBits, Index> { | ||
fn from(val: usize) -> Self { | ||
// Self{val} | ||
todo!() | ||
} | ||
} | ||
|
||
// impl<NBits, Index> PrimeFieldElement<NBits, Index> { | ||
// // ... other methods as needed | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
#![allow(unused_imports)] | ||
#![allow(unused_variables)] | ||
#![allow(dead_code)] | ||
// todo | ||
mod fields; | ||
mod polymorphic; | ||
|
||
pub use polymorphic::{ConstFieldElementSpan, FieldElementSpan, FieldElementVector}; |