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

peerDAS: Public methods must accept raw bytes #3579

Merged
merged 5 commits into from
Jan 26, 2024

Conversation

asn-d6
Copy link
Contributor

@asn-d6 asn-d6 commented Jan 15, 2024

The cryptography public methods should take as input raw bytes. This is a lesson from the 4844 cryptography specs. It makes it clear that cryptographic validation of inputs is a responsibility of the cryptography spec and not the rest of the client code.

(Also switched int to uint64 after discussion in the specs call.)

Furthermore, merging this PR will likely break the currently active peerDAS PR #3574.

@asn-d6 asn-d6 force-pushed the peerdas_public_method_bytes branch from 789e24e to a4331e7 Compare January 15, 2024 16:38
@hwwhww hwwhww added the EIP-7594 PeerDAS label Jan 16, 2024
Copy link
Member

@jtraglia jtraglia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Here's my initial review.

def verify_cell_proof(commitment_bytes: Bytes48,
cell_id: uint64,
cell_bytes: Vector[Bytes32, FIELD_ELEMENTS_PER_CELL],
proof: Bytes48) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be proof_bytes, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 6679860

bytes_to_kzg_commitment(commitment_bytes),
coset,
bytes_to_cell(cell_bytes),
bytes_to_kzg_proof(proof))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also be proof_bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 6679860

Copy link
Member

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, like verify_kzg_proof_multi_impl, are missing punctuation.

Copy link
Contributor Author

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)

cell: Cell,
proof: KZGProof) -> bool:
def verify_cell_proof(commitment_bytes: Bytes48,
cell_id: uint64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the new CellID type here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in 6679860

proofs: Sequence[KZGProof]) -> bool:
def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48],
row_ids: Sequence[uint64],
column_ids: Sequence[uint64],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be CellID too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 CellID here. IMO another approach would be to define a RowID and ColumnID type for these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree now, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related commit that will cause conflicts: 665e6fa

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went address it in #3574 -> RowIndex and ColumnIndex. IMO "index" implies they are consecutive numbers but ID is not.

We can fix conflict later whichever merge late.

row_ids=[0],
column_ids=[0, 1],
cells=cells[0:1],
proofs=proofs,
cells_bytes=cells_bytes[0:1],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many cells are we trying to verify here? Since column_ids has two values, it appears to be two. But [0:1] will result in a single value. Think there's a bit of an accident here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that unittest was a bit working by accident. I made it more robust in 2000a4f.

In the future we will want certainly want test_verify_cell_proof_batch() to do a multi-blob cell verification, but to do that we need to figure out a solution to compute_cells_and_proofs() taking multiple minutes (perhaps load them directly from a file?).

cells=cells[0:1],
proofs=proofs,
cells_bytes=cells_bytes[0:1],
proofs_bytes=proofs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're sending all the proofs when only the first one is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 2000a4f

@@ -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:
Copy link
Member

@jtraglia jtraglia Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think cell_id should be column_index (or column_id) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, column_id and cell_id can be used interchangeably in this function, since each cell corresponds to a column in a one-to-one fashion.

I think it's better for us to choose which notion is more intuitive in a separate PR.

Copy link
Member

@jtraglia jtraglia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🥇

Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@asn-d6 asn-d6 merged commit ae3ef6f into ethereum:dev Jan 26, 2024
30 checks passed
@asn-d6
Copy link
Contributor Author

asn-d6 commented Jan 26, 2024

Merged. Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EIP-7594 PeerDAS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants