Skip to content

Commit

Permalink
updated message validation benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
AKorpusenko committed Apr 9, 2024
1 parent 11cef51 commit f352802
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions message/validation/rsa_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
package validation

import (
"crypto"
crand "crypto/rand"
"crypto/rsa"
"crypto/sha256"
"testing"

eth2apiv1 "github.com/attestantio/go-eth2-client/api/v1"
specqbft "github.com/bloxapp/ssv-spec/qbft"
spectypes "github.com/bloxapp/ssv-spec/types"
spectestingutils "github.com/bloxapp/ssv-spec/types/testingutils"
"github.com/bloxapp/ssv/network/commons"
"github.com/bloxapp/ssv/networkconfig"
"github.com/bloxapp/ssv/operator/keys"
"github.com/bloxapp/ssv/operator/storage"
beaconprotocol "github.com/bloxapp/ssv/protocol/v2/blockchain/beacon"
ssvtypes "github.com/bloxapp/ssv/protocol/v2/types"
registrystorage "github.com/bloxapp/ssv/registry/storage"
"github.com/bloxapp/ssv/storage/basedb"
"github.com/bloxapp/ssv/storage/kv"
"github.com/bloxapp/ssv/utils/rsaencryption"
"go.uber.org/zap/zaptest"
"testing"

specqbft "github.com/bloxapp/ssv-spec/qbft"
spectypes "github.com/bloxapp/ssv-spec/types"
spectestingutils "github.com/bloxapp/ssv-spec/types/testingutils"
"github.com/bloxapp/ssv/network/commons"
registrystorage "github.com/bloxapp/ssv/registry/storage"
"github.com/ethereum/go-ethereum/common"
pubsub "github.com/libp2p/go-libp2p-pubsub"
pspb "github.com/libp2p/go-libp2p-pubsub/pb"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

func BenchmarkVerifyRSASignature(b *testing.B) {
Expand Down Expand Up @@ -56,8 +52,6 @@ func BenchmarkVerifyRSASignature(b *testing.B) {

roleAttester := spectypes.BNRoleAttester

mv := NewMessageValidator(netCfg, WithNodeStorage(ns)).(*messageValidator)

slot := netCfg.Beacon.FirstSlotAtEpoch(123456789)

validSignedMessage := spectestingutils.TestingProposalMessageWithHeight(ks.Shares[1], 1, specqbft.Height(slot))
Expand All @@ -74,26 +68,23 @@ func BenchmarkVerifyRSASignature(b *testing.B) {
encodedMsg, err := commons.EncodeNetworkMsg(message)
require.NoError(b, err)

hash := sha256.Sum256(encodedMsg)
privateKey, err := rsa.GenerateKey(crand.Reader, 2048)
privKey, err := keys.GeneratePrivateKey()
require.NoError(b, err)
pubkey := privateKey.Public().(*rsa.PublicKey)

pubKey, err := rsaencryption.ExtractPublicKey(pubkey)
pubKey, err := privKey.Public().Base64()
require.NoError(b, err)

od := &registrystorage.OperatorData{
ID: operatorID,
PublicKey: []byte(pubKey),
PublicKey: pubKey,
OwnerAddress: common.Address{},
}

found, err := ns.SaveOperatorData(nil, od)
require.NoError(b, err)

require.False(b, found)

signature, err := rsa.SignPKCS1v15(crand.Reader, privateKey, crypto.SHA256, hash[:])
signature, err := privKey.Sign(encodedMsg)
require.NoError(b, err)

encodedMsg = commons.EncodeSignedSSVMessage(encodedMsg, operatorID, signature)
Expand All @@ -106,6 +97,8 @@ func BenchmarkVerifyRSASignature(b *testing.B) {
},
}

mv := NewMessageValidator(netCfg, WithNodeStorage(ns)).(*messageValidator)

messageData := pMsg.GetData()
decMessageData, operatorIDX, signature, err := commons.DecodeSignedSSVMessage(messageData)
require.NoError(b, err)
Expand Down

0 comments on commit f352802

Please sign in to comment.