Merge pull request #1 from ethereum/verify_takes_bytes

Update interface for verify_kzg_proof
This commit is contained in:
Ramana Kumar 2022-11-21 17:52:41 +00:00 committed by GitHub
commit d9e0f133e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 17 deletions

View File

@ -33,7 +33,7 @@ public class Ckzg
public static unsafe extern int verify_aggregate_kzg_proof(byte[] blobs, byte[] commitments, int blobCount, byte[] proof, IntPtr ts); public static unsafe extern int verify_aggregate_kzg_proof(byte[] blobs, byte[] commitments, int blobCount, byte[] proof, IntPtr ts);
[DllImport("ckzg", EntryPoint = "verify_kzg_proof_wrap", CallingConvention = CallingConvention.Cdecl)] // returns 0 on success [DllImport("ckzg", EntryPoint = "verify_kzg_proof_wrap", CallingConvention = CallingConvention.Cdecl)] // returns 0 on success
public static extern int verify_kzg_proof(byte[/*48*/] commitment, byte[/*32*/] x, byte[/*32*/] y, byte[/*48*/] proof, IntPtr ts); public static extern int verify_kzg_proof(byte[/*48*/] commitment, byte[/*32*/] z, byte[/*32*/] y, byte[/*48*/] proof, IntPtr ts);
[DllImport("ckzg", EntryPoint = "load_trusted_setup_wrap")] // free result with free_trusted_setup() [DllImport("ckzg", EntryPoint = "load_trusted_setup_wrap")] // free result with free_trusted_setup()
public static extern IntPtr load_trusted_setup(string filename); public static extern IntPtr load_trusted_setup(string filename);

View File

