Skip to content
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
2 changes: 1 addition & 1 deletion src/fields/U1024.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub global U1024_PARAMS: BigNumParams<9, 1025> = BigNumParams {
redc_param: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x400000000000000000],
};

#[derive_bignum(9, 1025, quote {U1024_PARAMS})]
#[derive_bignum(9, 1025, quote { U1024_PARAMS })]
pub struct U1024 {
limbs: [u128; 9],
}
2 changes: 1 addition & 1 deletion src/fields/U2048.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub global U2048_PARAMS: BigNumParams<18, 2049> = BigNumParams {
],
};

#[derive_bignum(18, 2049, quote {U2048_PARAMS})]
#[derive_bignum(18, 2049, quote { U2048_PARAMS })]
pub struct U2048 {
limbs: [u128; 18],
}
2 changes: 1 addition & 1 deletion src/fields/U256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub global U256_PARAMS: BigNumParams<3, 257> = BigNumParams {
redc_param: [0x00, 0x00, 0x400000],
};

#[derive_bignum(3, 257, quote {U256_PARAMS})]
#[derive_bignum(3, 257, quote { U256_PARAMS })]
pub struct U256 {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/U384.nr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub global U384_PARAMS: BigNumParams<4, 385> = BigNumParams {
redc_param: [0x00, 0x00, 0x00, 0x40000000],
};

#[derive_bignum(4, 385, quote {U384_PARAMS})]
#[derive_bignum(4, 385, quote { U384_PARAMS })]
pub struct U384 {
limbs: [u128; 4],
}
2 changes: 1 addition & 1 deletion src/fields/U4096.nr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub global U4096_PARAMS: BigNumParams<35, 4097> = BigNumParams {
],
};

#[derive_bignum(35, 4097, quote {U4096_PARAMS})]
#[derive_bignum(35, 4097, quote { U4096_PARAMS })]
pub struct U4096 {
limbs: [u128; 35],
}
2 changes: 1 addition & 1 deletion src/fields/U512.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub global U512_PARAMS: BigNumParams<5, 513> = BigNumParams {
redc_param: [0x00, 0x00, 0x00, 0x00, 0x4000000000],
};

#[derive_bignum(5, 513, quote {U512_PARAMS})]
#[derive_bignum(5, 513, quote { U512_PARAMS })]
pub struct U512 {
limbs: [u128; 5],
}
2 changes: 1 addition & 1 deletion src/fields/U768.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub global U768_PARAMS: BigNumParams<7, 769> = BigNumParams {
redc_param: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40000000000000],
};

#[derive_bignum(7, 769, quote {U768_PARAMS})]
#[derive_bignum(7, 769, quote { U768_PARAMS })]
pub struct U768 {
limbs: [u128; 7],
}
4 changes: 2 additions & 2 deletions src/fields/U8192.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::bignum::BigNum;
use crate::bignum::derive_bignum;
use crate::params::BigNumParams;

