Skip to content

Commit

Permalink
Refactor is_cell_used array & usage (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtraglia authored Aug 16, 2024
1 parent 65e39fe commit 29932c3
Showing 1 changed file with 19 additions and 9 deletions.
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++) {
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

0 comments on commit 29932c3

Please sign in to comment.