Handle n < 2 cases better in compute_aggregated_poly_and_commitment
This commit is contained in:
parent
dc6e43ae55
commit
fec7acb87e
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue