Add alloc_polynomial and free_polynomial

This commit is contained in:
Ramana Kumar 2022-09-27 22:05:52 +01:00
parent 9b46788ac7
commit 8a072d68ba
No known key found for this signature in database
GPG Key ID: ED471C788B900433
2 changed files with 11 additions and 7 deletions

View File

@ -937,6 +937,16 @@ C_KZG_RET verify_kzg_proof(bool *out, const g1_t *commitment, const fr_t *x, con
return C_KZG_OK;
}
C_KZG_RET alloc_polynomial(PolynomialEvalForm *out, uint64_t length) {
out->length = length;
return new_fr_array(&out->values, length);
}
void free_polynomial(PolynomialEvalForm *p) {
p->length = 0;
free(p->values);
}
/**
* Compute KZG proof for polynomial in Lagrange form at position x
*
@ -959,8 +969,7 @@ C_KZG_RET compute_kzg_proof(KZGProof *out, const PolynomialEvalForm *p, const BL
const fr_t *roots_of_unity = s->fs->roots_of_unity;
uint64_t i, m = 0;
q.length = p->length;
TRY(new_fr_array(&q.values, q.length));
TRY(alloc_polynomial(&q, p->length));
fr_t *inverses_in, *inverses;

View File

@ -44,8 +44,6 @@ typedef fr_t BLSFieldElement;
* @warning In the case of @p C_KZG_OK or @p C_KZG_BADARGS, the caller can assume that all memory allocated by the
* called routines has been deallocated. However, in the case of @p C_KZG_ERROR or @p C_KZG_MALLOC being returned, these
* are unrecoverable and memory may have been leaked.
*
* @todo Check that memory is not leaked anywhere in the case of C_KZG_BADARGS.
*/
typedef enum {
C_KZG_OK = 0, /**< Success! */
@ -54,7 +52,6 @@ typedef enum {
C_KZG_MALLOC, /**< Could not allocate memory */
} C_KZG_RET;
/**
* Stores the setup and parameters needed for performing FFTs.
*/
@ -65,7 +62,6 @@ typedef struct {
fr_t *roots_of_unity; /**< Powers of the root of unity in bit-reversal permutation, size `width`. */
} FFTSettings;
/**
* Stores the setup and parameters needed for computing KZG proofs.
*/
@ -76,7 +72,6 @@ typedef struct {
uint64_t length; /**< The number of elements in g1_values */
} KZGSettings;
/**
* Lagrange form polynomial, with values under the bit-reversal permutation
*/