Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rust product of extension field elements utilities. #161

Closed
feltroidprime opened this issue Aug 19, 2024 · 0 comments
Closed

feat: Rust product of extension field elements utilities. #161

feltroidprime opened this issue Aug 19, 2024 · 0 comments
Assignees
Labels
enhancement Enhancement of the code, not introducing new features.

Comments

@feltroidprime
Copy link
Collaborator

feltroidprime commented Aug 19, 2024

To compute multi pairings checks hints, we need to have a function that computes a product of extension field elements (the 12-degree extension) in the form of polynomials of degree 11, and store both the quotient Q and the remainder R, as polynomials.

Q can be of arbitrary degree, but R must of degree 11 (12 coefficients)

def nondeterministic_extension_field_mul_divmod(
Ps: list[list[PyFelt | ModuloCircuitElement]],
curve_id: int,
extension_degree: int,
) -> tuple[list[PyFelt], list[PyFelt]]:
Ps = [Polynomial(P) for P in Ps]
field = get_base_field(curve_id)
P_irr = get_irreducible_poly(curve_id, extension_degree)
z_poly = reduce(operator.mul, Ps) # Π(Pi)
z_polyq, z_polyr = divmod(z_poly, P_irr)
z_polyr_coeffs = z_polyr.get_coeffs()
z_polyq_coeffs = z_polyq.get_coeffs()
# assert len(z_polyq_coeffs) <= (
# extension_degree - 1
# ), f"len z_polyq_coeffs={len(z_polyq_coeffs)}, degree: {z_polyq.degree()}"
assert (
len(z_polyr_coeffs) <= extension_degree
), f"len z_polyr_coeffs={len(z_polyr_coeffs)}, degree: {z_polyr.degree()}"
# Extend polynomials with 0 coefficients to match the expected lengths.
# TODO : pass exact expected max degree when len(Ps)>2.
z_polyq_coeffs += [field(0)] * (extension_degree - 1 - len(z_polyq_coeffs))
z_polyr_coeffs += [field(0)] * (extension_degree - len(z_polyr_coeffs))
return (z_polyq_coeffs, z_polyr_coeffs)

Implement an equivalent version of this function that works with polynomials in input and output., parametrized by <F> (or Polynomial<F>), although it should work only for BN and BLS.

They key is that this function takes a list of Polynomial<F> as input, and returns Q, R, two polynomials such that they correspond to the euclidean division of the product of the input by some constant Polynomial parametrized by <F>

The constant polynomials are defined in definitions.py. Only use the degree-12 one.

To perform the computation, polynomial.rs has the necessary methods, especially divmod.

@feltroidprime feltroidprime added the enhancement Enhancement of the code, not introducing new features. label Aug 19, 2024
@feltroidprime feltroidprime changed the title feat: Rust extension field multiplications utilities. feat: Rust product of extension field utilities. Aug 19, 2024
@feltroidprime feltroidprime changed the title feat: Rust product of extension field utilities. feat: Rust product of extension field elements utilities. Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of the code, not introducing new features.
Projects
None yet
Development

No branches or pull requests

2 participants