@ -60,18 +60,15 @@ C_KZG_RET compute_aggregate_kzg_proof_wrap(uint8_t out[48], const Blob blobs[],
return C_KZG_OK; return C_KZG_OK;
} }
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) { int verify_kzg_proof_wrap(const uint8_t c[48], const uint8_t z[32], const uint8_t y[32], const uint8_t p[48], KZGSettings *s) {
KZGCommitment commitment; KZGCommitment commitment;
KZGProof proof; KZGProof proof;
BLSFieldElement fx, fy;
bool out; bool out;
bytes_to_bls_field(&fx, x);
bytes_to_bls_field(&fy, y);
if (bytes_to_g1(&commitment, c) != C_KZG_OK) return -1; if (bytes_to_g1(&commitment, c) != C_KZG_OK) return -1;
if (bytes_to_g1(&proof, p) != C_KZG_OK) return -1; if (bytes_to_g1(&proof, p) != C_KZG_OK) return -1;
if (verify_kzg_proof(&out, &commitment, &fx, &fy, &proof, s) != C_KZG_OK) if (verify_kzg_proof(&out, &commitment, z, y, &proof, s) != C_KZG_OK)
return -2; return -2;
return out ? 0 : 1; return out ? 0 : 1;

View File

@ -6,7 +6,7 @@
#ifdef _WIN32 #ifdef _WIN32
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT #define DLLEXPORT
#endif #endif
DLLEXPORT KZGSettings* load_trusted_setup_wrap(const char* file); DLLEXPORT KZGSettings* load_trusted_setup_wrap(const char* file);
@ -19,4 +19,4 @@ DLLEXPORT int verify_aggregate_kzg_proof_wrap(const Blob blobs[], const uint8_t
DLLEXPORT C_KZG_RET compute_aggregate_kzg_proof_wrap(uint8_t out[48], const Blob blobs[], size_t n, const KZGSettings *s); DLLEXPORT C_KZG_RET compute_aggregate_kzg_proof_wrap(uint8_t out[48], const Blob blobs[], size_t n, const KZGSettings *s);
DLLEXPORT 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); DLLEXPORT int verify_kzg_proof_wrap(const uint8_t c[48], const uint8_t z[32], const uint8_t y[32], const uint8_t p[48], KZGSettings *s);

View File

@ -306,10 +306,6 @@ Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
auto kzg_settings = info[4].As<Napi::External<KZGSettings>>().Data(); auto kzg_settings = info[4].As<Napi::External<KZGSettings>>().Data();
BLSFieldElement fz, fy;
bytes_to_bls_field(&fz, z);
bytes_to_bls_field(&fy, y);
KZGCommitment commitment; KZGCommitment commitment;
auto ret = bytes_to_g1(&commitment, polynomial_kzg); auto ret = bytes_to_g1(&commitment, polynomial_kzg);
if (ret != C_KZG_OK) { if (ret != C_KZG_OK) {
@ -327,7 +323,7 @@ Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
} }
bool out; bool out;
if (verify_kzg_proof(&out, &commitment, &fz, &fy, &proof, kzg_settings) != C_KZG_OK) { if (verify_kzg_proof(&out, &commitment, z, y, &proof, kzg_settings) != C_KZG_OK) {
Napi::TypeError::New(env, "Failed to verify KZG proof").ThrowAsJavaScriptException(); Napi::TypeError::New(env, "Failed to verify KZG proof").ThrowAsJavaScriptException();
return env.Null(); return env.Null();
} }

View File

@ -934,7 +934,7 @@ void blob_to_kzg_commitment(KZGCommitment *out, const Blob blob, const KZGSettin
* @param[in] ks The settings containing the secrets, previously initialised with #new_kzg_settings * @param[in] ks The settings containing the secrets, previously initialised with #new_kzg_settings
* @retval C_CZK_OK All is well * @retval C_CZK_OK All is well
*/ */
C_KZG_RET verify_kzg_proof(bool *out, const g1_t *commitment, const fr_t *x, const fr_t *y, static C_KZG_RET verify_kzg_proof_impl(bool *out, const g1_t *commitment, const fr_t *x, const fr_t *y,
const g1_t *proof, const KZGSettings *ks) { const g1_t *proof, const KZGSettings *ks) {
g2_t x_g2, s_minus_x; g2_t x_g2, s_minus_x;
g1_t y_g1, commitment_minus_y; g1_t y_g1, commitment_minus_y;
@ -948,6 +948,18 @@ C_KZG_RET verify_kzg_proof(bool *out, const g1_t *commitment, const fr_t *x, con
return C_KZG_OK; return C_KZG_OK;
} }
C_KZG_RET verify_kzg_proof(bool *out,
const KZGCommitment *commitment,
const uint8_t z[BYTES_PER_FIELD_ELEMENT],
const uint8_t y[BYTES_PER_FIELD_ELEMENT],
const KZGProof *kzg_proof,
const KZGSettings *s) {
BLSFieldElement frz, fry;
bytes_to_bls_field(&frz, z);
bytes_to_bls_field(&fry, y);
return verify_kzg_proof_impl(out, commitment, &frz, &fry, kzg_proof, s);
}
static C_KZG_RET evaluate_polynomial_in_evaluation_form(BLSFieldElement *out, const Polynomial p, const BLSFieldElement *x, const KZGSettings *s) { static C_KZG_RET evaluate_polynomial_in_evaluation_form(BLSFieldElement *out, const Polynomial p, const BLSFieldElement *x, const KZGSettings *s) {
fr_t tmp, *inverses_in, *inverses; fr_t tmp, *inverses_in, *inverses;
uint64_t i; uint64_t i;
@ -1190,5 +1202,5 @@ C_KZG_RET verify_aggregate_kzg_proof(bool *out,
BLSFieldElement y; BLSFieldElement y;
TRY(evaluate_polynomial_in_evaluation_form(&y, aggregated_poly, &evaluation_challenge, s)); TRY(evaluate_polynomial_in_evaluation_form(&y, aggregated_poly, &evaluation_challenge, s));
return verify_kzg_proof(out, &aggregated_poly_commitment, &evaluation_challenge, &y, kzg_aggregated_proof, s); return verify_kzg_proof_impl(out, &aggregated_poly_commitment, &evaluation_challenge, &y, kzg_aggregated_proof, s);
} }

View File

@ -116,8 +116,8 @@ void blob_to_kzg_commitment(KZGCommitment *out,
C_KZG_RET verify_kzg_proof(bool *out, C_KZG_RET verify_kzg_proof(bool *out,
const KZGCommitment *polynomial_kzg, const KZGCommitment *polynomial_kzg,
const BLSFieldElement *z, const uint8_t z[BYTES_PER_FIELD_ELEMENT],
const BLSFieldElement *y, const uint8_t y[BYTES_PER_FIELD_ELEMENT],
const KZGProof *kzg_proof, const KZGProof *kzg_proof,
const KZGSettings *s); const KZGSettings *s);