Modify and rename hash_commitment method. Now we just hash the column commitment itself.

This commit is contained in:
danielSanchezQ 2025-01-24 14:28:35 +00:00
parent 5434fcb315
commit 543e0549ca
4 changed files with 6 additions and 9 deletions

View File

@ -89,7 +89,7 @@ class DAEncoder:
chunks_matrix: ChunksMatrix, column_commitments: Sequence[Commitment]
) -> Tuple[Polynomial, Commitment]:
data = bytes(chain.from_iterable(
DAEncoder.hash_column_and_commitment(column, commitment)
DAEncoder.hash_commitment_blake2b31(column, commitment)
for column, commitment in zip(chunks_matrix.columns, column_commitments)
))
return kzg.bytes_to_commitment(data, GLOBAL_PARAMETERS)
@ -129,8 +129,5 @@ class DAEncoder:
return result
@staticmethod
def hash_column_and_commitment(column: Column, commitment: Commitment) -> bytes:
return (
# digest size must be 31 bytes as we cannot encode 32 without risking overflowing the BLS_MODULUS
int.from_bytes(blake2b(column.as_bytes() + bytes(commitment), digest_size=31).digest())
).to_bytes(32, byteorder="big")
def hash_commitment_blake2b31(commitment: Commitment) -> bytes:
return blake2b(bytes(commitment), digest_size=31).digest()

View File

@ -47,7 +47,7 @@ class TestEncoder(TestCase):
# verify column aggregation
for i, (column, proof) in enumerate(zip(encoded_data.extended_matrix.columns, encoded_data.aggregated_column_proofs)):
data = DAEncoder.hash_column_and_commitment(column, commitment)
data = DAEncoder.hash_commitment_blake2b31(commitment)
kzg.verify_element_proof(
bytes_to_bls_field(data),
encoded_data.aggregated_column_commitment,

View File

@ -17,7 +17,7 @@ class TestVerifier(TestCase):
column = Column(int.to_bytes(i, length=32) for i in range(8))
_, column_commitment = kzg.bytes_to_commitment(column.as_bytes(), GLOBAL_PARAMETERS)
aggregated_poly, aggregated_column_commitment = kzg.bytes_to_commitment(
DAEncoder.hash_column_and_commitment(column, column_commitment), GLOBAL_PARAMETERS
DAEncoder.hash_commitment_blake2b31(column_commitment), GLOBAL_PARAMETERS
)
aggregated_proof = kzg.generate_element_proof(0, aggregated_poly, GLOBAL_PARAMETERS, ROOTS_OF_UNITY)
self.assertTrue(

View File

@ -51,7 +51,7 @@ class DAVerifier:
if column_commitment != computed_column_commitment:
return False
# 3. compute column hash
column_hash = DAEncoder.hash_column_and_commitment(column, column_commitment)
column_hash = DAEncoder.hash_commitment_blake2b31(column_commitment)
# 4. Check proof with commitment and proof over the aggregated column commitment
chunk = BLSFieldElement.from_bytes(column_hash)
return kzg.verify_element_proof(