@@ -81,6 +81,18 @@ Cells are the smallest unit of blob data that can come with their own KZG proofs
81
81
82
82
## Helper functions
83
83
84
+ ### BLS12-381 helpers
85
+
86
+ #### ` bytes_to_cell `
87
+
88
+ ``` python
89
+ def bytes_to_cell (cell_bytes : Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ]) -> Cell:
90
+ """
91
+ Convert untrusted bytes into a Cell.
92
+ """
93
+ return [bytes_to_bls_field(element) for element in cell_bytes]
94
+ ```
95
+
84
96
### Linear combinations
85
97
86
98
#### ` g2_lincomb `
@@ -397,28 +409,32 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]:
397
409
#### ` verify_cell_proof `
398
410
399
411
``` python
400
- def verify_cell_proof (commitment : KZGCommitment ,
412
+ def verify_cell_proof (commitment_bytes : Bytes48 ,
401
413
cell_id : int ,
402
- cell : Cell ,
403
- proof : KZGProof ) -> bool :
414
+ cell_bytes : Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ] ,
415
+ proof : Bytes48 ) -> bool :
404
416
"""
405
417
Check a cell proof
406
418
407
419
Public method.
408
420
"""
409
421
coset = coset_for_cell(cell_id)
410
422
411
- return verify_kzg_proof_multi_impl(commitment, coset, cell, proof)
423
+ return verify_kzg_proof_multi_impl(
424
+ bytes_to_kzg_commitment(commitment_bytes),
425
+ coset,
426
+ bytes_to_cell(cell_bytes),
427
+ bytes_to_kzg_proof(proof))
412
428
```
413
429
414
430
#### ` verify_cell_proof_batch `
415
431
416
432
``` python
417
- def verify_cell_proof_batch (row_commitments : Sequence[KZGCommitment ],
433
+ def verify_cell_proof_batch (row_commitments_bytes : Sequence[Bytes48 ],
418
434
row_ids : Sequence[int ],
419
435
column_ids : Sequence[int ],
420
- cells : Sequence[Cell ],
421
- proofs : Sequence[KZGProof ]) -> bool :
436
+ cells_bytes : Sequence[Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ] ],
437
+ proofs_bytes : Sequence[Bytes48 ]) -> bool :
422
438
"""
423
439
Check multiple cell proofs. This function implements the naive algorithm of checking every cell
424
440
individually; an efficient algorithm can be found here:
@@ -430,10 +446,14 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
430
446
431
447
Public method.
432
448
"""
433
-
434
449
# Get commitments via row IDs
435
- commitments = [row_commitments[row_id] for row_id in row_ids]
436
-
450
+ commitments_bytes = [row_commitments_bytes[row_id] for row_id in row_ids]
451
+
452
+ # Get objects from bytes
453
+ commitments = [bytes_to_kzg_commitment(commitment_bytes) for commitment_bytes in commitments_bytes]
454
+ cells = [bytes_to_cell(cell_bytes) for cell_bytes in cells_bytes]
455
+ proofs = [bytes_to_kzg_proof(proof_bytes) for proof_bytes in proofs_bytes]
456
+
437
457
return all (
438
458
verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_id), cell, proof)
439
459
for commitment, column_id, cell, proof in zip (commitments, column_ids, cells, proofs)
@@ -445,7 +465,8 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
445
465
### ` recover_polynomial `
446
466
447
467
``` python
448
- def recover_polynomial (cell_ids : Sequence[CellID], cells : Sequence[Cell]) -> Polynomial:
468
+ def recover_polynomial (cell_ids : Sequence[CellID],
469
+ cells_bytes : Sequence[Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ]]) -> Polynomial:
449
470
"""
450
471
Recovers a polynomial from 2 * FIELD_ELEMENTS_PER_CELL evaluations, half of which can be missing.
451
472
@@ -455,7 +476,10 @@ def recover_polynomial(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Pol
455
476
456
477
Public method.
457
478
"""
458
- assert len (cell_ids) == len (cells)
479
+ assert len (cell_ids) == len (cells_bytes)
480
+
481
+ cells = [bytes_to_cell(cell_bytes) for cell_bytes in cells_bytes]
482
+
459
483
assert len (cells) >= CELLS_PER_BLOB // 2
460
484
missing_cell_ids = [cell_id for cell_id in range (CELLS_PER_BLOB ) if cell_id not in cell_ids]
461
485
roots_of_unity_reduced = compute_roots_of_unity(CELLS_PER_BLOB )
0 commit comments