Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Sep 24, 2024
1 parent 431ab31 commit c9c19c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/runtime_bignum.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use dep::std;
use crate::utils::u60_representation::U60Repr;
use crate::utils::split_bits;
use crate::utils::split_bits::__normalize_limbs;
use crate::BigNum;
/**
* @brief runtime_bignum::BigNumTrait defines methods available to BigNum *if* the modulus is not known at compile time.
Expand Down Expand Up @@ -923,7 +922,7 @@ impl<let N: u32, Params> BigNumInstance<N, Params> where Params: BigNumParamsTra
}
}
let (q, r) = __barrett_reduction(
__normalize_limbs(mul, 2 * N),
split_bits::__normalize_limbs(mul, 2 * N),
self.redc_param,
Params::modulus_bits(),
self.modulus,
Expand Down Expand Up @@ -1301,7 +1300,7 @@ impl<let N: u32, Params> BigNumInstance<N, Params> where Params: BigNumParamsTra
linear_terms,
linear_flags
);
let mut relation_result: [Field; 2 * N] = __normalize_limbs(mulout, 2 * N);
let mut relation_result: [Field; 2 * N] = split_bits::__normalize_limbs(mulout, 2 * N);

// TODO: ugly! Will fail if input slice is empty
let k = Params::modulus_bits();
Expand Down Expand Up @@ -1364,7 +1363,7 @@ impl<let N: u32, Params> BigNumInstance<N, Params> where Params: BigNumParamsTra
linear_flags
);
let mut mulout_n: [Field; 2 * N] = [0; 2 * N];
let mut relation_result: [Field; 2 * N] = __normalize_limbs(mulout_p, 2 * N);
let mut relation_result: [Field; 2 * N] = split_bits::__normalize_limbs(mulout_p, 2 * N);

let modulus: [Field; N] = self.modulus;
let (quotient, remainder) = __barrett_reduction(
Expand Down Expand Up @@ -1485,7 +1484,7 @@ unconstrained fn __barrett_reduction<let N: u32>(
mulout[i + j] += x[i] * redc_param[j];
}
}
mulout = __normalize_limbs(mulout, 3 * N - 1);
mulout = split_bits::__normalize_limbs(mulout, 3 * N - 1);
let mulout_u60: U60Repr<N, 6> = U60Repr::new(mulout);
let mut quotient_u60 = mulout_u60.shr((k + k));

Expand Down
5 changes: 4 additions & 1 deletion src/utils/split_bits.nr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ unconstrained pub fn split_60_bits(x: Field) -> (u64, u64) {
(low, high)
}

unconstrained pub fn __normalize_limbs<let N: u32>(input: [Field; N], range: u32) -> [Field; N] {
unconstrained pub(crate) fn __normalize_limbs<let N: u32>(
input: [Field; N],
range: u32
) -> [Field; N] {
let mut normalized: [Field; N] = [0; N];
let mut inp: _ = input;
for i in 0..(range - 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/u60_representation.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::utils::msb::get_msb64;
* It is helpful to use u60 types when evaluating addition operations that can overflow the field modulus,
* as well as when performing bit shifts.
*/
struct U60Repr<let N: u32, let NumSegments: u32>
pub(crate) struct U60Repr<let N: u32, let NumSegments: u32>
{
limbs: [u64; N * NumSegments]
}
Expand Down

0 comments on commit c9c19c5

Please sign in to comment.