perf(bn254): include G2 membership check in ML #1387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Including G2 subgroup membership in the pairing computations saves a lot of constraints. For Linea zkEVM, gnark circuit has only to check G2 membership as the arithemtization does the check for G1.
In
computeLines
the accumulated point is[6x₀+2]Q
(x₀
being the curve seed). We can tweak* the subgroup membership to check[6x₀+2]Q + ψ(Q) + ψ³(Q) == ψ²(Q)
instead ofψ³([2x₀]Q) - ψ²([x₀]Q) - ψ([x₀]Q) - [x₀]Q == Q
. This saves the multiplication by6x₀+2
and enforces G2 membership check systematically in pairing calls, simplifying probably the Wizard glue.* since
x₀ ≠ 4 mod 13 and x₀ ≠ 92 mod 97
for BN254,V=(6x₀+ 2,1,−1,1)
is also a valid short vector.TL;DR: G2 subgroup membership becomes ~2 point additions instead of ~81 point additions.
Type of change
How has this been tested?
All current tests pass.
How has this been benchmarked?
On one hand a product of 2 pairings check increases by 18,857 scs but on the other hand the G2 membership which costs (for 2 points) 407,729 scs is removed.
Checklist:
golangci-lint
does not output errors locally