Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ChihChengLiang committed May 7, 2019
1 parent fd36a53 commit a93dfd3
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions scripts/benchmark_multi_multi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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)
print(len())
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()

0 comments on commit a93dfd3

Please sign in to comment.