mirror of
https://github.com/status-im/c-kzg-4844.git
synced 2025-02-18 13:06:37 +00:00
Check more allocations for failure
This commit is contained in:
parent
78bf846f69
commit
2bd4c3b252
@ -805,6 +805,7 @@ C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in) {
|
|||||||
while (((uint64_t)1 << max_scale) < FIELD_ELEMENTS_PER_BLOB) max_scale++;
|
while (((uint64_t)1 << max_scale) < FIELD_ELEMENTS_PER_BLOB) max_scale++;
|
||||||
|
|
||||||
out->fs = (FFTSettings*)malloc(sizeof(FFTSettings));
|
out->fs = (FFTSettings*)malloc(sizeof(FFTSettings));
|
||||||
|
if (out->fs == NULL) { free(g1_projective); return C_KZG_MALLOC; }
|
||||||
|
|
||||||
C_KZG_RET ret;
|
C_KZG_RET ret;
|
||||||
ret = new_fft_settings((FFTSettings*)out->fs, max_scale);
|
ret = new_fft_settings((FFTSettings*)out->fs, max_scale);
|
||||||
@ -871,7 +872,7 @@ static void poly_lincomb(Polynomial out, const Polynomial vectors[], const fr_t
|
|||||||
*
|
*
|
||||||
* We do the second of these to save memory here.
|
* We do the second of these to save memory here.
|
||||||
*/
|
*/
|
||||||
static void g1_lincomb(g1_t *out, const g1_t *p, const fr_t *coeffs, const uint64_t len) {
|
static C_KZG_RET g1_lincomb(g1_t *out, const g1_t *p, const fr_t *coeffs, const uint64_t len) {
|
||||||
if (len < 8) { // Tunable parameter: must be at least 2 since Blst fails for 0 or 1
|
if (len < 8) { // Tunable parameter: must be at least 2 since Blst fails for 0 or 1
|
||||||
// Direct approach
|
// Direct approach
|
||||||
g1_t tmp;
|
g1_t tmp;
|
||||||
@ -883,8 +884,11 @@ static void g1_lincomb(g1_t *out, const g1_t *p, const fr_t *coeffs, const uint6
|
|||||||
} else {
|
} else {
|
||||||
// Blst's implementation of the Pippenger method
|
// Blst's implementation of the Pippenger method
|
||||||
void *scratch = malloc(blst_p1s_mult_pippenger_scratch_sizeof(len));
|
void *scratch = malloc(blst_p1s_mult_pippenger_scratch_sizeof(len));
|
||||||
|
if (scratch == NULL) return C_KZG_MALLOC;
|
||||||
blst_p1_affine *p_affine = malloc(len * sizeof(blst_p1_affine));
|
blst_p1_affine *p_affine = malloc(len * sizeof(blst_p1_affine));
|
||||||
|
if (p_affine == NULL) { free(scratch); return C_KZG_MALLOC; }
|
||||||
blst_scalar *scalars = malloc(len * sizeof(blst_scalar));
|
blst_scalar *scalars = malloc(len * sizeof(blst_scalar));
|
||||||
|
if (scalars == NULL) { free(scratch); free(p_affine); return C_KZG_MALLOC; }
|
||||||
|
|
||||||
// Transform the points to affine representation
|
// Transform the points to affine representation
|
||||||
const blst_p1 *p_arg[2] = {p, NULL};
|
const blst_p1 *p_arg[2] = {p, NULL};
|
||||||
@ -905,10 +909,11 @@ static void g1_lincomb(g1_t *out, const g1_t *p, const fr_t *coeffs, const uint6
|
|||||||
free(p_affine);
|
free(p_affine);
|
||||||
free(scalars);
|
free(scalars);
|
||||||
}
|
}
|
||||||
|
return C_KZG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void poly_to_kzg_commitment(KZGCommitment *out, const Polynomial p, const KZGSettings *s) {
|
static C_KZG_RET poly_to_kzg_commitment(KZGCommitment *out, const Polynomial p, const KZGSettings *s) {
|
||||||
g1_lincomb(out, s->g1_values, p, FIELD_ELEMENTS_PER_BLOB);
|
return g1_lincomb(out, s->g1_values, p, FIELD_ELEMENTS_PER_BLOB);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void poly_from_blob(Polynomial p, const Blob blob) {
|
static void poly_from_blob(Polynomial p, const Blob blob) {
|
||||||
@ -916,10 +921,10 @@ static void poly_from_blob(Polynomial p, const Blob blob) {
|
|||||||
bytes_to_bls_field(&p[i], &blob[i * BYTES_PER_FIELD_ELEMENT]);
|
bytes_to_bls_field(&p[i], &blob[i * BYTES_PER_FIELD_ELEMENT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void blob_to_kzg_commitment(KZGCommitment *out, const Blob blob, const KZGSettings *s) {
|
C_KZG_RET blob_to_kzg_commitment(KZGCommitment *out, const Blob blob, const KZGSettings *s) {
|
||||||
Polynomial p;
|
Polynomial p;
|
||||||
poly_from_blob(p, blob);
|
poly_from_blob(p, blob);
|
||||||
poly_to_kzg_commitment(out, p, s);
|
return poly_to_kzg_commitment(out, p, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,7 +109,7 @@ C_KZG_RET verify_aggregate_kzg_proof(bool *out,
|
|||||||
const KZGProof *kzg_aggregated_proof,
|
const KZGProof *kzg_aggregated_proof,
|
||||||
const KZGSettings *s);
|
const KZGSettings *s);
|
||||||
|
|
||||||
void blob_to_kzg_commitment(KZGCommitment *out,
|
C_KZG_RET blob_to_kzg_commitment(KZGCommitment *out,
|
||||||
const Blob blob,
|
const Blob blob,
|
||||||
const KZGSettings *s);
|
const KZGSettings *s);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user