Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init bls only once before serving api #37

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions listener/cmd/listener/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/dappnode/validator-monitoring/listener/internal/api"
"github.com/dappnode/validator-monitoring/listener/internal/config"
"github.com/dappnode/validator-monitoring/listener/internal/logger"
"github.com/herumi/bls-eth-go-binary/bls"
)

func main() {
Expand All @@ -15,6 +16,15 @@ func main() {
}
logger.SetLogLevelFromString(config.LogLevel)

// This is a configuration of the BLS library at the process level. Notice how bls.Init() does not return an initialized BLS object.
// Any call to bls functions within the process will use this configuration. We initialize bls before starting the api.
if err := bls.Init(bls.BLS12_381); err != nil {
logger.Fatal("Failed to initialize BLS: " + err.Error())
}
if err := bls.SetETHmode(bls.EthModeDraft07); err != nil {
logger.Fatal("Failed to set BLS ETH mode: " + err.Error())
}

s := api.NewApi(
config.Port,
config.MongoDBURI,
Expand Down
11 changes: 0 additions & 11 deletions listener/internal/api/validation/VerifySignature.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ import (
)

func VerifySignature(req types.SignatureRequestDecoded) (bool, error) {
// Initialize the BLS system
if err := bls.Init(bls.BLS12_381); err != nil {
logger.Error("Failed to initialize BLS system: " + err.Error())
return false, err
}
// Set the BLS mode to ETH draft 07
if err := bls.SetETHmode(bls.EthModeDraft07); err != nil {
logger.Error("Failed to set BLS mode to ETH draft 07: " + err.Error())
return false, err
}

// Decode the public key from hex, remove the 0x prefix ONLY if exists from req.Pubkey
req.Pubkey = strings.TrimPrefix(req.Pubkey, "0x")
req.Pubkey = strings.TrimSpace(req.Pubkey)
Expand Down
Loading