Skip to content

Commit

Permalink
Init bls only once before serving api (#37)
Browse files Browse the repository at this point in the history
* init bls only once before serving api

* change bls init to main
  • Loading branch information
Marketen authored May 15, 2024
1 parent 381e7fa commit ecbf1e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
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

0 comments on commit ecbf1e4

Please sign in to comment.