Skip to content

Commit

Permalink
*: allow deposits greater than 32eth (#3466)
Browse files Browse the repository at this point in the history
Co-authored-by: Kaloyan Tanev <[email protected]>
  • Loading branch information
pinebit and KaloyanTanev committed Jan 31, 2025
1 parent 75796b7 commit 379d0b7
Show file tree
Hide file tree
Showing 27 changed files with 136 additions and 71 deletions.
4 changes: 2 additions & 2 deletions cluster/cluster_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,6 @@ func RandomDepositDataSeed(r *rand.Rand) DepositData {
}

func TestSupportPartialDeposits(t *testing.T) {
require.True(t, supportPartialDeposits(MinVersionForPartialDeposits))
require.False(t, supportPartialDeposits(v1_7))
require.True(t, SupportPartialDeposits(MinVersionForPartialDeposits))
require.False(t, SupportPartialDeposits(v1_7))
}
10 changes: 5 additions & 5 deletions cluster/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewDefinition(name string, numVals int, threshold int, feeRecipientAddresse
opt(&def)
}

if len(depositAmounts) > 1 && !supportPartialDeposits(def.Version) {
if len(depositAmounts) > 1 && !SupportPartialDeposits(def.Version) {
return Definition{}, errors.New("the version does not support partial deposits", z.Str("version", def.Version))
}

Expand Down Expand Up @@ -142,7 +142,7 @@ type Definition struct {
// Note that this was added in v1.1.0, so may be empty for older versions.
Timestamp string `config_hash:"3" definition_hash:"3" json:"timestamp" ssz:"ByteList[32]"`

// NumValidators is the number of DVs (n*32ETH) to be created in the cluster lock file.
// NumValidators is the number of DVs to be created in the cluster lock file.
NumValidators int `config_hash:"4" definition_hash:"4" json:"num_validators" ssz:"uint64"`

// Threshold required for signature reconstruction. Defaults to safe value for number of nodes/peers.
Expand All @@ -163,7 +163,7 @@ type Definition struct {
// ValidatorAddresses define addresses of each validator.
ValidatorAddresses []ValidatorAddresses `config_hash:"10" definition_hash:"10" json:"validators" ssz:"CompositeList[65536]"`

// DepositAmounts specifies partial deposit amounts that sum up to 32ETH.
// DepositAmounts specifies partial deposit amounts that sum up to [32ETH..2048ETH].
DepositAmounts []eth2p0.Gwei `config_hash:"11" definition_hash:"11" json:"deposit_amounts" ssz:"uint64[256]"`

// ConsensusProtocol is the consensus protocol name preferred by the cluster, e.g. "abft".
Expand Down Expand Up @@ -938,8 +938,8 @@ func supportEIP712Sigs(version string) bool {
return !isAnyVersion(version, v1_0, v1_1, v1_2)
}

// supportPartialDeposits returns true if the provided definition version supports partial deposits.
func supportPartialDeposits(version string) bool {
// SupportPartialDeposits returns true if the provided definition version supports partial deposits.
func SupportPartialDeposits(version string) bool {
return !isAnyVersion(version, v1_0, v1_1, v1_2, v1_3, v1_4, v1_5, v1_6, v1_7)
}

Expand Down
2 changes: 1 addition & 1 deletion cluster/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type DepositData struct {
// WithdrawalCredentials included in the deposit.
WithdrawalCredentials []byte `json:"withdrawal_credentials" lock_hash:"1" ssz:"Bytes32"`

// Amount is the amount in Gwei to be deposited [1ETH..32ETH].
// Amount is the amount in Gwei to be deposited [1ETH..2048ETH].
Amount int `json:"amount" lock_hash:"2" ssz:"uint64"`

// Signature is the BLS signature of the deposit message (above three fields).
Expand Down
2 changes: 1 addition & 1 deletion cluster/distvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/obolnetwork/charon/tbls/tblsconv"
)

// DistValidator is a distributed validator (1x32ETH) managed by the cluster.
// DistValidator is a distributed validator managed by the cluster.
type DistValidator struct {
// PubKey is the distributed validator group public key.
PubKey []byte `json:"distributed_public_key" lock_hash:"0" ssz:"Bytes48"`
Expand Down
2 changes: 1 addition & 1 deletion cluster/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Lock struct {
// Definition is embedded and extended by Lock.
Definition `json:"cluster_definition" lock_hash:"0" ssz:"Composite"`

// Validators are the distributed validators (n*32ETH) managed by the cluster.
// Validators are the distributed validators managed by the cluster.
Validators []DistValidator `json:"distributed_validators" lock_hash:"1" ssz:"Composite[65536]"`

// LockHash uniquely identifies a cluster lock.
Expand Down
2 changes: 1 addition & 1 deletion cmd/addvalidators.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func writeDepositDatas(ctx context.Context, clusterDir string, numOps int, secre

var depositDatas []eth2p0.DepositData
for i, val := range vals {
depositMsg, err := deposit.NewMessage(eth2p0.BLSPubKey(val.GetPublicKey()), val.GetWithdrawalAddress(), deposit.MaxDepositAmount)
depositMsg, err := deposit.NewMessage(eth2p0.BLSPubKey(val.GetPublicKey()), val.GetWithdrawalAddress(), deposit.DefaultDepositAmount)
if err != nil {
return errors.Wrap(err, "new deposit message")
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func bindClusterFlags(flags *pflag.FlagSet, config *clusterConfig) {
flags.StringVar(&config.testnetConfig.GenesisForkVersionHex, "testnet-fork-version", "", "Genesis fork version of the custom test network (in hex).")
flags.Uint64Var(&config.testnetConfig.ChainID, "testnet-chain-id", 0, "Chain ID of the custom test network.")
flags.Int64Var(&config.testnetConfig.GenesisTimestamp, "testnet-genesis-timestamp", 0, "Genesis timestamp of the custom test network.")
flags.IntSliceVar(&config.DepositAmounts, "deposit-amounts", nil, "List of partial deposit amounts (integers) in ETH. Values must sum up to exactly 32ETH.")
flags.IntSliceVar(&config.DepositAmounts, "deposit-amounts", nil, "List of partial deposit amounts (integers) in ETH. Values must sum up to at least 32ETH.")
flags.StringVar(&config.ConsensusProtocol, "consensus-protocol", "", "Preferred consensus protocol name for the cluster. Selected automatically when not specified.")
flags.UintVar(&config.TargetGasLimit, "target-gas-limit", 36000000, "Preferred target gas limit for transactions.")
}
Expand Down Expand Up @@ -217,8 +217,7 @@ func runCreateCluster(ctx context.Context, w io.Writer, conf clusterConfig) erro
}

if len(depositAmounts) == 0 {
// If partial deposit amounts were not specified, default to single amount of 32ETH.
depositAmounts = []eth2p0.Gwei{deposit.MaxDepositAmount}
depositAmounts = deposit.DefaultDepositAmounts()
}

if len(secrets) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions cmd/createcluster_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"testing"
"time"

eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"
keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4"

Expand Down Expand Up @@ -373,7 +372,7 @@ func testCreateCluster(t *testing.T, conf clusterConfig, def cluster.Definition,
vals := make(map[string]struct{})
amounts := deposit.DedupAmounts(deposit.EthsToGweis(conf.DepositAmounts))
if len(amounts) == 0 {
amounts = []eth2p0.Gwei{deposit.MaxDepositAmount}
amounts = deposit.DefaultDepositAmounts()
}
for _, val := range lock.Validators {
vals[val.PublicKeyHex()] = struct{}{}
Expand Down
4 changes: 2 additions & 2 deletions cmd/createdkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ func bindCreateDKGFlags(cmd *cobra.Command, config *createDKGConfig) {

cmd.Flags().StringVar(&config.Name, "name", "", "Optional cosmetic cluster name")
cmd.Flags().StringVar(&config.OutputDir, "output-dir", ".charon", "The folder to write the output cluster-definition.json file to.")
cmd.Flags().IntVar(&config.NumValidators, "num-validators", 1, "The number of distributed validators the cluster will manage (32ETH staked for each).")
cmd.Flags().IntVar(&config.NumValidators, "num-validators", 1, "The number of distributed validators the cluster will manage (32ETH+ staked for each).")
cmd.Flags().IntVarP(&config.Threshold, "threshold", "t", 0, "Optional override of threshold required for signature reconstruction. Defaults to ceil(n*2/3) if zero. Warning, non-default values decrease security.")
cmd.Flags().StringSliceVar(&config.FeeRecipientAddrs, "fee-recipient-addresses", nil, "Comma separated list of Ethereum addresses of the fee recipient for each validator. Either provide a single fee recipient address or fee recipient addresses for each validator.")
cmd.Flags().StringSliceVar(&config.WithdrawalAddrs, "withdrawal-addresses", nil, "Comma separated list of Ethereum addresses to receive the returned stake and accrued rewards for each validator. Either provide a single withdrawal address or withdrawal addresses for each validator.")
cmd.Flags().StringVar(&config.Network, "network", defaultNetwork, "Ethereum network to create validators for. Options: mainnet, goerli, sepolia, holesky, gnosis, chiado.")
cmd.Flags().StringVar(&config.DKGAlgo, "dkg-algorithm", "default", "DKG algorithm to use; default, frost")
cmd.Flags().IntSliceVar(&config.DepositAmounts, "deposit-amounts", nil, "List of partial deposit amounts (integers) in ETH. Values must sum up to exactly 32ETH.")
cmd.Flags().IntSliceVar(&config.DepositAmounts, "deposit-amounts", nil, "List of partial deposit amounts (integers) in ETH. Values must sum up to at least 32ETH.")
cmd.Flags().StringSliceVar(&config.OperatorENRs, operatorENRs, nil, "[REQUIRED] Comma-separated list of each operator's Charon ENR address.")
cmd.Flags().StringVar(&config.ConsensusProtocol, "consensus-protocol", "", "Preferred consensus protocol name for the cluster. Selected automatically when not specified.")
cmd.Flags().UintVar(&config.TargetGasLimit, "target-gas-limit", 36000000, "Preferred target gas limit for transactions.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/createdkg_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestValidateDKGConfig(t *testing.T) {

t.Run("wrong deposit amounts sum", func(t *testing.T) {
err := validateDKGConfig(4, "goerli", []int{8, 16}, "")
require.ErrorContains(t, err, "sum of partial deposit amounts must sum up to 32ETH")
require.ErrorContains(t, err, "sum of partial deposit amounts must be at least 32ETH")
})

t.Run("unsupported consensus protocol", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
"node3",
"node0/charon-enr-private-key",
"node0/cluster-lock.json",
"node0/deposit-data-1eth.json",
"node0/deposit-data.json",
"node0/validator_keys",
"node1/charon-enr-private-key",
"node1/cluster-lock.json",
"node1/deposit-data-1eth.json",
"node1/deposit-data.json",
"node1/validator_keys",
"node2/charon-enr-private-key",
"node2/cluster-lock.json",
"node2/deposit-data-1eth.json",
"node2/deposit-data.json",
"node2/validator_keys",
"node3/charon-enr-private-key",
"node3/cluster-lock.json",
"node3/deposit-data-1eth.json",
"node3/deposit-data.json",
"node3/validator_keys"
]
3 changes: 3 additions & 0 deletions cmd/testdata/TestCreateCluster_goerli_files.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"node2",
"node0/charon-enr-private-key",
"node0/cluster-lock.json",
"node0/deposit-data-1eth.json",
"node0/deposit-data.json",
"node0/validator_keys",
"node1/charon-enr-private-key",
"node1/cluster-lock.json",
"node1/deposit-data-1eth.json",
"node1/deposit-data.json",
"node1/validator_keys",
"node2/charon-enr-private-key",
"node2/cluster-lock.json",
"node2/deposit-data-1eth.json",
"node2/deposit-data.json",
"node2/validator_keys"
]
4 changes: 4 additions & 0 deletions cmd/testdata/TestCreateCluster_simnet_files.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
"node3",
"node0/charon-enr-private-key",
"node0/cluster-lock.json",
"node0/deposit-data-1eth.json",
"node0/deposit-data.json",
"node0/validator_keys",
"node1/charon-enr-private-key",
"node1/cluster-lock.json",
"node1/deposit-data-1eth.json",
"node1/deposit-data.json",
"node1/validator_keys",
"node2/charon-enr-private-key",
"node2/cluster-lock.json",
"node2/deposit-data-1eth.json",
"node2/deposit-data.json",
"node2/validator_keys",
"node3/charon-enr-private-key",
"node3/cluster-lock.json",
"node3/deposit-data-1eth.json",
"node3/deposit-data.json",
"node3/validator_keys"
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
"node3",
"node0/charon-enr-private-key",
"node0/cluster-lock.json",
"node0/deposit-data-1eth.json",
"node0/deposit-data.json",
"node0/validator_keys",
"node1/charon-enr-private-key",
"node1/cluster-lock.json",
"node1/deposit-data-1eth.json",
"node1/deposit-data.json",
"node1/validator_keys",
"node2/charon-enr-private-key",
"node2/cluster-lock.json",
"node2/deposit-data-1eth.json",
"node2/deposit-data.json",
"node2/validator_keys",
"node3/charon-enr-private-key",
"node3/cluster-lock.json",
"node3/deposit-data-1eth.json",
"node3/deposit-data.json",
"node3/validator_keys"
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
"node3",
"node0/charon-enr-private-key",
"node0/cluster-lock.json",
"node0/deposit-data-1eth.json",
"node0/deposit-data.json",
"node0/validator_keys",
"node1/charon-enr-private-key",
"node1/cluster-lock.json",
"node1/deposit-data-1eth.json",
"node1/deposit-data.json",
"node1/validator_keys",
"node2/charon-enr-private-key",
"node2/cluster-lock.json",
"node2/deposit-data-1eth.json",
"node2/deposit-data.json",
"node2/validator_keys",
"node3/charon-enr-private-key",
"node3/cluster-lock.json",
"node3/deposit-data-1eth.json",
"node3/deposit-data.json",
"node3/validator_keys"
]
4 changes: 4 additions & 0 deletions cmd/testdata/TestCreateCluster_splitkeys_files.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
"node3",
"node0/charon-enr-private-key",
"node0/cluster-lock.json",
"node0/deposit-data-1eth.json",
"node0/deposit-data.json",
"node0/validator_keys",
"node1/charon-enr-private-key",
"node1/cluster-lock.json",
"node1/deposit-data-1eth.json",
"node1/deposit-data.json",
"node1/validator_keys",
"node2/charon-enr-private-key",
"node2/cluster-lock.json",
"node2/deposit-data-1eth.json",
"node2/deposit-data.json",
"node2/validator_keys",
"node3/charon-enr-private-key",
"node3/cluster-lock.json",
"node3/deposit-data-1eth.json",
"node3/deposit-data.json",
"node3/validator_keys"
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
"node3",
"node0/charon-enr-private-key",
"node0/cluster-lock.json",
"node0/deposit-data-1eth.json",
"node0/deposit-data.json",
"node0/validator_keys",
"node1/charon-enr-private-key",
"node1/cluster-lock.json",
"node1/deposit-data-1eth.json",
"node1/deposit-data.json",
"node1/validator_keys",
"node2/charon-enr-private-key",
"node2/cluster-lock.json",
"node2/deposit-data-1eth.json",
"node2/deposit-data.json",
"node2/validator_keys",
"node3/charon-enr-private-key",
"node3/cluster-lock.json",
"node3/deposit-data-1eth.json",
"node3/deposit-data.json",
"node3/validator_keys"
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"node2",
"node0/charon-enr-private-key",
"node0/cluster-lock.json",
"node0/deposit-data-1eth.json",
"node0/deposit-data.json",
"node0/validator_keys",
"node1/charon-enr-private-key",
"node1/cluster-lock.json",
"node1/deposit-data-1eth.json",
"node1/deposit-data.json",
"node1/validator_keys",
"node2/charon-enr-private-key",
"node2/cluster-lock.json",
"node2/deposit-data-1eth.json",
"node2/deposit-data.json",
"node2/validator_keys"
]
6 changes: 5 additions & 1 deletion dkg/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ func Run(ctx context.Context, conf Config) (err error) {
// Sign, exchange and aggregate Deposit Data
depositAmounts := def.DepositAmounts
if len(depositAmounts) == 0 {
depositAmounts = []eth2p0.Gwei{deposit.MaxDepositAmount}
if cluster.SupportPartialDeposits(def.Version) {
depositAmounts = deposit.DefaultDepositAmounts()
} else {
depositAmounts = []eth2p0.Gwei{deposit.DefaultDepositAmount}
}
} else {
depositAmounts = deposit.DedupAmounts(depositAmounts)
}
Expand Down
2 changes: 1 addition & 1 deletion dkg/dkg_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestValidSignatures(t *testing.T) {
withdrawalAddr := testutil.RandomETHAddress()
network := eth2util.Goerli.Name

msg, err := deposit.NewMessage(eth2Pubkey, withdrawalAddr, deposit.MaxDepositAmount)
msg, err := deposit.NewMessage(eth2Pubkey, withdrawalAddr, deposit.DefaultDepositAmount)
require.NoError(t, err)
sigRoot, err := deposit.GetMessageSigningRoot(msg, network)
require.NoError(t, err)
Expand Down
6 changes: 5 additions & 1 deletion dkg/dkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ func verifyDistValidators(t *testing.T, lock cluster.Lock, def cluster.Definitio
// Assert Deposit Data
depositAmounts := deposit.DedupAmounts(def.DepositAmounts)
if len(depositAmounts) == 0 {
depositAmounts = []eth2p0.Gwei{deposit.MaxDepositAmount}
if !cluster.SupportPartialDeposits(def.Version) {
depositAmounts = []eth2p0.Gwei{deposit.DefaultDepositAmount}
} else {
depositAmounts = deposit.DefaultDepositAmounts()
}
}
require.Len(t, val.PartialDepositData, len(depositAmounts))

Expand Down
Loading

0 comments on commit 379d0b7

Please sign in to comment.