mirror of
https://github.com/logos-co/nomos-specs.git
synced 2025-02-08 13:33:49 +00:00
Added compute proofs (wip)
This commit is contained in:
parent
b692a47f7b
commit
906b626e67
15
da/kzg_rs.py
15
da/kzg_rs.py
@ -3,7 +3,7 @@ from typing import List, Sequence
|
||||
|
||||
from eth2spec.eip7594.mainnet import (
|
||||
bit_reversal_permutation, KZG_SETUP_G1_LAGRANGE, Polynomial,
|
||||
BYTES_PER_FIELD_ELEMENT, bytes_to_bls_field, BLSFieldElement,
|
||||
BYTES_PER_FIELD_ELEMENT, bytes_to_bls_field, BLSFieldElement, compute_kzg_proof_impl, KZG_ENDIANNESS,
|
||||
)
|
||||
from eth2spec.eip7594.mainnet import KZGCommitment as Commitment, KZGProof as Proof
|
||||
from eth2spec.utils import bls
|
||||
@ -38,3 +38,16 @@ def bytes_to_kzg_commitment(b: bytearray) -> Commitment:
|
||||
return g1_lincomb(
|
||||
bit_reversal_permutation(KZG_SETUP_G1_LAGRANGE), bytes_to_polynomial(b)
|
||||
)
|
||||
|
||||
|
||||
def compute_kzg_proofs(b: bytearray, commitment: Commitment) -> List[Proof]:
|
||||
assert len(b) % BYTES_PER_FIELD_ELEMENT == 0
|
||||
polynomial = bytes_to_polynomial(b)
|
||||
return [
|
||||
compute_kzg_proof_impl(
|
||||
polynomial,
|
||||
bytes_to_bls_field(i.to_bytes(length=BYTES_PER_FIELD_ELEMENT, byteorder=KZG_ENDIANNESS))
|
||||
)[0]
|
||||
for i in range(len(b)//BYTES_PER_FIELD_ELEMENT)
|
||||
]
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
from itertools import chain
|
||||
from random import randrange
|
||||
from unittest import TestCase
|
||||
from da.kzg_rs import Polynomial, bytes_to_polynomial, bytes_to_kzg_commitment
|
||||
from da.kzg_rs import Polynomial, bytes_to_polynomial, bytes_to_kzg_commitment, compute_kzg_proofs
|
||||
from eth2spec.eip7594.mainnet import (
|
||||
Polynomial as EthPolynomial, blob_to_polynomial, BLS_MODULUS,
|
||||
BYTES_PER_FIELD_ELEMENT, FIELD_ELEMENTS_PER_BLOB, Blob, blob_to_kzg_commitment
|
||||
@ -37,3 +37,9 @@ class TestKzgRs(TestCase):
|
||||
rand_bytes = self.rand_bytes()
|
||||
commitment2 = bytes_to_kzg_commitment(rand_bytes)
|
||||
self.assertEqual(len(commitment), len(commitment2))
|
||||
|
||||
def test_compute_kzg_proofs(self):
|
||||
rand_bytes = self.rand_bytes()
|
||||
commitment = bytes_to_kzg_commitment(rand_bytes)
|
||||
proofs = compute_kzg_proofs(rand_bytes, commitment)
|
||||
self.assertEqual(len(proofs), FIELD_ELEMENTS_PER_BLOB)
|
Loading…
x
Reference in New Issue
Block a user