Handle n < 2 cases better in compute_aggregated_poly_and_commitment

This commit is contained in:
Ramana Kumar 2022-11-08 20:06:57 +00:00
parent dc6e43ae55
commit fec7acb87e
No known key found for this signature in database
GPG Key ID: ED471C788B900433
1 changed files with 15 additions and 4 deletions

View File

@ -1109,14 +1109,25 @@ static C_KZG_RET compute_aggregated_poly_and_commitment(Polynomial poly_out, KZG
const Polynomial polys[],
const KZGCommitment kzg_commitments[],
size_t n) {
BLSFieldElement* r_powers = calloc(n, sizeof(BLSFieldElement));
if (r_powers == NULL) return C_KZG_MALLOC;
if (n == 0) return C_KZG_BADARGS;
C_KZG_RET ret;
uint8_t* hash = calloc(32, sizeof(uint8_t));
if (hash == NULL) { free(r_powers); return C_KZG_MALLOC; }
if (hash == NULL) return C_KZG_MALLOC;
ret = hash_to_bytes(hash, polys, kzg_commitments, n);
if (ret != C_KZG_OK) { free(r_powers); free(hash); return ret; }
if (ret != C_KZG_OK) { free(hash); return ret; }
if (n == 1) {
bytes_to_bls_field(chal_out, hash);
poly_lincomb(poly_out, polys, chal_out, n);
g1_lincomb(comm_out, kzg_commitments, chal_out, n);
free(hash);
return C_KZG_OK;
}
BLSFieldElement* r_powers = calloc(n, sizeof(BLSFieldElement));
if (r_powers == NULL) { free(hash); return C_KZG_MALLOC; }
bytes_to_bls_field(&r_powers[1], hash);
free(hash);