mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 00:24:37 +03:00
Optimize code to not perform useless subgroup checks (#11546)
* Optimize code to not perform useless subgroup checks * Revert less important optimizations
This commit is contained in:
parent
99275e6e37
commit
31ed32628f
@ -122,7 +122,8 @@ def batch_pre_validate_blocks(
|
||||
if npc_result is not None and block.transactions_info is not None:
|
||||
assert npc_result.conds
|
||||
pairs_pks, pairs_msgs = pkm_pairs(npc_result.conds, constants.AGG_SIG_ME_ADDITIONAL_DATA)
|
||||
pks_objects: List[G1Element] = [G1Element.from_bytes(pk) for pk in pairs_pks]
|
||||
# Using AugSchemeMPL.aggregate_verify, so it's safe to use from_bytes_unchecked
|
||||
pks_objects: List[G1Element] = [G1Element.from_bytes_unchecked(pk) for pk in pairs_pks]
|
||||
if not AugSchemeMPL.aggregate_verify(
|
||||
pks_objects, pairs_msgs, block.transactions_info.aggregated_signature
|
||||
):
|
||||
|
@ -33,6 +33,8 @@ def get_pairings(cache: LRUCache, pks: List[bytes48], msgs: Sequence[bytes], for
|
||||
|
||||
pk_parsed: Optional[G1Element] = pk_bytes_to_g1.get(pks[i])
|
||||
if pk_parsed is None:
|
||||
# In this case, we use from_bytes instead of from_bytes_unchecked, because we will not be using
|
||||
# the bls_signatures aggregate_verify method which performs the subgroup checks
|
||||
pk_parsed = G1Element.from_bytes(pks[i])
|
||||
pk_bytes_to_g1[pks[i]] = pk_parsed
|
||||
|
||||
@ -53,7 +55,8 @@ def aggregate_verify(
|
||||
):
|
||||
pairings: List[GTElement] = get_pairings(cache, pks, msgs, force_cache)
|
||||
if len(pairings) == 0:
|
||||
pks_objects: List[G1Element] = [G1Element.from_bytes(pk) for pk in pks]
|
||||
# Using AugSchemeMPL.aggregate_verify, so it's safe to use from_bytes_unchecked
|
||||
pks_objects: List[G1Element] = [G1Element.from_bytes_unchecked(pk) for pk in pks]
|
||||
return AugSchemeMPL.aggregate_verify(pks_objects, msgs, sig)
|
||||
|
||||
pairings_prod: GTElement = functools.reduce(GTElement.__mul__, pairings)
|
||||
|
Loading…
Reference in New Issue
Block a user