Skip to content

Commit

Permalink
Rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
b-wagn committed Oct 9, 2024
1 parent e4fa09d commit 447c5b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
34 changes: 17 additions & 17 deletions src/eip7594/fk20.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void toeplitz_coeffs_stride(fr_t *out, const fr_t *in, size_t offset) {
*/
C_KZG_RET compute_fk20_cell_proofs(g1_t *out, const fr_t *p, const KZGSettings *s) {
C_KZG_RET ret;
size_t k, k2;
size_t k, size_circ_domain;

blst_scalar *scalars = NULL;
fr_t **coeffs = NULL;
Expand All @@ -72,22 +72,22 @@ C_KZG_RET compute_fk20_cell_proofs(g1_t *out, const fr_t *p, const KZGSettings *
bool precompute = s->wbits != 0;

/* Initialize length variables */
k = FIELD_ELEMENTS_PER_BLOB / FIELD_ELEMENTS_PER_CELL;
k = CELLS_PER_BLOB;
/*
* Note: this constant 2 is not related to `LOG_EXPANSION_FACTOR`.
* Instead, it is related to circulant matrices used in FK20, see
* Section 2.2 and 3.2 in https://eprint.iacr.org/2023/033.pdf.
*/
k2 = k * 2;
size_circ_domain = k * 2;

/* Do allocations */
ret = new_fr_array(&toeplitz_coeffs, k2);
ret = new_fr_array(&toeplitz_coeffs, size_circ_domain);
if (ret != C_KZG_OK) goto out;
ret = new_fr_array(&toeplitz_coeffs_fft, k2);
ret = new_fr_array(&toeplitz_coeffs_fft, size_circ_domain);
if (ret != C_KZG_OK) goto out;
ret = new_g1_array(&h_ext_fft, k2);
ret = new_g1_array(&h_ext_fft, size_circ_domain);
if (ret != C_KZG_OK) goto out;
ret = new_g1_array(&h, k2);
ret = new_g1_array(&h, size_circ_domain);
if (ret != C_KZG_OK) goto out;

if (precompute) {
Expand All @@ -99,30 +99,30 @@ C_KZG_RET compute_fk20_cell_proofs(g1_t *out, const fr_t *p, const KZGSettings *
}

/* Allocate 2d array for coefficients by column */
ret = c_kzg_calloc((void **)&coeffs, k2, sizeof(void *));
ret = c_kzg_calloc((void **)&coeffs, size_circ_domain, sizeof(void *));
if (ret != C_KZG_OK) goto out;
for (size_t i = 0; i < k2; i++) {
for (size_t i = 0; i < size_circ_domain; i++) {
ret = new_fr_array(&coeffs[i], k);
if (ret != C_KZG_OK) goto out;
}

/* Initialize values to zero */
for (size_t i = 0; i < k2; i++) {
for (size_t i = 0; i < size_circ_domain; i++) {
h_ext_fft[i] = G1_IDENTITY;
}

/* Compute toeplitz coefficients and organize by column */
for (size_t i = 0; i < FIELD_ELEMENTS_PER_CELL; i++) {
toeplitz_coeffs_stride(toeplitz_coeffs, p, i);
ret = fr_fft(toeplitz_coeffs_fft, toeplitz_coeffs, k2, s);
ret = fr_fft(toeplitz_coeffs_fft, toeplitz_coeffs, size_circ_domain, s);
if (ret != C_KZG_OK) goto out;
for (size_t j = 0; j < k2; j++) {
for (size_t j = 0; j < size_circ_domain; j++) {
coeffs[j][i] = toeplitz_coeffs_fft[j];
}
}

/* Compute h_ext_fft via MSM */
for (size_t i = 0; i < k2; i++) {
for (size_t i = 0; i < size_circ_domain; i++) {
if (precompute) {
/* Transform the field elements to 255-bit scalars */
for (size_t j = 0; j < FIELD_ELEMENTS_PER_CELL; j++) {
Expand All @@ -149,21 +149,21 @@ C_KZG_RET compute_fk20_cell_proofs(g1_t *out, const fr_t *p, const KZGSettings *
}
}

ret = g1_ifft(h, h_ext_fft, k2, s);
ret = g1_ifft(h, h_ext_fft, size_circ_domain, s);
if (ret != C_KZG_OK) goto out;

/* Zero the second half of h */
for (size_t i = k; i < k2; i++) {
for (size_t i = k; i < size_circ_domain; i++) {
h[i] = G1_IDENTITY;
}

ret = g1_fft(out, h, k2, s);
ret = g1_fft(out, h, size_circ_domain, s);
if (ret != C_KZG_OK) goto out;

out:
c_kzg_free(scalars);
if (coeffs != NULL) {
for (size_t i = 0; i < k2; i++) {
for (size_t i = 0; i < size_circ_domain; i++) {
c_kzg_free(coeffs[i]);
}
c_kzg_free(coeffs);
Expand Down
26 changes: 13 additions & 13 deletions src/setup/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,23 @@ static C_KZG_RET toeplitz_part_1(g1_t *out, const g1_t *x, size_t n, const KZGSe
* Instead, it is related to circulant matrices used in FK20, see
* Section 2.2 and 3.2 in https://eprint.iacr.org/2023/033.pdf.
*/
size_t n2 = n * 2;
size_t size_circ_domain = n * 2;
g1_t *x_ext;

/* Create extended array of points */
ret = new_g1_array(&x_ext, n2);
ret = new_g1_array(&x_ext, size_circ_domain);
if (ret != C_KZG_OK) goto out;

/* Copy x & extend with zero */
for (size_t i = 0; i < n; i++) {
x_ext[i] = x[i];
}
for (size_t i = n; i < n2; i++) {
for (size_t i = n; i < size_circ_domain; i++) {
x_ext[i] = G1_IDENTITY;
}

/* Peform forward transformation */
ret = g1_fft(out, x_ext, n2, s);
ret = g1_fft(out, x_ext, size_circ_domain, s);
if (ret != C_KZG_OK) goto out;

out:
Expand All @@ -236,20 +236,20 @@ static C_KZG_RET toeplitz_part_1(g1_t *out, const g1_t *x, size_t n, const KZGSe
*/
static C_KZG_RET init_fk20_multi_settings(KZGSettings *s) {
C_KZG_RET ret;
size_t n, k, k2;
size_t n, k, size_circ_domain;
g1_t *x = NULL;
g1_t *points = NULL;
blst_p1_affine *p_affine = NULL;
bool precompute = s->wbits != 0;

n = FIELD_ELEMENTS_PER_BLOB;
k = n / FIELD_ELEMENTS_PER_CELL;
k = CELLS_PER_BLOB;
/*
* Note: this constant 2 is not related to `LOG_EXPANSION_FACTOR`.
* Instead, it is related to circulant matrices used in FK20, see
* Section 2.2 and 3.2 in https://eprint.iacr.org/2023/033.pdf.
*/
k2 = 2 * k;
size_circ_domain = 2 * k;

if (FIELD_ELEMENTS_PER_CELL >= NUM_G2_POINTS) {
ret = C_KZG_BADARGS;
Expand All @@ -259,13 +259,13 @@ static C_KZG_RET init_fk20_multi_settings(KZGSettings *s) {
/* Allocate space for arrays */
ret = new_g1_array(&x, k);
if (ret != C_KZG_OK) goto out;
ret = new_g1_array(&points, k2);
ret = new_g1_array(&points, size_circ_domain);
if (ret != C_KZG_OK) goto out;

/* Allocate space for array of pointers, this is a 2D array */
ret = c_kzg_calloc((void **)&s->x_ext_fft_columns, k2, sizeof(void *));
ret = c_kzg_calloc((void **)&s->x_ext_fft_columns, size_circ_domain, sizeof(void *));
if (ret != C_KZG_OK) goto out;
for (size_t i = 0; i < k2; i++) {
for (size_t i = 0; i < size_circ_domain; i++) {
ret = new_g1_array(&s->x_ext_fft_columns[i], FIELD_ELEMENTS_PER_CELL);
if (ret != C_KZG_OK) goto out;
}
Expand All @@ -284,14 +284,14 @@ static C_KZG_RET init_fk20_multi_settings(KZGSettings *s) {
if (ret != C_KZG_OK) goto out;

/* Reorganize from rows into columns */
for (size_t row = 0; row < k2; row++) {
for (size_t row = 0; row < size_circ_domain; row++) {
s->x_ext_fft_columns[row][offset] = points[row];
}
}

if (precompute) {
/* Allocate space for precomputed tables */
ret = c_kzg_calloc((void **)&s->tables, k2, sizeof(void *));
ret = c_kzg_calloc((void **)&s->tables, size_circ_domain, sizeof(void *));
if (ret != C_KZG_OK) goto out;

/* Allocate space for points in affine representation */
Expand All @@ -303,7 +303,7 @@ static C_KZG_RET init_fk20_multi_settings(KZGSettings *s) {
s->wbits, FIELD_ELEMENTS_PER_CELL
);

for (size_t i = 0; i < k2; i++) {
for (size_t i = 0; i < size_circ_domain; i++) {
/* Transform the points to affine representation */
const blst_p1 *p_arg[2] = {s->x_ext_fft_columns[i], NULL};
blst_p1s_to_affine(p_affine, p_arg, FIELD_ELEMENTS_PER_CELL);
Expand Down

0 comments on commit 447c5b2

Please sign in to comment.