mirror of
https://github.com/logos-co/nomos-specs.git
synced 2025-02-03 11:03:33 +00:00
9a54d90d14
* Added da encoder pipeline draft * Remove unnecessary method * Added verifier module and blob type * Fill verifier skeleton * Add comments on implementation, remove unnecessary intermediary method * Added dispersal skeleton * Added test modules for dispersal and verifier * Added test modules for encoder, implemented basic test * Added missing test cases * Added missing calls to encode method * Use single megabyte test in encoder * Added basic testcases for dispersal * Added basic testcases for verifier * Remove duplicated column proofs from encoding schema * Remove parameters from test functions in encoder * Extract common types to common module * Make test pass * Remove node id dep from mixnet and fix columns access
78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
from dataclasses import dataclass
|
|
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
|
|
|
|
from da.common import Column, Chunk, Attestation
|
|
|
|
|
|
@dataclass
|
|
class DABlob:
|
|
# this should be removed, but for now it shows the purpose
|
|
index: int
|
|
column: bytearray
|
|
column_commitment: Commitment
|
|
aggregated_column_commitment: Commitment
|
|
aggregated_column_proof: Proof
|
|
rows_commitments: List[Commitment]
|
|
rows_proofs: List[Proof]
|
|
|
|
|
|
class DAVerifier:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@staticmethod
|
|
def _verify_column(
|
|
column: Column,
|
|
column_commitment: Commitment,
|
|
aggregated_column_commitment: Commitment,
|
|
aggregated_column_proof: Proof,
|
|
# this is temporary and should be removed
|
|
index: int
|
|
) -> bool:
|
|
|
|
# 1. compute commitment for column
|
|
# 2. If computed column commitment != column commitment, fail
|
|
# 3. compute column hash
|
|
column_hash: bytearray = bytearray(hash(column))
|
|
# 4. Check proof with commitment and proof over the aggregated column commitment
|
|
return False
|
|
|
|
@staticmethod
|
|
def _verify_chunk(chunk: Chunk, commitment: Commitment, proof: Proof) -> bool:
|
|
pass
|
|
|
|
@staticmethod
|
|
def _verify_chunks(
|
|
chunks: List[Chunk],
|
|
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)
|