ETH1 withdrawal credentials.

This commit is contained in:
Jim McDonald
2021-02-26 15:19:37 +00:00
parent 4d5660ccbb
commit 1ed3a51117
2 changed files with 24 additions and 5 deletions

View File

@@ -83,6 +83,8 @@ func input() (*dataIn, error) {
return nil, errors.Wrap(err, "failed to obtain public key for withdrawal account")
}
data.withdrawalCredentials = util.SHA256(pubKey.Marshal())
// This is hard-coded, to allow deposit data to be generated without a connection to the beacon node.
data.withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX
case viper.GetString("withdrawalpubkey") != "":
withdrawalPubKeyBytes, err := hex.DecodeString(strings.TrimPrefix(viper.GetString("withdrawalpubkey"), "0x"))
if err != nil {
@@ -96,11 +98,24 @@ func input() (*dataIn, error) {
return nil, errors.Wrap(err, "withdrawal public key is not valid")
}
data.withdrawalCredentials = util.SHA256(withdrawalPubKey.Marshal())
// This is hard-coded, to allow deposit data to be generated without a connection to the beacon node.
data.withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX
case viper.GetString("withdrawaladdress") != "":
// TODO checksum.
withdrawalAddressBytes, err := hex.DecodeString(strings.TrimPrefix(viper.GetString("withdrawaladdress"), "0x"))
if err != nil {
return nil, errors.Wrap(err, "failed to decode withdrawal address")
}
if len(withdrawalAddressBytes) != 20 {
return nil, errors.New("withdrawal address must be exactly 20 bytes in length")
}
data.withdrawalCredentials = make([]byte, 32)
copy(data.withdrawalCredentials[12:32], withdrawalAddressBytes[:])
// This is hard-coded, to allow deposit data to be generated without a connection to the beacon node.
data.withdrawalCredentials[0] = byte(1) // ETH1_ADDRESS_WITHDRAWAL_PREFIX
default:
return nil, errors.New("withdrawalaccount or withdrawal public key is required")
return nil, errors.New("withdrawal account, public key or address is required")
}
// This is hard-coded, to allow deposit data to be generated without a connection to the beacon node.
data.withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX
if viper.GetString("depositvalue") == "" {
return nil, errors.New("deposit value is required")

View File

@@ -49,9 +49,10 @@ In quiet mode this will return 0 if the the data can be generated correctly, oth
func init() {
validatorCmd.AddCommand(validatorDepositDataCmd)
validatorFlags(validatorDepositDataCmd)
validatorDepositDataCmd.Flags().String("validatoraccount", "", "Account of the account carrying out the validation")
validatorDepositDataCmd.Flags().String("withdrawalaccount", "", "Account of the account to which the validator funds will be withdrawn")
validatorDepositDataCmd.Flags().String("validatoraccount", "", "Account carrying out the validation")
validatorDepositDataCmd.Flags().String("withdrawalaccount", "", "Account to which the validator funds will be withdrawn")
validatorDepositDataCmd.Flags().String("withdrawalpubkey", "", "Public key of the account to which the validator funds will be withdrawn")
validatorDepositDataCmd.Flags().String("withdrawaladdress", "", "Ethereum 1 address of the account to which the validator funds will be withdrawn")
validatorDepositDataCmd.Flags().String("depositvalue", "", "Value of the amount to be deposited")
validatorDepositDataCmd.Flags().Bool("raw", false, "Print raw deposit data transaction data")
validatorDepositDataCmd.Flags().String("forkversion", "", "Use a hard-coded fork version (default is to fetch it from the node)")
@@ -68,6 +69,9 @@ func validatorDepositdataBindings() {
if err := viper.BindPFlag("withdrawalpubkey", validatorDepositDataCmd.Flags().Lookup("withdrawalpubkey")); err != nil {
panic(err)
}
if err := viper.BindPFlag("withdrawaladdress", validatorDepositDataCmd.Flags().Lookup("withdrawaladdress")); err != nil {
panic(err)
}
if err := viper.BindPFlag("depositvalue", validatorDepositDataCmd.Flags().Lookup("depositvalue")); err != nil {
panic(err)
}