global U8192_PARAMS: BigNumParams<69, 8193> = BigNumParams {
pub global U8192_PARAMS: BigNumParams<69, 8193> = BigNumParams {
has_multiplicative_inverse: false,
modulus: [
0x00,
Expand Down Expand Up @@ -219,7 +219,7 @@ global U8192_PARAMS: BigNumParams<69, 8193> = BigNumParams {
],
};

#[derive_bignum(69, 8193, quote {U8192_PARAMS})]
#[derive_bignum(69, 8193, quote { U8192_PARAMS })]
pub struct U8192 {
limbs: [u128; 69],
}
2 changes: 1 addition & 1 deletion src/fields/bls12_377Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub global BLS12_377_Fq_PARAMS: BigNumParams<4, 377> = BigNumParams {
],
};

#[derive_bignum(4, 377, quote {BLS12_377_Fq_PARAMS})]
#[derive_bignum(4, 377, quote { BLS12_377_Fq_PARAMS })]
pub struct BLS12_377_Fq {
limbs: [u128; 4],
}
2 changes: 1 addition & 1 deletion src/fields/bls12_377Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub global BLS12_377_Fr_PARAMS: BigNumParams<3, 253> = BigNumParams {
redc_param: [0xa180b8d69e258f5204c21151e79ea1, 0x91ec40b2c9ee4e51e49faa80548fd0, 0x036d94],
};

#[derive_bignum(3, 253, quote {BLS12_377_Fr_PARAMS})]
#[derive_bignum(3, 253, quote { BLS12_377_Fr_PARAMS })]
pub struct BLS12_377_Fr {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/bls12_381Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub global BLS12_381_Fq_PARAMS: BigNumParams<4, 381> = BigNumParams {
],
};

#[derive_bignum(4, 381, quote {BLS12_381_Fq_PARAMS})]
#[derive_bignum(4, 381, quote { BLS12_381_Fq_PARAMS })]
pub struct BLS12_381_Fq {
limbs: [u128; 4],
}
2 changes: 1 addition & 1 deletion src/fields/bls12_381Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub global BLS12_381_Fr_PARAMS: BigNumParams<3, 255> = BigNumParams {
redc_param: [0x10fad2f92eb5c509cde80830358e4c, 0x53b7fb78ddf0e2d772dc1f823b4d94, 0x08d542],
};

#[derive_bignum(3, 255, quote {BLS12_381_Fr_PARAMS})]
#[derive_bignum(3, 255, quote { BLS12_381_Fr_PARAMS })]
pub struct BLS12_381_Fr {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/bn254Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub global BN254_Fq_PARAMS: BigNumParams<3, 254> = BigNumParams {
redc_param: [0x65e1767cd4c086f3aed8a19bf90e51, 0x462623a04a7ab074a5868073013ae9, 0x054a47],
};

#[derive_bignum(3, 254, quote {BN254_Fq_PARAMS})]
#[derive_bignum(3, 254, quote { BN254_Fq_PARAMS })]
pub struct BN254_Fq {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/ed25519Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub global ED25519_Fq_PARAMS: BigNumParams<3, 255> = BigNumParams {
redc_param: [0x0130, 0x00, 0x080000],
};

#[derive_bignum(3, 255, quote {ED25519_Fq_PARAMS})]
#[derive_bignum(3, 255, quote { ED25519_Fq_PARAMS })]
pub struct ED25519_Fq {
limbs: [u128; 3],
}
4 changes: 2 additions & 2 deletions src/fields/ed25519Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::bignum::BigNum;
use crate::bignum::derive_bignum;
use crate::params::BigNumParams;

pub global ED25519_Fr_PARAMS: BigNumParams<3, 255> = BigNumParams {
pub global ED25519_Fr_PARAMS: BigNumParams<3, 253> = BigNumParams {
has_multiplicative_inverse: true,
modulus: [0xdef9dea2f79cd65812631a5cf5d3ed, 0x14, 0x1000],
double_modulus: [
Expand All @@ -13,7 +13,7 @@ pub global ED25519_Fr_PARAMS: BigNumParams<3, 255> = BigNumParams {
redc_param: [0x4188574218ca69fb673968c28b04c6, 0xfffffffffffffffffffffffffffac8, 0x03ffff],
};

#[derive_bignum(3, 255, quote {ED25519_Fr_PARAMS})]
#[derive_bignum(3, 253, quote { ED25519_Fr_PARAMS })]
pub struct ED25519_Fr {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/mnt4_753Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub global MNT4_753_Fq_PARAMS: BigNumParams<7, 753> = BigNumParams {
],
};

#[derive_bignum(7, 753, quote {MNT4_753_Fq_PARAMS})]
#[derive_bignum(7, 753, quote { MNT4_753_Fq_PARAMS })]
pub struct MNT4_753_Fq {
limbs: [u128; 7],
}
2 changes: 1 addition & 1 deletion src/fields/mnt4_753Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub global MNT4_753_Fr_PARAMS: BigNumParams<7, 753> = BigNumParams {
],
};

#[derive_bignum(7, 753, quote {MNT4_753_Fr_PARAMS})]
#[derive_bignum(7, 753, quote { MNT4_753_Fr_PARAMS })]
pub struct MNT4_753_Fr {
limbs: [u128; 7],
}
2 changes: 1 addition & 1 deletion src/fields/mnt6_753Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub global MNT6_753_Fq_PARAMS: BigNumParams<7, 753> = BigNumParams {
],
};

#[derive_bignum(7, 753, quote {MNT6_753_Fq_PARAMS})]
#[derive_bignum(7, 753, quote { MNT6_753_Fq_PARAMS })]
pub struct MNT6_753_Fq {
limbs: [u128; 7],
}
2 changes: 1 addition & 1 deletion src/fields/mnt6_753Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub global MNT6_753_Fr_PARAMS: BigNumParams<7, 753> = BigNumParams {
],
};

#[derive_bignum(7, 753, quote {MNT6_753_Fr_PARAMS})]
#[derive_bignum(7, 753, quote { MNT6_753_Fr_PARAMS })]
pub struct MNT6_753_Fr {
limbs: [u128; 7],
}
2 changes: 1 addition & 1 deletion src/fields/pallasFq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub global Pallas_Fq_PARAMS: BigNumParams<3, 255> = BigNumParams {
redc_param: [0x59c0fdacc1b919b4b3c4bfffffffc4, 0xfffffffffffffffffffffffffff76e, 0x0fffff],
};

#[derive_bignum(3, 255, quote {Pallas_Fq_PARAMS})]
#[derive_bignum(3, 255, quote { Pallas_Fq_PARAMS })]
pub struct Pallas_Fq {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/pallasFr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub global Pallas_Fr_PARAMS: BigNumParams<3, 255> = BigNumParams {
redc_param: [0x59c0fd9ad5c89cee4537bfffffffc4, 0xfffffffffffffffffffffffffff76e, 0x0fffff],
};

#[derive_bignum(3, 255, quote {Pallas_Fr_PARAMS})]
#[derive_bignum(3, 255, quote { Pallas_Fr_PARAMS })]
pub struct Pallas_Fr {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/secp256k1Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub global Secp256k1_Fq_PARAMS: BigNumParams<3, 256> = BigNumParams {
redc_param: [0x1000003d10, 0x00, 0x100000],
};

#[derive_bignum(3, 256, quote {Secp256k1_Fq_PARAMS})]
#[derive_bignum(3, 256, quote { Secp256k1_Fq_PARAMS })]
pub struct Secp256k1_Fq {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/secp256k1Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub global Secp256k1_Fr_PARAMS: BigNumParams<3, 256> = BigNumParams {
redc_param: [0x1231950b75fc4402da1732fc9bec09, 0x1455, 0x100000],
};

#[derive_bignum(3, 256, quote {Secp256k1_Fr_PARAMS})]
#[derive_bignum(3, 256, quote { Secp256k1_Fr_PARAMS })]
pub struct Secp256k1_Fr {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/secp256r1Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub global Secp256r1_Fq_PARAMS: BigNumParams<3, 256> = BigNumParams {
redc_param: [0xffffeffffffff00000000000000030, 0x0fffffffffffffffefffffffefff, 0x100000],
};

#[derive_bignum(3, 256, quote {Secp256r1_Fq_PARAMS})]
#[derive_bignum(3, 256, quote { Secp256r1_Fq_PARAMS })]
pub struct Secp256r1_Fq {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/secp256r1Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub global Secp256r1_Fr_PARAMS: BigNumParams<3, 256> = BigNumParams {
redc_param: [0x90552df1a6c21012ffd85eedf9bfe6, 0x0fffffffffffffffeffffffff431, 0x100000],
};

#[derive_bignum(3, 256, quote {Secp256r1_Fr_PARAMS})]
#[derive_bignum(3, 256, quote { Secp256r1_Fr_PARAMS })]
pub struct Secp256r1_Fr {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/secp384r1Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub global Secp384r1_Fq_PARAMS: BigNumParams<4, 384> = BigNumParams {
redc_param: [0x0ffffffffffffffff000000010, 0x1000, 0x00, 0x10000000],
};

#[derive_bignum(4, 384, quote {Secp384r1_Fq_PARAMS})]
#[derive_bignum(4, 384, quote { Secp384r1_Fq_PARAMS })]
pub struct Secp384r1_Fq {
limbs: [u128; 4],
}
2 changes: 1 addition & 1 deletion src/fields/secp384r1Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub global Secp384r1_Fr_PARAMS: BigNumParams<4, 384> = BigNumParams {
redc_param: [0x5f24db74f58851313e695333ad68d0, 0x0389cb27e0bc8d220a7e, 0x00, 0x10000000],
};

#[derive_bignum(4, 384, quote {Secp384r1_Fr_PARAMS})]
#[derive_bignum(4, 384, quote { Secp384r1_Fr_PARAMS })]
pub struct Secp384r1_Fr {
limbs: [u128; 4],
}
2 changes: 1 addition & 1 deletion src/fields/vestaFq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub global Vesta_Fq_PARAMS: BigNumParams<3, 255> = BigNumParams {
redc_param: [0x59c0fd9ad5c89cee4537bfffffffc4, 0xfffffffffffffffffffffffffff76e, 0x0fffff],
};

#[derive_bignum(3, 255, quote {Vesta_Fq_PARAMS})]
#[derive_bignum(3, 255, quote { Vesta_Fq_PARAMS })]
pub struct Vesta_Fq {
limbs: [u128; 3],
}
2 changes: 1 addition & 1 deletion src/fields/vestaFr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub global Vesta_Fr_PARAMS: BigNumParams<3, 255> = BigNumParams {
redc_param: [0x59c0fdacc1b919b4b3c4bfffffffc4, 0xfffffffffffffffffffffffffff76e, 0x0fffff],
};

#[derive_bignum(3, 255, quote {Vesta_Fr_PARAMS})]
#[derive_bignum(3, 255, quote { Vesta_Fr_PARAMS })]
pub struct Vesta_Fr {
limbs: [u128; 3],
}
6 changes: 3 additions & 3 deletions src/fns/unconstrained_helpers.nr
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ comptime global BARRETT_REDUCTION_OVERFLOW_BITS: u32 = 4;
/// This is highly unlikely though.
///
/// ### TODO:
/// Possibly change the `BARRETT_REDUCTION_OVERFLOW_BITS` to 6, so that we need only 1 reduction here
/// However we will have to recompute all the fields `redc_param`s and fix paramgen
/// Possibly change the `BARRETT_REDUCTION_OVERFLOW_BITS` to 6, so that we need only 1 reduction here.
/// Not a significant decrease in brillig opcodes though (https://github.com/noir-lang/noir-bignum/pull/241).
pub(crate) unconstrained fn __barrett_reduction<let N: u32>(
x: [u128; 2 * N],
redc_param: [u128; N],
Expand Down Expand Up @@ -331,7 +331,7 @@ pub(crate) unconstrained fn __barrett_reduction<let N: u32>(
remainder[i] = long_remainder[i];
}

for _ in 0..2 {
for _ in 0..4 {
if (__gte(remainder, modulus)) {
remainder = __helper_sub(remainder, modulus);
smaller_quotient = __increment(smaller_quotient);
Expand Down
10 changes: 10 additions & 0 deletions src/tests/bignum_test.nr
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ pub struct BN2048 {

// ------------------------------ REGRESSION TESTS ------------------------------

/// `MOD_BITS` parameter was incorrect in ed5519_Fr
#[test]
fn test_mul_ed25519_fr_regression() {
test_mul::<3, crate::fields::ed25519Fr::ED25519_Fr>();
}

/// This example was failing - sanity test to validate it now works
#[test]
fn test_bls_reduction() {
Expand Down Expand Up @@ -1412,3 +1418,7 @@ fn test_sqrt_equality_fuzz(seed: [u8; 3]) {
};
assert((c == d) | (c == -d));
}

// ------------------------------ FIELD SANITY TESTS ------------------------------

// TODO: a set of basic tests to check that the fields in our directory all behave normally