mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-04-01 08:33:22 +00:00
Update verifier
This commit is contained in:
parent
fa4b97926b
commit
ccb21826e0
@ -32,41 +32,15 @@ class Dispersal:
|
||||
)
|
||||
yield blob
|
||||
|
||||
def _send_and_await_response(self, node: NodeId, blob: DAShare) -> bool:
|
||||
def _send_and_await_response(self, node: NodeId, blob: DABlob) -> bool:
|
||||
pass
|
||||
|
||||
def _build_certificate(
|
||||
self,
|
||||
encoded_data: EncodedData,
|
||||
attestations: Sequence[Attestation],
|
||||
signers: Bitfield
|
||||
) -> Certificate:
|
||||
assert len(attestations) >= self.settings.threshold
|
||||
assert len(attestations) == signers.count(True)
|
||||
aggregated = bls_pop.Aggregate([attestation.signature for attestation in attestations])
|
||||
return Certificate(
|
||||
aggregated_signatures=aggregated,
|
||||
signers=signers,
|
||||
aggregated_column_commitment=encoded_data.aggregated_column_commitment,
|
||||
row_commitments=encoded_data.row_commitments
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _verify_attestation(public_key: BLSPublicKey, attested_message: bytes, attestation: Attestation) -> bool:
|
||||
return bls_pop.Verify(public_key, attested_message, attestation.signature)
|
||||
|
||||
@staticmethod
|
||||
def _build_attestation_message(encoded_data: EncodedData) -> bytes:
|
||||
return build_blob_id(encoded_data.aggregated_column_commitment, encoded_data.row_commitments)
|
||||
|
||||
def disperse(self, encoded_data: EncodedData) -> Optional[Certificate]:
|
||||
def disperse(self, encoded_data: EncodedData):
|
||||
attestations = []
|
||||
attested_message = self._build_attestation_message(encoded_data)
|
||||
signed = Bitfield(False for _ in range(len(self.settings.nodes_ids)))
|
||||
blob_data = zip(
|
||||
self.settings.nodes_ids,
|
||||
self._prepare_data(encoded_data)
|
||||
)
|
||||
for node, blob in blob_data:
|
||||
for i, node, blob in blob_data:
|
||||
self._send_and_await_response(node, blob)
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@ from unittest import TestCase
|
||||
|
||||
from da.encoder import DAEncoderParams, DAEncoder
|
||||
from da.test_encoder import TestEncoder
|
||||
from da.verifier import DAVerifier, DAShare
|
||||
from da.common import NodeId
|
||||
from da.verifier import DAVerifier, DABlob
|
||||
from da.common import NodeId, NomosDaG2ProofOfPossession as bls_pop
|
||||
from da.dispersal import Dispersal, DispersalSettings
|
||||
|
||||
|
||||
@ -25,15 +25,11 @@ class TestDispersal(TestCase):
|
||||
encoded_data = DAEncoder(encoding_params).encode(data)
|
||||
|
||||
# mock send and await method with local verifiers
|
||||
verifiers_res = []
|
||||
def __send_and_await_response(_, blob: DAShare):
|
||||
def __send_and_await_response(blob: DABlob):
|
||||
verifier = DAVerifier()
|
||||
res = verifier.verify(blob)
|
||||
verifiers_res.append(res)
|
||||
return res
|
||||
return verifier.verify(blob)
|
||||
# inject mock send and await method
|
||||
self.dispersal._send_and_await_response = __send_and_await_response
|
||||
self.dispersal.disperse(encoded_data)
|
||||
for res in verifiers_res:
|
||||
self.assertTrue(res)
|
||||
|
||||
self.assertTrue(self.dispersal.disperse(encoded_data))
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ _DST = b"NOMOS_DA_V1"
|
||||
@dataclass
|
||||
class DAShare:
|
||||
column: Column
|
||||
column_idx: int
|
||||
column_commitment: Commitment
|
||||
aggregated_column_commitment: Commitment
|
||||
aggregated_column_proof: Proof
|
||||
@ -35,17 +36,16 @@ class DAShare:
|
||||
return build_blob_id(self.row_commitments)
|
||||
|
||||
class DAVerifier:
|
||||
def __init__(self, nodes_pks: List[BLSPublicKey]):
|
||||
def __init__(self):
|
||||
self.attested_blobs: Set[BlobId] = set()
|
||||
self.index = nodes_pks.index(bls_pop.SkToPk(self.sk))
|
||||
|
||||
@staticmethod
|
||||
def _verify_column(
|
||||
column: Column,
|
||||
column_idx: int,
|
||||
column_commitment: Commitment,
|
||||
aggregated_column_commitment: Commitment,
|
||||
aggregated_column_proof: Proof,
|
||||
index: int
|
||||
) -> bool:
|
||||
# 1. compute commitment for column
|
||||
_, computed_column_commitment = kzg.bytes_to_commitment(column.as_bytes(), GLOBAL_PARAMETERS)
|
||||
@ -57,11 +57,7 @@ class DAVerifier:
|
||||
# 4. Check proof with commitment and proof over the aggregated column commitment
|
||||
chunk = BLSFieldElement.from_bytes(column_hash)
|
||||
return kzg.verify_element_proof(
|
||||
combined_eval_point,
|
||||
combined_commitment,
|
||||
blob.combined_column_proof,
|
||||
blob.column_idx,
|
||||
ROOTS_OF_UNITY
|
||||
chunk, aggregated_column_commitment, aggregated_column_proof, column_idx, ROOTS_OF_UNITY
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@ -85,25 +81,21 @@ class DAVerifier:
|
||||
|
||||
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
|
||||
if column_id == blob.column_id():
|
||||
return attestation
|
||||
# we already attested and they are asking us to attest the same data different column
|
||||
if blob_id in self.attested_blobs:
|
||||
# we already attested and they are asking us to attest again
|
||||
# skip
|
||||
return False
|
||||
is_column_verified = DAVerifier._verify_column(
|
||||
blob.column,
|
||||
blob.column_idx,
|
||||
blob.column_commitment,
|
||||
blob.aggregated_column_commitment,
|
||||
blob.aggregated_column_proof,
|
||||
self.index
|
||||
)
|
||||
if not is_column_verified:
|
||||
return False
|
||||
are_chunks_verified = DAVerifier._verify_chunks(
|
||||
blob.column, blob.rows_commitments, blob.rows_proofs, self.index
|
||||
blob.column, blob.rows_commitments, blob.rows_proofs, blob.column_idx
|
||||
)
|
||||
if not are_chunks_verified:
|
||||
return False
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user