12
12
- [ Preset] ( #preset )
13
13
- [ Cells] ( #cells )
14
14
- [ Helper functions] ( #helper-functions )
15
+ - [ BLS12-381 helpers] ( #bls12-381-helpers )
16
+ - [ ` bytes_to_cell ` ] ( #bytes_to_cell )
15
17
- [ Linear combinations] ( #linear-combinations )
16
18
- [ ` g2_lincomb ` ] ( #g2_lincomb )
17
19
- [ FFTs] ( #ffts )
@@ -81,6 +83,18 @@ Cells are the smallest unit of blob data that can come with their own KZG proofs
81
83
82
84
## Helper functions
83
85
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
+
84
98
### Linear combinations
85
99
86
100
#### ` g2_lincomb `
@@ -397,28 +411,32 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]:
397
411
#### ` verify_cell_proof `
398
412
399
413
``` python
400
- def verify_cell_proof (commitment : KZGCommitment ,
414
+ def verify_cell_proof (commitment_bytes : Bytes48 ,
401
415
cell_id : int ,
402
- cell : Cell ,
403
- proof : KZGProof ) -> bool :
416
+ cell_bytes : Vector[Bytes32, FIELD_ELEMENTS_PER_CELL ] ,
417
+ proof : Bytes48 ) -> bool :
404
418
"""
405
419
Check a cell proof
406
420
407
421
Public method.
408
422
"""
409
423
coset = coset_for_cell(cell_id)
410
424
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))
412
430
```
413
431
414
432
#### ` verify_cell_proof_batch `
415
433
416
434
``` python
417
- def verify_cell_proof_batch (row_commitments : Sequence[KZGCommitment ],
435
+ def verify_cell_proof_batch (row_commitments_bytes : Sequence[Bytes48 ],
418
436
row_ids : Sequence[int ],
419
437
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 :
422
440
"""
423
441
Check multiple cell proofs. This function implements the naive algorithm of checking every cell
424
442
individually; an efficient algorithm can be found here:
@@ -430,10 +448,14 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
430
448
431
449
Public method.
432
450
"""
433
-
434
451
# 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
+
437
459
return all (
438
460
verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_id), cell, proof)
439
461
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],
445
467
### ` recover_polynomial `
446
468
447
469
``` 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:
449
472
"""
450
473
Recovers a polynomial from 2 * FIELD_ELEMENTS_PER_CELL evaluations, half of which can be missing.
451
474
@@ -455,7 +478,10 @@ def recover_polynomial(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Pol
455
478
456
479
Public method.
457
480
"""
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
+
459
485
assert len (cells) >= CELLS_PER_BLOB // 2
460
486
missing_cell_ids = [cell_id for cell_id in range (CELLS_PER_BLOB ) if cell_id not in cell_ids]
461
487
roots_of_unity_reduced = compute_roots_of_unity(CELLS_PER_BLOB )
0 commit comments