Remove certificate from verifier

This commit is contained in:
danielSanchezQ 2025-01-24 15:14:02 +00:00
parent 58d9f3d43d
commit 03aafc82f0
4 changed files with 21 additions and 29 deletions

View File

@ -7,6 +7,8 @@ from eth2spec.eip7594.mainnet import Bytes32, KZGCommitment as Commitment
from py_ecc.bls import G2ProofOfPossession
type BlobId = bytes
class NodeId(Bytes32):
pass
@ -56,7 +58,7 @@ class Certificate:
row_commitments: List[Commitment]
def id(self) -> bytes:
return build_attestation_message(self.aggregated_column_commitment, self.row_commitments)
return build_blob_id(self.aggregated_column_commitment, self.row_commitments)
def verify(self, nodes_public_keys: List[BLSPublicKey]) -> bool:
"""
@ -66,11 +68,11 @@ class Certificate:
"""
# we sort them as the signers bitfield is sorted by the public keys as well
signers_keys = list(compress(sorted(nodes_public_keys), self.signers))
message = build_attestation_message(self.aggregated_column_commitment, self.row_commitments)
message = build_blob_id(self.aggregated_column_commitment, self.row_commitments)
return NomosDaG2ProofOfPossession.AggregateVerify(signers_keys, [message]*len(signers_keys), self.aggregated_signatures)
def build_attestation_message(aggregated_column_commitment: Commitment, row_commitments: Sequence[Commitment]) -> bytes:
def build_blob_id(aggregated_column_commitment: Commitment, row_commitments: Sequence[Commitment]) -> BlobId:
hasher = sha3_256()
hasher.update(bytes(aggregated_column_commitment))
for c in row_commitments:

View File

@ -2,7 +2,7 @@ from dataclasses import dataclass
from hashlib import sha3_256
from typing import List, Optional, Generator, Sequence
from da.common import Certificate, NodeId, BLSPublicKey, Bitfield, build_attestation_message, NomosDaG2ProofOfPossession as bls_pop
from da.common import Certificate, NodeId, BLSPublicKey, Bitfield, build_blob_id, NomosDaG2ProofOfPossession as bls_pop
from da.encoder import EncodedData
from da.verifier import DABlob, Attestation
@ -68,7 +68,7 @@ class Dispersal:
@staticmethod
def _build_attestation_message(encoded_data: EncodedData) -> bytes:
return build_attestation_message(encoded_data.aggregated_column_commitment, encoded_data.row_commitments)
return build_blob_id(encoded_data.aggregated_column_commitment, encoded_data.row_commitments)
def disperse(self, encoded_data: EncodedData) -> Optional[Certificate]:
attestations = []

View File

@ -2,7 +2,7 @@ from itertools import chain
from unittest import TestCase
from typing import List, Optional
from da.common import NodeId, build_attestation_message, BLSPublicKey, NomosDaG2ProofOfPossession as bls_pop
from da.common import NodeId, build_blob_id, BLSPublicKey, NomosDaG2ProofOfPossession as bls_pop
from da.api.common import DAApi, VID, Metadata
from da.verifier import DAVerifier, DABlob
from da.api.test_flow import MockStore
@ -21,7 +21,7 @@ class DAVerifierWApi:
if attestation := self.verifier.verify(blob):
# Warning: If aggregated col commitment and row commitment are the same,
# the build_attestation_message method will produce the same output.
cert_id = build_attestation_message(blob.aggregated_column_commitment, blob.rows_commitments)
cert_id = build_blob_id(blob.aggregated_column_commitment, blob.rows_commitments)
self.store.populate(blob, cert_id)
return attestation

View File

@ -9,7 +9,7 @@ from eth2spec.eip7594.mainnet import (
)
import da.common
from da.common import Column, Chunk, Attestation, BLSPrivateKey, BLSPublicKey, NomosDaG2ProofOfPossession as bls_pop
from da.common import Column, Chunk, Attestation, BlobId, BLSPublicKey, NomosDaG2ProofOfPossession as bls_pop
from da.encoder import DAEncoder
from da.kzg_rs import kzg
from da.kzg_rs.common import ROOTS_OF_UNITY, GLOBAL_PARAMETERS, BLS_MODULUS
@ -24,17 +24,16 @@ class DABlob:
rows_commitments: List[Commitment]
rows_proofs: List[Proof]
def id(self) -> bytes:
return da.common.build_attestation_message(self.aggregated_column_commitment, self.rows_commitments)
def blob_id(self) -> bytes:
return da.common.build_blob_id(self.aggregated_column_commitment, self.rows_commitments)
def column_id(self) -> bytes:
return sha3_256(self.column.as_bytes()).digest()
class DAVerifier:
def __init__(self, sk: BLSPrivateKey, nodes_pks: List[BLSPublicKey]):
self.attested_blobs: Dict[bytes, (bytes, Attestation)] = dict()
self.sk = sk
def __init__(self, nodes_pks: List[BLSPublicKey]):
self.attested_blobs: Set[BlobId] = set()
self.index = nodes_pks.index(bls_pop.SkToPk(self.sk))
@staticmethod
@ -77,16 +76,8 @@ class DAVerifier:
return False
return True
def _build_attestation(self, blob: DABlob) -> Attestation:
hasher = sha3_256()
hasher.update(bytes(blob.aggregated_column_commitment))
for c in blob.rows_commitments:
hasher.update(bytes(c))
message = hasher.digest()
return Attestation(signature=bls_pop.Sign(self.sk, message))
def verify(self, blob: DABlob) -> Optional[Attestation]:
blob_id = blob.id()
def verify(self, blob: DABlob) -> bool:
blob_id = blob.blob_id()
if previous_attestation := self.attested_blobs.get(blob_id):
column_id, attestation = previous_attestation
# we already attested, is cached so we return it
@ -94,7 +85,7 @@ class DAVerifier:
return attestation
# we already attested and they are asking us to attest the same data different column
# skip
return None
return False
is_column_verified = DAVerifier._verify_column(
blob.column,
blob.column_commitment,
@ -103,12 +94,11 @@ class DAVerifier:
self.index
)
if not is_column_verified:
return
return False
are_chunks_verified = DAVerifier._verify_chunks(
blob.column, blob.rows_commitments, blob.rows_proofs, self.index
)
if not are_chunks_verified:
return
attestation = self._build_attestation(blob)
self.attested_blobs[blob_id] = (blob.column_id(), attestation)
return attestation
return False
self.attested_blobs.add(blob_id)
return True