Skip to content

Commit

Permalink
chore: fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jul 7, 2023
1 parent f29ef1c commit fa67a3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
15 changes: 13 additions & 2 deletions client/keys/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ func SignMsgKeysCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "sign [message]",
Short: "Sign message",
Long: "Return a signature from their associated name and address private key.",
RunE: runSignMsgCmd,
Long: `Return a signature from their associated name and address private key.
!!!NOTE!!!
This is not a secure way to sign messages.
This command is allowed to sign any message from your private key.
Please *DO NOT* use this command unless you know what you are doing.
Example For Signing BLS PoP Message:
$ gnfd keys add bls --keyring-backend test --algo eth_bls
$ BLS=$(./build/bin/gnfd keys show bls --keyring-backend test --output json | jq -r .pubkey_hex)
$ gnfd keys sign $BLS --from bls
`,
RunE: runSignMsgCmd,
}

cmd.Flags().String(flags.FlagFrom, "", "Name or address of private key with which to sign")
Expand Down
24 changes: 11 additions & 13 deletions x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,10 @@ func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateVa
if err != nil {
return nil, sdkerrors.Wrap(types.ErrValidatorInvalidBlsProof, err.Error())
}
ok, err = k.CheckBlsProof(ctx, blsPk, blsProof, valAddr)
err = k.CheckBlsProof(blsPk, blsProof)
if err != nil {
return nil, sdkerrors.Wrap(types.ErrValidatorInvalidBlsProof, err.Error())
}
if !ok {
return nil, types.ErrValidatorInvalidBlsProof
}

bondDenom := k.BondDenom(ctx)
if msg.Value.Denom != bondDenom {
Expand Down Expand Up @@ -315,13 +312,11 @@ func (k msgServer) EditValidator(goCtx context.Context, msg *types.MsgEditValida
if err != nil {
return nil, sdkerrors.Wrap(types.ErrValidatorInvalidBlsProof, err.Error())
}
ok, err := k.CheckBlsProof(ctx, blsPk, blsProof, validator.GetOperator())
err = k.CheckBlsProof(blsPk, blsProof)
if err != nil {
return nil, sdkerrors.Wrap(types.ErrValidatorInvalidBlsProof, err.Error())
}
if !ok {
return nil, sdkerrors.Wrap(types.ErrValidatorInvalidBlsProof, "signature verification failed")
}

if tmpValidator, found := k.GetValidatorByBlsKey(ctx, blsPk); found {
if tmpValidator.OperatorAddress != validator.OperatorAddress {
return nil, types.ErrValidatorBlsKeyExists
Expand Down Expand Up @@ -658,21 +653,24 @@ func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdatePara
}

// CheckBlsProof checks the BLS signature of the validator
func (ms msgServer) CheckBlsProof(goCtx context.Context, blsPk, sig []byte, valAddr sdk.Address) (bool, error) {
func (ms msgServer) CheckBlsProof(blsPk, sig []byte) error {
if len(sig) != sdk.BLSSignatureLength {
return false, sdkerrors.Wrapf(sdkerrors.ErrorInvalidSigner, "signature length (actual: %d) doesn't match typical BLS signature 96 bytes", len(sig))
return sdkerrors.Wrapf(sdkerrors.ErrorInvalidSigner, "signature length (actual: %d) doesn't match typical BLS signature 96 bytes", len(sig))
}

blsPubKey, err := bls.PublicKeyFromBytes(blsPk)
if err != nil {
return false, sdkerrors.Wrap(sdkerrors.ErrorInvalidSigner, "BLS public key is invalid")
return sdkerrors.Wrap(sdkerrors.ErrorInvalidSigner, "BLS public key is invalid")
}

signature, err := bls.SignatureFromBytes(sig)
if err != nil {
return false, sdkerrors.Wrap(sdkerrors.ErrorInvalidSigner, "BLS signature key is invalid")
return sdkerrors.Wrap(sdkerrors.ErrorInvalidSigner, "BLS signature key is invalid")
}

sigHash := tmhash.Sum(blsPk)
return signature.Verify(blsPubKey, sigHash), nil
if !signature.Verify(blsPubKey, sigHash) {
return sdkerrors.Wrap(sdkerrors.ErrorInvalidSigner, "BLS signature verification is failed")
}
return nil
}

0 comments on commit fa67a3f

Please sign in to comment.