Improve comments

This commit is contained in:
Ben Edgington 2021-03-04 15:10:28 +00:00
parent 9d1b622f21
commit 7d3d422005
2 changed files with 17 additions and 7 deletions

View File

@ -26,7 +26,7 @@
#include "utility.h"
#include "zero_poly.h"
/** 5 is a primitive element, but actually this can be pretty much anything not 1 or 0*/
/** 5 is a primitive element, but actually this can be pretty much anything not 0 or a low-degree root of unity */
#define SHIFT_FACTOR 5
/**
@ -125,6 +125,7 @@ C_KZG_RET recover_poly_from_samples(fr_t *reconstructed_data, fr_t *samples, uin
TRY(fr_is_null(&samples[i]) == fr_is_zero(&zero_eval[i]) ? C_KZG_OK : C_KZG_ERROR);
}
// Construct E * Z_r,I: the loop makes the evaluation polynomial
for (uint64_t i = 0; i < len_samples; i++) {
if (fr_is_null(&samples[i])) {
poly_evaluations_with_zero[i] = fr_zero;
@ -132,13 +133,19 @@ C_KZG_RET recover_poly_from_samples(fr_t *reconstructed_data, fr_t *samples, uin
fr_mul(&poly_evaluations_with_zero[i], &samples[i], &zero_eval[i]);
}
}
// Now inverse FFT so that poly_with_zero is (E * Z_r,I)(x) = (D * Z_r,I)(x)
TRY(fft_fr(poly_with_zero, poly_evaluations_with_zero, true, len_samples, fs));
// x -> k * x
shift_poly(poly_with_zero, len_samples);
shift_poly(zero_poly.coeffs, zero_poly.length);
// Q1 = (D * Z_r,I)(k * x)
fr_t *shifted_poly_with_zero = poly_with_zero; // Renaming
fr_t *shifted_zero_poly = zero_poly.coeffs; // Renaming
// Q2 = Z_r,I(k * x)
fr_t *shifted_zero_poly = zero_poly.coeffs; // Renaming
// Polynomial division by convolution: Q3 = Q1 / Q2
TRY(fft_fr(eval_shifted_poly_with_zero, shifted_poly_with_zero, false, len_samples, fs));
TRY(fft_fr(eval_shifted_zero_poly, shifted_zero_poly, false, len_samples, fs));
@ -147,11 +154,16 @@ C_KZG_RET recover_poly_from_samples(fr_t *reconstructed_data, fr_t *samples, uin
fr_div(&eval_shifted_reconstructed_poly[i], &eval_shifted_poly_with_zero[i], &eval_shifted_zero_poly[i]);
}
// The result of the division is D(k * x):
TRY(fft_fr(shifted_reconstructed_poly, eval_shifted_reconstructed_poly, true, len_samples, fs));
// k * x -> x
unshift_poly(shifted_reconstructed_poly, len_samples);
// Finally we have D(x) which evaluates to our original data at the powers of roots of unity
fr_t *reconstructed_poly = shifted_reconstructed_poly; // Renaming
// The evaluation polynomial for D(x) is the reconstructed data:
TRY(fft_fr(reconstructed_data, reconstructed_poly, false, len_samples, fs));
// Check all is well

View File

@ -28,8 +28,8 @@
/**
* Calculates the minimal polynomial that evaluates to zero for powers of roots of unity at the given indices.
*
* Uses straightforward multiplication to calculate the product of `(x - r^i)` where `r` is a root of unity and the `i`s
* are the indices at which it must evaluate to zero. This results in a polynomial of degree @p len_indices.
* Uses straightforward long multiplication to calculate the product of `(x - r^i)` where `r` is a root of unity and the
* `i`s are the indices at which it must evaluate to zero. This results in a polynomial of degree @p len_indices.
*
* @param[in,out] dst The zero polynomial for @p indices. The space allocated for coefficients must be at least @p
* len_indices + 1, as indicated by the `length` value on entry.
@ -39,8 +39,6 @@
* @param[in] fs The FFT settings previously initialised with #new_fft_settings
* @retval C_CZK_OK All is well
* @retval C_CZK_BADARGS Invalid parameters were supplied
*
* @todo rework to pass polynomials in and out
*/
C_KZG_RET do_zero_poly_mul_partial(poly *dst, const uint64_t *indices, uint64_t len_indices, uint64_t stride,
const FFTSettings *fs) {
@ -126,7 +124,7 @@ C_KZG_RET reduce_partials(poly *out, uint64_t len_out, fr_t *scratch, uint64_t l
fr_t *mul_eval_ps = scratch + len_out;
fr_t *p_eval = scratch + 2 * len_out;
// Do the last partial first: it may be shorter than the others and the padding can remain in place for the rest.
// Do the last partial first: it is no longer than the others and the padding can remain in place for the rest.
TRY(pad_p(p_padded, len_out, &partials[partial_count - 1]));
TRY(fft_fr(mul_eval_ps, p_padded, false, len_out, fs));