HorizenOfficial / ginger-lib

Ginger-lib is a general purpose zk-SNARK library that supports recursive proof composition
Apache License 2.0
84 stars 17 forks source link

Restructuring pairings #42

Closed UlrichHaboeck75 closed 2 years ago

UlrichHaboeck75 commented 4 years ago

By now the pairing engines for different types of pairing-friendly curves are implemented independently, resulting in five pieces of very similar code for the Ate pairing evaluation:

I propose a different level of abstraction, introducing twist2Ate and twist6Ate as pairing types according to the two representations of G2 as found in the above implementations: either as a subgroup of a quadratic twist (as for MNT4/6, mnt6, sw6) or sextic twist (BLS12) of the curve. Both twist2Ate and twist6Ate need to allow the base field for the twist E' to be a general extension field of the same characteristic as the one for E - but the operations for the evaluation of the Ate paring are generic, i.e. independent of the degree of the base field for E'.

Such abstraction makes it possible to reuse these two types of pairing types, and to aggregate pairing evaluation code in an own folder (e.g. algebra/src/pairings/ ) separated from algebra/src/curves, which contain also non-pairing-friendly curves such as the JubJub.

In my opinion such a structure is more clear than the present. Moreover, it makes it is easier to find all the pairing code when extending the lib by further pairing types (which use cubic twists, e.g.).

DanieleDiBenedetto commented 2 years ago

Not needed anymore after #144