Added missing calls to encode method

This commit is contained in:
Daniel Sanchez Quiros 2024-02-08 15:34:34 +01:00
parent 92c5a64b02
commit 07d20ba3ce
2 changed files with 39 additions and 17 deletions

View File

@ -3,6 +3,10 @@ from typing import List
from eth2spec.eip7594.mainnet import KZGCommitment as Commitment, KZGProof as Proof
class ChunksMatrix(List[bytearray]):
pass
@dataclass
class DAEncoderParams:
column_count: int
@ -12,52 +16,70 @@ class DAEncoderParams:
@dataclass
class EncodedData:
data: bytearray
columns: List[bytearray]
extended_matrix: ChunksMatrix
row_commitments: List[Commitment]
row_proofs: List[List[Proof]]
column_commitments: List[Commitment]
column_proofs: List[Proof]
aggregated_column_commitment: Commitment
aggregated_column_proof: Proof
aggregated_column_proofs: List[Proof]
class DAEncoder:
def __init__(self, params: DAEncoderParams):
self.params = params
def _chunkify_data(self, data: bytearray) -> List[bytearray]:
def _chunkify_data(self, data: bytearray) -> ChunksMatrix:
...
def _compute_row_kzg_commitments(self, rows: List[bytearray]) -> List[Commitment]:
...
def _rs_encode_rows(self, rows: List[bytearray]) -> List[bytearray]:
def _rs_encode_rows(self, chunks_matrix: ChunksMatrix) -> ChunksMatrix:
...
def _compute_rows_proofs(self, rows: List[bytearray], row_commitments: List[Commitment]) -> List[List[Proof]]:
def _compute_rows_proofs(self, chunks_matrix: ChunksMatrix, row_commitments: List[Commitment]) -> List[List[Proof]]:
...
def _compute_column_kzg_commitments(self, rows: List[bytearray]) -> List[Commitment]:
def _compute_column_kzg_commitments(self, chunks_matrix: ChunksMatrix) -> List[Commitment]:
...
def _generate_aggregated_column_commitments(
self, rows: List[bytearray], column_commitments: List[Commitment]
def _compute_column_kzg_proofs(
self,
chunks_matrix: ChunksMatrix,
column_commitments: List[Commitment]
) -> List[Proof]:
...
def _compute_aggregated_column_commitments(
self, chunks_matrix: ChunksMatrix, column_commitments: List[Commitment]
) -> Commitment:
...
def _compute_aggregated_column_proofs(
self,
chunks_matrix: ChunksMatrix,
aggregated_column_commitment: Commitment
) -> List[Proof]:
...
def encode(self, data: bytearray) -> EncodedData:
rows = self._chunkify_data(data)
row_commitments = self._compute_row_kzg_commitments(rows)
encoded_rows = self._rs_encode_rows(rows)
row_proofs = self._compute_rows_proofs(encoded_rows, row_commitments)
column_commitments = self._compute_column_kzg_commitments(encoded_rows)
aggregated_column_commitment = self._generate_aggregated_column_commitments(encoded_rows, column_commitments)
chunks_matrix = self._chunkify_data(data)
row_commitments = self._compute_row_kzg_commitments(chunks_matrix)
extended_matrix = self._rs_encode_rows(chunks_matrix)
row_proofs = self._compute_rows_proofs(extended_matrix, row_commitments)
column_commitments = self._compute_column_kzg_commitments(extended_matrix)
column_proofs = self._compute_column_kzg_proofs(extended_matrix, column_commitments)
aggregated_column_commitment = self._compute_aggregated_column_commitments(extended_matrix, column_commitments)
aggregated_column_proofs = self._compute_aggregated_column_proofs(extended_matrix, aggregated_column_commitment)
result = EncodedData(
data,
extended_matrix,
row_commitments,
row_proofs,
column_commitments,
aggregated_column_commitment
column_proofs,
aggregated_column_commitment,
aggregated_column_proofs
)
return result

View File

@ -10,7 +10,7 @@ class TestEncoder(TestCase):
def assert_encoding(self, encoder_params: DAEncoderParams, data: bytearray):
encoded_data = encoder.DAEncoder(encoder_params).encode(data)
self.assertEqual(encoded_data.data, data)
self.assertEqual(len(encoded_data.columns), encoder_params.column_count)
self.assertEqual(len(encoded_data.extended_matrix), encoder_params.column_count)
self.assertEqual(len(encoded_data.column_proofs), encoder_params.column_count)
chunks_size = (len(data) // encoder_params.bytes_per_field_element) // encoder_params.column_count
self.assertEqual(len(encoded_data.row_commitments), chunks_size)