Skip to content

Openmina changes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: for-3.0.1-devnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions curves/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ ark-ff = { version = "0.3.0", features = ["parallel", "asm"] }
rand = { version = "0.8.0", default-features = false }
ark-algebra-test-templates = "0.3.0"
ark-std = "0.3.0"

[features]
32x9 = []
147 changes: 93 additions & 54 deletions curves/src/pasta/fields/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,110 @@ use ark_ff::{biginteger::BigInteger256 as BigInteger, FftParameters, Fp256, Fp25

pub type Fp = Fp256<FpParameters>;

#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct FpParameters;

impl Fp256Parameters for FpParameters {}

#[rustfmt::skip]
impl FftParameters for FpParameters {
type BigInt = BigInteger;

const TWO_ADICITY: u32 = 32;

#[rustfmt::skip]
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
0xa28db849bad6dbf0, 0x9083cd03d3b539df, 0xfba6b9ca9dc8448e, 0x3ec928747b89c6da
]);
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = {
const TWO_ADIC_ROOT_OF_UNITY: Fp = ark_ff::field_new!(Fp, "19814229590243028906643993866117402072516588566294623396325693409366934201135");
TWO_ADIC_ROOT_OF_UNITY.0
};
}

impl ark_ff::FpParameters for FpParameters {
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
const MODULUS: BigInteger = BigInteger([
0x992d30ed00000001,
0x224698fc094cf91b,
0x0,
0x4000000000000000,
]);

const R: BigInteger = BigInteger([
0x34786d38fffffffd,
0x992c350be41914ad,
0xffffffffffffffff,
0x3fffffffffffffff,
]);

const R2: BigInteger = BigInteger([
0x8c78ecb30000000f,
0xd7d30dbd8b0de0e7,
0x7797a99bc3c95d18,
0x96d41af7b9cb714,
]);

const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
0xcc96987680000000,
0x11234c7e04a67c8d,
0x0,
0x2000000000000000,
]);

// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
const T: BigInteger = BigInteger([0x94cf91b992d30ed, 0x224698fc, 0x0, 0x40000000]);

const T_MINUS_ONE_DIV_TWO: BigInteger =
BigInteger([0x4a67c8dcc969876, 0x11234c7e, 0x0, 0x20000000]);

// GENERATOR = 5
const GENERATOR: BigInteger = BigInteger([
0xa1a55e68ffffffed,
0x74c2a54b4f4982f3,
0xfffffffffffffffd,
0x3fffffffffffffff,
]);

const MODULUS_BITS: u32 = 255;

const CAPACITY: u32 = Self::MODULUS_BITS - 1;
#[cfg(not(any(target_family = "wasm", feature = "32x9")))]
pub mod native {
use super::*;

impl ark_ff::FpParameters for FpParameters {
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
const MODULUS: BigInteger = BigInteger::new([
0x992d30ed00000001,
0x224698fc094cf91b,
0x0,
0x4000000000000000,
]);
const R: BigInteger = BigInteger::new([
0x34786d38fffffffd,
0x992c350be41914ad,
0xffffffffffffffff,
0x3fffffffffffffff,
]);
const R2: BigInteger = BigInteger::new([
0x8c78ecb30000000f,
0xd7d30dbd8b0de0e7,
0x7797a99bc3c95d18,
0x96d41af7b9cb714,
]);
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
0xcc96987680000000,
0x11234c7e04a67c8d,
0x0,
0x2000000000000000,
]);
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
const T: BigInteger = BigInteger::new([0x94cf91b992d30ed, 0x224698fc, 0x0, 0x40000000]);
const T_MINUS_ONE_DIV_TWO: BigInteger =
BigInteger::new([0x4a67c8dcc969876, 0x11234c7e, 0x0, 0x20000000]);
// GENERATOR = 5
const GENERATOR: BigInteger = BigInteger::new([
0xa1a55e68ffffffed,
0x74c2a54b4f4982f3,
0xfffffffffffffffd,
0x3fffffffffffffff,
]);
const MODULUS_BITS: u32 = 255;
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
const REPR_SHAVE_BITS: u32 = 1;
// -(MODULUS^{-1} mod 2^64) mod 2^64
const INV: u64 = 11037532056220336127;
}
}

