Skip to content

Commit 6cdb9db

Browse files
authored
chore: remove ROOTS arg from unconstrained functions in bloblib (#12418)
Some cleanup See: noir-lang/noir#7559 (comment)
1 parent 8f13fd5 commit 6cdb9db

File tree

1 file changed

+9
-16
lines changed
  • noir-projects/noir-protocol-circuits/crates/blob/src

1 file changed

+9
-16
lines changed

noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr

+9-16
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {
152152

153153
let NUM_PARTIAL_SUMS = FIELDS_PER_BLOB / 8;
154154
// Safety: This sum is checked by the following `F::evaluate_quadratic_expression` calls.
155-
let partial_sums: [F; FIELDS_PER_BLOB / 8] =
156-
unsafe { __compute_partial_sums(fracs, ROOTS) };
155+
let partial_sums: [F; FIELDS_PER_BLOB / 8] = unsafe { __compute_partial_sums(fracs) };
157156

158157
// We split off the first term to check the initial sum
159158

@@ -237,7 +236,7 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {
237236

238237
// Safety: We're running under the condition that `std::runtime::is_unconstrained()` is true.
239238
unsafe {
240-
__compute_sum(fracs, ROOTS)
239+
__compute_sum(fracs)
241240
}
242241
};
243242

@@ -335,10 +334,7 @@ fn compute_fracs(z: F, ys: [F; FIELDS_PER_BLOB]) -> [F; FIELDS_PER_BLOB] {
335334
}
336335

337336
// TODO: Clean me
338-
unconstrained fn __compute_partial_sums(
339-
fracs: [F; FIELDS_PER_BLOB],
340-
unconstrained_roots: [F; FIELDS_PER_BLOB],
341-
) -> [F; FIELDS_PER_BLOB / 8] {
337+
unconstrained fn __compute_partial_sums(fracs: [F; FIELDS_PER_BLOB]) -> [F; FIELDS_PER_BLOB / 8] {
342338
let mut partial_sums: [F; FIELDS_PER_BLOB / 8] = std::mem::zeroed();
343339

344340
// Seeking:
@@ -352,7 +348,7 @@ unconstrained fn __compute_partial_sums(
352348
let mut partial_sum: F = F::zero();
353349
for i in 0..8 {
354350
// y_k * ( omega^k / (z - omega^k) )
355-
let summand = unconstrained_roots[i].__mul(fracs[i]);
351+
let summand = ROOTS[i].__mul(fracs[i]);
356352

357353
// partial_sum + ( y_k * ( omega^k / (z - omega^k) ) -> partial_sum
358354
partial_sum = partial_sum.__add(summand);
@@ -371,7 +367,7 @@ unconstrained fn __compute_partial_sums(
371367
for j in 0..8 {
372368
let k = i * 8 + j;
373369
// y_k * ( omega^k / (z - omega^k) )
374-
let summand = unconstrained_roots[k].__mul(fracs[k]);
370+
let summand = ROOTS[k].__mul(fracs[k]);
375371
// partial_sum + ( y_k * ( omega^k / (z - omega^k) ) -> partial_sum
376372
partial_sum = partial_sum.__add(summand);
377373
}
@@ -381,10 +377,7 @@ unconstrained fn __compute_partial_sums(
381377
partial_sums
382378
}
383379

384-
unconstrained fn __compute_sum(
385-
fracs: [F; FIELDS_PER_BLOB],
386-
unconstrained_roots: [F; FIELDS_PER_BLOB],
387-
) -> F {
380+
unconstrained fn __compute_sum(fracs: [F; FIELDS_PER_BLOB]) -> F {
388381
// Seeking:
389382
// ___d-1
390383
// \ omega^i
@@ -395,7 +388,7 @@ unconstrained fn __compute_sum(
395388
let mut sum: F = F::zero();
396389
for i in 0..FIELDS_PER_BLOB {
397390
// y_k * ( omega^k / (z - omega^k) )
398-
let summand = unconstrained_roots[i].__mul(fracs[i]);
391+
let summand = ROOTS[i].__mul(fracs[i]);
399392

400393
// partial_sum + ( y_k * ( omega^k / (z - omega^k) ) -> partial_sum
401394
sum = sum.__add(summand);
@@ -658,8 +651,8 @@ mod tests {
658651
}
659652
// Safety: this is a test
660653
unsafe {
661-
let partial_sums = __compute_partial_sums(fields, ROOTS);
662-
let sum = __compute_sum(fields, ROOTS);
654+
let partial_sums = __compute_partial_sums(fields);
655+
let sum = __compute_sum(fields);
663656

664657
assert_eq(partial_sums[FIELDS_PER_BLOB / 8 - 1], sum);
665658
}

0 commit comments

Comments
 (0)