Skip to content

Commit

Permalink
Move aggregation bench to BDN
Browse files Browse the repository at this point in the history
  • Loading branch information
K1li4nL committed Sep 25, 2024
1 parent 41dd529 commit bd676f6
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions pairing/bls12381/bls12381_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.dedis.ch/kyber/v4/pairing"
circl "go.dedis.ch/kyber/v4/pairing/bls12381/circl"
kilic "go.dedis.ch/kyber/v4/pairing/bls12381/kilic"
"go.dedis.ch/kyber/v4/sign/bdn"
"go.dedis.ch/kyber/v4/sign/bls"
"go.dedis.ch/kyber/v4/sign/tbls"
"go.dedis.ch/kyber/v4/util/random"
Expand Down Expand Up @@ -665,14 +666,15 @@ var (
var result interface{}

func BenchmarkKilic(b *testing.B) {
BLSBenchmark(b, "kilic")
BDNBenchmark(b, "kilic")
}

func BenchmarkCircl(b *testing.B) {
BLSBenchmark(b, "circl")
BDNBenchmark(b, "circl")
}

func BLSBenchmark(b *testing.B, curveOption string) {
//nolint: gocyclo,cyclop // breaking this down doesn't make sense
func BDNBenchmark(b *testing.B, curveOption string) {
b.Logf("----------------------")
b.Logf("Payload to sign: %d bytes\n", dataSize)
b.Logf("Numbers of signatures: %v\n", numSigs)
Expand Down Expand Up @@ -700,8 +702,8 @@ func BLSBenchmark(b *testing.B, curveOption string) {
panic(fmt.Errorf("invalid curve option: %s", curveOption))
}

schemeOnG1 := bls.NewSchemeOnG1(suite)
schemeOnG2 := bls.NewSchemeOnG2(suite)
schemeOnG1 := bdn.NewSchemeOnG1(suite)
schemeOnG2 := bdn.NewSchemeOnG2(suite)

maxN := 1
for _, s := range numSigs {
Expand Down Expand Up @@ -730,31 +732,52 @@ func BLSBenchmark(b *testing.B, curveOption string) {
}
}

// Prepare masks for aggregation
maskG1, err := bdn.NewMask(suite.G1(), pubKeysOnG1, nil)
if err != nil {
panic(err)
}
maskG2, err := bdn.NewMask(suite.G2(), pubKeysOnG2, nil)
if err != nil {
panic(err)
}

for _, n := range numSigs {
for i := 0; i < n; i++ {
maskG1.SetBit(i, true)
maskG2.SetBit(i, true)
}

// Benchmark aggregation of public keys
b.Run(fmt.Sprintf("AggregatePublicKeys-G1 on %d signs", n), func(bb *testing.B) {
for j := 0; j < bb.N; j++ {
result = schemeOnG1.AggregatePublicKeys(pubKeysOnG1[:n]...)
result, err = schemeOnG1.AggregatePublicKeys(maskG1)
if err != nil {
require.NoError(b, err)
}
}
})
b.Run(fmt.Sprintf("AggregatePublicKeys-G2 on %d signs", n), func(bb *testing.B) {
for j := 0; j < bb.N; j++ {
result = schemeOnG2.AggregatePublicKeys(pubKeysOnG2[:n]...)
result, err = schemeOnG2.AggregatePublicKeys(maskG2)
if err != nil {
panic(err)
}
}
})

// Benchmark aggregation of signatures
b.Run(fmt.Sprintf("AggregateSign-G1 on %d signs", n), func(bb *testing.B) {
for j := 0; j < bb.N; j++ {
result, err = schemeOnG1.AggregateSignatures(sigsOnG1[:n]...)
result, err = schemeOnG1.AggregateSignatures(sigsOnG1[:n], maskG1)
if err != nil {
panic(err)
}
}
})
b.Run(fmt.Sprintf("AggregateSign-G1 on %d signs", n), func(bb *testing.B) {
b.Run(fmt.Sprintf("AggregateSign-G2 on %d signs", n), func(bb *testing.B) {
for j := 0; j < bb.N; j++ {
result, err = schemeOnG2.AggregateSignatures(sigsOnG2[:n]...)
result, err = schemeOnG2.AggregateSignatures(sigsOnG2[:n], maskG2)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit bd676f6

Please sign in to comment.