Fill verifier skeleton

This commit is contained in:
Daniel Sanchez Quiros 2024-02-06 13:32:41 +01:00
parent 20d639435d
commit 3732f3eb74
1 changed files with 76 additions and 2 deletions

View File

@ -1,6 +1,11 @@
from dataclasses import dataclass
from typing import List
from eth2spec.eip7594.mainnet import KZGCommitment as Commitment, KZGProof as Proof
from typing import List, Optional
from eth2spec.eip7594.mainnet import (
KZGCommitment as Commitment,
KZGProof as Proof,
BYTES_PER_CELL as BYTES_PER_CHUNK
)
from itertools import batched
@dataclass
@ -13,3 +18,72 @@ class DABlob:
aggregated_column_proof: Proof
rows_commitments: List[Commitment]
rows_proofs: List[Proof]
@dataclass
class Attestation:
pass
class DAVerifier:
def __init__(self):
pass
@staticmethod
def _verify_aggregated_column_commitment(
aggregated_column_commitment: Commitment,
aggregated_column_proof: Proof,
column_hash: bytearray,
# this is temporary and should be removed
index: int
) -> bool:
pass
@staticmethod
def _verify_column(
column: bytearray,
aggregated_column_commitment: Commitment,
aggregated_column_proof: Proof,
index: int
) -> bool:
# TODO: Use a proper hashing scheme
column_hash: bytearray = bytearray(hash(column))
return DAVerifier._verify_aggregated_column_commitment(
aggregated_column_commitment,
aggregated_column_proof,
column_hash,
index
)
@staticmethod
def _verify_chunk(chunk: bytearray, commitment: Commitment, proof: Proof) -> bool:
pass
@staticmethod
def _verify_chunks(
chunks: List[bytearray],
commitments: List[Commitment],
proofs: List[Proof]
) -> bool:
for chunk, commitment, proof in zip(chunks, commitments, proofs):
if not DAVerifier._verify_chunk(chunk, commitment, proof):
return False
return True
def _build_attestation(self, _blob: DABlob) -> Attestation:
return Attestation()
@staticmethod
def verify(self, blob: DABlob) -> Optional[Attestation]:
is_column_verified = DAVerifier._verify_column(
blob.column, blob.aggregated_column_commitment, blob.aggregated_column_proof, blob.index
)
if not is_column_verified:
return
chunks = batched(blob.column, BYTES_PER_CHUNK)
are_chunks_verified = DAVerifier._verify_chunks(
chunks, blob.rows_commitments, blob.rows_proofs
)
if not are_chunks_verified:
return
return self._build_attestation(blob)