Skip to content

Instantly share code, notes, and snippets.

@nisdas
Created July 10, 2020 13:46
Show Gist options
  • Save nisdas/bd312413bf3edb6b903453e677383b92 to your computer and use it in GitHub Desktop.
Save nisdas/bd312413bf3edb6b903453e677383b92 to your computer and use it in GitHub Desktop.
MultipleVerify BLST Benchmark
func BenchmarkVerifyMultipleSignatures(b *testing.B) {
var dst = []byte("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_")
pubkeys := make([]*blst.P1Affine, 0, 100)
sigs := make([]*blst.P2Affine, 0, 100)
var msgs [][]byte
for i := 0; i < 100; i++ {
msg := [32]byte{'h', 'e', 'l', 'l', 'o', byte(i)}
rdbyte := [32]byte{}
mrand.Read(rdbyte[:])
priv := blst.KeyGen(rdbyte[:])
pub := new(blst.P1Affine).From(priv)
sig := new(blst.P2Affine).Sign(priv, msg[:], dst)
pubkeys = append(pubkeys, pub)
sigs = append(sigs, sig)
msgs = append(msgs, msg[:])
}
b.Run("AggregateVerify", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
agg := new(blst.P2Aggregate).Aggregate(sigs).ToAffine()
agg.AggregateVerify(pubkeys, msgs, dst)
}
})
b.Run("MultipleAggregateVerify", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
randFunc := func(scalar *blst.Scalar) {
var rbytes [32]byte
mrand.Read(rbytes[:])
scalar.FromBEndian(rbytes[:])
}
dummySig := new(blst.P2Affine)
dummySig.MultipleAggregateVerify(sigs, pubkeys, msgs, dst, randFunc, 64)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment