1212- [ Preset] ( #preset )
1313 - [ Cells] ( #cells )
1414- [ Helper functions] ( #helper-functions )
15+ - [ BLS12-381 helpers] ( #bls12-381-helpers )
16+ - [ ` bytes_to_cell ` ] ( #bytes_to_cell )
1517 - [ Linear combinations] ( #linear-combinations )
1618 - [ ` g2_lincomb ` ] ( #g2_lincomb )
1719 - [ FFTs] ( #ffts )
@@ -81,6 +83,18 @@ Cells are the smallest unit of blob data that can come with their own KZG proofs
8183
8284## Helper functions
8385
86+ ### BLS12-381 helpers
87+
88+ #### ` bytes_to_cell `
89+
90+ ``` python
91+ def bytes_to_cell (cell_bytes : Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ]) -> Cell:
92+ """
93+ Convert untrusted bytes into a Cell.
94+ """
95+ return [bytes_to_bls_field(element) for element in cell_bytes]
96+ ```
97+
8498### Linear combinations
8599
86100#### ` g2_lincomb `
@@ -397,28 +411,32 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]:
397411#### ` verify_cell_proof `
398412
399413``` python
400- def verify_cell_proof (commitment : KZGCommitment ,
414+ def verify_cell_proof (commitment_bytes : Bytes48 ,
401415 cell_id : int ,
402- cell : Cell ,
403- proof : KZGProof ) -> bool :
416+ cell_bytes : Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ] ,
417+ proof : Bytes48 ) -> bool :
404418 """
405419 Check a cell proof
406420
407421 Public method.
408422 """
409423 coset = coset_for_cell(cell_id)
410424
411- return verify_kzg_proof_multi_impl(commitment, coset, cell, proof)
425+ return verify_kzg_proof_multi_impl(
426+ bytes_to_kzg_commitment(commitment_bytes),
427+ coset,
428+ bytes_to_cell(cell_bytes),
429+ bytes_to_kzg_proof(proof))
412430```
413431
414432#### ` verify_cell_proof_batch `
415433
416434``` python
417- def verify_cell_proof_batch (row_commitments : Sequence[KZGCommitment ],
435+ def verify_cell_proof_batch (row_commitments_bytes : Sequence[Bytes48 ],
418436 row_ids : Sequence[int ],
419437 column_ids : Sequence[int ],
420- cells : Sequence[Cell ],
421- proofs : Sequence[KZGProof ]) -> bool :
438+ cells_bytes : Sequence[Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ] ],
439+ proofs_bytes : Sequence[Bytes48 ]) -> bool :
422440 """
423441 Check multiple cell proofs. This function implements the naive algorithm of checking every cell
424442 individually; an efficient algorithm can be found here:
@@ -430,10 +448,14 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
430448
431449 Public method.
432450 """
433-
434451 # Get commitments via row IDs
435- commitments = [row_commitments[row_id] for row_id in row_ids]
436-
452+ commitments_bytes = [row_commitments_bytes[row_id] for row_id in row_ids]
453+
454+ # Get objects from bytes
455+ commitments = [bytes_to_kzg_commitment(commitment_bytes) for commitment_bytes in commitments_bytes]
456+ cells = [bytes_to_cell(cell_bytes) for cell_bytes in cells_bytes]
457+ proofs = [bytes_to_kzg_proof(proof_bytes) for proof_bytes in proofs_bytes]
458+
437459 return all (
438460 verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_id), cell, proof)
439461 for commitment, column_id, cell, proof in zip (commitments, column_ids, cells, proofs)
@@ -445,7 +467,8 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
445467### ` recover_polynomial `
446468
447469``` python
448- def recover_polynomial (cell_ids : Sequence[CellID], cells : Sequence[Cell]) -> Polynomial:
470+ def recover_polynomial (cell_ids : Sequence[CellID],
471+ cells_bytes : Sequence[Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ]]) -> Polynomial:
449472 """
450473 Recovers a polynomial from 2 * FIELD_ELEMENTS_PER_CELL evaluations, half of which can be missing.
451474
@@ -455,7 +478,10 @@ def recover_polynomial(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Pol
455478
456479 Public method.
457480 """
458- assert len (cell_ids) == len (cells)
481+ assert len (cell_ids) == len (cells_bytes)
482+
483+ cells = [bytes_to_cell(cell_bytes) for cell_bytes in cells_bytes]
484+
459485 assert len (cells) >= CELLS_PER_BLOB // 2
460486 missing_cell_ids = [cell_id for cell_id in range (CELLS_PER_BLOB ) if cell_id not in cell_ids]
461487 roots_of_unity_reduced = compute_roots_of_unity(CELLS_PER_BLOB )
0 commit comments