2022-10-04 18:45:12 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
2022-10-04 21:40:18 +00:00
|
|
|
#include <stdlib.h>
|
2022-10-04 18:45:12 +00:00
|
|
|
#include "c_kzg_4844.h"
|
2022-11-07 16:50:32 +00:00
|
|
|
#include "ckzg.h"
|
2022-10-04 18:45:12 +00:00
|
|
|
|
2022-10-20 18:29:36 +00:00
|
|
|
KZGSettings* load_trusted_setup_wrap(const char* file) {
|
|
|
|
KZGSettings* out = malloc(sizeof(KZGSettings));
|
2022-10-10 19:12:31 +00:00
|
|
|
|
2022-10-20 18:29:36 +00:00
|
|
|
if (out == NULL) return NULL;
|
2022-10-10 19:12:31 +00:00
|
|
|
|
2022-10-20 18:29:36 +00:00
|
|
|
FILE* f = fopen(file, "r");
|
2022-10-10 19:12:31 +00:00
|
|
|
|
2022-10-20 18:29:36 +00:00
|
|
|
if (f == NULL) { free(out); return NULL; }
|
2022-10-10 19:12:31 +00:00
|
|
|
|
2022-12-10 16:07:40 +00:00
|
|
|
if (load_trusted_setup_file(out, f) != C_KZG_OK) { free(out); fclose(f); return NULL; }
|
2022-10-10 19:12:31 +00:00
|
|
|
|
2022-11-10 16:23:40 +00:00
|
|
|
fclose(f);
|
2022-10-10 19:12:31 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2022-10-20 18:29:36 +00:00
|
|
|
void free_trusted_setup_wrap(KZGSettings *s) {
|
|
|
|
free_trusted_setup(s);
|
|
|
|
free(s);
|
|
|
|
}
|
2022-10-05 19:04:35 +00:00
|
|
|
|
2023-01-16 20:05:23 +00:00
|
|
|
int verify_aggregate_kzg_proof_wrap(const Blob *blobs, const KZGCommitment *commitments, size_t n, const KZGProof *proof, const KZGSettings *s) {
|
2022-10-20 18:29:36 +00:00
|
|
|
bool b;
|
2023-01-16 20:05:23 +00:00
|
|
|
C_KZG_RET ret = verify_aggregate_kzg_proof(&b, blobs, commitments, n, proof, s);
|
2022-11-04 09:07:05 +00:00
|
|
|
if (ret != C_KZG_OK) return -1;
|
2022-10-04 21:40:18 +00:00
|
|
|
|
2022-10-20 18:29:36 +00:00
|
|
|
return b ? 0 : 1;
|
|
|
|
}
|
2022-10-06 23:45:42 +00:00
|
|
|
|
2023-01-24 18:23:42 +00:00
|
|
|
int verify_kzg_proof_wrap(const KZGCommitment *c, const Bytes32 *z, const Bytes32 *y, const KZGProof *p, KZGSettings *s) {
|
2022-10-31 13:42:38 +00:00
|
|
|
bool out;
|
2023-01-16 20:05:23 +00:00
|
|
|
if (verify_kzg_proof(&out, c, z, y, p, s) != C_KZG_OK)
|
2022-10-31 13:42:38 +00:00
|
|
|
return -2;
|
|
|
|
|
|
|
|
return out ? 0 : 1;
|
|
|
|
}
|