diff --git a/min-src/c_kzg_4844.c b/min-src/c_kzg_4844.c index f9b0e63..1537316 100644 --- a/min-src/c_kzg_4844.c +++ b/min-src/c_kzg_4844.c @@ -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; diff --git a/min-src/c_kzg_4844.h b/min-src/c_kzg_4844.h index 9e6378e..699c38e 100644 --- a/min-src/c_kzg_4844.h +++ b/min-src/c_kzg_4844.h @@ -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 */