Skip to content

Commit

Permalink
benchmark for signature verification
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Jul 8, 2022
1 parent cbdc1a5 commit f551695
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -15,6 +15,9 @@ build:
test:
go test ./...

bench:
go test -benchmem -bench=. ./...

lint:
gofmt -d ./
go vet ./...
Expand Down
34 changes: 34 additions & 0 deletions types/signing_test.go
Expand Up @@ -32,6 +32,40 @@ func TestVerifySignature(t *testing.T) {
require.True(t, ok)
}

func genValidatorRegistration(t require.TestingT, domain Domain) *SignedValidatorRegistration {
sk, pk, err := bls.GenerateNewKeypair()
require.NoError(t, err)

var pubKey PublicKey
pubKey.FromSlice(pk.Compress())

msg := &RegisterValidatorRequestMessage{
FeeRecipient: Address{0x42},
GasLimit: 15_000_000,
Timestamp: 1652369368,
Pubkey: pubKey,
}

signature, err := SignMessage(msg, domain, sk)
require.NoError(t, err)
return &SignedValidatorRegistration{
Message: msg,
Signature: signature,
}
}

func BenchmarkSignatureVerification(b *testing.B) {
domain := ComputeDomain(DomainType{0x01, 0x00, 0x00, 0x00}, ForkVersion{}, Root{})
reg := genValidatorRegistration(b, domain)

b.ResetTimer()
for n := 0; n < b.N; n++ {
ok, err := VerifySignature(reg.Message, domain, reg.Message.Pubkey[:], reg.Signature[:])
require.NoError(b, err)
require.True(b, ok)
}
}

func TestVerifySignatureManualPk(t *testing.T) {
msg2 := RegisterValidatorRequestMessage{
FeeRecipient: Address{0x42},
Expand Down

0 comments on commit f551695

Please sign in to comment.