From 5a551a0aa6b253d9d48f3c0253709fdcfe8ca9ff Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Tue, 9 Jan 2024 16:04:38 +0200 Subject: [PATCH] Work on hww's round-trip FFT test --- .../test_polynomial_commitments.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/peerdas/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/peerdas/unittests/polynomial_commitments/test_polynomial_commitments.py index 1b06f9cde..0e0f787fb 100644 --- a/tests/core/pyspec/eth2spec/test/peerdas/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/peerdas/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -7,19 +7,23 @@ from eth2spec.test.context import ( from eth2spec.test.helpers.sharding import ( get_sample_blob, ) - +from eth2spec.utils.bls import BLS_MODULUS @with_peerdas_and_later @spec_test @single_phase def test_fft(spec): - vals = [int.from_bytes(x, spec.KZG_ENDIANNESS) for x in spec.KZG_SETUP_G1_MONOMIAL] - roots_of_unity = spec.compute_roots_of_unity(spec.FIELD_ELEMENTS_PER_BLOB) - result = spec.fft_field(vals, roots_of_unity) - assert len(result) == len(vals) - # TODO: add more assertions? - # One possible test would be to use polynomial_eval_to_coeff() + rng = random.Random(5566) + roots_of_unity = spec.compute_roots_of_unity(spec.FIELD_ELEMENTS_PER_BLOB) + + poly_coeff = [rng.randint(0, BLS_MODULUS - 1) for _ in range(spec.FIELD_ELEMENTS_PER_BLOB)] + + poly_eval = spec.fft_field(poly_coeff, roots_of_unity) + poly_coeff_inversed = spec.fft_field(poly_eval, roots_of_unity, inv=True) + + assert len(poly_eval) == len(poly_coeff) == len(poly_coeff_inversed) + assert poly_coeff_inversed == poly_coeff @with_peerdas_and_later @spec_test