Added compute row commitments

Added row commitments size test
This commit is contained in:
Daniel Sanchez Quiros 2024-03-05 13:54:06 +01:00
parent f3097a6be4
commit e72935ec49
2 changed files with 20 additions and 6 deletions

View File

@ -1,10 +1,11 @@
from dataclasses import dataclass
from itertools import batched
from typing import List
from typing import List, Sequence
from eth2spec.eip7594.mainnet import KZGCommitment as Commitment, KZGProof as Proof
from da.common import ChunksMatrix
from da.kzg_rs import kzg, rs, poly
from da.kzg_rs.common import GLOBAL_PARAMETERS
@dataclass
class DAEncoderParams:
@ -31,8 +32,9 @@ class DAEncoder:
size: int = self.params.column_count * self.params.bytes_per_field_element
return ChunksMatrix(batched(data, size))
def _compute_row_kzg_commitments(self, rows: List[bytearray]) -> List[Commitment]:
...
@staticmethod
def _compute_row_kzg_commitments(rows: Sequence[bytearray]) -> List[Commitment]:
return [kzg.bytes_to_commitment(row, GLOBAL_PARAMETERS) for row in rows]
def _rs_encode_rows(self, chunks_matrix: ChunksMatrix) -> ChunksMatrix:
...

View File

@ -4,7 +4,7 @@ from typing import List
from unittest import TestCase
from da import encoder
from da.encoder import DAEncoderParams, Commitment
from da.encoder import DAEncoderParams, Commitment, DAEncoder
from eth2spec.eip7594.mainnet import BYTES_PER_FIELD_ELEMENT
from da.kzg_rs.common import BLS_MODULUS
@ -12,6 +12,17 @@ from da.kzg_rs.common import BLS_MODULUS
class TestEncoder(TestCase):
def setUp(self):
self.params: DAEncoderParams = DAEncoderParams(column_count=10, bytes_per_field_element=32)
self.encoder: DAEncoder = DAEncoder(self.params)
self.elements = 100
self.data = bytearray(
chain.from_iterable(
randrange(BLS_MODULUS).to_bytes(length=self.params.bytes_per_field_element, byteorder='big')
for _ in range(self.elements)
)
)
def assert_encoding(self, encoder_params: DAEncoderParams, data: bytearray):
encoded_data = encoder.DAEncoder(encoder_params).encode(data)
self.assertEqual(encoded_data.data, data)
@ -30,9 +41,10 @@ class TestEncoder(TestCase):
for column in chunks_matrix:
self.assertEqual(len(column), encoder_settings.bytes_per_field_element*encoder_settings.column_count)
def test_compute_row_kzg_commitments(self):
pass
chunks_matrix = self.encoder._chunkify_data(self.data)
commitments = self.encoder._compute_row_kzg_commitments(chunks_matrix)
self.assertEqual(len(commitments), len(chunks_matrix))
def test_rs_encode_rows(self):
pass