2024-02-12 15:35:23 +01:00
|
|
|
from dataclasses import dataclass
|
2025-06-04 15:14:04 +02:00
|
|
|
from typing import List
|
|
|
|
|
|
2024-02-12 15:35:23 +01:00
|
|
|
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
|
2024-03-11 10:01:34 +01:00
|
|
|
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
|
2024-02-12 15:35:23 +01:00
|
|
|
|
2025-05-20 13:45:53 +03:00
|
|
|
# Domain separation tag
|
|
|
|
|
_DST = b"NOMOS_DA_V1"
|
2024-02-12 15:35:23 +01:00
|
|
|
|
|
|
|
|
@dataclass
|
2025-05-20 13:45:53 +03:00
|
|
|
class DAShare:
|
2024-03-11 10:01:34 +01:00
|
|
|
column: Column
|
2025-01-29 10:42:53 +00:00
|
|
|
column_idx: int
|
2025-05-20 13:45:53 +03:00
|
|
|
combined_column_proof: Proof
|
|
|
|
|
row_commitments: List[Commitment]
|
2024-03-22 10:36:00 +01:00
|
|
|
|
2025-05-20 13:45:53 +03:00
|
|
|
def blob_id(self) -> BlobId:
|
|
|
|
|
return build_blob_id(self.row_commitments)
|
2024-02-12 15:35:23 +01:00
|
|
|
|
|
|
|
|
class DAVerifier:
|
|
|
|
|
@staticmethod
|
2025-05-20 13:45:53 +03:00
|
|
|
def verify(blob: DAShare) -> bool:
|
2025-01-29 10:42:53 +00:00
|
|
|
"""
|
2025-06-04 13:58:18 +03:00
|
|
|
Verifies that blob.column at index blob.column_idx is consistent
|
|
|
|
|
with the row commitments and the combined column proof.
|
2025-01-29 10:42:53 +00:00
|
|
|
|
2025-05-20 13:45:53 +03:00
|
|
|
Returns True if verification succeeds, False otherwise.
|
2025-01-29 10:42:53 +00:00
|
|
|
"""
|
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
|
|
|
|
|
)
|