nomos-specs/da/kzg_rs/test_fk20.py
Daniel Sanchez 422359acd7
Da: fk20 proof generation (#95)
* Kickstart fk20

* Implement i/fft from ethspecs

* Expand test to different sizes

* Implement toeplizt

* Finish implementing fk20

* Fix roots of unity generation

* Implement fft for g1 values

* Fix fk20 and tests

* Add len assertion in test

* Fix roots computations

* Fix test

* Fix imports

* Fmt

* Docs and format
2024-06-17 09:20:11 +02:00

29 lines
1.1 KiB
Python

from itertools import chain
from unittest import TestCase
import random
from .fk20 import fk20_generate_proofs
from .kzg import generate_element_proof, bytes_to_polynomial
from .common import BLS_MODULUS, BYTES_PER_FIELD_ELEMENT, GLOBAL_PARAMETERS, PRIMITIVE_ROOT
from .roots import compute_roots_of_unity
class TestFK20(TestCase):
@staticmethod
def rand_bytes(n_chunks=1024):
return bytes(
chain.from_iterable(
int.to_bytes(random.randrange(BLS_MODULUS), length=BYTES_PER_FIELD_ELEMENT)
for _ in range(n_chunks)
)
)
def test_fk20(self):
for size in [16, 32, 64, 128, 256]:
roots_of_unity = compute_roots_of_unity(PRIMITIVE_ROOT, size, BLS_MODULUS)
rand_bytes = self.rand_bytes(size)
polynomial = bytes_to_polynomial(rand_bytes)
proofs = [generate_element_proof(i, polynomial, GLOBAL_PARAMETERS, roots_of_unity) for i in range(size)]
fk20_proofs = fk20_generate_proofs(polynomial, GLOBAL_PARAMETERS)
self.assertEqual(len(proofs), len(fk20_proofs))
self.assertEqual(proofs, fk20_proofs)