-
Notifications
You must be signed in to change notification settings - Fork 1.1k
peerDAS: Public methods must accept raw bytes #3579
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
Changes from all commits
b4d418d
a4331e7
87f2ad2
6679860
2000a4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
- [Preset](#preset) | ||
- [Cells](#cells) | ||
- [Helper functions](#helper-functions) | ||
- [BLS12-381 helpers](#bls12-381-helpers) | ||
- [`bytes_to_cell`](#bytes_to_cell) | ||
- [Linear combinations](#linear-combinations) | ||
- [`g2_lincomb`](#g2_lincomb) | ||
- [FFTs](#ffts) | ||
|
@@ -81,6 +83,18 @@ Cells are the smallest unit of blob data that can come with their own KZG proofs | |
|
||
## Helper functions | ||
|
||
### BLS12-381 helpers | ||
|
||
#### `bytes_to_cell` | ||
|
||
```python | ||
def bytes_to_cell(cell_bytes: Vector[Bytes32, FIELD_ELEMENTS_PER_CELL]) -> Cell: | ||
""" | ||
Convert untrusted bytes into a Cell. | ||
""" | ||
return [bytes_to_bls_field(element) for element in cell_bytes] | ||
``` | ||
|
||
### Linear combinations | ||
|
||
#### `g2_lincomb` | ||
|
@@ -242,7 +256,7 @@ def interpolate_polynomialcoeff(xs: Sequence[BLSFieldElement], ys: Sequence[BLSF | |
summand, [(- int(weight_adjustment) * int(xs[j])) % BLS_MODULUS, weight_adjustment] | ||
) | ||
r = add_polynomialcoeff(r, summand) | ||
|
||
return r | ||
``` | ||
|
||
|
@@ -330,7 +344,7 @@ def verify_kzg_proof_multi_impl(commitment: KZGCommitment, | |
#### `coset_for_cell` | ||
|
||
```python | ||
def coset_for_cell(cell_id: int) -> Cell: | ||
def coset_for_cell(cell_id: CellID) -> Cell: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In practice, I think it's better for us to choose which notion is more intuitive in a separate PR. |
||
""" | ||
Get the coset for a given ``cell_id`` | ||
""" | ||
|
@@ -385,7 +399,7 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]: | |
polynomial = blob_to_polynomial(blob) | ||
polynomial_coeff = polynomial_eval_to_coeff(polynomial) | ||
|
||
extended_data = fft_field(polynomial_coeff + [0] * FIELD_ELEMENTS_PER_BLOB, | ||
extended_data = fft_field(polynomial_coeff + [0] * FIELD_ELEMENTS_PER_BLOB, | ||
compute_roots_of_unity(2 * FIELD_ELEMENTS_PER_BLOB)) | ||
extended_data_rbo = bit_reversal_permutation(extended_data) | ||
return [extended_data_rbo[i * FIELD_ELEMENTS_PER_CELL:(i + 1) * FIELD_ELEMENTS_PER_CELL] | ||
|
@@ -397,30 +411,37 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]: | |
#### `verify_cell_proof` | ||
|
||
```python | ||
def verify_cell_proof(commitment: KZGCommitment, | ||
cell_id: int, | ||
cell: Cell, | ||
proof: KZGProof) -> bool: | ||
def verify_cell_proof(commitment_bytes: Bytes48, | ||
cell_id: CellID, | ||
cell_bytes: Vector[Bytes32, FIELD_ELEMENTS_PER_CELL], | ||
proof_bytes: Bytes48) -> bool: | ||
""" | ||
Check a cell proof | ||
|
||
Public method. | ||
""" | ||
coset = coset_for_cell(cell_id) | ||
|
||
return verify_kzg_proof_multi_impl(commitment, coset, cell, proof) | ||
return verify_kzg_proof_multi_impl( | ||
bytes_to_kzg_commitment(commitment_bytes), | ||
coset, | ||
bytes_to_cell(cell_bytes), | ||
bytes_to_kzg_proof(proof_bytes)) | ||
``` | ||
|
||
#### `verify_cell_proof_batch` | ||
|
||
```python | ||
def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment], | ||
row_ids: Sequence[int], | ||
column_ids: Sequence[int], | ||
cells: Sequence[Cell], | ||
proofs: Sequence[KZGProof]) -> bool: | ||
def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], | ||
row_ids: Sequence[uint64], | ||
column_ids: Sequence[uint64], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not IMO. The ID of a row or column is semantically different from a cell ID, even if the underlying type is the same. Specifically, we expect to have just a few rows. We also expect the amount of columns to be equal to the amount of cells per blob. However, due to the semantic difference, I would be hesitant in reusing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree now, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related commit that will cause conflicts: 665e6fa There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went address it in #3574 -> We can fix conflict later whichever merge late. |
||
cells_bytes: Sequence[Vector[Bytes32, FIELD_ELEMENTS_PER_CELL]], | ||
proofs_bytes: Sequence[Bytes48]) -> bool: | ||
""" | ||
Check multiple cell proofs. This function implements the naive algorithm of checking every cell | ||
Verify a set of cells, given their corresponding proofs and their coordinates (row_id, column_id) in the blob | ||
matrix. The list of all commitments is also provided in row_commitments_bytes. | ||
|
||
This function implements the naive algorithm of checking every cell | ||
individually; an efficient algorithm can be found here: | ||
https://ethresear.ch/t/a-universal-verification-equation-for-data-availability-sampling/13240 | ||
|
||
|
@@ -430,10 +451,16 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment], | |
|
||
Public method. | ||
""" | ||
assert len(cells_bytes) == len(proofs_bytes) == len(row_ids) == len(column_ids) | ||
|
||
# Get commitments via row IDs | ||
commitments = [row_commitments[row_id] for row_id in row_ids] | ||
|
||
commitments_bytes = [row_commitments_bytes[row_id] for row_id in row_ids] | ||
|
||
# Get objects from bytes | ||
commitments = [bytes_to_kzg_commitment(commitment_bytes) for commitment_bytes in commitments_bytes] | ||
cells = [bytes_to_cell(cell_bytes) for cell_bytes in cells_bytes] | ||
proofs = [bytes_to_kzg_proof(proof_bytes) for proof_bytes in proofs_bytes] | ||
|
||
return all( | ||
verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_id), cell, proof) | ||
for commitment, column_id, cell, proof in zip(commitments, column_ids, cells, proofs) | ||
|
@@ -445,7 +472,8 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment], | |
### `recover_polynomial` | ||
|
||
```python | ||
def recover_polynomial(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Polynomial: | ||
def recover_polynomial(cell_ids: Sequence[CellID], | ||
cells_bytes: Sequence[Vector[Bytes32, FIELD_ELEMENTS_PER_CELL]]) -> Polynomial: | ||
""" | ||
Recovers a polynomial from 2 * FIELD_ELEMENTS_PER_CELL evaluations, half of which can be missing. | ||
|
||
|
@@ -455,7 +483,10 @@ def recover_polynomial(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Pol | |
|
||
Public method. | ||
""" | ||
assert len(cell_ids) == len(cells) | ||
assert len(cell_ids) == len(cells_bytes) | ||
|
||
cells = [bytes_to_cell(cell_bytes) for cell_bytes in cells_bytes] | ||
|
||
assert len(cells) >= CELLS_PER_BLOB // 2 | ||
missing_cell_ids = [cell_id for cell_id in range(CELLS_PER_BLOB) if cell_id not in cell_ids] | ||
roots_of_unity_reduced = compute_roots_of_unity(CELLS_PER_BLOB) | ||
|
@@ -504,7 +535,7 @@ def recover_polynomial(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Pol | |
|
||
eval_shifted_extended_evaluation = fft_field(shifted_extended_evaluation, roots_of_unity_extended) | ||
eval_shifted_zero_poly = fft_field(shifted_zero_poly, roots_of_unity_extended) | ||
|
||
eval_shifted_reconstructed_poly = [ | ||
div(a, b) | ||
for a, b in zip(eval_shifted_extended_evaluation, eval_shifted_zero_poly) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you ensure that all the docstrings have proper punctuation? Lots of the
*_polynomialcoeff
methods and other funcs, likeverify_kzg_proof_multi_impl
, are missing punctuation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think the documentation of the entire file is a bit lacking to the point that I would suggest we do it in another PR since it requires quite a bit of work.
(PS: That also made me look at the 4844 documentation, and it also seems severely incomplete or outdated)