Pass polys when calculating quotient size

This commit is contained in:
Ben Edgington 2021-02-05 08:10:08 +00:00
parent 686d1c5ca7
commit b4df409614
4 changed files with 11 additions and 5 deletions

View File

@ -32,7 +32,7 @@ void compute_proof_single(blst_p1 *out, const KZGSettings *ks, poly *p, const ui
divisor.coeffs[1] = one;
// Calculate q = p / (x - x0)
init_poly(&q, poly_long_div_length(p->length, 2));
init_poly(&q, poly_quotient_length(p, &divisor));
poly_long_div(&q, p, &divisor);
linear_combination_g1(out, ks->secret_g1, q.coeffs, q.length);

View File

@ -47,8 +47,8 @@ void eval_poly_at(blst_fr *out, const poly *p, const blst_fr *x) {
}
// Call this to find out how much space to allocate for the result
uint64_t poly_long_div_length(const uint64_t len_dividend, const uint64_t len_divisor) {
return len_dividend - len_divisor + 1;
uint64_t poly_quotient_length(const poly *dividend, const poly *divisor) {
return dividend->length - divisor->length + 1;
}
// `out` must have been pre-allocated to the correct size, and the length is provided

View File

@ -26,5 +26,5 @@ typedef struct {
void init_poly(poly *out, const uint64_t length);
void free_poly(poly p);
void eval_poly_at(blst_fr *out, const poly *p, const blst_fr *x);
uint64_t poly_long_div_length(const uint64_t len_dividend, const uint64_t len_divisor);
uint64_t poly_quotient_length(const poly *dividend, const poly *divisor);
C_KZG_RET poly_long_div(poly *out, const poly *dividend, const poly *divisor);

View File

@ -18,8 +18,13 @@
#include "debug_util.h"
#include "poly.h"
void title(void) {;}
void poly_div_length(void) {
TEST_CHECK(3 == poly_long_div_length(4, 2));
poly a, b;
init_poly(&a, 17);
init_poly(&b, 5);
TEST_CHECK(13 == poly_quotient_length(&a, &b));
}
void poly_div_0(void) {
@ -113,6 +118,7 @@ void eval_poly(void) {
TEST_LIST =
{
{"POLY_TEST", title},
{"poly_div_length", poly_div_length},
{"poly_div_0", poly_div_0},
{"poly_div_1", poly_div_1},