Update csharp ckzg.c

This commit is contained in:
Ramana Kumar 2022-11-04 09:07:05 +00:00
parent 99a990ff32
commit ce8707b5b7
No known key found for this signature in database
GPG Key ID: ED471C788B900433
1 changed files with 16 additions and 36 deletions

View File

@ -22,59 +22,39 @@ void free_trusted_setup_wrap(KZGSettings *s) {
free(s);
}
void blob_to_kzg_commitment_wrap(uint8_t out[48], const uint8_t blob[FIELD_ELEMENTS_PER_BLOB * 32], const KZGSettings *s) {
Polynomial p;
for (size_t i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++)
bytes_to_bls_field(&p[i], &blob[i * 32]);
void blob_to_kzg_commitment_wrap(uint8_t out[48], const Blob blob, const KZGSettings *s) {
KZGCommitment c;
blob_to_kzg_commitment(&c, p, s);
blob_to_kzg_commitment(&c, blob, s);
bytes_from_g1(out, &c);
}
int verify_aggregate_kzg_proof_wrap(const uint8_t blobs[], const uint8_t commitments[], size_t n, const uint8_t proof[48], const KZGSettings *s) {
Polynomial* p = calloc(n, sizeof(Polynomial));
if (p == NULL) return -1;
int verify_aggregate_kzg_proof_wrap(const Blob blobs[], const uint8_t commitments[], size_t n, const uint8_t proof[48], const KZGSettings *s) {
KZGProof f;
C_KZG_RET ret;
ret = bytes_to_g1(&f, proof);
if (ret != C_KZG_OK) return -1;
KZGCommitment* c = calloc(n, sizeof(KZGCommitment));
if (c == NULL) { free(p); return -1; }
C_KZG_RET ret;
if (c == NULL) return -2;
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < FIELD_ELEMENTS_PER_BLOB; j++)
bytes_to_bls_field(&p[i][j], &blobs[i * FIELD_ELEMENTS_PER_BLOB * 32 + j * 32]);
ret = bytes_to_g1(&c[i], &commitments[i * 48]);
if (ret != C_KZG_OK) { free(c); free(p); return -1; }
if (ret != C_KZG_OK) { free(c); return -1; }
}
KZGProof f;
ret = bytes_to_g1(&f, proof);
if (ret != C_KZG_OK) { free(c); free(p); return -1; }
bool b;
ret = verify_aggregate_kzg_proof(&b, p, c, n, &f, s);
if (ret != C_KZG_OK) { free(c); free(p); return -1; }
ret = verify_aggregate_kzg_proof(&b, blobs, c, n, &f, s);
free(c);
if (ret != C_KZG_OK) return -1;
free(c); free(p);
return b ? 0 : 1;
}
C_KZG_RET compute_aggregate_kzg_proof_wrap(uint8_t out[48], const uint8_t blobs[], size_t n, const KZGSettings *s) {
Polynomial* p = calloc(n, sizeof(Polynomial));
if (p == NULL) return -1;
for (size_t i = 0; i < n; i++)
for (size_t j = 0; j < FIELD_ELEMENTS_PER_BLOB; j++)
bytes_to_bls_field(&p[i][j], &blobs[i * FIELD_ELEMENTS_PER_BLOB * 32 + j * 32]);
C_KZG_RET compute_aggregate_kzg_proof_wrap(uint8_t out[48], const Blob blobs[], size_t n, const KZGSettings *s) {
KZGProof f;
C_KZG_RET ret = compute_aggregate_kzg_proof(&f, p, n, s);
free(p);
if (ret != C_KZG_OK) return ret;
C_KZG_RET ret;
ret = compute_aggregate_kzg_proof(&f, blobs, n, s);
if (ret != C_KZG_OK) return -1;
bytes_from_g1(out, &f);
return C_KZG_OK;
}