From 6b5140af660bf02a77a061b283c5f8a7a5c49bd4 Mon Sep 17 00:00:00 2001 From: Dankrad Feist Date: Thu, 15 Sep 2022 15:44:21 +0100 Subject: [PATCH] Fixed test for check_proof_multi --- src/kzg_proofs.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/kzg_proofs.c b/src/kzg_proofs.c index 3a99e64..faf89e4 100644 --- a/src/kzg_proofs.c +++ b/src/kzg_proofs.c @@ -296,15 +296,15 @@ void proof_multi(void) { uint64_t coeffs[] = {1, 2, 3, 4, 7, 7, 7, 7, 13, 13, 13, 13, 13, 13, 13, 13}; int poly_len = sizeof coeffs / sizeof coeffs[0]; - FFTSettings fs1, fs2; - KZGSettings ks1, ks2; + FFTSettings fs; + KZGSettings ks; poly p; g1_t commitment, proof; fr_t x, tmp; bool result; // Compute proof at 2^coset_scale points - int coset_scale = 4, coset_len = (1 << coset_scale); + int coset_scale = 3, coset_len = (1 << coset_scale); fr_t y[coset_len]; uint64_t secrets_len = poly_len > coset_len ? poly_len : coset_len; @@ -319,38 +319,34 @@ void proof_multi(void) { // Initialise the secrets and data structures generate_trusted_setup(s1, s2, &secret, secrets_len); - TEST_CHECK(C_KZG_OK == new_fft_settings(&fs1, 4)); // ln_2 of poly_len - TEST_CHECK(C_KZG_OK == new_kzg_settings(&ks1, s1, s2, secrets_len, &fs1)); + TEST_CHECK(C_KZG_OK == new_fft_settings(&fs, 4)); // ln_2 of poly_len + TEST_CHECK(C_KZG_OK == new_kzg_settings(&ks, s1, s2, secrets_len, &fs)); // Commit to the polynomial - TEST_CHECK(C_KZG_OK == commit_to_poly(&commitment, &p, &ks1)); - - TEST_CHECK(C_KZG_OK == new_fft_settings(&fs2, coset_scale)); - TEST_CHECK(C_KZG_OK == new_kzg_settings(&ks2, s1, s2, secrets_len, &fs2)); + TEST_CHECK(C_KZG_OK == commit_to_poly(&commitment, &p, &ks)); // Compute proof at the points [x * root_i] 0 <= i < coset_len fr_from_uint64(&x, 5431); - TEST_CHECK(C_KZG_OK == compute_proof_multi(&proof, &p, &x, coset_len, &ks2)); + TEST_CHECK(C_KZG_OK == compute_proof_multi(&proof, &p, &x, coset_len, &ks)); // y_i is the value of the polynomial at each x_i + uint64_t stride = secrets_len / coset_len; for (int i = 0; i < coset_len; i++) { - fr_mul(&tmp, &x, &ks2.fs->expanded_roots_of_unity[i]); + fr_mul(&tmp, &x, &fs.expanded_roots_of_unity[i * stride]); eval_poly(&y[i], &p, &tmp); } // Verify the proof that the (unknown) polynomial has value y_i at x_i - TEST_CHECK(C_KZG_OK == check_proof_multi(&result, &commitment, &proof, &x, y, coset_len, &ks2)); + TEST_CHECK(C_KZG_OK == check_proof_multi(&result, &commitment, &proof, &x, y, coset_len, &ks)); TEST_CHECK(true == result); // Change a value and check that the proof fails fr_add(y + coset_len / 2, y + coset_len / 2, &fr_one); - TEST_CHECK(C_KZG_OK == check_proof_multi(&result, &commitment, &proof, &x, y, coset_len, &ks2)); + TEST_CHECK(C_KZG_OK == check_proof_multi(&result, &commitment, &proof, &x, y, coset_len, &ks)); TEST_CHECK(false == result); - free_fft_settings(&fs1); - free_fft_settings(&fs2); - free_kzg_settings(&ks1); - free_kzg_settings(&ks2); + free_fft_settings(&fs); + free_kzg_settings(&ks); free_poly(&p); }