Fixed test for check_proof_multi
This commit is contained in:
parent
9bd8c3fdf8
commit
6b5140af66
|
@ -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};
|
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];
|
int poly_len = sizeof coeffs / sizeof coeffs[0];
|
||||||
|
|
||||||
FFTSettings fs1, fs2;
|
FFTSettings fs;
|
||||||
KZGSettings ks1, ks2;
|
KZGSettings ks;
|
||||||
poly p;
|
poly p;
|
||||||
g1_t commitment, proof;
|
g1_t commitment, proof;
|
||||||
fr_t x, tmp;
|
fr_t x, tmp;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
// Compute proof at 2^coset_scale points
|
// 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];
|
fr_t y[coset_len];
|
||||||
|
|
||||||
uint64_t secrets_len = poly_len > coset_len ? poly_len : 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
|
// Initialise the secrets and data structures
|
||||||
generate_trusted_setup(s1, s2, &secret, secrets_len);
|
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_fft_settings(&fs, 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_kzg_settings(&ks, s1, s2, secrets_len, &fs));
|
||||||
|
|
||||||
// Commit to the polynomial
|
// Commit to the polynomial
|
||||||
TEST_CHECK(C_KZG_OK == commit_to_poly(&commitment, &p, &ks1));
|
TEST_CHECK(C_KZG_OK == commit_to_poly(&commitment, &p, &ks));
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
// Compute proof at the points [x * root_i] 0 <= i < coset_len
|
// Compute proof at the points [x * root_i] 0 <= i < coset_len
|
||||||
fr_from_uint64(&x, 5431);
|
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
|
// 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++) {
|
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);
|
eval_poly(&y[i], &p, &tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the proof that the (unknown) polynomial has value y_i at x_i
|
// 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);
|
TEST_CHECK(true == result);
|
||||||
|
|
||||||
// Change a value and check that the proof fails
|
// Change a value and check that the proof fails
|
||||||
fr_add(y + coset_len / 2, y + coset_len / 2, &fr_one);
|
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);
|
TEST_CHECK(false == result);
|
||||||
|
|
||||||
free_fft_settings(&fs1);
|
free_fft_settings(&fs);
|
||||||
free_fft_settings(&fs2);
|
free_kzg_settings(&ks);
|
||||||
free_kzg_settings(&ks1);
|
|
||||||
free_kzg_settings(&ks2);
|
|
||||||
free_poly(&p);
|
free_poly(&p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue