From 5c90a4e5a06f0b0bd5f76c5026ad439c42f664b9 Mon Sep 17 00:00:00 2001 From: Ramana Kumar Date: Mon, 10 Oct 2022 23:21:05 +0100 Subject: [PATCH] Change evaluate_polynomial_in_evaluation_form interface --- min-bindings/csharp/ckzg.c | 26 ++++++-------------------- min-bindings/csharp/tests.cs | 8 ++++---- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/min-bindings/csharp/ckzg.c b/min-bindings/csharp/ckzg.c index 56ccd84..a71a8d9 100644 --- a/min-bindings/csharp/ckzg.c +++ b/min-bindings/csharp/ckzg.c @@ -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) { diff --git a/min-bindings/csharp/tests.cs b/min-bindings/csharp/tests.cs index 4f6d6e9..3601b5b 100644 --- a/min-bindings/csharp/tests.cs +++ b/min-bindings/csharp/tests.cs @@ -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))