From 3a8f8167a9cdde2c8b4d61df6acc9e75426ef9b6 Mon Sep 17 00:00:00 2001 From: gusto Date: Wed, 29 Jan 2025 13:15:10 +0300 Subject: [PATCH] Make da verification indempotent (#118) --- da/test_verifier.py | 2 +- da/verifier.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/da/test_verifier.py b/da/test_verifier.py index 8a65d51..101895b 100644 --- a/da/test_verifier.py +++ b/da/test_verifier.py @@ -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)) diff --git a/da/verifier.py b/da/verifier.py index fa39c30..6d1dacf 100644 --- a/da/verifier.py +++ b/da/verifier.py @@ -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, @@ -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, @@ -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