From 05eb48cd6b93cd2f0bad51754b5a5b723f114eb5 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Wed, 17 Apr 2024 11:11:48 -0500 Subject: [PATCH 1/8] Add length asserts for public PeerDAS functions --- .../eip7594/polynomial-commitments-sampling.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 829e16ebaa..fce67e05fd 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -383,6 +383,8 @@ def compute_cells_and_proofs(blob: Blob) -> Tuple[ Public method. """ + assert len(blob) == BYTES_PER_BLOB + polynomial = blob_to_polynomial(blob) polynomial_coeff = polynomial_eval_to_coeff(polynomial) @@ -407,6 +409,8 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]: Public method. """ + assert len(blob) == BYTES_PER_BLOB + polynomial = blob_to_polynomial(blob) polynomial_coeff = polynomial_eval_to_coeff(polynomial) @@ -431,6 +435,10 @@ def verify_cell_proof(commitment_bytes: Bytes48, Public method. """ + assert len(commitment_bytes) == BYTES_PER_COMMITMENT + assert len(cell_bytes) == BYTES_PER_CELL + assert len(proof_bytes) == BYTES_PER_PROOF + coset = coset_for_cell(cell_id) return verify_kzg_proof_multi_impl( @@ -463,6 +471,12 @@ def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], Public method. """ assert len(cells_bytes) == len(proofs_bytes) == len(row_indices) == len(column_indices) + for commitment_bytes in row_commitments_bytes: + assert len(commitment_bytes) == BYTES_PER_COMMITMENT + for cell_bytes in cells_bytes: + assert len(cell_bytes) == BYTES_PER_CELL + for proof_bytes in proofs_bytes: + assert len(proof_bytes) == BYTES_PER_PROOF # Get commitments via row IDs commitments_bytes = [row_commitments_bytes[row_index] for row_index in row_indices] @@ -608,6 +622,9 @@ def recover_polynomial(cell_ids: Sequence[CellID], assert CELLS_PER_BLOB / 2 <= len(cell_ids) <= CELLS_PER_BLOB # Check for duplicates assert len(cell_ids) == len(set(cell_ids)) + # Check that each cell is the correct length + for cell_bytes in cells_bytes: + assert len(cell_bytes) == BYTES_PER_CELL # Get the extended domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) From 5ed6db90aed25c2e85d8fbe7ba2b44cb918220cf Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Wed, 17 Apr 2024 12:03:34 -0500 Subject: [PATCH 2/8] Fix cell asserts --- .../eip7594/polynomial-commitments-sampling.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index fce67e05fd..293e1d23ad 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -436,7 +436,9 @@ def verify_cell_proof(commitment_bytes: Bytes48, Public method. """ assert len(commitment_bytes) == BYTES_PER_COMMITMENT - assert len(cell_bytes) == BYTES_PER_CELL + assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL + for field in cell_bytes: + assert len(field) == BYTES_PER_FIELD_ELEMENT assert len(proof_bytes) == BYTES_PER_PROOF coset = coset_for_cell(cell_id) @@ -474,7 +476,9 @@ def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], for commitment_bytes in row_commitments_bytes: assert len(commitment_bytes) == BYTES_PER_COMMITMENT for cell_bytes in cells_bytes: - assert len(cell_bytes) == BYTES_PER_CELL + assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL + for field in cell_bytes: + assert len(field) == BYTES_PER_FIELD_ELEMENT for proof_bytes in proofs_bytes: assert len(proof_bytes) == BYTES_PER_PROOF @@ -624,7 +628,9 @@ def recover_polynomial(cell_ids: Sequence[CellID], assert len(cell_ids) == len(set(cell_ids)) # Check that each cell is the correct length for cell_bytes in cells_bytes: - assert len(cell_bytes) == BYTES_PER_CELL + assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL + for field in cell_bytes: + assert len(field) == BYTES_PER_FIELD_ELEMENT # Get the extended domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) From d6f4a8d036a80780f6d91bc180135e0007916264 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Wed, 17 Apr 2024 12:11:04 -0500 Subject: [PATCH 3/8] Rename field variable to satisfy linter --- .../eip7594/polynomial-commitments-sampling.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 293e1d23ad..0ae9701efe 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -437,8 +437,8 @@ def verify_cell_proof(commitment_bytes: Bytes48, """ assert len(commitment_bytes) == BYTES_PER_COMMITMENT assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL - for field in cell_bytes: - assert len(field) == BYTES_PER_FIELD_ELEMENT + for field_bytes in cell_bytes: + assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT assert len(proof_bytes) == BYTES_PER_PROOF coset = coset_for_cell(cell_id) @@ -477,8 +477,8 @@ def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], assert len(commitment_bytes) == BYTES_PER_COMMITMENT for cell_bytes in cells_bytes: assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL - for field in cell_bytes: - assert len(field) == BYTES_PER_FIELD_ELEMENT + for field_bytes in cell_bytes: + assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT for proof_bytes in proofs_bytes: assert len(proof_bytes) == BYTES_PER_PROOF @@ -629,8 +629,8 @@ def recover_polynomial(cell_ids: Sequence[CellID], # Check that each cell is the correct length for cell_bytes in cells_bytes: assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL - for field in cell_bytes: - assert len(field) == BYTES_PER_FIELD_ELEMENT + for field_bytes in cell_bytes: + assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT # Get the extended domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) From e7cb37e2874df3eac14440decf0c9164528e9d95 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 22 Apr 2024 08:02:03 -0500 Subject: [PATCH 4/8] Add asserts for row/column indices --- specs/_features/eip7594/polynomial-commitments-sampling.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 0ae9701efe..fba54c77a8 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -475,6 +475,10 @@ def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], assert len(cells_bytes) == len(proofs_bytes) == len(row_indices) == len(column_indices) for commitment_bytes in row_commitments_bytes: assert len(commitment_bytes) == BYTES_PER_COMMITMENT + for row_index in row_indices: + assert row_index < len(row_commitments_bytes) + for column_index in column_indices: + assert column_index < CELLS_PER_BLOB for cell_bytes in cells_bytes: assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL for field_bytes in cell_bytes: From e957324dae144586696786e998dea343bde4f9cc Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 22 Apr 2024 10:54:00 -0500 Subject: [PATCH 5/8] Use CELLS_PER_EXT_BLOB --- specs/_features/eip7594/polynomial-commitments-sampling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index fba54c77a8..6ea317e428 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -478,7 +478,7 @@ def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], for row_index in row_indices: assert row_index < len(row_commitments_bytes) for column_index in column_indices: - assert column_index < CELLS_PER_BLOB + assert column_index < CELLS_PER_EXT_BLOB for cell_bytes in cells_bytes: assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL for field_bytes in cell_bytes: From e505b9ea8682632de3496df90ce16734adb49cf3 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 22 Apr 2024 11:29:31 -0500 Subject: [PATCH 6/8] Update to work with new spec changes --- .../eip7594/polynomial-commitments-sampling.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index b420f6cf6e..dc3452f935 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -483,9 +483,7 @@ def verify_cell_proof(commitment_bytes: Bytes48, Public method. """ assert len(commitment_bytes) == BYTES_PER_COMMITMENT - assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL - for field_bytes in cell_bytes: - assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT + assert len(cell) == BYTES_PER_CELL assert len(proof_bytes) == BYTES_PER_PROOF coset = coset_for_cell(cell_id) @@ -526,10 +524,8 @@ def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], assert row_index < len(row_commitments_bytes) for column_index in column_indices: assert column_index < CELLS_PER_EXT_BLOB - for cell_bytes in cells_bytes: - assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL - for field_bytes in cell_bytes: - assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT + for cell in cells: + assert len(cell) == BYTES_PER_CELL for proof_bytes in proofs_bytes: assert len(proof_bytes) == BYTES_PER_PROOF @@ -678,10 +674,8 @@ def recover_all_cells(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Sequ # Check for duplicates assert len(cell_ids) == len(set(cell_ids)) # Check that each cell is the correct length - for cell_bytes in cells_bytes: - assert len(cell_bytes) == FIELD_ELEMENTS_PER_CELL - for field_bytes in cell_bytes: - assert len(field_bytes) == BYTES_PER_FIELD_ELEMENT + for cell in cells: + assert len(cell) == BYTES_PER_CELL # Get the extended domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) From 10629ed125d916f09a3871c59dec365ad456f3cd Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 22 Apr 2024 11:31:45 -0500 Subject: [PATCH 7/8] Fix indentation --- specs/_features/eip7594/polynomial-commitments-sampling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index dc3452f935..5a7f44610e 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -675,7 +675,7 @@ def recover_all_cells(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Sequ assert len(cell_ids) == len(set(cell_ids)) # Check that each cell is the correct length for cell in cells: - assert len(cell) == BYTES_PER_CELL + assert len(cell) == BYTES_PER_CELL # Get the extended domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) From f96cc640b69760be66de161ce361e0931e2891b4 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 22 Apr 2024 11:34:36 -0500 Subject: [PATCH 8/8] Add explict check for cell_id --- specs/_features/eip7594/polynomial-commitments-sampling.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 5a7f44610e..cf3b2c7593 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -483,6 +483,7 @@ def verify_cell_proof(commitment_bytes: Bytes48, Public method. """ assert len(commitment_bytes) == BYTES_PER_COMMITMENT + assert cell_id < CELLS_PER_EXT_BLOB assert len(cell) == BYTES_PER_CELL assert len(proof_bytes) == BYTES_PER_PROOF