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

EIP-7594: Add asserts for public functions #3684

Merged
merged 9 commits into from
Apr 23, 2024
23 changes: 23 additions & 0 deletions specs/_features/eip7594/polynomial-commitments-sampling.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ def compute_cells_and_proofs(blob: Blob) -> Tuple[

Public method.
"""
assert len(blob) == BYTES_PER_BLOB

polynomial = blob_to_polynomial(blob)
polynomial_coeff = polynomial_eval_to_coeff(polynomial)

Expand All @@ -407,6 +409,8 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]:

Public method.
"""
assert len(blob) == BYTES_PER_BLOB

polynomial = blob_to_polynomial(blob)
polynomial_coeff = polynomial_eval_to_coeff(polynomial)

Expand All @@ -431,6 +435,12 @@ def verify_cell_proof(commitment_bytes: Bytes48,

Public method.
"""
assert len(commitment_bytes) == BYTES_PER_COMMITMENT
assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL
for field_bytes in cell_bytes:
assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT
assert len(proof_bytes) == BYTES_PER_PROOF

coset = coset_for_cell(cell_id)

return verify_kzg_proof_multi_impl(
Expand Down Expand Up @@ -463,6 +473,14 @@ def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48],
Public method.
"""
assert len(cells_bytes) == len(proofs_bytes) == len(row_indices) == len(column_indices)
for commitment_bytes in row_commitments_bytes:
assert len(commitment_bytes) == BYTES_PER_COMMITMENT
for cell_bytes in cells_bytes:
assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL
for field_bytes in cell_bytes:
assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT
for proof_bytes in proofs_bytes:
assert len(proof_bytes) == BYTES_PER_PROOF

jtraglia marked this conversation as resolved.
Show resolved Hide resolved
# Get commitments via row IDs
commitments_bytes = [row_commitments_bytes[row_index] for row_index in row_indices]
Expand Down Expand Up @@ -608,6 +626,11 @@ def recover_polynomial(cell_ids: Sequence[CellID],
assert CELLS_PER_BLOB / 2 <= len(cell_ids) <= CELLS_PER_BLOB
# Check for duplicates
assert len(cell_ids) == len(set(cell_ids))
# Check that each cell is the correct length
for cell_bytes in cells_bytes:
assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL
for field_bytes in cell_bytes:
assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT

# Get the extended domain
roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB)
Expand Down
Loading