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

355 mnt4 mnt6 pairing component #357

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

vo-nil
Copy link
Contributor

@vo-nil vo-nil commented Mar 29, 2024

No description provided.

@vo-nil vo-nil force-pushed the 355-mnt4-mnt6-pairing-component branch 3 times, most recently from 1ca01f0 to 1321b8f Compare April 22, 2024 06:52
@vo-nil vo-nil requested review from Iluvmagick and ayashunsky April 22, 2024 06:56
gate_list.push_back(bp.add_gate(mult_constrs));
}

if (std::count(exp_precompute.begin(),exp_precompute.end(),3)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cubing and square gates are used only to build cube/square in the beginning and are unused everywhere else. More efficient to just build cube/square through multiplications, without adding more gates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obviously inspired by my BLS12 pairing code, which also used cube and square only once. Back then I just didn't realize how important gate economy was. Right now I would also suggest replacing squaring and cubing by multiplication at the expense of some extra rows.
That is, unless we need this component really quick.

* Ensures x_next = x_prev/x : x_next * x - x_prev = 0
*/
{
R = Xn*X - Xp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to forbid passing 0 into this circuit: if x_prev = x = 0, we can set x_next arbitrarily.
Unsure if this is going to actually come up in practice.
But given that it can be solved with one-row constraint in the beginning to the tune of x * y = 1, we probably still should? Open to discussion on this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the issue of division by zero should be, of course, analyzed, I would question the necessity of a division gate in general. It is used only once and can be replaced by a multiplication gate using some copy constraints. In view of the gate (i.e. selector column) economy this achieves, I would seriously consider that.

* Tnext.y = (3*T.x^2+a)/2T.y *(T.x-Tnext.x)-T.y
* Rewrite:
* (Tnext.x + 2*Tx) * (2*T.y)^2 - (3*T.x^2+a)^2 = 0
* (Tnext.y + T.y) * (2*T.y) - (3*T.x^2+a)*(T.x-Tnext.x) = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While T cannot start as zero point during the calculation, I am unsure what guarantees that it cannot become a zero point during it.
Is the above guaranteed by some property?
Otherwise, if both T.x and T.y are zero, there is no possible assignment which would satisfy the above constraints.
(there is also a similar assumption made in calculation of lf just above this)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment.
T starts with Q, then it is 2Q, 3Q, 6Q and so on, up to ate_loop_count*Q, point Q (all points on E') has order q, T will never be zero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is certainly a clever and important observation, I believe it should be placed as a comment to the code, not just mentionned in an answer in a github discussion.

test/test_plonk_component.hpp Outdated Show resolved Hide resolved
@vo-nil vo-nil force-pushed the 355-mnt4-mnt6-pairing-component branch from f61f69e to 0de7980 Compare April 29, 2024 21:10
@vo-nil vo-nil requested a review from Iluvmagick April 29, 2024 21:12
// SOFTWARE.
//---------------------------------------------------------------------------//
// @file Declaration of F_p^3 elements over an abstract entity (to be used with constraints)
// with F_p^3 = F_p[u]/(u^3 + non_residue).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it should be "minus non-residue", not "plus", i.e. F_p[u]/(u^3 - non_residue) instead of F_p[u]/(u^3 + non_residue)


constexpr abstract_fp4_element operator*(abstract_fp4_element const& y) {
// Devegili et al - Multiplication and squaring in pairing-friendly fields
// https://eprint.iacr.org/2006/471.pdf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say the reference is misleading because we don't use any optimisation here. Just the "schoolbook" formulas.

Copy link
Contributor

@ayashunsky ayashunsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is most important that the reasons for T != O in the Miller loop make their way into the code comments and are preserved for future reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants