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-10-05 19:04:35 +00:00
|
|
|
int verify_kzg_proof_wrap(const uint8_t c[48], const uint8_t x[32], const uint8_t y[32], const uint8_t p[48], KZGSettings *s) {
|
|
|
|
KZGCommitment commitment;
|
|
|
|
BLSFieldElement px, py;
|
|
|
|
KZGProof proof;
|
|
|
|
bool out;
|
|
|
|
|
|
|
|
if (bytes_to_g1(&commitment, c) != C_KZG_OK) return -1;
|
|
|
|
bytes_to_bls_field(&px, x);
|
|
|
|
bytes_to_bls_field(&py, y);
|
|
|
|
if (bytes_to_g1(&proof, p) != C_KZG_OK) return -1;
|
|
|
|
|
|
|
|
if (verify_kzg_proof(&out, &commitment, &px, &py, &proof, s) != C_KZG_OK)
|
|
|
|
return -2;
|
|
|
|
return out ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
KZGSettings* load_trusted_setup_wrap(const char* file) {
|
|
|
|
KZGSettings* out = (KZGSettings*)malloc(sizeof(KZGSettings));
|
|
|
|
|
|
|
|
if (out == NULL) return NULL;
|
|
|
|
|
|
|
|
FILE* f = fopen(file, "r");
|
|
|
|
|
|
|
|
if (f == NULL) return NULL;
|
|
|
|
|
|
|
|
if (load_trusted_setup(out, f) != C_KZG_OK) return NULL;
|
|
|
|
|
|
|
|
return out;
|
2022-10-04 18:45:12 +00:00
|
|
|
}
|
2022-10-04 21:40:18 +00:00
|
|
|
|
2022-10-05 20:33:16 +00:00
|
|
|
void free_trusted_setup_wrap(KZGSettings* s) {
|
|
|
|
free_trusted_setup(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
2022-10-04 21:40:18 +00:00
|
|
|
BLSFieldElement* bytes_to_bls_field_wrap(const uint8_t bytes[]) {
|
|
|
|
BLSFieldElement* out = (BLSFieldElement*)malloc(sizeof(BLSFieldElement));
|
|
|
|
bytes_to_bls_field(out, bytes);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t* uint64s_from_bls_field(BLSFieldElement *fr) {
|
|
|
|
uint64_t *r = (uint64_t*)calloc(4, sizeof(uint64_t));
|
|
|
|
uint64s_from_BLSFieldElement(r, fr);
|
|
|
|
return r;
|
|
|
|
}
|