@@ -65,6 +65,7 @@ C_KZG_RET compute_cells_and_kzg_proofs(
6565 fr_t * poly_lagrange = NULL ;
6666 fr_t * data_fr = NULL ;
6767 g1_t * proofs_g1 = NULL ;
68+ blst_p1_affine * proofs_affine = NULL ;
6869
6970 /* If both of these are null, something is wrong */
7071 if (cells == NULL && proofs == NULL ) {
@@ -131,9 +132,17 @@ C_KZG_RET compute_cells_and_kzg_proofs(
131132 ret = bit_reversal_permutation (proofs_g1 , sizeof (g1_t ), CELLS_PER_EXT_BLOB );
132133 if (ret != C_KZG_OK ) goto out ;
133134
134- /* Convert all of the proofs to byte-form */
135+ /* Allocate space for affine proofs */
136+ ret = c_kzg_malloc ((void * * )& proofs_affine , CELLS_PER_EXT_BLOB * sizeof (blst_p1_affine ));
137+ if (ret != C_KZG_OK ) goto out ;
138+
139+ /* Batch convert proofs to affine */
140+ const blst_p1 * proofs_arg [2 ] = {proofs_g1 , NULL };
141+ blst_p1s_to_affine (proofs_affine , proofs_arg , CELLS_PER_EXT_BLOB );
142+
143+ /* Compress all of the proofs to byte-form */
135144 for (size_t i = 0 ; i < CELLS_PER_EXT_BLOB ; i ++ ) {
136- bytes_from_g1 ( & proofs [i ], & proofs_g1 [i ]);
145+ blst_p1_affine_compress ( proofs [i ]. bytes , & proofs_affine [i ]);
137146 }
138147 }
139148
@@ -142,6 +151,7 @@ C_KZG_RET compute_cells_and_kzg_proofs(
142151 c_kzg_free (poly_lagrange );
143152 c_kzg_free (data_fr );
144153 c_kzg_free (proofs_g1 );
154+ c_kzg_free (proofs_affine );
145155 return ret ;
146156}
147157
@@ -174,6 +184,7 @@ C_KZG_RET recover_cells_and_kzg_proofs(
174184 C_KZG_RET ret ;
175185 fr_t * recovered_cells_fr = NULL ;
176186 g1_t * recovered_proofs_g1 = NULL ;
187+ blst_p1_affine * recovered_proofs_affine = NULL ;
177188
178189 /* Ensure only one blob's worth of cells was provided */
179190 if (num_cells > CELLS_PER_EXT_BLOB ) {
@@ -268,15 +279,26 @@ C_KZG_RET recover_cells_and_kzg_proofs(
268279 ret = bit_reversal_permutation (recovered_proofs_g1 , sizeof (g1_t ), CELLS_PER_EXT_BLOB );
269280 if (ret != C_KZG_OK ) goto out ;
270281
271- /* Convert all of the proofs to byte-form */
282+ /* Allocate space for affine proofs */
283+ ret = c_kzg_malloc (
284+ (void * * )& recovered_proofs_affine , CELLS_PER_EXT_BLOB * sizeof (blst_p1_affine )
285+ );
286+ if (ret != C_KZG_OK ) goto out ;
287+
288+ /* Batch convert proofs to affine */
289+ const blst_p1 * recovered_proofs_arg [2 ] = {recovered_proofs_g1 , NULL };
290+ blst_p1s_to_affine (recovered_proofs_affine , recovered_proofs_arg , CELLS_PER_EXT_BLOB );
291+
292+ /* Compress all of the proofs to byte-form */
272293 for (size_t i = 0 ; i < CELLS_PER_EXT_BLOB ; i ++ ) {
273- bytes_from_g1 ( & recovered_proofs [i ], & recovered_proofs_g1 [i ]);
294+ blst_p1_affine_compress ( recovered_proofs [i ]. bytes , & recovered_proofs_affine [i ]);
274295 }
275296 }
276297
277298out :
278299 c_kzg_free (recovered_cells_fr );
279300 c_kzg_free (recovered_proofs_g1 );
301+ c_kzg_free (recovered_proofs_affine );
280302 return ret ;
281303}
282304
0 commit comments