From ec9efb73623080d6328309ad64d939c08c44c3f2 Mon Sep 17 00:00:00 2001 From: Tom French Date: Tue, 25 Feb 2025 11:58:58 +0000 Subject: [PATCH] chore!: bump bignum version to `v0.6.0` --- Nargo.toml | 2 +- src/bigcurve_test.nr | 12 ++++++------ src/scalar_field.nr | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Nargo.toml b/Nargo.toml index b0da72c..34cd5c3 100644 --- a/Nargo.toml +++ b/Nargo.toml @@ -5,4 +5,4 @@ authors = [""] compiler_version = ">=1.0.0" [dependencies] -bignum = {tag = "v0.5.4", git = "https://github.com/noir-lang/noir-bignum"} +bignum = {tag = "v0.6.0", git = "https://github.com/noir-lang/noir-bignum"} diff --git a/src/bigcurve_test.nr b/src/bigcurve_test.nr index 5b2a69d..c99ec34 100644 --- a/src/bigcurve_test.nr +++ b/src/bigcurve_test.nr @@ -26,8 +26,8 @@ type Fq = BigNum<3, 254, BN254_Fq_Params>; type BN254J = CurveJ; -fn main(x: Field) { - let mut foo: [Field; 12] = [0; 12]; +fn main(x: u128) { + let mut foo: [u128; 12] = [0; 12]; foo[0] = x; for i in 1..12 { foo[i] = foo[i - 1] * x; @@ -38,16 +38,16 @@ fn main(x: Field) { is_infinity: false, }; - let scalar: ScalarField<64> = ScalarField::from(x); // p - 2 ? + let scalar: ScalarField<64> = ScalarField::from(x as Field); // p - 2 ? let transcript = unsafe { get_transcript(CurveJ::from(P), scalar) }; // 30768 // 31020 let mut A = P; for i in 0..101 { for j in 0..3 { - std::as_witness(transcript[i].lambda.limbs[j]); - std::as_witness(transcript[i].x3.limbs[j]); - std::as_witness(transcript[i].y3.limbs[j]); + std::as_witness(transcript[i].lambda.limbs[j] as Field); + std::as_witness(transcript[i].x3.limbs[j] as Field); + std::as_witness(transcript[i].y3.limbs[j] as Field); } A = A.double_with_hint(transcript[i]); } diff --git a/src/scalar_field.nr b/src/scalar_field.nr index 30ae659..c2d9cec 100644 --- a/src/scalar_field.nr +++ b/src/scalar_field.nr @@ -45,9 +45,9 @@ where { let mut result: [u8; N] = [0; N]; let mut nibbles: [[u8; 30]; (N / 30) + 1] = [[0; 30]; (N / 30) + 1]; - let x: [Field] = x.get_limbs_slice(); + let x: [u128] = x.get_limbs_slice(); for i in 0..x.len() { - nibbles[i] = x[i].to_le_radix::<30>(16); + nibbles[i] = (x[i] as Field).to_le_radix::<30>(16); } let skew: bool = nibbles[0][0] & 1 == 0; @@ -221,7 +221,7 @@ impl ScalarFieldTrait for ScalarField { let mut result = BigNum::zero(); let mut count: u64 = 0; { - let mut acc = 0; + let mut acc: u128 = 0; let mut last_bits = (result.modulus_bits() % 120) as u64; if (last_bits == 0) { last_bits = 120; @@ -229,19 +229,19 @@ impl ScalarFieldTrait for ScalarField { let mut last_nibbles = (last_bits / 4) + (last_bits % 4 != 0) as u64; for _ in 0..last_nibbles { acc = acc * 16; - acc = acc + (self.base4_slices[count] as Field) * 2 - 15; + acc = acc + (self.base4_slices[count] as u128) * 2 - 15; count = count + 1; } result.set_limb(result.num_limbs() - 1, acc); } for i in 1..result.num_limbs() { - let mut acc: Field = 0; + let mut acc: u128 = 0; for _ in 0..30 { acc = acc * 16; - acc = acc + (self.base4_slices[count] as Field) * 2 - 15; + acc = acc + (self.base4_slices[count] as u128) * 2 - 15; count = count + 1; } - if acc.lt(0x1000000000000000000000000000000) == false { + if acc >= 0x1000000000000000000000000000000 { acc += 0x1000000000000000000000000000000; result.set_limb( result.num_limbs() - i, @@ -250,7 +250,7 @@ impl ScalarFieldTrait for ScalarField { } result.set_limb(result.num_limbs() - 1 - i, acc); } - result.set_limb(0, result.get_limb(0) - self.skew as Field); + result.set_limb(0, result.get_limb(0) - self.skew as u128); result }