50 lines
1.6 KiB
Python
Raw Normal View History

from dataclasses import dataclass
2025-06-04 15:14:04 +02:00
from typing import List
from eth2spec.eip7594.mainnet import (
KZGCommitment as Commitment,
KZGProof as Proof,
)
2025-06-04 15:14:04 +02:00
from da.common import Column, BlobId, build_blob_id
from da.kzg_rs import kzg
2025-06-04 15:14:04 +02:00
from da.kzg_rs.bdfg_proving import combine_commitments, derive_challenge, compute_combined_evaluation
from da.kzg_rs.common import ROOTS_OF_UNITY
2025-05-20 13:45:53 +03:00
# Domain separation tag
_DST = b"NOMOS_DA_V1"
@dataclass
2025-05-20 13:45:53 +03:00
class DAShare:
column: Column
column_idx: int
2025-05-20 13:45:53 +03:00
combined_column_proof: Proof
row_commitments: List[Commitment]
2025-05-20 13:45:53 +03:00
def blob_id(self) -> BlobId:
return build_blob_id(self.row_commitments)
class DAVerifier:
@staticmethod
2025-05-20 13:45:53 +03:00
def verify(blob: DAShare) -> bool:
"""
Verifies that blob.column at index blob.column_idx is consistent
with the row commitments and the combined column proof.
2025-05-20 13:45:53 +03:00
Returns True if verification succeeds, False otherwise.
"""
2025-05-20 13:45:53 +03:00
# 1. Derive challenge
2025-05-22 13:41:45 +03:00
h = derive_challenge(blob.row_commitments)
# 2. Reconstruct combined commitment: combined_commitment = sum_{i=0..l-1} h^i * row_commitments[i]
2025-06-04 15:14:04 +02:00
combined_commitment = combine_commitments(blob.row_commitments, h)
2025-05-20 13:45:53 +03:00
# 3. Compute combined evaluation v = sum_{i=0..l-1} (h^i * column_data[i])
2025-06-04 15:14:04 +02:00
combined_eval_point = compute_combined_evaluation(blob.column, h)
2025-05-20 13:45:53 +03:00
# 4. Verify the single KZG proof for evaluation at point w^{column_idx}
2025-06-04 15:14:04 +02:00
return kzg.verify_element_proof(
combined_eval_point,
combined_commitment,
blob.combined_column_proof,
blob.column_idx,
ROOTS_OF_UNITY
)