Skip to content

Commit

Permalink
Update bls aggregation benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Nov 8, 2018
1 parent 386d246 commit b9b9e0e
Showing 1 changed file with 69 additions and 29 deletions.
98 changes: 69 additions & 29 deletions benchmarks/bench_bls_sig_agggregation.nim
Expand Up @@ -57,7 +57,13 @@ proc main(nb_samples: Natural) =
parent_hashes = newSeqWith(num_parent_hashes, randBytes32())
shard_block_hash = randBytes32()

echo "\n#### Block parameters"
echo '\n'
echo "######################"
echo "#"
echo "# Benchmark parameters"
echo "#"
echo "######################"
echo '\n'
echo &"Number of validators: {num_validators:>64}"
echo &"Number of block parent hashes: {num_parent_hashes:>64}"
echo &"Fork version: {fork_version:>64}"
Expand All @@ -67,59 +73,93 @@ proc main(nb_samples: Natural) =
echo &"Shard_block_hash: {shard_block_hash.toHex:>64}"
echo &"justified_slot: {justified_slot:>64}"

#####################
echo '\n'
echo "######################"
echo "#"
echo "# Benchmark prologue"
echo "#"
echo "######################"
echo '\n'

var start = cpuTime()
let secret_public_keypairs = newSeqWith(num_validators, newKeyPair())
var stop = cpuTime()

echo '\n'
echo "#### Message, crypto keys and signatures"
echo "#### Message crypto keys, signatures and proofs of possession"
echo &"{num_validators} secret and public keys pairs generated in {stop - start :>4.3f} s"
echo &"Throughput: {num_validators.float / (stop - start) :>4.3f} kps/s (key pairs/second)"

echo '\n'
start = cpuTime()
let proof_of_possessions = secret_public_keypairs.mapIt(it.generatePoP())
stop = cpuTime()
echo &"{num_validators} proof of possessions in {stop - start :>4.3f} s"
echo &"Throughput: {num_validators.float / (stop - start) :>4.3f} pops/s (proofs-of-possession/second)"

start = cpuTime()
let msg = attestation_signed_data(
fork_version,
slot,
shard_id,
parent_hashes,
shard_block_hash,
justified_slot
fork_version,
slot,
shard_id,
parent_hashes,
shard_block_hash,
justified_slot
)
stop = cpuTime()
echo &"Message generated in {(stop - start) * 1_000 :>4.3f} ms"

echo '\n'
var pubkey_sig_pairs: tuple[pubkeys: seq[VerKey], signatures: seq[Signature]]
var pubkeys: seq[VerKey]
var signatures: seq[Signature]
start = cpuTime()
for kp in secret_public_keypairs:
# Note that message is first passed through
# Blake2 384 at the moment
pubkey_sig_pairs.pubkeys.add kp.verkey
pubkey_sig_pairs.signatures.add kp.sigkey.signMessage(msg.data) # toOpenArray?
pubkeys.add kp.verkey
signatures.add kp.sigkey.signMessage(msg.data) # toOpenArray?
stop = cpuTime()
echo &"{num_validators} public key and message signature pairs generated in {stop - start :>4.3f} s"
echo &"Throughput: {num_validators.float / (stop - start) :>4.3f} kps/s (keysig pairs/second)"
echo "Note: message is re-hashed through Blake2B-384."
echo " Eth2.0 spec mentions hashing with Blake2b-512 and slicing the first 256-bit."
echo " However message signing is unspecified, and Milagro BLS12-384 requires a 384-bit input."

echo '\n'
echo "######################"
echo "#"
echo "# Benchmark main body"
echo "#"
echo "######################"
echo '\n'

echo '\n'
echo "#### Benchmark: proofs-of-possessions verification"
var pop_valid: bool
bench "Benchmarking proofs-of-possessions verification", pop_valid:
for i in 0 ..< proof_of_possessions.len:
pop_valid = pop_valid and proof_of_possessions[i].verifyPoP(pubkeys[i])

### Bench stuck in ECP2 multiplication at the moment
# echo '\n'
# echo "#### Benchmark: public keys aggregation"
# var agg_pubkey: AggregatedVerKey
# bench "Benchmarking public key aggregation", agg_pubkey:
# agg_pubkey = initAggregatedKey(pubkey_sig_pairs.pubkeys)
echo '\n'
echo "#### Benchmark: public keys aggregation"
var agg_pubkey: VerKey
bench "Benchmarking public key aggregation", agg_pubkey:
agg_pubkey = combine(pubkeys)

echo '\n'
echo "#### Benchmark: signature aggregation"
var agg_sig: AggregatedSignature
var agg_sig: Signature
bench "Benchmarking signature aggregation", agg_sig:
agg_sig = initAggregatedSignature(pubkey_sig_pairs)
agg_sig = combine(signatures)

echo '\n'
echo "#### Benchmark: message verification"
var msg_verif: bool
bench "Benchmarking message verification", msg_verif:
msg_verif = agg_sig.verifyMessage(msg.data, agg_pubkey)

# echo '\n'
# echo "#### Benchmark: message verification"
# var verif: bool
# bench "Benchmarking message verification", verif:
# verif = agg_sig.verifyMessage(msg.data, agg_pubkey)
#####################
#
# Benchmark epilogue
#
#####################
discard

when isMainModule:
main(100)

0 comments on commit b9b9e0e

Please sign in to comment.