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

Optimized final exponentiation in the pairing implementation + faster proof verification #41

Closed
wants to merge 8 commits into from

Conversation

yelhousni
Copy link
Contributor

@yelhousni yelhousni commented Feb 12, 2020

Solves #31.

Currently, the final exponentiation in the snarkjs pairing implementation consists in raising to a 2790-bit integer in Fq12. This PR implements an optimized lattice-based final exponentiation following [SAC:FueKnaRod11].

        /**
         * Final exponentiation on alt-bn128:
         *
         * elt^final_exponent = elt^((q^12-1)/r)
         *                    = elt^((q^6-1)*(q^2+1)) * elt^((q^4-q^2+1)/r)
         *                            "easy part"           "hard part"
         * 
         * "easy part":
         * elt^((q^6-1)*(q^2+1)) = (elt^(q^6) * elt^(-1))^(q^2) * (elt^(q^6) * elt^(-1)) 
         * where:
         * (.)^(q^6) is a conjugate and (.)^(q^2) a q^2-Frobenius power in F12
         *
         * "hard part":
         * We raise to a multiple of the exponent and decompose it in a q(z)-base (LLL algorithm)
         * where z in the bn curve seed.
         * (Laura Fuentes-Castaneda et al. "Faster hashing to G2")
         * elt^( 2z * ( 6z^2 + 3z + 1 ) * (q^4 - q^2 + 1)/r ) = elt^(q^3 * (12*z^3 + 6z^2 + 4z - 1) +
         *                                                           q^2 * (12*z^3 + 6z^2 + 6z) +
         *                                                           q   * (12*z^3 + 6z^2 + 4z) +
         *                                                           1   * (12*z^3 + 12z^2 + 6z + 1)) 
         * where:
         * (.)^(q^i) are q^i-Frobenius powers in F12 for i in {1,2,3}
         */

In addition to the pairing test with the new version in ./test/algebra.js, the PR implements a test to check if the optimized method gives the same result as the old method, and compares timings (~14x faster).

Type: Enhacement
Status: Ready to review

@yelhousni
Copy link
Contributor Author

yelhousni commented Feb 12, 2020

Also, the current Groth16 proof verification equation is e(proof.pi_a, proof.pi_b) == vk_alfabeta_12 * e(cpub , vk_verifier.vk_gamma_2) * e(proof.pi_c , vk_verifier.vk_delta_2) which costs 3 Miller loops, 3 final exponentiations, 2 multiplications in Fq12 and 1 equality check in Fq12. The last commit of this PR changes the equation into vk_alfabeta_12 == FE( ML(proof.pi_a, proof.pi_b), conj(2ML( cpub , vk_verifier.vk_gamma_2, proof.pi_c , vk_verifier.vk_delta_ )) ), where FE is factored for the 3 pairings and double Miller loop (2ML) is implemented to factor one square inside the loop. This reduces the verification cost to 1 Miller loop + 1 double Miller loop + 1 final exponentiation + 1 multiplication in Fq12 + 1 conjugate in Fq12 + 1 equality check in Fq12.

This can be applied to pghr13 and kimleeoh too. [update] Last two commits rearrange pghr13 and kimleeoh the same way.

@yelhousni yelhousni changed the title Optimized final exponentiation in the pairing implementation Optimized final exponentiation in the pairing implementation + faster Groth16 proof verification Feb 12, 2020
@yelhousni yelhousni changed the title Optimized final exponentiation in the pairing implementation + faster Groth16 proof verification Optimized final exponentiation in the pairing implementation + faster proof verification Feb 12, 2020
@yelhousni yelhousni closed this Feb 12, 2020
@yelhousni yelhousni deleted the youssef/optimized-final-exp branch February 12, 2020 21:55
@yelhousni yelhousni restored the youssef/optimized-final-exp branch February 13, 2020 08:36
@yelhousni yelhousni reopened this Feb 13, 2020
@jbaylina
Copy link
Member

Current version uses wasmcurves and it already implements the fast final exp algorithm

@jbaylina jbaylina closed this Jul 14, 2020
@yelhousni yelhousni deleted the youssef/optimized-final-exp branch August 7, 2024 18:08
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.

2 participants