Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #19

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fft_g1.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ TEST_LIST = {
{NULL, NULL} /* zero record marks the end of the list */
};

#endif // KZGTEST
#endif // KZGTEST
8 changes: 4 additions & 4 deletions src/fk20_proofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void fk_single(void) {
FFTSettings fs;
KZGSettings ks;
FK20SingleSettings fk;
uint64_t secrets_len = n_len + 1;
uint64_t secrets_len = n_len;
g1_t s1[secrets_len];
g2_t s2[secrets_len];
poly p;
Expand Down Expand Up @@ -558,7 +558,7 @@ void fk_single_strided(void) {
FFTSettings fs;
KZGSettings ks;
FK20SingleSettings fk;
uint64_t secrets_len = n_len + 1;
uint64_t secrets_len = n_len;
g1_t s1[secrets_len];
g2_t s2[secrets_len];
poly p;
Expand Down Expand Up @@ -606,7 +606,7 @@ void fk_multi_settings(void) {
KZGSettings ks;
FK20MultiSettings fk;
uint64_t n = 5;
uint64_t secrets_len = 33;
uint64_t secrets_len = 32;
g1_t s1[secrets_len];
g2_t s2[secrets_len];

Expand Down Expand Up @@ -764,4 +764,4 @@ TEST_LIST = {
{NULL, NULL} /* zero record marks the end of the list */
};

#endif
#endif
32 changes: 14 additions & 18 deletions src/kzg_proofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void proof_single(void) {
// Our polynomial: degree 15, 16 coefficients
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];
uint64_t secrets_len = poly_len + 1;
uint64_t secrets_len = poly_len;

FFTSettings fs;
KZGSettings ks;
Expand Down Expand Up @@ -296,8 +296,8 @@ 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;
Expand All @@ -307,7 +307,7 @@ void proof_multi(void) {
int coset_scale = 3, coset_len = (1 << coset_scale);
fr_t y[coset_len];

uint64_t secrets_len = poly_len > coset_len ? poly_len + 1 : coset_len + 1;
uint64_t secrets_len = poly_len > coset_len ? poly_len : coset_len;
g1_t s1[secrets_len];
g2_t s2[secrets_len];

Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,4 +978,4 @@ TEST_LIST = {
{NULL, NULL} /* zero record marks the end of the list */
};

#endif // KZGTEST
#endif // KZGTEST