Skip to content

Commit

Permalink
Make da verification indempotent (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bacv authored Jan 29, 2025
1 parent 44af97f commit 3a8f816
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion da/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def test_verify_duplicated_blob(self):
encoded_data.row_commitments,
[row[i] for row in encoded_data.row_proofs],
)
self.assertFalse(self.verifier.verify(da_blob))
self.assertTrue(self.verifier.verify(da_blob))
24 changes: 15 additions & 9 deletions da/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def column_id(self) -> bytes:


class DAVerifier:
def __init__(self):
self.attested_blobs: Set[BlobId] = set()

@staticmethod
def _verify_column(
column: Column,
Expand Down Expand Up @@ -77,11 +74,18 @@ def _verify_chunks(
return True

def verify(self, blob: DABlob) -> bool:
blob_id = blob.blob_id()
if blob_id in self.attested_blobs:
# we already attested and they are asking us to attest again
# skip
return False
"""
Verify the integrity of the given blob.
This function must be idempotent. The implementer should ensure that
repeated verification attempts do not result in inconsistent states.
Args:
blob (DABlob): The blob to verify.
Returns:
bool: True if the blob is verified successfully, False otherwise.
"""
is_column_verified = DAVerifier._verify_column(
blob.column,
blob.column_idx,
Expand All @@ -91,10 +95,12 @@ def verify(self, blob: DABlob) -> bool:
)
if not is_column_verified:
return False

are_chunks_verified = DAVerifier._verify_chunks(
blob.column, blob.rows_commitments, blob.rows_proofs, blob.column_idx
)
if not are_chunks_verified:
return False
self.attested_blobs.add(blob_id)

# Ensure idempotency: Implementers should define how to avoid redundant verification.
return True

0 comments on commit 3a8f816

Please sign in to comment.