prysm-pulse/validator/slashing-protection/local/standard-protection-format/helpers.go
Shay Zluf 3fb78ff575
Verify GenesisValidatorRoot Matches the One in DB on Slashing Protection Import (#7864)
* Add GenValRoot dbs

* Test genvalroot

* Fix names

* Add overwrite rejection

* validate metadata genesis validator root

* remove env

* fix database functions

* fix tests

* raul feedback

Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-11-20 22:33:51 +00:00

39 lines
876 B
Go

package interchangeformat
import (
"encoding/hex"
"fmt"
"strconv"
"strings"
)
func uint64FromString(str string) (uint64, error) {
return strconv.ParseUint(str, 10, 64)
}
func pubKeyFromHex(str string) ([48]byte, error) {
pubKeyBytes, err := hex.DecodeString(strings.TrimPrefix(str, "0x"))
if err != nil {
return [48]byte{}, err
}
if len(pubKeyBytes) != 48 {
return [48]byte{}, fmt.Errorf("public key is not correct, 48-byte length: %s", str)
}
var pk [48]byte
copy(pk[:], pubKeyBytes[:48])
return pk, nil
}
func rootFromHex(str string) ([32]byte, error) {
rootHexBytes, err := hex.DecodeString(strings.TrimPrefix(str, "0x"))
if err != nil {
return [32]byte{}, err
}
if len(rootHexBytes) != 32 {
return [32]byte{}, fmt.Errorf("wrong root length, 32-byte length: %s", str)
}
var root [32]byte
copy(root[:], rootHexBytes[:32])
return root, nil
}