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

chore(cli): Enforce valid withdrawal address set for add-premined-deposit & create-validator #2174

Merged
merged 39 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7a29a1b
enforce withdrawal address
calbera Nov 24, 2024
9dc7cc2
undo
calbera Nov 24, 2024
6a7e2fb
undo
calbera Nov 24, 2024
f4569b3
create-validator
calbera Nov 24, 2024
26cff08
Merge branch 'main' of github.com:berachain/beacon-kit into withdrawa…
calbera Nov 28, 2024
ac9e59a
val set optimization
calbera Nov 28, 2024
03b6fda
gen
calbera Nov 28, 2024
7d20585
Merge branch 'main' of github.com:berachain/beacon-kit into withdrawa…
calbera Nov 29, 2024
41d1a33
undo
calbera Nov 29, 2024
4a334f4
gen
calbera Nov 29, 2024
7cd92fd
berachain deposit contract
calbera Nov 29, 2024
835eb81
Merge branch 'main' into withdrawal-cli
calbera Nov 29, 2024
34871dd
fix deposit contract tests
calbera Nov 29, 2024
1ec0176
Fix e2de
calbera Nov 29, 2024
5032533
gen new deposit
calbera Nov 29, 2024
9753679
slither
calbera Nov 29, 2024
737ccb9
remove unneeded test
calbera Nov 29, 2024
c5ee10f
gen
calbera Nov 29, 2024
41579df
remove
calbera Nov 29, 2024
d824058
bet
calbera Nov 29, 2024
3220996
Default withdrawal of 0
calbera Nov 29, 2024
c5b07ce
remove forced gas limit from e2e
calbera Nov 29, 2024
2c5b519
Merge branch 'main' into withdrawal-cli
calbera Dec 3, 2024
dcf7187
Merge branch 'main' into withdrawal-cli
calbera Dec 3, 2024
9df3a71
Merge branch 'main' of github.com:berachain/beacon-kit into withdrawa…
calbera Dec 4, 2024
b2f1273
clean tests
calbera Dec 4, 2024
519b13e
Merge branch 'main' of github.com:berachain/beacon-kit into withdrawa…
calbera Dec 5, 2024
3e940a9
use deposit contract with MIN_DEPOSIT_AMOUNT fix
calbera Dec 5, 2024
8da430b
removed defaults
calbera Dec 5, 2024
39037a2
Remove flag for required values
calbera Dec 5, 2024
a02bb08
allow 0 values for amount & address
calbera Dec 5, 2024
64446b4
Fix deposit contract unit test
calbera Dec 5, 2024
5198666
Deposit contract renaming
calbera Dec 5, 2024
bb38963
lint
calbera Dec 5, 2024
2b7dcc6
Merge branch 'main' of github.com:berachain/beacon-kit into withdrawa…
calbera Dec 6, 2024
081ad11
fix e2e test by using different pubkeys
calbera Dec 6, 2024
5dbb29a
bet
calbera Dec 6, 2024
1fb5989
restore 80084 genesis files
calbera Dec 6, 2024
7cbfc84
Merge branch 'main' of github.com:berachain/beacon-kit into withdrawa…
calbera Dec 6, 2024
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
9 changes: 6 additions & 3 deletions cli/commands/deposit/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func NewCreateValidator[
cmd := &cobra.Command{
Use: "create-validator",
Short: "Creates a validator deposit",
Long: `Creates a validator deposit with the necessary credentials. The
arguments are expected in the order of withdrawal credentials, deposit
Long: `Creates a validator deposit with the necessary credentials. The
arguments are expected in the order of withdrawal address, deposit
amount, current version, and genesis validator root. If the broadcast
flag is set to true, a private key must be provided to sign the transaction.`,
calbera marked this conversation as resolved.
Show resolved Hide resolved
Args: cobra.ExactArgs(4), //nolint:mnd // The number of arguments.
Expand Down Expand Up @@ -80,10 +80,13 @@ func createValidatorCmd[
return err
}

credentials, err := parser.ConvertWithdrawalCredentials(args[0])
withdrawalAddress, err := parser.ConvertWithdrawalAddress(args[0])
if err != nil {
return err
}
credentials := types.NewCredentialsFromExecutionAddress(
withdrawalAddress,
)

amount, err := parser.ConvertAmount(args[1])
if err != nil {
Expand Down
32 changes: 13 additions & 19 deletions cli/commands/genesis/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ import (

// AddGenesisDepositCmd - returns the cobra command to
// add a premined deposit to the genesis file.
//

func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command {
cmd := &cobra.Command{
Use: "add-premined-deposit",
Short: "adds a validator to the genesis file",
RunE: func(cmd *cobra.Command, _ []string) error {
Long: `Adds a validator to the genesis file with the necessary
credentials. The arguments are expected in the order of the deposit
amount and withdrawal address.`,
Args: cobra.ExactArgs(2), //nolint:mnd // The number of arguments.
RunE: func(cmd *cobra.Command, args []string) error {
config := context.GetConfigFromCmd(cmd)

_, valPubKey, err := genutil.InitializeNodeValidatorFiles(
Expand All @@ -61,11 +67,6 @@ func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command {
)
}

var (
depositAmountString string
depositAmount math.Gwei
)

// Get the BLS signer.
blsSigner, err := components.ProvideBlsSigner(
components.BlsSignerInput{
Expand All @@ -77,12 +78,8 @@ func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command {
}

// Get the deposit amount.
depositAmountString, err = cmd.Flags().GetString(depositAmountFlag)
if err != nil {
return err
}

depositAmount, err = parser.ConvertAmount(depositAmountString)
var depositAmount math.Gwei
depositAmount, err = parser.ConvertAmount(args[0])
calbera marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand All @@ -92,14 +89,14 @@ func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command {
version.Deneb,
)

// Get the withdrawal address.
withdrawalAddress := common.NewExecutionAddressFromHex(args[1])

depositMsg, signature, err := types.CreateAndSignDepositMessage(
types.NewForkData(currentVersion, common.Root{}),
cs.DomainTypeDeposit(),
blsSigner,
// TODO: configurable.
types.NewCredentialsFromExecutionAddress(
common.ExecutionAddress{},
),
types.NewCredentialsFromExecutionAddress(withdrawalAddress),
depositAmount,
)
if err != nil {
Expand Down Expand Up @@ -141,9 +138,6 @@ func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command {
},
}

cmd.Flags().
String(depositAmountFlag, defaultDepositAmount, depositAmountFlagMsg)

return cmd
}

Expand Down
27 changes: 0 additions & 27 deletions cli/commands/genesis/flags.go

This file was deleted.

19 changes: 19 additions & 0 deletions cli/utils/parser/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package parser

import (
"fmt"
"math/big"

"github.com/berachain/beacon-kit/consensus-types/types"
Expand All @@ -45,6 +46,24 @@ func ConvertPubkey(pubkey string) (crypto.BLSPubkey, error) {
return crypto.BLSPubkey(pubkeyBytes), nil
}

// ConvertWithdrawalAddress converts a string to a withdrawal address.
func ConvertWithdrawalAddress(address string) (common.ExecutionAddress, error) {
// Wrap the call in a recover to handle potential panics from invalid
// addresses.
var (
addr common.ExecutionAddress
err error
)
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("invalid withdrawal address: %v", r)
}
}()

addr = common.NewExecutionAddressFromHex(address)
return addr, err
}
calbera marked this conversation as resolved.
Show resolved Hide resolved

// ConvertWithdrawalCredentials converts a string to a withdrawal credentials.
func ConvertWithdrawalCredentials(credentials string) (
types.WithdrawalCredentials,
Expand Down
2 changes: 1 addition & 1 deletion cmd/beacond/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func DefaultComponents() []any {
*AvailabilityStore, *BeaconBlock, *BeaconBlockBody,
*BeaconBlockHeader, *BlobSidecars, *Logger,
],
components.ProvideBeaconDepositContract[
components.ProvideDepositContract[
*Deposit, *ExecutionPayload, *ExecutionPayloadHeader,
],
components.ProvideBlockStore[
Expand Down
2 changes: 1 addition & 1 deletion cmd/beacond/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ type (
Deposit = types.Deposit

// DepositContract is a type alias for the deposit contract.
DepositContract = deposit.WrappedBeaconDepositContract[
DepositContract = deposit.WrappedDepositContract[
*Deposit,
WithdrawalCredentials,
]
Expand Down
8 changes: 4 additions & 4 deletions consensus/cometbft/service/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,16 @@ func (s *Service[LoggerT]) internalFinalizeBlock(
//
// NOTE: Not all raw transactions may adhere to the sdk.Tx interface, e.g.
// vote extensions, so skip those.
txResults := make([]*cmtabci.ExecTxResult, 0, len(req.Txs))
for range req.Txs {
txResults := make([]*cmtabci.ExecTxResult, len(req.Txs))
for i := range req.Txs {
//nolint:mnd // its okay for now.
txResults = append(txResults, &cmtabci.ExecTxResult{
txResults[i] = &cmtabci.ExecTxResult{
Codespace: "sdk",
Code: 2,
Log: "skip decoding",
GasWanted: 0,
GasUsed: 0,
})
}
calbera marked this conversation as resolved.
Show resolved Hide resolved
}

finalizeBlock, err := s.Middleware.FinalizeBlock(
Expand Down
2 changes: 1 addition & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ forge-lint-fix:

forge-lint:
@echo "--> Running forge lint"
@cd $(CONTRACTS_DIR) && forge fmt --check
@cd $(CONTRACTS_DIR) && forge fmt --check
Loading
Loading