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

Refactor is_cell_used array & usage #495

Merged
merged 4 commits into from
Aug 16, 2024
Merged
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
28 changes: 19 additions & 9 deletions src/eip7594/eip7594.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ static C_KZG_RET compute_commitment_to_aggregated_interpolation_poly(
// Array allocations
////////////////////////////////////////////////////////////////////////////////////////////////

ret = new_bool_array(&is_cell_used, FIELD_ELEMENTS_PER_EXT_BLOB);
ret = new_bool_array(&is_cell_used, CELLS_PER_EXT_BLOB);
if (ret != C_KZG_OK) goto out;
ret = new_fr_array(&aggregated_column_cells, FIELD_ELEMENTS_PER_EXT_BLOB);
if (ret != C_KZG_OK) goto out;
Expand All @@ -502,7 +502,6 @@ static C_KZG_RET compute_commitment_to_aggregated_interpolation_poly(
for (size_t j = 0; j < FIELD_ELEMENTS_PER_CELL; j++) {
size_t index = i * FIELD_ELEMENTS_PER_CELL + j;
aggregated_column_cells[index] = FR_ZERO;
is_cell_used[index] = false;
}
}

Expand All @@ -524,12 +523,23 @@ static C_KZG_RET compute_commitment_to_aggregated_interpolation_poly(
blst_fr_add(
&aggregated_column_cells[index], &aggregated_column_cells[index], &scaled_fr
);

/* Mark the cell as being used */
is_cell_used[index] = true;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////
// Determine which cells are used
////////////////////////////////////////////////////////////////////////////////////////////////

/* Start with false values */
for (size_t i = 0; i < CELLS_PER_EXT_BLOB; i++) {
is_cell_used[i] = false;
}

/* Mark each cell index as used */
for (uint64_t i = 0; i < num_cells; i++) {
jtraglia marked this conversation as resolved.
Show resolved Hide resolved
is_cell_used[cell_indices[i]] = true;
}

////////////////////////////////////////////////////////////////////////////////////////////////
// Compute interpolation polynomials using the aggregated cells
////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -541,12 +551,12 @@ static C_KZG_RET compute_commitment_to_aggregated_interpolation_poly(

/* Interpolate each column */
for (size_t i = 0; i < CELLS_PER_EXT_BLOB; i++) {
/* We can skip columns without any cells */
if (!is_cell_used[i]) continue;

/* Offset to the first cell for this column */
size_t index = i * FIELD_ELEMENTS_PER_CELL;

/* We only care about initialized cells */
if (!is_cell_used[index]) continue;

/* We don't need to copy this because it's not used again */
ret = bit_reversal_permutation(
&aggregated_column_cells[index], sizeof(fr_t), FIELD_ELEMENTS_PER_CELL
Expand Down Expand Up @@ -660,7 +670,7 @@ C_KZG_RET verify_cell_kzg_proof_batch(
}

////////////////////////////////////////////////////////////////////////////////////////////////
// Deduplicate Commitments
// Deduplicate commitments
////////////////////////////////////////////////////////////////////////////////////////////////

ret = c_kzg_calloc((void **)&unique_commitments, num_cells, sizeof(Bytes48));
Expand Down
Loading