const REPR_SHAVE_BITS: u32 = 1;
#[cfg(any(target_family = "wasm", feature = "32x9"))]
pub mod x32x9 {
use super::*;

// -(MODULUS^{-1} mod 2^64) mod 2^64
const INV: u64 = 11037532056220336127;
#[rustfmt::skip]
impl ark_ff::FpParameters for FpParameters {
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
const MODULUS: BigInteger = BigInteger::new([
0x1, 0x9698768, 0x133e46e6, 0xd31f812, 0x224, 0x0, 0x0, 0x0, 0x400000,
]);
const R: BigInteger = BigInteger::new([
0x1fffff81, 0x14a5d367, 0x141ad3c0, 0x1435eec5, 0x1ffeefef, 0x1fffffff, 0x1fffffff,
0x1fffffff, 0x3fffff,
]);
const R2: BigInteger = BigInteger::new([
0x3b6a, 0x19c10910, 0x1a6a0188, 0x12a4fd88, 0x634b36d, 0x178792ba, 0x7797a99, 0x1dce5b8a,
0x3506bd,
]);
// TODO
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
0x0, 0x4b4c3b4, 0x99f2373, 0x698fc09, 0x112, 0x0, 0x0, 0x0, 0x200000,
]);
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
const T: BigInteger = BigInteger::new([
0x192d30ed, 0xa67c8dc, 0x11a63f02, 0x44, 0x0, 0x0, 0x0, 0x80000, 0x0,
]);
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
0xc969876, 0x533e46e, 0x8d31f81, 0x22, 0x0, 0x0, 0x0, 0x40000, 0x0,
]);
// GENERATOR = 5
const GENERATOR: BigInteger = {
const FIVE: Fp = ark_ff::field_new!(Fp, "5");
FIVE.0
};
const MODULUS_BITS: u32 = 255;
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
const REPR_SHAVE_BITS: u32 = 1;
// -(MODULUS^{-1} mod 2^64) mod 2^64
const INV: u64 = 0x1fffffff;
}
}
155 changes: 96 additions & 59 deletions curves/src/pasta/fields/fq.rs
Original file line number Diff line number Diff line change
@@ -1,73 +1,110 @@
use ark_ff::{
biginteger::BigInteger256 as BigInteger, FftParameters, Fp256, Fp256Parameters, FpParameters,
};

pub struct FqParameters;
use ark_ff::{biginteger::BigInteger256 as BigInteger, FftParameters, Fp256, Fp256Parameters};

pub type Fq = Fp256<FqParameters>;

#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct FqParameters;

impl Fp256Parameters for FqParameters {}

#[rustfmt::skip]
impl FftParameters for FqParameters {
type BigInt = BigInteger;

const TWO_ADICITY: u32 = 32;

#[rustfmt::skip]
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
0x218077428c9942de, 0xcc49578921b60494, 0xac2e5d27b2efbee2, 0xb79fa897f2db056
]);
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = {
const TWO_ADIC_ROOT_OF_UNITY: Fq = ark_ff::field_new!(Fq, "20761624379169977859705911634190121761503565370703356079647768903521299517535");
TWO_ADIC_ROOT_OF_UNITY.0
};
}
impl FpParameters for FqParameters {
// 28948022309329048855892746252171976963363056481941647379679742748393362948097
const MODULUS: BigInteger = BigInteger([
0x8c46eb2100000001,
0x224698fc0994a8dd,
0x0,
0x4000000000000000,
]);

const R: BigInteger = BigInteger([
0x5b2b3e9cfffffffd,
0x992c350be3420567,
0xffffffffffffffff,
0x3fffffffffffffff,
]);

const R2: BigInteger = BigInteger([
0xfc9678ff0000000f,
0x67bb433d891a16e3,
0x7fae231004ccf590,
0x96d41af7ccfdaa9,
]);

const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
0xc623759080000000,
0x11234c7e04ca546e,
0x0,
0x2000000000000000,
]);

// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T

const T: BigInteger = BigInteger([0x994a8dd8c46eb21, 0x224698fc, 0x0, 0x40000000]);

