Make da verification indempotent (#118)

This commit is contained in:
gusto 2025-01-29 13:15:10 +03:00 committed by GitHub
parent 44af97f493
commit 3a8f8167a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View File

@ -69,4 +69,4 @@ class TestVerifier(TestCase):
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))

View File

@ -33,9 +33,6 @@ class DABlob:
class DAVerifier:
def __init__(self):
self.attested_blobs: Set[BlobId] = set()
@staticmethod
def _verify_column(
column: Column,
@ -77,11 +74,18 @@ class DAVerifier:
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,
@ -91,10 +95,12 @@ class DAVerifier:
)
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