From fa8d20cead061acf516cba96dd6123c0c60f6a66 Mon Sep 17 00:00:00 2001 From: Tom French Date: Mon, 2 Sep 2024 18:49:09 +0100 Subject: [PATCH 1/4] fix: update to use new `to_le_bytes` --- src/runtime_bignum.nr | 4 ++-- src/utils/split_bits.nr | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime_bignum.nr b/src/runtime_bignum.nr index a73f053e..92dd5387 100644 --- a/src/runtime_bignum.nr +++ b/src/runtime_bignum.nr @@ -187,12 +187,12 @@ impl BigNumTrait for BigNum where Params: BigNumP let mut result: [u8; NBytes] = [0; NBytes]; for i in 0..N - 1 { - let limb_bytes = val.limbs[i].to_le_bytes(15); + let limb_bytes: [u8; 15] = val.limbs[i].to_le_bytes(); for j in 0..15 { result[i * 15 + j] = limb_bytes[j]; } } - let last_limb_bytes = val.limbs[N - 1].to_le_bytes(15); + let last_limb_bytes: [u8; 15] = val.limbs[N - 1].to_le_bytes(); let num_last_bytes = (NBytes - (N - 1) * 15); for i in 0..num_last_bytes { result[(N-1) * 15 + i] = last_limb_bytes[i]; diff --git a/src/utils/split_bits.nr b/src/utils/split_bits.nr index 23d250c7..603e8ec1 100644 --- a/src/utils/split_bits.nr +++ b/src/utils/split_bits.nr @@ -1,7 +1,7 @@ // Decomposes a single field into two 120 bit fields and a carry unconstrained pub fn split_120_bits(x: Field) -> (Field, Field) { - let x_bytes: [u8] = x.to_le_bytes(32); + let x_bytes: [u8; 32] = x.to_le_bytes(); let mut low: Field = 0; let mut high: Field = 0; @@ -27,7 +27,7 @@ unconstrained pub fn split_120_bits(x: Field) -> (Field, Field) { * @description Expects the input limb to be in the range [0, ..., 2^{120 - 1}] **/ unconstrained pub fn split_60_bits(x: Field) -> (u64, u64) { - let x_bytes = x.to_le_bytes(32); + let x_bytes: [u8; 32] = x.to_le_bytes(); let mut low: u64 = 0; let mut high: u64 = 0; From 052ed254292cf855288c1403103a62e657bfbf76 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 13 Sep 2024 17:12:11 +0100 Subject: [PATCH 2/4] more stuff --- src/bignum_test.nr | 1 - src/fields.nr | 2 +- src/fields/U1024.nr | 9 ++++++--- src/fields/U2048.nr | 9 ++++++--- src/fields/U256.nr | 9 ++++++--- src/fields/U384.nr | 9 ++++++--- src/fields/U4096.nr | 9 ++++++--- src/fields/U512.nr | 9 ++++++--- src/fields/U768.nr | 9 ++++++--- src/fields/U8192.nr | 9 ++++++--- src/fields/bls12_377Fq.nr | 2 +- src/fields/bls12_377Fr.nr | 2 +- src/fields/bls12_381Fq.nr | 2 +- src/fields/bls12_381Fr.nr | 2 +- src/fields/bn254Fq.nr | 1 - src/fields/ed25519Fq.nr | 1 - src/fields/ed25519Fr.nr | 1 - src/fields/mnt4_753Fq.nr | 2 +- src/fields/mnt4_753Fr.nr | 2 +- src/fields/mnt6_753Fq.nr | 2 +- src/fields/mnt6_753Fr.nr | 2 +- src/fields/pallasFq.nr | 2 +- src/fields/pallasFr.nr | 2 +- src/fields/secp256k1Fq.nr | 1 - src/fields/secp256k1Fr.nr | 1 - src/fields/secp256r1Fq.nr | 1 - src/fields/secp256r1Fr.nr | 1 - src/fields/secp384r1Fq.nr | 1 - src/fields/secp384r1Fr.nr | 1 - src/fields/vestaFq.nr | 1 - src/fields/vestaFr.nr | 2 +- src/lib.nr | 14 ++++++-------- src/runtime_bignum_test.nr | 1 - src/utils/msb.nr | 4 +--- src/utils/u60_representation_test.nr | 1 - 35 files changed, 67 insertions(+), 60 deletions(-) diff --git a/src/bignum_test.nr b/src/bignum_test.nr index b714dd3a..6958dd3e 100644 --- a/src/bignum_test.nr +++ b/src/bignum_test.nr @@ -1,4 +1,3 @@ -use crate::utils::arrayX::ArrayX; use crate::BigNum; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; use crate::BigNumParamsTrait as BigNumParamsTrait; diff --git a/src/fields.nr b/src/fields.nr index 3b6b9fc6..d24f3c34 100644 --- a/src/fields.nr +++ b/src/fields.nr @@ -29,7 +29,7 @@ mod U4096; mod U8192; use crate::BigNum; -use crate::runtime_bignum::BigNumInstance; +pub use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; use crate::fields::bn254Fq::BNParams; diff --git a/src/fields/U1024.nr b/src/fields/U1024.nr index 6632126a..54fc7d69 100644 --- a/src/fields/U1024.nr +++ b/src/fields/U1024.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; @@ -10,7 +9,9 @@ impl RuntimeBigNumParamsTrait<18> for U1024Params { fn modulus_bits() -> u32 { 2049 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } impl BigNumParamsTrait<18> for U1024Params { fn get_instance() -> BigNumInstance<18, Self> { @@ -19,7 +20,9 @@ impl BigNumParamsTrait<18> for U1024Params { fn modulus_bits() -> u32 { 2049 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } global U1024_Instance: BigNumInstance<18, U1024Params> = BigNumInstance { modulus: [ diff --git a/src/fields/U2048.nr b/src/fields/U2048.nr index 015ac829..72d6ba33 100644 --- a/src/fields/U2048.nr +++ b/src/fields/U2048.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; @@ -10,7 +9,9 @@ impl RuntimeBigNumParamsTrait<18> for U2048Params { fn modulus_bits() -> u32 { 2049 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } impl BigNumParamsTrait<18> for U2048Params { fn get_instance() -> BigNumInstance<18, Self> { @@ -19,7 +20,9 @@ impl BigNumParamsTrait<18> for U2048Params { fn modulus_bits() -> u32 { 2049 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } global U2048_Instance: BigNumInstance<18, U2048Params> = BigNumInstance { modulus: [ diff --git a/src/fields/U256.nr b/src/fields/U256.nr index e499de69..82bd3e73 100644 --- a/src/fields/U256.nr +++ b/src/fields/U256.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; @@ -10,7 +9,9 @@ impl RuntimeBigNumParamsTrait<3> for U256Params { fn modulus_bits() -> u32 { 257 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } impl BigNumParamsTrait<3> for U256Params { fn get_instance() -> BigNumInstance<3, Self> { @@ -19,7 +20,9 @@ impl BigNumParamsTrait<3> for U256Params { fn modulus_bits() -> u32 { 257 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } global U256_Instance: BigNumInstance<3, U256Params> = BigNumInstance { modulus: [ diff --git a/src/fields/U384.nr b/src/fields/U384.nr index 803c8dc6..55741229 100644 --- a/src/fields/U384.nr +++ b/src/fields/U384.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; @@ -10,7 +9,9 @@ impl RuntimeBigNumParamsTrait<4> for U384_Params { fn modulus_bits() -> u32 { 385 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } impl BigNumParamsTrait<4> for U384_Params { fn get_instance() -> BigNumInstance<4, Self> { @@ -19,7 +20,9 @@ impl BigNumParamsTrait<4> for U384_Params { fn modulus_bits() -> u32 { 385 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } global U384_Instance: BigNumInstance<4, U384_Params> = BigNumInstance { modulus: [ diff --git a/src/fields/U4096.nr b/src/fields/U4096.nr index 90dbd80a..f11b1144 100644 --- a/src/fields/U4096.nr +++ b/src/fields/U4096.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; @@ -10,7 +9,9 @@ impl RuntimeBigNumParamsTrait<35> for U4096Params { fn modulus_bits() -> u32 { 4097 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } impl BigNumParamsTrait<35> for U4096Params { fn get_instance() -> BigNumInstance<35, Self> { @@ -19,7 +20,9 @@ impl BigNumParamsTrait<35> for U4096Params { fn modulus_bits() -> u32 { 4097 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } global U4096_Instance: BigNumInstance<35, U4096Params> = BigNumInstance { modulus: [ diff --git a/src/fields/U512.nr b/src/fields/U512.nr index 2e43fa99..a7b7e2a7 100644 --- a/src/fields/U512.nr +++ b/src/fields/U512.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; @@ -13,7 +12,9 @@ impl RuntimeBigNumParamsTrait<5> for U512Params { fn modulus_bits() -> u32 { 513 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } impl BigNumParamsTrait<5> for U512Params { fn get_instance() -> BigNumInstance<5, Self> { @@ -22,7 +23,9 @@ impl BigNumParamsTrait<5> for U512Params { fn modulus_bits() -> u32 { 513 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } global U512_Instance: BigNumInstance<5, U512Params> = BigNumInstance { modulus: [ diff --git a/src/fields/U768.nr b/src/fields/U768.nr index 825d91c9..a413f138 100644 --- a/src/fields/U768.nr +++ b/src/fields/U768.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; @@ -10,7 +9,9 @@ impl RuntimeBigNumParamsTrait<13> for U768Params { fn modulus_bits() -> u32 { 1537 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } impl BigNumParamsTrait<13> for U768Params { fn get_instance() -> BigNumInstance<13, Self> { @@ -19,7 +20,9 @@ impl BigNumParamsTrait<13> for U768Params { fn modulus_bits() -> u32 { 1537 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } global U768_Instance: BigNumInstance<13, U768Params> = BigNumInstance { modulus: [ diff --git a/src/fields/U8192.nr b/src/fields/U8192.nr index 9b9f906a..391d97c2 100644 --- a/src/fields/U8192.nr +++ b/src/fields/U8192.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; @@ -10,7 +9,9 @@ impl RuntimeBigNumParamsTrait<69> for U8192Params { fn modulus_bits() -> u32 { 8193 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } impl BigNumParamsTrait<69> for U8192Params { fn get_instance() -> BigNumInstance<69, Self> { @@ -19,7 +20,9 @@ impl BigNumParamsTrait<69> for U8192Params { fn modulus_bits() -> u32 { 8193 } - fn has_multiplicative_inverse() -> bool { false } + fn has_multiplicative_inverse() -> bool { + false + } } global U8192_Instance: BigNumInstance<69, U8192Params> = BigNumInstance { modulus: [ diff --git a/src/fields/bls12_377Fq.nr b/src/fields/bls12_377Fq.nr index 27b85509..45e4b9c2 100644 --- a/src/fields/bls12_377Fq.nr +++ b/src/fields/bls12_377Fq.nr @@ -16,7 +16,7 @@ //! * G1 curve equation: y^2 = x^3 + 1 //! * G2 curve equation: y^2 = x^3 + B, where //! * B = Fq2(0, 155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906) -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/bls12_377Fr.nr b/src/fields/bls12_377Fr.nr index a6b48264..475a9ff7 100644 --- a/src/fields/bls12_377Fr.nr +++ b/src/fields/bls12_377Fr.nr @@ -16,7 +16,7 @@ //! * G1 curve equation: y^2 = x^3 + 1 //! * G2 curve equation: y^2 = x^3 + B, where //! * B = Fq2(0, 155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906) -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/bls12_381Fq.nr b/src/fields/bls12_381Fq.nr index 2268c75a..e7ce74b3 100644 --- a/src/fields/bls12_381Fq.nr +++ b/src/fields/bls12_381Fq.nr @@ -14,7 +14,7 @@ //! * valuation(r - 1, 2) = 32 //! * G1 curve equation: y^2 = x^3 + 4 //! * G2 curve equation: y^2 = x^3 + Fq2(4, 4) -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/bls12_381Fr.nr b/src/fields/bls12_381Fr.nr index 19dffb1e..625a7fca 100644 --- a/src/fields/bls12_381Fr.nr +++ b/src/fields/bls12_381Fr.nr @@ -14,7 +14,7 @@ //! * valuation(r - 1, 2) = 32 //! * G1 curve equation: y^2 = x^3 + 4 //! * G2 curve equation: y^2 = x^3 + Fq2(4, 4) -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/bn254Fq.nr b/src/fields/bn254Fq.nr index b16fa130..3c5c8a43 100644 --- a/src/fields/bn254Fq.nr +++ b/src/fields/bn254Fq.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/ed25519Fq.nr b/src/fields/ed25519Fq.nr index 3bb74e81..4fd5ff8a 100644 --- a/src/fields/ed25519Fq.nr +++ b/src/fields/ed25519Fq.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; use crate::BigNumParamsTrait as BigNumParamsTrait; diff --git a/src/fields/ed25519Fr.nr b/src/fields/ed25519Fr.nr index dc4174ab..a35ca961 100644 --- a/src/fields/ed25519Fr.nr +++ b/src/fields/ed25519Fr.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/mnt4_753Fq.nr b/src/fields/mnt4_753Fq.nr index 5bde5bba..7910d2fc 100644 --- a/src/fields/mnt4_753Fq.nr +++ b/src/fields/mnt4_753Fq.nr @@ -19,7 +19,7 @@ //! * B = Fq2(0, b * NON_RESIDUE) //! * NON_RESIDUE = 13 is the quadratic non-residue used to construct the //! extension field Fq2 -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/mnt4_753Fr.nr b/src/fields/mnt4_753Fr.nr index 9a0c5f0a..08dae1ab 100644 --- a/src/fields/mnt4_753Fr.nr +++ b/src/fields/mnt4_753Fr.nr @@ -19,7 +19,7 @@ //! * B = Fq2(0, b * NON_RESIDUE) //! * NON_RESIDUE = 13 is the quadratic non-residue used to construct the //! extension field Fq2 -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/mnt6_753Fq.nr b/src/fields/mnt6_753Fq.nr index f3675b51..c0aea5d4 100644 --- a/src/fields/mnt6_753Fq.nr +++ b/src/fields/mnt6_753Fq.nr @@ -19,7 +19,7 @@ //! * B = Fq3(b * NON_RESIDUE, 0, 0) //! * NON_RESIDUE = 11 is the cubic non-residue used to construct the //! extension field Fq3 -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/mnt6_753Fr.nr b/src/fields/mnt6_753Fr.nr index d8bc5714..09eda2de 100644 --- a/src/fields/mnt6_753Fr.nr +++ b/src/fields/mnt6_753Fr.nr @@ -19,7 +19,7 @@ //! * B = Fq3(b * NON_RESIDUE, 0, 0) //! * NON_RESIDUE = 11 is the cubic non-residue used to construct the //! extension field Fq3 -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/pallasFq.nr b/src/fields/pallasFq.nr index 87b26b23..9a2d6a3e 100644 --- a/src/fields/pallasFq.nr +++ b/src/fields/pallasFq.nr @@ -13,7 +13,7 @@ //! * Curve equation: y^2 = x^3 + 5 //! * Valuation(q - 1, 2) = 32 //! * Valuation(r - 1, 2) = 32 -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/pallasFr.nr b/src/fields/pallasFr.nr index b7ecfc41..715c916c 100644 --- a/src/fields/pallasFr.nr +++ b/src/fields/pallasFr.nr @@ -13,7 +13,7 @@ //! * Curve equation: y^2 = x^3 + 5 //! * Valuation(q - 1, 2) = 32 //! * Valuation(r - 1, 2) = 32 -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/secp256k1Fq.nr b/src/fields/secp256k1Fq.nr index dd3405a4..f29ae51b 100644 --- a/src/fields/secp256k1Fq.nr +++ b/src/fields/secp256k1Fq.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/secp256k1Fr.nr b/src/fields/secp256k1Fr.nr index 053fafe4..9939027c 100644 --- a/src/fields/secp256k1Fr.nr +++ b/src/fields/secp256k1Fr.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/secp256r1Fq.nr b/src/fields/secp256r1Fq.nr index f8c957b4..09959595 100644 --- a/src/fields/secp256r1Fq.nr +++ b/src/fields/secp256r1Fq.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/secp256r1Fr.nr b/src/fields/secp256r1Fr.nr index c5f2f6b0..9a7c8fa7 100644 --- a/src/fields/secp256r1Fr.nr +++ b/src/fields/secp256r1Fr.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/secp384r1Fq.nr b/src/fields/secp384r1Fq.nr index 85742dc7..af7ac995 100644 --- a/src/fields/secp384r1Fq.nr +++ b/src/fields/secp384r1Fq.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/secp384r1Fr.nr b/src/fields/secp384r1Fr.nr index e06f9e77..90eee9fc 100644 --- a/src/fields/secp384r1Fr.nr +++ b/src/fields/secp384r1Fr.nr @@ -1,4 +1,3 @@ -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/vestaFq.nr b/src/fields/vestaFq.nr index d5a923d1..cf8c5e34 100644 --- a/src/fields/vestaFq.nr +++ b/src/fields/vestaFq.nr @@ -14,7 +14,6 @@ //! * Curve equation: y^2 = x^3 + 5 //! * Valuation(q - 1, 2) = 32 //! * Valuation(r - 1, 2) = 32 -use crate::BigNum; use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/fields/vestaFr.nr b/src/fields/vestaFr.nr index d58d6a66..44b39343 100644 --- a/src/fields/vestaFr.nr +++ b/src/fields/vestaFr.nr @@ -14,7 +14,7 @@ //! * Curve equation: y^2 = x^3 + 5 //! * Valuation(q - 1, 2) = 32 //! * Valuation(r - 1, 2) = 32 -use crate::BigNum; + use crate::BigNumParamsTrait; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; diff --git a/src/lib.nr b/src/lib.nr index f606df06..5291f681 100644 --- a/src/lib.nr +++ b/src/lib.nr @@ -4,14 +4,12 @@ mod fields; mod runtime_bignum; mod runtime_bignum_test; -use dep::std; -use crate::utils::u60_representation::U60Repr; -use crate::utils::arrayX::ArrayX; -use crate::utils::split_bits; -use crate::runtime_bignum::BigNumInstance as RuntimeBigNumInstance; -use crate::runtime_bignum::BigNumInstanceTrait as RuntimeBigNumInstanceTrait; -use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; -use crate::runtime_bignum::BigNumTrait as RuntimeBigNumTrait; +pub use crate::utils::u60_representation::U60Repr; +pub use crate::utils::arrayX::ArrayX; +pub use crate::runtime_bignum::BigNumInstance as RuntimeBigNumInstance; +pub use crate::runtime_bignum::BigNumInstanceTrait as RuntimeBigNumInstanceTrait; +pub use crate::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait; +pub use crate::runtime_bignum::BigNumTrait as RuntimeBigNumTrait; struct BigNum { limbs: [Field; N] } diff --git a/src/runtime_bignum_test.nr b/src/runtime_bignum_test.nr index 0be7c3da..210464ce 100644 --- a/src/runtime_bignum_test.nr +++ b/src/runtime_bignum_test.nr @@ -1,4 +1,3 @@ -use crate::utils::arrayX::ArrayX; use crate::BigNum; use crate::runtime_bignum::BigNumInstance; use crate::runtime_bignum::BigNumParamsTrait; diff --git a/src/utils/msb.nr b/src/utils/msb.nr index b8041957..172ca12b 100644 --- a/src/utils/msb.nr +++ b/src/utils/msb.nr @@ -1,5 +1,3 @@ -use crate::utils::u60_representation::U60Repr; - /// Multiple entires in the `MUL_DE_BRUIJN_BIT` list do not map to a valid output of `v * 0x6c04f118e9966f6b`. /// This is a dummy value to fill the gaps in the map. global n1: u32 = 0xffffffff; @@ -27,4 +25,4 @@ unconstrained pub fn get_msb64(x: u64) -> u32 { MUL_DE_BRUIJN_BIT[(std::wrapping_mul(v, 0x6c04f118e9966f6b)) >> 57] } -// 1100 \ No newline at end of file +// 1100 diff --git a/src/utils/u60_representation_test.nr b/src/utils/u60_representation_test.nr index 4bf4d28b..c067ebeb 100644 --- a/src/utils/u60_representation_test.nr +++ b/src/utils/u60_representation_test.nr @@ -1,6 +1,5 @@ use crate::utils::u60_representation::U60Repr; use crate::utils::arrayX::ArrayX; -use dep::std; #[test] fn test_conversion() { From 74780f0df09994b4f34e4e6aab9e03e7ade539b8 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 13 Sep 2024 17:12:43 +0100 Subject: [PATCH 3/4] . --- .github/workflows/test.yml | 4 ++-- Nargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ffba86e..d8ab9901 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - toolchain: [nightly, 0.32.0] + toolchain: [nightly, 0.34.0] steps: - name: Checkout sources uses: actions/checkout@v4 @@ -38,7 +38,7 @@ jobs: - name: Install Nargo uses: noir-lang/noirup@v0.1.3 with: - toolchain: 0.32.0 + toolchain: 0.34.0 - name: Run formatter run: nargo fmt --check diff --git a/Nargo.toml b/Nargo.toml index 4f1c12ca..848d8a1d 100644 --- a/Nargo.toml +++ b/Nargo.toml @@ -2,6 +2,6 @@ name = "bignum" type = "lib" authors = [""] -compiler_version = ">=0.32.0" +compiler_version = ">=0.34.0" -[dependencies] \ No newline at end of file +[dependencies] From 06d20cf99532c3f802009e833f1180a3a9c88102 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 13 Sep 2024 17:13:48 +0100 Subject: [PATCH 4/4] . --- src/bignum_test.nr | 122 ++++++++++++++++---------------- src/utils/arrayX.nr | 8 +-- src/utils/u60_representation.nr | 4 +- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/bignum_test.nr b/src/bignum_test.nr index 6958dd3e..e8207df9 100644 --- a/src/bignum_test.nr +++ b/src/bignum_test.nr @@ -17,67 +17,67 @@ impl RuntimeBigNumParamsTrait<18> for Test2048Params { } impl BigNumParamsTrait<18> for Test2048Params { fn get_instance() -> BigNumInstance<18, Self> { - let modulus: [Field; 18] = [ - 0x0000000000000000000000000000000000c0a197a5ae0fcdceb052c9732614fe, - 0x0000000000000000000000000000000000656ae034423283422243918ab83be3, - 0x00000000000000000000000000000000006bf590da48a7c1070b7d5aabaac678, - 0x00000000000000000000000000000000000cce39f530238b606f24b296e2bda9, - 0x000000000000000000000000000000000001e1fef9bb9c1c3ead98f226f1bfa0, - 0x0000000000000000000000000000000000ad8c1c816e12e0ed1379055e373abf, - 0x0000000000000000000000000000000000cebe80e474f753aa9d1461c435123d, - 0x0000000000000000000000000000000000aee5a18ceedef88d115a8b93c167ad, - 0x0000000000000000000000000000000000268ba83c4a65c4307427fc495d9e44, - 0x0000000000000000000000000000000000dd2777926848667b7df79f342639d4, - 0x0000000000000000000000000000000000f455074c96855ca0068668efe7da3d, - 0x00000000000000000000000000000000005ddba6b30bbc168bfb3a1225f27d65, - 0x0000000000000000000000000000000000591fec484f36707524133bcd6f4258, - 0x000000000000000000000000000000000059641b756766aeebe66781dd01d062, - 0x000000000000000000000000000000000058bc5eaff4b165e142bf9e2480eebb, - 0x0000000000000000000000000000000000667a3964f08e06df772ce64b229a72, - 0x00000000000000000000000000000000009c1fdb18907711bfe3e3c1cf918395, - 0x00000000000000000000000000000000000000000000000000000000000000b8 - ]; - // fn double_modulus() -> [Field; 18] {[ - // 0x000000000000000000000000000000000181432f4b5c1f9b9d60a592e64c29fc, - // 0x0000000000000000000000000000000001cad5c06884650684448723157077c6, - // 0x0000000000000000000000000000000001d7eb21b4914f820e16fab557558cef, - // 0x0000000000000000000000000000000001199c73ea604716c0de49652dc57b51, - // 0x000000000000000000000000000000000103c3fdf37738387d5b31e44de37f3f, - // 0x00000000000000000000000000000000015b183902dc25c1da26f20abc6e757d, - // 0x00000000000000000000000000000000019d7d01c8e9eea7553a28c3886a247a, - // 0x00000000000000000000000000000000015dcb4319ddbdf11a22b5172782cf5a, - // 0x00000000000000000000000000000000014d17507894cb8860e84ff892bb3c88, - // 0x0000000000000000000000000000000001ba4eef24d090ccf6fbef3e684c73a7, - // 0x0000000000000000000000000000000001e8aa0e992d0ab9400d0cd1dfcfb47a, - // 0x0000000000000000000000000000000001bbb74d6617782d17f674244be4faca, - // 0x0000000000000000000000000000000001b23fd8909e6ce0ea4826779ade84af, - // 0x0000000000000000000000000000000001b2c836eacecd5dd7cccf03ba03a0c3, - // 0x0000000000000000000000000000000001b178bd5fe962cbc2857f3c4901dd75, - // 0x0000000000000000000000000000000001ccf472c9e11c0dbeee59cc964534e3, - // 0x0000000000000000000000000000000001383fb63120ee237fc7c7839f230729, - // 0x0000000000000000000000000000000000000000000000000000000000000170 - // ]} - let redc_param: [Field; 18] = [ - 0x000000000000000000000000000000000091697def7100cd5cf8d890b4ef2ec3, - 0x00000000000000000000000000000000006765ba8304214dac764d3f4adc3185, - 0x000000000000000000000000000000000048404bd14d927ea230e60d4bebf940, - 0x00000000000000000000000000000000007c4d53a23bacc251ecbfc4b7ba5a0b, - 0x000000000000000000000000000000000093eaf3499474a6f5b2fff83f1259c8, - 0x00000000000000000000000000000000005bff4c737b97281f1a5f2384a8c16d, - 0x000000000000000000000000000000000061b4cf2f55358476b5323782999055, - 0x00000000000000000000000000000000001e7a804e8eacfe3a2a5673bc3885b8, - 0x0000000000000000000000000000000000eabadeae4282906c817adf70eab4ae, - 0x0000000000000000000000000000000000166f7df257fe2bf27f0809aceed9b0, - 0x00000000000000000000000000000000007d90fb7428901b8bed11f6b81e36bf, - 0x0000000000000000000000000000000000f36e6ba885c60b7024c563605df7e0, - 0x000000000000000000000000000000000052b7c58d2fb5d2c8478963ae6d4a44, - 0x000000000000000000000000000000000036ee761de26635f114ccc3f7d74f85, - 0x0000000000000000000000000000000000e3fb726a10cf2220897513f05243de, - 0x0000000000000000000000000000000000f43a26bbd732496eb4d828591b8056, - 0x0000000000000000000000000000000000ff4e42304e60fb3a54fca735499f2c, - 0x0000000000000000000000000000000000000000000000000000000000000162 - ]; - BigNumInstance::new(modulus, redc_param) + let modulus: [Field; 18] = [ + 0x0000000000000000000000000000000000c0a197a5ae0fcdceb052c9732614fe, + 0x0000000000000000000000000000000000656ae034423283422243918ab83be3, + 0x00000000000000000000000000000000006bf590da48a7c1070b7d5aabaac678, + 0x00000000000000000000000000000000000cce39f530238b606f24b296e2bda9, + 0x000000000000000000000000000000000001e1fef9bb9c1c3ead98f226f1bfa0, + 0x0000000000000000000000000000000000ad8c1c816e12e0ed1379055e373abf, + 0x0000000000000000000000000000000000cebe80e474f753aa9d1461c435123d, + 0x0000000000000000000000000000000000aee5a18ceedef88d115a8b93c167ad, + 0x0000000000000000000000000000000000268ba83c4a65c4307427fc495d9e44, + 0x0000000000000000000000000000000000dd2777926848667b7df79f342639d4, + 0x0000000000000000000000000000000000f455074c96855ca0068668efe7da3d, + 0x00000000000000000000000000000000005ddba6b30bbc168bfb3a1225f27d65, + 0x0000000000000000000000000000000000591fec484f36707524133bcd6f4258, + 0x000000000000000000000000000000000059641b756766aeebe66781dd01d062, + 0x000000000000000000000000000000000058bc5eaff4b165e142bf9e2480eebb, + 0x0000000000000000000000000000000000667a3964f08e06df772ce64b229a72, + 0x00000000000000000000000000000000009c1fdb18907711bfe3e3c1cf918395, + 0x00000000000000000000000000000000000000000000000000000000000000b8 + ]; + // fn double_modulus() -> [Field; 18] {[ + // 0x000000000000000000000000000000000181432f4b5c1f9b9d60a592e64c29fc, + // 0x0000000000000000000000000000000001cad5c06884650684448723157077c6, + // 0x0000000000000000000000000000000001d7eb21b4914f820e16fab557558cef, + // 0x0000000000000000000000000000000001199c73ea604716c0de49652dc57b51, + // 0x000000000000000000000000000000000103c3fdf37738387d5b31e44de37f3f, + // 0x00000000000000000000000000000000015b183902dc25c1da26f20abc6e757d, + // 0x00000000000000000000000000000000019d7d01c8e9eea7553a28c3886a247a, + // 0x00000000000000000000000000000000015dcb4319ddbdf11a22b5172782cf5a, + // 0x00000000000000000000000000000000014d17507894cb8860e84ff892bb3c88, + // 0x0000000000000000000000000000000001ba4eef24d090ccf6fbef3e684c73a7, + // 0x0000000000000000000000000000000001e8aa0e992d0ab9400d0cd1dfcfb47a, + // 0x0000000000000000000000000000000001bbb74d6617782d17f674244be4faca, + // 0x0000000000000000000000000000000001b23fd8909e6ce0ea4826779ade84af, + // 0x0000000000000000000000000000000001b2c836eacecd5dd7cccf03ba03a0c3, + // 0x0000000000000000000000000000000001b178bd5fe962cbc2857f3c4901dd75, + // 0x0000000000000000000000000000000001ccf472c9e11c0dbeee59cc964534e3, + // 0x0000000000000000000000000000000001383fb63120ee237fc7c7839f230729, + // 0x0000000000000000000000000000000000000000000000000000000000000170 + // ]} + let redc_param: [Field; 18] = [ + 0x000000000000000000000000000000000091697def7100cd5cf8d890b4ef2ec3, + 0x00000000000000000000000000000000006765ba8304214dac764d3f4adc3185, + 0x000000000000000000000000000000000048404bd14d927ea230e60d4bebf940, + 0x00000000000000000000000000000000007c4d53a23bacc251ecbfc4b7ba5a0b, + 0x000000000000000000000000000000000093eaf3499474a6f5b2fff83f1259c8, + 0x00000000000000000000000000000000005bff4c737b97281f1a5f2384a8c16d, + 0x000000000000000000000000000000000061b4cf2f55358476b5323782999055, + 0x00000000000000000000000000000000001e7a804e8eacfe3a2a5673bc3885b8, + 0x0000000000000000000000000000000000eabadeae4282906c817adf70eab4ae, + 0x0000000000000000000000000000000000166f7df257fe2bf27f0809aceed9b0, + 0x00000000000000000000000000000000007d90fb7428901b8bed11f6b81e36bf, + 0x0000000000000000000000000000000000f36e6ba885c60b7024c563605df7e0, + 0x000000000000000000000000000000000052b7c58d2fb5d2c8478963ae6d4a44, + 0x000000000000000000000000000000000036ee761de26635f114ccc3f7d74f85, + 0x0000000000000000000000000000000000e3fb726a10cf2220897513f05243de, + 0x0000000000000000000000000000000000f43a26bbd732496eb4d828591b8056, + 0x0000000000000000000000000000000000ff4e42304e60fb3a54fca735499f2c, + 0x0000000000000000000000000000000000000000000000000000000000000162 + ]; + BigNumInstance::new(modulus, redc_param) } fn modulus_bits() -> u32 { 2048 diff --git a/src/utils/arrayX.nr b/src/utils/arrayX.nr index f34ec1e1..05dd9daf 100644 --- a/src/utils/arrayX.nr +++ b/src/utils/arrayX.nr @@ -12,7 +12,7 @@ struct ArrayX { segments: [[T; N]; SizeMultiplier] } -impl std::convert::From<[T; N]> for ArrayX where T: std::default::Default { +impl std::convert::From<[T; N]> for ArrayX where T: std::default::Default { fn from(input: [T; N]) -> Self { assert(N == 1); let mut result = ArrayX::new(); @@ -21,13 +21,13 @@ impl std::convert::From<[T; N]> for Arra } } -impl std::convert::From<[[T; N]; SizeMultiplier]> for ArrayX where T: std::default::Default { +impl std::convert::From<[[T; N]; SizeMultiplier]> for ArrayX where T: std::default::Default { fn from(input: [[T; N]; SizeMultiplier]) -> Self { - ArrayX{ segments: input } + ArrayX { segments: input } } } -impl std::cmp::Eq for ArrayX where T: std::cmp::Eq { +impl std::cmp::Eq for ArrayX where T: std::cmp::Eq { fn eq(self, other: Self) -> bool { let mut result: bool = true; for i in 0..SizeMultiplier { diff --git a/src/utils/u60_representation.nr b/src/utils/u60_representation.nr index 37b8ed8f..56946dde 100644 --- a/src/utils/u60_representation.nr +++ b/src/utils/u60_representation.nr @@ -52,7 +52,7 @@ impl std::ops::Sub for U60Repr } } -impl std::convert::From<[Field; N]> for U60Repr { +impl std::convert::From<[Field; N]> for U60Repr { fn from(input: [Field; N]) -> Self { let mut result: Self = U60Repr { limbs: ArrayX { segments: [[0; N]; NumSegments] } }; for i in 0..(N) { @@ -75,7 +75,7 @@ impl std::convert::Into<[Field; N]> for U60Rep } } -impl std::cmp::Eq for U60Repr { +impl std::cmp::Eq for U60Repr { fn eq(self, other: Self) -> bool { self.limbs == other.limbs }