Skip to content

Commit

Permalink
Merge pull request #5 from noir-lang/mv/u32-numeric-generics
Browse files Browse the repository at this point in the history
fix!: Switch usage of u64 in numeric generics to u32
  • Loading branch information
vezenovm authored Jul 30, 2024
2 parents 93a80e8 + f3fdc68 commit 83a4d3b
Show file tree
Hide file tree
Showing 37 changed files with 180 additions and 179 deletions.
14 changes: 7 additions & 7 deletions src/bignum_test.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::BigNumTrait;

struct Test2048Params{}
impl RuntimeBigNumParamsTrait<18> for Test2048Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
2048
}
}
Expand Down Expand Up @@ -80,15 +80,15 @@ impl BigNumParamsTrait<18> for Test2048Params {
];
BigNumInstance::new(modulus, redc_param)
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
2048
}
}

type Fq = BigNum<3, BNParams>;
type Fqq = BigNum<18, Test2048Params>;

fn test_eq<BigNum, let N: u64>(_: BigNum, __: [Field; N]) where BigNum: BigNumTrait {
fn test_eq<BigNum, let N: u32>(_: BigNum, __: [Field; N]) where BigNum: BigNumTrait {
let a = BigNum::__derive_from_seed([1, 2, 3, 4]);
let b = BigNum::__derive_from_seed([1, 2, 3, 4]);
let c = BigNum::__derive_from_seed([2, 2, 3, 4]);
Expand All @@ -103,7 +103,7 @@ fn test_eq<BigNum, let N: u64>(_: BigNum, __: [Field; N]) where BigNum: BigNumTr
assert(c.eq(a) == false);
}

// fn test_eq<let N: u64, Params>(_: BigNum<N, Params>) where Params: BigNumParamsTrait<N> + RuntimeBigNumParamsTrait<N> {
// fn test_eq<let N: u32, Params>(_: BigNum<N, Params>) where Params: BigNumParamsTrait<N> + RuntimeBigNumParamsTrait<N> {
// let a = BigNum::__derive_from_seed([1, 2, 3, 4]);
// let b = BigNum::__derive_from_seed([1, 2, 3, 4]);
// let c = BigNum::__derive_from_seed([2, 2, 3, 4]);
Expand Down Expand Up @@ -188,7 +188,7 @@ fn assert_is_not_equal_fail<BigNum>(_: BigNum) where BigNum: BigNumTrait {
a.assert_is_not_equal(b);
}

fn assert_is_not_equal_overloaded_lhs_fail<BigNum, let N: u64>(_: BigNum, __: [Field; N]) where BigNum: BigNumTrait {
fn assert_is_not_equal_overloaded_lhs_fail<BigNum, let N: u32>(_: BigNum, __: [Field; N]) where BigNum: BigNumTrait {
let a = BigNum::__derive_from_seed([1, 2, 3, 4]);
let b = BigNum::__derive_from_seed([1, 2, 3, 4]);

Expand All @@ -200,7 +200,7 @@ fn assert_is_not_equal_overloaded_lhs_fail<BigNum, let N: u64>(_: BigNum, __: [F
a_plus_modulus.assert_is_not_equal(b);
}

fn assert_is_not_equal_overloaded_rhs_fail<BigNum, let N: u64>(_: BigNum, __: [Field; N]) where BigNum: BigNumTrait {
fn assert_is_not_equal_overloaded_rhs_fail<BigNum, let N: u32>(_: BigNum, __: [Field; N]) where BigNum: BigNumTrait {
let a = BigNum::__derive_from_seed([1, 2, 3, 4]);
let b = BigNum::__derive_from_seed([1, 2, 3, 4]);

Expand All @@ -212,7 +212,7 @@ fn assert_is_not_equal_overloaded_rhs_fail<BigNum, let N: u64>(_: BigNum, __: [F
a.assert_is_not_equal(b_plus_modulus);
}

fn assert_is_not_equal_overloaded_fail<BigNum, let N: u64>(_: BigNum, __: [Field; N]) where BigNum: BigNumTrait {
fn assert_is_not_equal_overloaded_fail<BigNum, let N: u32>(_: BigNum, __: [Field; N]) where BigNum: BigNumTrait {
let a = BigNum::__derive_from_seed([1, 2, 3, 4]);
let b = BigNum::__derive_from_seed([1, 2, 3, 4]);

Expand Down
10 changes: 5 additions & 5 deletions src/fields.nr
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ use crate::fields::bn254Fq::BNParams;
**/
struct Params512 {}
impl RuntimeBigNumParamsTrait<5> for Params512 {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
512
}
}
struct Params768 {}
impl RuntimeBigNumParamsTrait<7> for Params768 {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
768
}
}
struct Params1024 {}
impl RuntimeBigNumParamsTrait<9> for Params1024 {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
1024
}
}
struct Params2048 {}
impl RuntimeBigNumParamsTrait<18> for Params2048 {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
2048
}
}
struct Params4096 {}
impl RuntimeBigNumParamsTrait<35> for Params4096 {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
4096
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/fields/U1024.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::arrayX::ArrayX;

struct U1024Params {}
impl RuntimeBigNumParamsTrait<18> for U1024Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
2049
}
fn has_multiplicative_inverse() -> bool { false }
Expand All @@ -16,7 +16,7 @@ impl BigNumParamsTrait<18> for U1024Params {
fn get_instance() -> BigNumInstance<18, Self> {
U1024_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
2049
}
fn has_multiplicative_inverse() -> bool { false }
Expand Down
4 changes: 2 additions & 2 deletions src/fields/U2048.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::arrayX::ArrayX;

struct U2048Params {}
impl RuntimeBigNumParamsTrait<18> for U2048Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
2049
}
fn has_multiplicative_inverse() -> bool { false }
Expand All @@ -16,7 +16,7 @@ impl BigNumParamsTrait<18> for U2048Params {
fn get_instance() -> BigNumInstance<18, Self> {
U2048_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
2049
}
fn has_multiplicative_inverse() -> bool { false }
Expand Down
4 changes: 2 additions & 2 deletions src/fields/U256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::arrayX::ArrayX;

struct U256Params {}
impl RuntimeBigNumParamsTrait<3> for U256Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
257
}
fn has_multiplicative_inverse() -> bool { false }
Expand All @@ -16,7 +16,7 @@ impl BigNumParamsTrait<3> for U256Params {
fn get_instance() -> BigNumInstance<3, Self> {
U256_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
257
}
fn has_multiplicative_inverse() -> bool { false }
Expand Down
4 changes: 2 additions & 2 deletions src/fields/U384.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::arrayX::ArrayX;

struct U384_Params {}
impl RuntimeBigNumParamsTrait<4> for U384_Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
385
}
fn has_multiplicative_inverse() -> bool { false }
Expand All @@ -16,7 +16,7 @@ impl BigNumParamsTrait<4> for U384_Params {
fn get_instance() -> BigNumInstance<4, Self> {
U384_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
385
}
fn has_multiplicative_inverse() -> bool { false }
Expand Down
4 changes: 2 additions & 2 deletions src/fields/U4096.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::arrayX::ArrayX;

struct U4096Params {}
impl RuntimeBigNumParamsTrait<35> for U4096Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
4097
}
fn has_multiplicative_inverse() -> bool { false }
Expand All @@ -16,7 +16,7 @@ impl BigNumParamsTrait<35> for U4096Params {
fn get_instance() -> BigNumInstance<35, Self> {
U4096_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
4097
}
fn has_multiplicative_inverse() -> bool { false }
Expand Down
4 changes: 2 additions & 2 deletions src/fields/U512.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::utils::arrayX::ArrayX;
// b * c + (rem < modulus) = a
struct U512Params {}
impl RuntimeBigNumParamsTrait<5> for U512Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
513
}
fn has_multiplicative_inverse() -> bool { false }
Expand All @@ -19,7 +19,7 @@ impl BigNumParamsTrait<5> for U512Params {
fn get_instance() -> BigNumInstance<5, Self> {
U512_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
513
}
fn has_multiplicative_inverse() -> bool { false }
Expand Down
4 changes: 2 additions & 2 deletions src/fields/U768.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::arrayX::ArrayX;

struct U768Params {}
impl RuntimeBigNumParamsTrait<13> for U768Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
1537
}
fn has_multiplicative_inverse() -> bool { false }
Expand All @@ -16,7 +16,7 @@ impl BigNumParamsTrait<13> for U768Params {
fn get_instance() -> BigNumInstance<13, Self> {
U768_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
1537
}
fn has_multiplicative_inverse() -> bool { false }
Expand Down
4 changes: 2 additions & 2 deletions src/fields/U8192.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::arrayX::ArrayX;

struct U8192Params {}
impl RuntimeBigNumParamsTrait<69> for U8192Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
8193
}
fn has_multiplicative_inverse() -> bool { false }
Expand All @@ -16,7 +16,7 @@ impl BigNumParamsTrait<69> for U8192Params {
fn get_instance() -> BigNumInstance<69, Self> {
U8192_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
8193
}
fn has_multiplicative_inverse() -> bool { false }
Expand Down
4 changes: 2 additions & 2 deletions src/fields/bls12_377Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use crate::utils::arrayX::ArrayX;

struct BLS12_377_Fq_Params {}
impl RuntimeBigNumParamsTrait<4> for BLS12_377_Fq_Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
377
}
}
impl BigNumParamsTrait<4> for BLS12_377_Fq_Params {
fn get_instance() -> BigNumInstance<4, Self> {
BLS12_377_Fq_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
377
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/fields/bls12_377Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use crate::utils::arrayX::ArrayX;

struct BLS12_377_Fr_Params {}
impl RuntimeBigNumParamsTrait<3> for BLS12_377_Fr_Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
253
}
}
impl BigNumParamsTrait<3> for BLS12_377_Fr_Params {
fn get_instance() -> BigNumInstance<3, Self> {
BLS12_377_Fr_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
253
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/fields/bls12_381Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ use crate::utils::arrayX::ArrayX;

struct BLS12_381_Fq_Params {}
impl RuntimeBigNumParamsTrait<4> for BLS12_381_Fq_Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
381
}
}
impl BigNumParamsTrait<4> for BLS12_381_Fq_Params {
fn get_instance() -> BigNumInstance<4, Self> {
BLS12_381_Fq_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
381
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/fields/bls12_381Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ use crate::utils::arrayX::ArrayX;

struct BLS12_381_Fr_Params {}
impl RuntimeBigNumParamsTrait<3> for BLS12_381_Fr_Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
255
}
}
impl BigNumParamsTrait<3> for BLS12_381_Fr_Params {
fn get_instance() -> BigNumInstance<3, Self> {
BLS12_381_Fr_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
255
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/fields/bn254Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::arrayX::ArrayX;

struct BNParams {}
impl RuntimeBigNumParamsTrait<3> for BNParams {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
254
}
}
Expand All @@ -32,7 +32,7 @@ impl BigNumParamsTrait<3> for BNParams {
fn get_instance() -> BigNumInstance<3, Self> {
BN254INSTANCE
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
254
}
}
4 changes: 2 additions & 2 deletions src/fields/ed25519Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use crate::utils::arrayX::ArrayX;

struct ED25519_Fq_Params {}
impl RuntimeBigNumParamsTrait<3> for ED25519_Fq_Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
255
}
}
impl BigNumParamsTrait<3> for ED25519_Fq_Params {
fn get_instance() -> BigNumInstance<3, Self> {
ED25519_Fq_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
255
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/fields/ed25519Fr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use crate::utils::arrayX::ArrayX;

struct ED25519_Fr_Params {}
impl RuntimeBigNumParamsTrait<3> for ED25519_Fr_Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
253
}
}
impl BigNumParamsTrait<3> for ED25519_Fr_Params {
fn get_instance() -> BigNumInstance<3, Self> {
ED25519_Fr_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
253
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/fields/mnt4_753Fq.nr
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ use crate::utils::arrayX::ArrayX;

struct MNT4_753_Fq_Params {}
impl RuntimeBigNumParamsTrait<7> for MNT4_753_Fq_Params {
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
753
}
}
impl BigNumParamsTrait<7> for MNT4_753_Fq_Params {
fn get_instance() -> BigNumInstance<7, Self> {
MNT4_753_Fq_Instance
}
fn modulus_bits() -> u64 {
fn modulus_bits() -> u32 {
753
}
}
Expand Down
Loading

0 comments on commit 83a4d3b

Please sign in to comment.