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

fast-verification-of-multiple-bls-signatures #67

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

Conversation

ChihChengLiang
Copy link
Contributor

What was wrong?

https://ethresear.ch/t/fast-verification-of-multiple-bls-signatures/5407

How was it fixed?

Cute Animal Picture

put a cute animal picture link inside the parentheses

@ChihChengLiang ChihChengLiang force-pushed the fast-verification-of-multiple-bls-signatures branch 4 times, most recently from cd57296 to 026b2f5 Compare May 6, 2019 08:17
py_ecc/bls/api.py Outdated Show resolved Hide resolved
py_ecc/bls/api.py Outdated Show resolved Hide resolved
py_ecc/bls/api.py Outdated Show resolved Hide resolved
py_ecc/bls/api.py Outdated Show resolved Hide resolved
py_ecc/bls/api.py Outdated Show resolved Hide resolved

class Attestation:
def __init__(self, msg_1, msg_2):
msg_1_validators = sample(validator_indices, 3)
Copy link
Member

Choose a reason for hiding this comment

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

Anytime we use randomness in tests we should be using the mechanisms provided by hypothesis since they allow us to reproduce failures when they occur. Otherwise failures due to random data will be opaque and we won't be able to recreate the conditions that produced them.

See: https://hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.random_module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed randomness for now. Planning to rewrite bls tests with pytest fixtures and hypothesis.

Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

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

Could you benchmark this v.s. verify_multiple?

@@ -109,3 +113,48 @@ def verify_multiple(pubkeys: Sequence[BLSPubkey],
return final_exponentiation == FQ12.one()
except (ValidationError, ValueError, AssertionError):
return False


def verify_multiple_multiple(
Copy link
Contributor

Choose a reason for hiding this comment

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

Renaming ideas: optimized_verify_multiple, fast_verify_multiple...

Copy link
Member

Choose a reason for hiding this comment

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

If it's faster why not just replace the existing implementation instead of maintaining two?

Also, if there's an existing one and we are keeping both around, seems prudent to test them against each other to ensure they have equal behavior (sorry if I missed the test that does 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.

The new function is an optimized version of doing multiple times of verify_multiple. The later verifies a single attestation and the former verifies many attestations in a block.

Copy link
Contributor Author

@ChihChengLiang ChihChengLiang May 7, 2019

Choose a reason for hiding this comment

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

I do desperately want to get rid of verify_multiple_multiple and rename it properly. Besides the name of the function, the function parameter pubkeys_and_messages: Sequence[Tuple[Sequence[BLSPubkey], Sequence[Hash32]]] is also confusing. Should we create some objects like

class SignedMessage:
    signature: BLSSignature
    public_keys: Sequence[BLSPubkey]
    message_hashes: Sequence[Hash32]
    def __init__(self, signature, public_keys, message_hashes):
        self.signature = signature
        if len(public_keys) != len(message_hashes)
            raise ValidationError()
        self.public_keys = public_keys
        self.message_hashes = message_hashes

Then write the function parameters in this fashion?

def verify_multiple(signed_message: SignedMessage): 
def verify_multiple_multiple(signed_messages: Sequence[SignedMessage]): 

Copy link

Choose a reason for hiding this comment

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

@ChihChengLiang

I do desperately want to get rid of verify_multiple_multiple and rename it properly.

how about batch_verify ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. We could also do "verify_multiple_aggregate_signatures" to match milagro's function name.

@ChihChengLiang
Copy link
Contributor Author

benchmark before rename and pr feedback

  • profile_verify_multiple 177 sec
  • profile_verify_multiple_multiple 92 sec

@ChihChengLiang ChihChengLiang force-pushed the fast-verification-of-multiple-bls-signatures branch 2 times, most recently from a93dfd3 to 295b71b Compare May 7, 2019 09:30

if len(pubkeys) != len_msgs:
o = FQ12.one()
for message_hash, group_pubkeys in _group_by_messages(message_hashes, pubkeys):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hwwhww This groupby step is actually useless. The use cases in the spec suggest that bls_verify_multiple shouldn't group the message_hash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Brought back groupby, since it's more like an optimization to save pairings for more general cases.

@pipermerriam
Copy link
Member

@ChihChengLiang glancing at the library I don't see any benchmarking tools which suggests you did the benchmarking manually. Would you mind contributing some version of that into the core library so we can have a starting point for future library optimizations?

@ChihChengLiang
Copy link
Contributor Author

@pipermerriam manually in this PR 😂scripts/benchmark_multi_multi.py https://github.com/ethereum/py_ecc/pull/67/files#diff-6603fa8fb24b1bbf0f65499a385162e4

@ChihChengLiang ChihChengLiang force-pushed the fast-verification-of-multiple-bls-signatures branch from 80b7c32 to e733f5e Compare May 28, 2019 08:42
@ChihChengLiang ChihChengLiang force-pushed the fast-verification-of-multiple-bls-signatures branch from e733f5e to 6f3382d Compare May 28, 2019 08:43
pacrob pushed a commit to pacrob/py_ecc that referenced this pull request Oct 29, 2023
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.

4 participants