perf(bls): remove redundant G2 subgroup check in signature verification#782
Open
sashass1315 wants to merge 1 commit intoa16z:masterfrom
Open
perf(bls): remove redundant G2 subgroup check in signature verification#782sashass1315 wants to merge 1 commit intoa16z:masterfrom
sashass1315 wants to merge 1 commit intoa16z:masterfrom
Conversation
Author
Contributor
|
For context, a similar optimization has been postponed, see here #751 (comment) |
Author
Ohh sorry, didn't really thought about looking at PRs. So I close this PR then? if it's yours idea |
Contributor
No of course not, let's keep it. Just added a pointer to remember that it's been discussed before. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


The [Signature::verify()](
helios/ethereum/consensus-core/src/types/bls.rs
Lines 39 to 50 in 4a32ac1
[subgroup_check_g2()]
helios/ethereum/consensus-core/src/types/bls.rs
Lines 84 to 90 in 4a32ac1
G2Affine::from_compressed(). However,from_compressed()already performs a subgroup check internally viais_torsion_free()- this is a documented property of the bls12_381 crate.The explicit check was performing an expensive scalar multiplication (
point * rwhere r is the 255-bit curve order) that duplicated work already done during decompression.Remove the redundant [subgroup_check_g2()] function and its call from [Signature::verify()]. Also remove the now-unused [hex_to_scalar()] helper and the
Scalarimport. This eliminates one full G2 scalar multiplicationper signature verification (~30-50% speedup for the verification path).