diff --git a/da/encoder.py b/da/encoder.py index 7c46091..196c479 100644 --- a/da/encoder.py +++ b/da/encoder.py @@ -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() diff --git a/da/test_encoder.py b/da/test_encoder.py index 5c7be12..5208e3a 100644 --- a/da/test_encoder.py +++ b/da/test_encoder.py @@ -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, diff --git a/da/test_verifier.py b/da/test_verifier.py index 8d9e763..1285ec7 100644 --- a/da/test_verifier.py +++ b/da/test_verifier.py @@ -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( diff --git a/da/verifier.py b/da/verifier.py index 3c0cef3..b3439b8 100644 --- a/da/verifier.py +++ b/da/verifier.py @@ -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(