-
Notifications
You must be signed in to change notification settings - Fork 84
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
ChihChengLiang
wants to merge
7
commits into
ethereum:main
Choose a base branch
from
ChihChengLiang:fast-verification-of-multiple-bls-signatures
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
93ca78a
fast-verification-of-multiple-bls-signatures
ChihChengLiang 7c8cd1a
no need to randomize the first sig
ChihChengLiang 5a81f04
add benchmark
ChihChengLiang 081d90a
PR feedback 1
ChihChengLiang 59c319d
remove groupby
ChihChengLiang fc65be3
PR feedback 2, remove randomness
ChihChengLiang 6f3382d
resurrect groupby
ChihChengLiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
sign, | ||
verify, | ||
verify_multiple, | ||
verify_multiple_multiple, | ||
) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from random import sample | ||
from py_ecc.bls import ( | ||
aggregate_pubkeys, | ||
aggregate_signatures, | ||
sign, | ||
privtopub, | ||
verify_multiple, | ||
verify_multiple_multiple, | ||
) | ||
import time | ||
|
||
domain = 0 | ||
validator_indices = tuple(range(1000)) | ||
privkeys = tuple(2**i for i in validator_indices) | ||
pubkeys = [privtopub(k) for k in privkeys] | ||
|
||
MAX_ATTESTATIONS = 128 | ||
TARGET_COMMITTEE_SIZE = 128 | ||
|
||
|
||
class Attestation: | ||
def __init__(self, msg_1, msg_2): | ||
msg_1_validators = sample(validator_indices, TARGET_COMMITTEE_SIZE//2) | ||
msg_2_validators = sample(validator_indices, TARGET_COMMITTEE_SIZE//2) | ||
self.agg_pubkeys = [ | ||
aggregate_pubkeys([pubkeys[i] for i in msg_1_validators]), | ||
aggregate_pubkeys([pubkeys[i] for i in msg_2_validators]), | ||
] | ||
self.msgs = [msg_1, msg_2] | ||
msg_1_sigs = [sign(msg_1, privkeys[i], domain) for i in msg_1_validators] | ||
msg_2_sigs = [sign(msg_2, privkeys[i], domain) for i in msg_2_validators] | ||
self.sig = aggregate_signatures([ | ||
aggregate_signatures(msg_1_sigs), | ||
aggregate_signatures(msg_2_sigs), | ||
]) | ||
|
||
|
||
att = Attestation(b'\x12' * 32, b'\x34' * 32) | ||
atts = (att,) * MAX_ATTESTATIONS | ||
|
||
|
||
def profile_verify_multiple(): | ||
t = time.time() | ||
for att in atts: | ||
assert verify_multiple( | ||
pubkeys=att.agg_pubkeys, | ||
message_hashes=att.msgs, | ||
signature=att.sig, | ||
domain=domain, | ||
) | ||
print(time.time() - t) | ||
|
||
|
||
def profile_verify_multiple_multiple(): | ||
t = time.time() | ||
assert verify_multiple_multiple( | ||
signatures=[att.sig for att in atts], | ||
pubkeys_and_messages=[[att.agg_pubkeys, att.msgs] for att in atts], | ||
domain=domain, | ||
) | ||
print(time.time() - t) | ||
|
||
|
||
if __name__ == '__main__': | ||
print("profile_verify_multiple") | ||
profile_verify_multiple() | ||
print("profile_verify_multiple_multiple") | ||
profile_verify_multiple_multiple() |
This file contains 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
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.
There was a problem hiding this comment.
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
...There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 parameterpubkeys_and_messages: Sequence[Tuple[Sequence[BLSPubkey], Sequence[Hash32]]]
is also confusing. Should we create some objects likeThen write the function parameters in this fashion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChihChengLiang
how about
batch_verify
?There was a problem hiding this comment.
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.