Renamings

This commit is contained in:
Ben Edgington 2021-02-05 09:13:16 +00:00
parent e32dc11697
commit 60a6d33f73
5 changed files with 18 additions and 18 deletions

View File

@ -26,19 +26,19 @@ void compute_proof_single(blst_p1 *out, const KZGSettings *ks, poly *p, const ui
blst_fr tmp; blst_fr tmp;
// The divisor is x - x0 // The divisor is x - x0
init_poly(&divisor, 2); poly_init(&divisor, 2);
fr_from_uint64(&tmp, x0); fr_from_uint64(&tmp, x0);
fr_negate(&divisor.coeffs[0],&tmp); fr_negate(&divisor.coeffs[0],&tmp);
divisor.coeffs[1] = one; divisor.coeffs[1] = one;
// Calculate q = p / (x - x0) // Calculate q = p / (x - x0)
init_poly(&q, poly_quotient_length(p, &divisor)); poly_init(&q, poly_quotient_length(p, &divisor));
poly_long_div(&q, p, &divisor); poly_long_div(&q, p, &divisor);
linear_combination_g1(out, ks->secret_g1, q.coeffs, q.length); linear_combination_g1(out, ks->secret_g1, q.coeffs, q.length);
free_poly(q); poly_free(q);
free_poly(divisor); poly_free(divisor);
} }
bool check_proof_single(const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof, const blst_fr *x, blst_fr *y) { bool check_proof_single(const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof, const blst_fr *x, blst_fr *y) {

View File

@ -48,7 +48,7 @@ void proof_single(void) {
uint64_t coeffs_u[16] = {1, 2, 3, 4, 7, 7, 7, 7, 13, 13, 13, 13, 13, 13, 13, 13}; uint64_t coeffs_u[16] = {1, 2, 3, 4, 7, 7, 7, 7, 13, 13, 13, 13, 13, 13, 13, 13};
blst_fr x, value; blst_fr x, value;
init_poly(&p, 16); poly_init(&p, 16);
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
fr_from_uint64(&p.coeffs[i], coeffs_u[i]); fr_from_uint64(&p.coeffs[i], coeffs_u[i]);
} }
@ -61,7 +61,7 @@ void proof_single(void) {
compute_proof_single(&proof, &ks, &p, 17); compute_proof_single(&proof, &ks, &p, 17);
fr_from_uint64(&x, 17); fr_from_uint64(&x, 17);
eval_poly_at(&value, &p, &x); poly_eval(&value, &p, &x);
TEST_CHECK(true == check_proof_single(&ks, &commitment, &proof, &x, &value)); TEST_CHECK(true == check_proof_single(&ks, &commitment, &proof, &x, &value));

View File

@ -21,16 +21,16 @@ static void poly_factor_div(blst_fr *out, const blst_fr *a, const blst_fr *b) {
blst_fr_mul(out, out, a); blst_fr_mul(out, out, a);
} }
void init_poly(poly *out, const uint64_t length) { void poly_init(poly *out, const uint64_t length) {
out->length = length; out->length = length;
out->coeffs = malloc(length * sizeof(blst_fr)); out->coeffs = malloc(length * sizeof(blst_fr));
} }
void free_poly(poly p) { void poly_free(poly p) {
free(p.coeffs); free(p.coeffs);
} }
void eval_poly_at(blst_fr *out, const poly *p, const blst_fr *x) { void poly_eval(blst_fr *out, const poly *p, const blst_fr *x) {
blst_fr tmp; blst_fr tmp;
if (p->length == 0) { if (p->length == 0) {

View File

@ -23,8 +23,8 @@ typedef struct {
uint64_t length; // one more than the polynomial's degree uint64_t length; // one more than the polynomial's degree
} poly; } poly;
void init_poly(poly *out, const uint64_t length); void poly_init(poly *out, const uint64_t length);
void free_poly(poly p); void poly_free(poly p);
void eval_poly_at(blst_fr *out, const poly *p, const blst_fr *x); void poly_eval(blst_fr *out, const poly *p, const blst_fr *x);
uint64_t poly_quotient_length(const poly *dividend, const poly *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); C_KZG_RET poly_long_div(poly *out, const poly *dividend, const poly *divisor);

View File

@ -22,8 +22,8 @@ void title(void) {;}
void poly_div_length(void) { void poly_div_length(void) {
poly a, b; poly a, b;
init_poly(&a, 17); poly_init(&a, 17);
init_poly(&b, 5); poly_init(&b, 5);
TEST_CHECK(13 == poly_quotient_length(&a, &b)); TEST_CHECK(13 == poly_quotient_length(&a, &b));
} }
@ -101,17 +101,17 @@ void poly_wrong_size(void) {
TEST_CHECK(poly_long_div(&result, &dividend, &divisor) == C_KZG_BADARGS); TEST_CHECK(poly_long_div(&result, &dividend, &divisor) == C_KZG_BADARGS);
} }
void eval_poly(void) { void poly_eval_check(void) {
uint64_t n = 10; uint64_t n = 10;
blst_fr res, expected; blst_fr res, expected;
poly p; poly p;
init_poly(&p, n); poly_init(&p, n);
for (uint64_t i = 0; i < n; i++) { for (uint64_t i = 0; i < n; i++) {
fr_from_uint64(&p.coeffs[i], i + 1); fr_from_uint64(&p.coeffs[i], i + 1);
} }
fr_from_uint64(&expected, n * (n + 1) / 2); fr_from_uint64(&expected, n * (n + 1) / 2);
eval_poly_at(&res, &p, &one); poly_eval(&res, &p, &one);
TEST_CHECK(fr_equal(&expected, &res)); TEST_CHECK(fr_equal(&expected, &res));
} }
@ -123,6 +123,6 @@ TEST_LIST =
{"poly_div_0", poly_div_0}, {"poly_div_0", poly_div_0},
{"poly_div_1", poly_div_1}, {"poly_div_1", poly_div_1},
{"poly_wrong_size", poly_wrong_size}, {"poly_wrong_size", poly_wrong_size},
{"eval_poly", eval_poly}, {"poly_eval_check", poly_eval_check},
{ NULL, NULL } /* zero record marks the end of the list */ { NULL, NULL } /* zero record marks the end of the list */
}; };