const T_MINUS_ONE_DIV_TWO: BigInteger =
BigInteger([0x4ca546ec6237590, 0x11234c7e, 0x0, 0x20000000]);

// GENERATOR = 5
const GENERATOR: BigInteger = BigInteger([
0x96bc8c8cffffffed,
0x74c2a54b49f7778e,
0xfffffffffffffffd,
0x3fffffffffffffff,
]);

const MODULUS_BITS: u32 = 255;

const CAPACITY: u32 = Self::MODULUS_BITS - 1;
#[cfg(not(any(target_family = "wasm", feature = "32x9")))]
pub mod native {
use super::*;

impl ark_ff::FpParameters for FqParameters {
// 28948022309329048855892746252171976963363056481941647379679742748393362948097
const MODULUS: BigInteger = BigInteger::new([
0x8c46eb2100000001,
0x224698fc0994a8dd,
0x0,
0x4000000000000000,
]);
const R: BigInteger = BigInteger::new([
0x5b2b3e9cfffffffd,
0x992c350be3420567,
0xffffffffffffffff,
0x3fffffffffffffff,
]);
const R2: BigInteger = BigInteger::new([
0xfc9678ff0000000f,
0x67bb433d891a16e3,
0x7fae231004ccf590,
0x96d41af7ccfdaa9,
]);
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
0xc623759080000000,
0x11234c7e04ca546e,
0x0,
0x2000000000000000,
]);
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
const T: BigInteger = BigInteger::new([0x994a8dd8c46eb21, 0x224698fc, 0x0, 0x40000000]);
const T_MINUS_ONE_DIV_TWO: BigInteger =
BigInteger::new([0x4ca546ec6237590, 0x11234c7e, 0x0, 0x20000000]);
// GENERATOR = 5
const GENERATOR: BigInteger = BigInteger::new([
0x96bc8c8cffffffed,
0x74c2a54b49f7778e,
0xfffffffffffffffd,
0x3fffffffffffffff,
]);
const MODULUS_BITS: u32 = 255;
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
const REPR_SHAVE_BITS: u32 = 1;
// -(MODULUS^{-1} mod 2^64) mod 2^64
const INV: u64 = 10108024940646105087;
}
}

const REPR_SHAVE_BITS: u32 = 1;
#[cfg(any(target_family = "wasm", feature = "32x9"))]
pub mod x32x9 {
use super::*;

// -(MODULUS^{-1} mod 2^64) mod 2^64
const INV: u64 = 10108024940646105087;
#[rustfmt::skip]
impl ark_ff::FpParameters for FqParameters {
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
const MODULUS: BigInteger = BigInteger::new([
0x1, 0x2375908, 0x52a3763, 0xd31f813, 0x224, 0x0, 0x0, 0x0, 0x400000,
]);
const R: BigInteger = BigInteger::new([
0x1fffff81, 0x68ad507, 0x100e85da, 0x1435ee7e, 0x1ffeefef, 0x1fffffff, 0x1fffffff,
0x1fffffff, 0x3fffff,
]);
const R2: BigInteger = BigInteger::new([
0x3b6a, 0x2b1b550, 0x1027888a, 0x1ea4ed96, 0x418ad7a, 0x999eb, 0x17fae231,
0x1e67ed54, 0x3506bd,
]);
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
0x0, 0x111bac84, 0x12951bb1, 0x698fc09, 0x112, 0x0, 0x0, 0x0, 0x200000,
]);
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
const T: BigInteger = BigInteger::new([
0xc46eb21, 0xca546ec, 0x11a63f02, 0x44, 0x0, 0x0, 0x0, 0x80000, 0x0,
]);
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
0x6237590, 0x652a376, 0x8d31f81, 0x22, 0x0, 0x0, 0x0, 0x40000, 0x0,
]);
// GENERATOR = 5
const GENERATOR: BigInteger = {
const FIVE: Fq = ark_ff::field_new!(Fq, "5");
FIVE.0
};
const MODULUS_BITS: u32 = 255;
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
const REPR_SHAVE_BITS: u32 = 1;
// -(MODULUS^{-1} mod 2^64) mod 2^64
const INV: u64 = 0x1fffffff;
}
}
Loading
Loading