Change evaluate_polynomial_in_evaluation_form interface

This commit is contained in:
Ramana Kumar 2022-10-10 23:21:05 +01:00
parent dd242cd93c
commit 5c90a4e5a0
No known key found for this signature in database
GPG Key ID: ED471C788B900433
2 changed files with 10 additions and 24 deletions

View File

@ -90,28 +90,14 @@ KZGSettings* load_trusted_setup_wrap(const char* file) {
return out;
}
int evaluate_polynomial_wrap(uint8_t out[32], const uint8_t pvals[], size_t n, const uint8_t point[32], const KZGSettings *s) {
PolynomialEvalForm p;
BLSFieldElement* evaluate_polynomial_wrap(const PolynomialEvalForm* p, const BLSFieldElement* z, const KZGSettings *s) {
BLSFieldElement *out = (BLSFieldElement*)malloc(sizeof(BLSFieldElement));
if (out == NULL) return NULL;
if (alloc_polynomial(&p, n) != C_KZG_OK)
return -1;
if (evaluate_polynomial_in_evaluation_form(out, p, z, s) != C_KZG_OK)
return NULL;
for (size_t i = 0; i < n; i++)
bytes_to_bls_field(&p.values[i], &pvals[i * 32]);
BLSFieldElement z;
bytes_to_bls_field(&z, point);
BLSFieldElement r;
if (evaluate_polynomial_in_evaluation_form(&r, &p, &z, s) != C_KZG_OK) {
free_polynomial(&p);
return -1;
}
bytes_from_bls_field(out, &r);
return 0;
return out;
}
void free_trusted_setup_wrap(KZGSettings* s) {

View File

@ -21,8 +21,8 @@ class ckzg
[DllImport("ckzg.dll", EntryPoint = "verify_kzg_proof_wrap")]
public static extern bool verify_kzg_proof(byte[] c, byte[] x, byte[] y, byte[] p, IntPtr ts);
[DllImport("ckzg.dll", EntryPoint = "evaluate_polynomial_wrap")]
public static extern bool evaluate_polynomial_in_evaluation_form(byte[] result, byte[] p, UInt64 n, byte[] z, IntPtr ts);
[DllImport("ckzg.dll", EntryPoint = "evaluate_polynomial_wrap")] // free result with free()
public static extern IntPtr evaluate_polynomial_in_evaluation_form(IntPtr p, IntPtr z, IntPtr ts);
[DllImport("ckzg.dll", EntryPoint = "load_trusted_setup_wrap")] // free result with free_trusted_setup()
public static extern IntPtr load_trusted_setup(string filename);
@ -40,7 +40,7 @@ class ckzg
class tests
{
IntPtr ts = ckzg.load_trusted_setup("../../src/trusted_setup.txt");
byte[] ssz_of(params object[] anything)
{
return new byte[1]; //mock
@ -103,7 +103,7 @@ class tests
ssz_of("PolynomialAndCommitment", aggregated_poly, aggregated_poly_commitment)
);
// Evaluate aggregated polynomial at `x` (evaluation function checks for div-by-zero)
var y = ckzg.evaluate_polynomial_in_evaluation_form(aggregated_poly, x, "need to clarify", "need to clarify", ts);
var y = ckzg.evaluate_polynomial_in_evaluation_form(aggregated_poly, x, ts);
// Verify aggregated proof
if (!ckzg.verify_kzg_proof(aggregated_poly_commitment, x, y, "need to clarify", ts))