From c95b25187b00b8d307dc18cdad666eb798f75836 Mon Sep 17 00:00:00 2001 From: kalo <24719519+KaloyanTanev@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:59:18 +0200 Subject: [PATCH 1/2] dkg: write a signed proposer config --- app/proposerconfig.go | 38 ++ cluster/proposerconfig/delta.go | 6 +- cluster/proposerconfig/proposerconfig.go | 37 ++ dkg/dkg.go | 95 +++- dkg/dkg_test.go | 320 ++++++++++++- dkg/dkgpb/v1/proposerconfig.pb.go | 132 ++++++ dkg/dkgpb/v1/proposerconfig.proto | 10 + dkg/nodesigs.go | 20 +- dkg/nodesigs_internal_test.go | 2 + dkg/proposerconfig.go | 312 +++++++++++++ dkg/proposerconfig_internal_test.go | 550 +++++++++++++++++++++++ dkg/protocol_addoperators.go | 2 +- dkg/protocol_removeoperators.go | 2 +- dkg/protocol_replaceoperator.go | 2 +- dkg/protocol_reshare.go | 2 +- dkg/protocolsteps_internal_test.go | 2 +- docs/dkg.md | 1 + testutil/integration/nightly_dkg_test.go | 7 +- 18 files changed, 1507 insertions(+), 33 deletions(-) create mode 100644 dkg/dkgpb/v1/proposerconfig.pb.go create mode 100644 dkg/dkgpb/v1/proposerconfig.proto create mode 100644 dkg/proposerconfig.go create mode 100644 dkg/proposerconfig_internal_test.go diff --git a/app/proposerconfig.go b/app/proposerconfig.go index 66eeb6ed73..6c434da6b3 100644 --- a/app/proposerconfig.go +++ b/app/proposerconfig.go @@ -10,6 +10,9 @@ import ( "strconv" "strings" + eth2api "github.com/attestantio/go-eth2-client/api" + eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/obolnetwork/charon/app/errors" "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/app/z" @@ -188,6 +191,41 @@ func DiffSummaryFields(lines []string) []z.Field { } } +// RegistrationFeeRecipientFunc returns the fee recipients the initial proposer config is derived from, as on charon run +// start: the builder registration service over the lock's registrations and the overrides file, so a registration +// override newer than the lock's wins. An invalid lock registration is an error, as on charon run. +func RegistrationFeeRecipientFunc(ctx context.Context, lock cluster.Lock, overridesFile string) (func(core.PubKey) string, error) { + var ( + regs = make([]*eth2api.VersionedSignedValidatorRegistration, 0, len(lock.Validators)) + fees = make(map[core.PubKey]string, len(lock.Validators)) + ) + + lockFees := lock.FeeRecipientAddresses() + + for i, val := range lock.Validators { + pubkey, err := core.PubKeyFromBytes(val.PubKey) + if err != nil { + return nil, errors.Wrap(err, "core pubkey", z.Int("validator", i)) + } + + fees[pubkey] = lockFees[i] + + reg, err := val.Eth2Registration() + if err != nil { + return nil, errors.Wrap(err, "convert builder registration", z.Int("validator", i)) + } + + regs = append(regs, reg) + } + + svc, err := NewBuilderRegistrationService(ctx, overridesFile, eth2p0.Version(lock.ForkVersion), regs, fees, nil, lock.LockHash) + if err != nil { + return nil, err + } + + return svc.FeeRecipient, nil +} + // InitialProposerConfig returns the unsigned revision 0 document: fee recipients from the effective builder // registrations falling back to the lock, gas limit and builder from the seed flags. func InitialProposerConfig(lock cluster.Lock, seed proposerconfig.Seed, feeRecipientFunc func(core.PubKey) string) (proposerconfig.Document, error) { diff --git a/cluster/proposerconfig/delta.go b/cluster/proposerconfig/delta.go index 8dcf19e1f5..92aca0e971 100644 --- a/cluster/proposerconfig/delta.go +++ b/cluster/proposerconfig/delta.go @@ -79,7 +79,7 @@ func Apply(lock cluster.Lock, c Config, d Delta) (Config, error) { return Config{}, err } - equal, err := sameConfig(c, res) + equal, err := SameConfig(c, res) if err != nil { return Config{}, err } @@ -173,8 +173,8 @@ func applyBuilder(b *Builder, d Delta) (*Builder, error) { return &res, nil } -// sameConfig returns whether a and b have the same canonical form. -func sameConfig(a, b Config) (bool, error) { +// SameConfig returns whether a and b have the same canonical form. +func SameConfig(a, b Config) (bool, error) { ha, err := Document{Config: a}.Hash() if err != nil { return false, err diff --git a/cluster/proposerconfig/proposerconfig.go b/cluster/proposerconfig/proposerconfig.go index 23a1affab9..117e2dae0a 100644 --- a/cluster/proposerconfig/proposerconfig.go +++ b/cluster/proposerconfig/proposerconfig.go @@ -223,3 +223,40 @@ func normaliseAddress(addr string) (string, error) { return strings.ToLower(checksummed), nil } + +// Normalise returns a copy of c with fee recipients lowercased after EIP-55 validation and +// proposer_config keys lowercased. Empty fee recipients are kept. +func Normalise(c Config) (Config, error) { + norm := func(s Settings) (Settings, error) { + if s.FeeRecipient == "" { + return s, nil + } + + fee, err := normaliseAddress(s.FeeRecipient) + if err != nil { + return Settings{}, err + } + + s.FeeRecipient = fee + + return s, nil + } + + def, err := norm(c.DefaultConfig) + if err != nil { + return Config{}, errors.Wrap(err, "default config") + } + + res := Config{DefaultConfig: def, ProposerConfig: make(map[string]Settings, len(c.ProposerConfig))} + + for k, v := range c.ProposerConfig { + s, err := norm(v) + if err != nil { + return Config{}, errors.Wrap(err, "proposer config entry", z.Str("pubkey", k)) + } + + res.ProposerConfig[strings.ToLower(k)] = s + } + + return res, nil +} diff --git a/dkg/dkg.go b/dkg/dkg.go index cd93df0fd4..68a2326d04 100644 --- a/dkg/dkg.go +++ b/dkg/dkg.go @@ -9,7 +9,9 @@ import ( "fmt" "net/url" "path" + "path/filepath" "slices" + "strconv" "sync/atomic" "time" @@ -32,6 +34,7 @@ import ( "github.com/obolnetwork/charon/app/version" "github.com/obolnetwork/charon/app/z" "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/core" "github.com/obolnetwork/charon/dkg/bcast" "github.com/obolnetwork/charon/dkg/pedersen" @@ -46,6 +49,15 @@ import ( "github.com/obolnetwork/charon/tbls/tblsconv" ) +// proposerConfigSeedMsgID is the message ID of the proposer config agreement before key generation. +const proposerConfigSeedMsgID = "/charon/dkg/proposer_config_seed" + +// Remedies ending a proposer config mismatch error. +const ( + proposerConfigSeedHint = "Align the --proposer-config-* flags across all operators and retry." + proposerConfigCarriedHint = "Converge the current proposer config first with charon alpha edit proposer-config, then retry." +) + // shutdownSyncTimeout bounds the final shutdown synchronization between peers. All protocol // steps are complete and artifacts are stored by then, so waiting longer serves no purpose. const shutdownSyncTimeout = 2 * time.Minute @@ -74,6 +86,9 @@ type Config struct { Zipped bool Nickname string + + // ProposerConfigSeed seeds the gas limit and builder of the proposer config signed at revision 1. + ProposerConfigSeed proposerconfig.Seed } // TestConfig defines additional test-only config for DKG. @@ -108,6 +123,10 @@ type AppendConfig struct { ValidatorAddresses []cluster.ValidatorAddresses // DepositData is the deposit data from the existing cluster. DepositData [][]eth2p0.DepositData + // ProposerConfigFile is the existing cluster's proposer config file, its config is carried over. + ProposerConfigFile string + // OverridesFile is the builder registration overrides file feeding the initial proposer config when ProposerConfigFile is absent. + OverridesFile string } // Run executes a dkg ceremony and writes secret share keystore and cluster lock files as output to disk. @@ -229,6 +248,49 @@ func Run(ctx context.Context, conf Config) (err error) { return err } + nodeIdx, err := def.NodeIdx(pID) + if err != nil { + return errors.Wrap(err, "private key not matching definition file") + } + + // The new validators' fee recipients go into the signed proposer config after key generation. + for i, addr := range newFeeRecipientAddrs { + _, err := eth2util.ValidateChecksumAddress(addr) + if err != nil { + return errors.Wrap(err, "invalid fee recipient address", z.Int("validator", i), z.Str("address", addr)) + } + } + + // The proposer config all operators must agree on before key generation, the lock describing a + // mismatch and its remedy. + var ( + localProposerConfig proposerconfig.Config + proposerConfigLock = cluster.Lock{Definition: def} + proposerConfigHint = proposerConfigSeedHint + ) + + if conf.AppendConfig != nil { + proposerConfigLock = *conf.AppendConfig.ClusterLock + proposerConfigHint = proposerConfigCarriedHint + + localProposerConfig, err = loadCarriedProposerConfig(ctx, proposerConfigLock, nodeIdx, conf.AppendConfig.ProposerConfigFile, conf.AppendConfig.OverridesFile) + if err != nil { + return err + } + } else { + seed := conf.ProposerConfigSeed + + err = seed.Validate() + if err != nil { + return err + } + + localProposerConfig.DefaultConfig = proposerconfig.Settings{ + GasLimit: strconv.FormatUint(seed.GasLimit, 10), + Builder: seed.Builder(), + } + } + log.Info(ctx, "Starting local P2P networking peer") logPeerSummary(ctx, pID, peers, def.Operators) @@ -239,11 +301,6 @@ func Run(ctx context.Context, conf Config) (err error) { } defer shutdown() - nodeIdx, err := def.NodeIdx(p2pNode.ID()) - if err != nil { - return errors.Wrap(err, "private key not matching definition file") - } - peerIDs, err := def.PeerIDs() if err != nil { return errors.Wrap(err, "get peer IDs") @@ -279,7 +336,9 @@ func Run(ctx context.Context, conf Config) (err error) { } // register bcast callbacks: node signatures and public shares - nodeSigCaster := newNodeSigBcast(peers, nodeIdx, caster) + nodeSigCaster := newNodeSigBcast(peers, nodeIdx, caster, nodeSigMsgID) + proposerConfigSigCaster := newNodeSigBcast(peers, nodeIdx, caster, proposerConfigSigMsgID) + proposerConfigAgreement := newConfigAgreement(peers, nodeIdx, caster, proposerConfigSeedMsgID) // register pedersen protocol messages phaseDuration := conf.Timeout / time.Duration(6) // 10 seconds per phase for default 1 minute DKG timeout @@ -318,6 +377,12 @@ func Run(ctx context.Context, conf Config) (err error) { log.Info(ctx, "All peers connected, starting DKG ceremony") + // Fail on differing proposer config seeding flags (or carried files) before generating keys. + agreedProposerConfig, err := proposerConfigAgreement.agree(ctx, proposerConfigLock, localProposerConfig, proposerConfigHint) + if err != nil { + return fatalOr(errors.Wrap(err, "agree proposer config")) + } + var shares []share.Share switch def.DKGAlgorithm { @@ -424,6 +489,17 @@ func Run(ctx context.Context, conf Config) (err error) { lock.NodeSignatures = nil } + // Sign, exchange K1 signatures over the revision 1 proposer config of the lock + lockProposerConfig, err := newLockProposerConfig(lock, agreedProposerConfig, proposerConfigLock, newFeeRecipientAddrs) + if err != nil { + return err + } + + proposerConfig, err := exchangeProposerConfig(ctx, proposerConfigSigCaster, key, lock, lockProposerConfig) + if err != nil { + return err + } + // Node signatures was step 5, advance to step 6 if err := nextStepSync(ctx); err != nil { return err @@ -472,6 +548,13 @@ func Run(ctx context.Context, conf Config) (err error) { log.Debug(ctx, "Saved lock file to disk") + err = proposerconfig.Write(filepath.Join(conf.DataDir, "vc-config", "proposer-config.json"), proposerConfig, lock, nodeIdx) + if err != nil { + return err + } + + log.Debug(ctx, "Saved proposer config file to disk") + if conf.AppendConfig != nil && conf.AppendConfig.DepositData != nil { // Merging existing deposit data files with the new ones (append mode). depositDatas = deposit.MergeDepositDataSets(depositDatas, conf.AppendConfig.DepositData) diff --git a/dkg/dkg_test.go b/dkg/dkg_test.go index 8014951d02..f77e707555 100644 --- a/dkg/dkg_test.go +++ b/dkg/dkg_test.go @@ -14,6 +14,7 @@ import ( "os" "path" "slices" + "strconv" "strings" "sync" "testing" @@ -24,6 +25,7 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" + "go.uber.org/zap" "golang.org/x/sync/errgroup" "github.com/obolnetwork/charon/app" @@ -32,6 +34,7 @@ import ( "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/app/z" "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/dkg" dkgsync "github.com/obolnetwork/charon/dkg/sync" "github.com/obolnetwork/charon/eth2util" @@ -59,6 +62,9 @@ const ( v1_0 = "v1.0.0" ) +// testSeed is the default proposer config seed of charon dkg. +var testSeed = proposerconfig.Seed{GasLimit: proposerconfig.DefaultGasLimit, BuilderBoostFactor: proposerconfig.DefaultBuilderBoostFactor} + func isAnyVersion(version string, list ...string) bool { return slices.Contains(list, version) } @@ -149,6 +155,8 @@ func TestDKG(t *testing.T) { if !test.keymanager { verifyDKGResults(t, lock.Definition, dir) + } else { + verifyProposerConfigs(t, dir, len(lock.Operators)) } }) } @@ -188,8 +196,35 @@ func TestAppendDKG(t *testing.T) { dstDir := t.TempDir() + // The existing cluster's signed proposer config carries a builder, a gas limit and a diverging fee recipient. + const divergingFee = "0x00000000000000000000000000000000000000aa" + + builder := &proposerconfig.Builder{ + MinBid: "1", + BuilderBoostFactor: "90", + MaxExecutionPayment: "2", + Builders: []proposerconfig.BuilderEntry{{URL: "https://builder.example.com"}}, + } + + lockFees := lock.FeeRecipientAddresses() + cfg, err := proposerconfig.NewConfig(lock, []string{divergingFee, lockFees[1]}, 60_000_000, builder) + require.NoError(t, err) + + pcDoc := proposerconfig.Document{Version: proposerconfig.Version, LockHash: lock.LockHash, Revision: 2, Config: cfg} + for i, key := range keys { + sig, err := proposerconfig.Sign(pcDoc, key) + require.NoError(t, err) + + pcDoc.Signatures = append(pcDoc.Signatures, proposerconfig.Signature{Operator: i, Signature: sig}) + } + + require.NoError(t, proposerconfig.Verify(pcDoc, lock)) + appendConfigs := make([]dkg.AppendConfig, nodes) for i := range nodes { + pcFile := path.Join(t.TempDir(), "proposer-config.json") + require.NoError(t, proposerconfig.Write(pcFile, pcDoc, lock, cluster.NodeIdx{PeerIdx: i, ShareIdx: i + 1})) + secretShares := make([]tbls.PrivateKey, vals) for j := range vals { secretShares[j] = pkShares[j][i] @@ -217,9 +252,11 @@ func TestAppendDKG(t *testing.T) { WithdrawalAddress: "0x0000000000000000000000000000000000000002", }, }, - ClusterLock: &lockCopy, - SecretShares: secretShares, - DepositData: depositData, + ClusterLock: &lockCopy, + SecretShares: secretShares, + DepositData: depositData, + ProposerConfigFile: pcFile, + OverridesFile: path.Join(t.TempDir(), "absent.json"), } } @@ -258,6 +295,21 @@ func TestAppendDKG(t *testing.T) { require.Len(t, dd[0], totalVals) require.Len(t, dd[1], totalVals) } + + // The new lock's proposer config carries the existing config and adds the new validators' fee recipients. + newFee := "0x0000000000000000000000000000000000000001" + + for _, doc := range verifyProposerConfigs(t, dstDir, nodes) { + require.Equal(t, "60000000", doc.Config.DefaultConfig.GasLimit) + require.Equal(t, builder, doc.Config.DefaultConfig.Builder) + + var newLock cluster.Lock + + lockFile, err := os.ReadFile(path.Join(dstDir, "node0", "cluster-lock.json")) + require.NoError(t, err) + require.NoError(t, json.Unmarshal(lockFile, &newLock)) + require.Equal(t, []string{divergingFee, strings.ToLower(lockFees[1]), newFee, newFee, newFee}, doc.Config.FeeRecipients(newLock)) + } } func testDKG(t *testing.T, def cluster.Definition, dir string, p2pKeys []*k1.PrivateKey, keymanager bool, publish bool, addConfig []dkg.AppendConfig) { @@ -287,9 +339,10 @@ func testDKG(t *testing.T, def cluster.Definition, dir string, p2pKeys []*k1.Pri }, SyncOpts: []func(*dkgsync.Client){dkgsync.WithPeriod(time.Millisecond * 50)}, }, - ShutdownDelay: 1 * time.Second, - PublishTimeout: 30 * time.Second, - Timeout: 8 * time.Second, + ShutdownDelay: 1 * time.Second, + PublishTimeout: 30 * time.Second, + Timeout: 8 * time.Second, + ProposerConfigSeed: testSeed, } allReceivedKeystores := make(chan struct{}) // Receives struct{} for each `numNodes` keystore intercepted by the keymanager server @@ -426,6 +479,12 @@ func verifyDKGResults(t *testing.T, def cluster.Definition, dir string) { verifyDistValidators(t, lock, def) } + docs := verifyProposerConfigs(t, dir, len(def.Operators)) + for i, doc := range docs { + require.Equal(t, strconv.FormatUint(proposerconfig.DefaultGasLimit, 10), doc.Config.DefaultConfig.GasLimit) + require.Equal(t, lowerAll(def.FeeRecipientAddresses()), doc.Config.FeeRecipients(locks[i])) + } + // Ensure locks hashes are identical. var hash []byte @@ -770,7 +829,8 @@ func getConfigs(t *testing.T, def cluster.Definition, keys []*k1.PrivateKey, dir }, P2PNodeCallback: p2pNodeCallback, }, - Timeout: 10 * time.Second, + Timeout: 10 * time.Second, + ProposerConfigSeed: testSeed, } require.NoError(t, os.MkdirAll(conf.DataDir, 0o755)) @@ -864,3 +924,249 @@ func clone[T any](t *testing.T, v T) T { return clone } + +// verifyProposerConfigs asserts each node wrote a revision 1 proposer config signed by all operators of its +// lock, identical across nodes, and returns the documents in node order. +func verifyProposerConfigs(t *testing.T, dir string, nodes int) []proposerconfig.Document { + t.Helper() + + var docs []proposerconfig.Document + + for i := range nodes { + dataDir := path.Join(dir, fmt.Sprintf("node%d", i)) + + lockFile, err := os.ReadFile(path.Join(dataDir, "cluster-lock.json")) + require.NoError(t, err) + + var lock cluster.Lock + require.NoError(t, json.Unmarshal(lockFile, &lock)) + + doc, err := proposerconfig.Load(path.Join(dataDir, "vc-config", "proposer-config.json"), lock, cluster.NodeIdx{PeerIdx: i, ShareIdx: i + 1}) + require.NoError(t, err) + require.NoError(t, proposerconfig.Verify(doc, lock)) + require.EqualValues(t, 1, doc.Revision) + require.Len(t, doc.Signatures, nodes) + + for j, sig := range doc.Signatures { + require.Equal(t, j, sig.Operator) + } + + docs = append(docs, doc) + } + + for _, doc := range docs[1:] { + h0, err := docs[0].Hash() + require.NoError(t, err) + h, err := doc.Hash() + require.NoError(t, err) + require.Equal(t, h0, h) + } + + return docs +} + +func lowerAll(addrs []string) []string { + res := make([]string, 0, len(addrs)) + for _, a := range addrs { + res = append(res, strings.ToLower(a)) + } + + return res +} + +// runMismatchedNodes runs dkg.Run on all nodes of lock, letting mutate change each node's config, and returns +// each node's error. Every node must fail before key generation. +func runMismatchedNodes(t *testing.T, lock cluster.Lock, keys []*k1.PrivateKey, mutate func(i int, conf *dkg.Config)) []error { + t.Helper() + + nodes := len(lock.Operators) + dir := t.TempDir() + + ctx, cancel := context.WithCancel(t.Context()) + defer cancel() + + relayAddr := relay.StartRelay(ctx, t) + + errs := make([]error, nodes) + + var eg errgroup.Group + + for i := range nodes { + def := clone(t, lock.Definition) + conf := dkg.Config{ + DataDir: path.Join(dir, fmt.Sprintf("node%d", i)), + P2P: p2p.Config{ + Relays: []string{relayAddr}, + TCPAddrs: []string{testutil.AvailableAddr(t).String()}, + }, + Log: log.DefaultConfig(), + TestConfig: dkg.TestConfig{ + Def: &def, + StoreKeysFunc: func(secrets []tbls.PrivateKey, dir string) error { + return keystore.StoreKeysInsecure(secrets, dir, keystore.ConfirmInsecureKeys) + }, + SyncOpts: []func(*dkgsync.Client){dkgsync.WithPeriod(time.Millisecond * 50)}, + }, + ShutdownDelay: time.Second, + Timeout: 8 * time.Second, + ProposerConfigSeed: testSeed, + } + mutate(i, &conf) + + require.NoError(t, os.MkdirAll(conf.DataDir, 0o755)) + require.NoError(t, k1util.Save(keys[i], p2p.KeyPath(conf.DataDir))) + + eg.Go(func() error { + errs[i] = dkg.Run(peerCtx(ctx, i), conf) + return nil + }) + } + + require.NoError(t, eg.Wait()) + + for i, err := range errs { + testutil.SkipIfBindErr(t, err) + + // Fails before key generation: nothing written. + _, statErr := os.Stat(path.Join(dir, fmt.Sprintf("node%d", i), "validator_keys")) + require.ErrorIs(t, statErr, os.ErrNotExist) + } + + return errs +} + +func TestDKGSeedMismatch(t *testing.T) { + random := rand.New(rand.NewSource(1)) + lock, keys, _ := cluster.NewForT(t, 2, 3, 3, 1, random) + + errs := runMismatchedNodes(t, lock, keys, func(i int, conf *dkg.Config) { + if i == 2 { + conf.ProposerConfigSeed.GasLimit = 60_000_000 + } + }) + + for i, err := range errs { + require.ErrorContains(t, err, "default.gas_limit: 200000000 -> 60000000", "node %d", i) + require.ErrorContains(t, err, "--proposer-config-*", "node %d", i) + } +} + +func TestAppendDKGMismatch(t *testing.T) { + random := rand.New(rand.NewSource(1)) + lock, keys, pkShares := cluster.NewForT(t, 2, 3, 3, 1, random) + + errs := runMismatchedNodes(t, lock, keys, func(i int, conf *dkg.Config) { + gasLimit := proposerconfig.DefaultGasLimit + if i == 2 { + gasLimit = 60_000_000 + } + + cfg, err := proposerconfig.NewConfig(lock, lock.FeeRecipientAddresses(), gasLimit, nil) + require.NoError(t, err) + + // Unsigned revision 0 files may differ between nodes. + pcFile := path.Join(t.TempDir(), "proposer-config.json") + doc := proposerconfig.Document{Version: proposerconfig.Version, LockHash: lock.LockHash, Config: cfg} + require.NoError(t, proposerconfig.Write(pcFile, doc, lock, cluster.NodeIdx{PeerIdx: i, ShareIdx: i + 1})) + + lockCopy := clone(t, lock) + conf.AppendConfig = &dkg.AppendConfig{ + ClusterLock: &lockCopy, + SecretShares: []tbls.PrivateKey{pkShares[0][i], pkShares[1][i]}, + AddValidators: 1, + ValidatorAddresses: []cluster.ValidatorAddresses{{FeeRecipientAddress: lock.FeeRecipientAddresses()[0], WithdrawalAddress: lock.WithdrawalAddresses()[0]}}, + ProposerConfigFile: pcFile, + } + }) + + for i, err := range errs { + require.ErrorContains(t, err, "default.gas_limit: 200000000 -> 60000000", "node %d", i) + require.ErrorContains(t, err, "charon alpha edit proposer-config", "node %d", i) + } +} + +func TestDKGInvalidInputs(t *testing.T) { + const badChecksum = "0x5AAeb6053F3E94C9b9A09f33669435E7Ef1BeAed" // EIP-55 is 0x5aAeb6... + + tests := []struct { + name string + mutate func(*dkg.Config) + errMsg string + address string + }{ + { + name: "bad fee recipient checksum", + mutate: func(conf *dkg.Config) { + conf.TestConfig.Def.ValidatorAddresses[1].FeeRecipientAddress = badChecksum + }, + errMsg: "invalid fee recipient address", + address: badChecksum, + }, + { + name: "zero gas limit seed", + mutate: func(conf *dkg.Config) { + conf.ProposerConfigSeed.GasLimit = 0 + }, + errMsg: "proposer-config-gas-limit must be greater than 0", + }, + { + name: "builder value without urls", + mutate: func(conf *dkg.Config) { + conf.ProposerConfigSeed.BuilderBoostFactor = 90 + conf.ProposerConfigSeed.NonDefault = []string{"proposer-config-builder-boost-factor"} + }, + errMsg: "require proposer-config-builder-urls", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + random := rand.New(rand.NewSource(1)) + lock, keys, _ := cluster.NewForT(t, 2, 3, 3, 1, random) + dir := t.TempDir() + def := clone(t, lock.Definition) + + conf := dkg.Config{ + DataDir: dir, + P2P: p2p.Config{TCPAddrs: []string{testutil.AvailableAddr(t).String()}}, + Log: log.DefaultConfig(), + TestConfig: dkg.TestConfig{ + Def: &def, + StoreKeysFunc: func(secrets []tbls.PrivateKey, dir string) error { + return keystore.StoreKeysInsecure(secrets, dir, keystore.ConfirmInsecureKeys) + }, + }, + Timeout: 8 * time.Second, + ProposerConfigSeed: testSeed, + } + test.mutate(&conf) + require.NoError(t, k1util.Save(keys[0], p2p.KeyPath(dir))) + + // A single node: it must fail before waiting for peers, which would time out. + ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second) + defer cancel() + + err := dkg.Run(ctx, conf) + testutil.SkipIfBindErr(t, err) + require.ErrorContains(t, err, test.errMsg) + + if test.address != "" { + require.Contains(t, fieldStrings(err), test.address) + } + + _, statErr := os.Stat(path.Join(dir, "validator_keys")) + require.ErrorIs(t, statErr, os.ErrNotExist) + }) + } +} + +// fieldStrings returns the string values of the structured error's fields. +func fieldStrings(err error) []string { + var res []string + + for _, field := range z.Fields(err) { + field(func(f zap.Field) { res = append(res, f.String) }) + } + + return res +} diff --git a/dkg/dkgpb/v1/proposerconfig.pb.go b/dkg/dkgpb/v1/proposerconfig.pb.go new file mode 100644 index 0000000000..d351d48ac6 --- /dev/null +++ b/dkg/dkgpb/v1/proposerconfig.pb.go @@ -0,0 +1,132 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.12 +// protoc (unknown) +// source: dkg/dkgpb/v1/proposerconfig.proto + +package v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type MsgProposerConfigContent struct { + state protoimpl.MessageState `protogen:"open.v1"` + Content []byte `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"` + PeerIndex uint32 `protobuf:"varint,3,opt,name=peer_index,json=peerIndex,proto3" json:"peer_index,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MsgProposerConfigContent) Reset() { + *x = MsgProposerConfigContent{} + mi := &file_dkg_dkgpb_v1_proposerconfig_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MsgProposerConfigContent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgProposerConfigContent) ProtoMessage() {} + +func (x *MsgProposerConfigContent) ProtoReflect() protoreflect.Message { + mi := &file_dkg_dkgpb_v1_proposerconfig_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MsgProposerConfigContent.ProtoReflect.Descriptor instead. +func (*MsgProposerConfigContent) Descriptor() ([]byte, []int) { + return file_dkg_dkgpb_v1_proposerconfig_proto_rawDescGZIP(), []int{0} +} + +func (x *MsgProposerConfigContent) GetContent() []byte { + if x != nil { + return x.Content + } + return nil +} + +func (x *MsgProposerConfigContent) GetPeerIndex() uint32 { + if x != nil { + return x.PeerIndex + } + return 0 +} + +var File_dkg_dkgpb_v1_proposerconfig_proto protoreflect.FileDescriptor + +const file_dkg_dkgpb_v1_proposerconfig_proto_rawDesc = "" + + "\n" + + "!dkg/dkgpb/v1/proposerconfig.proto\x12\fdkg.dkgpb.v1\"S\n" + + "\x18MsgProposerConfigContent\x12\x18\n" + + "\acontent\x18\x01 \x01(\fR\acontent\x12\x1d\n" + + "\n" + + "peer_index\x18\x03 \x01(\rR\tpeerIndexB,Z*github.com/obolnetwork/charon/dkg/dkgpb/v1b\x06proto3" + +var ( + file_dkg_dkgpb_v1_proposerconfig_proto_rawDescOnce sync.Once + file_dkg_dkgpb_v1_proposerconfig_proto_rawDescData []byte +) + +func file_dkg_dkgpb_v1_proposerconfig_proto_rawDescGZIP() []byte { + file_dkg_dkgpb_v1_proposerconfig_proto_rawDescOnce.Do(func() { + file_dkg_dkgpb_v1_proposerconfig_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_dkg_dkgpb_v1_proposerconfig_proto_rawDesc), len(file_dkg_dkgpb_v1_proposerconfig_proto_rawDesc))) + }) + return file_dkg_dkgpb_v1_proposerconfig_proto_rawDescData +} + +var file_dkg_dkgpb_v1_proposerconfig_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_dkg_dkgpb_v1_proposerconfig_proto_goTypes = []any{ + (*MsgProposerConfigContent)(nil), // 0: dkg.dkgpb.v1.MsgProposerConfigContent +} +var file_dkg_dkgpb_v1_proposerconfig_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_dkg_dkgpb_v1_proposerconfig_proto_init() } +func file_dkg_dkgpb_v1_proposerconfig_proto_init() { + if File_dkg_dkgpb_v1_proposerconfig_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_dkg_dkgpb_v1_proposerconfig_proto_rawDesc), len(file_dkg_dkgpb_v1_proposerconfig_proto_rawDesc)), + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_dkg_dkgpb_v1_proposerconfig_proto_goTypes, + DependencyIndexes: file_dkg_dkgpb_v1_proposerconfig_proto_depIdxs, + MessageInfos: file_dkg_dkgpb_v1_proposerconfig_proto_msgTypes, + }.Build() + File_dkg_dkgpb_v1_proposerconfig_proto = out.File + file_dkg_dkgpb_v1_proposerconfig_proto_goTypes = nil + file_dkg_dkgpb_v1_proposerconfig_proto_depIdxs = nil +} diff --git a/dkg/dkgpb/v1/proposerconfig.proto b/dkg/dkgpb/v1/proposerconfig.proto new file mode 100644 index 0000000000..54ce45a86f --- /dev/null +++ b/dkg/dkgpb/v1/proposerconfig.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package dkg.dkgpb.v1; + +option go_package = "github.com/obolnetwork/charon/dkg/dkgpb/v1"; + +message MsgProposerConfigContent { + bytes content = 1; + uint32 peer_index = 3; +} diff --git a/dkg/nodesigs.go b/dkg/nodesigs.go index e1fbe6504a..ec97bbcd66 100644 --- a/dkg/nodesigs.go +++ b/dkg/nodesigs.go @@ -23,14 +23,13 @@ import ( "github.com/obolnetwork/charon/p2p" ) -const nodeSigMsgID = "/charon/dkg/node_sig" +const ( + nodeSigMsgID = "/charon/dkg/node_sig" + proposerConfigSigMsgID = "/charon/dkg/proposer_config_sig" +) var noneData = []byte{0xde, 0xad, 0xbe, 0xef} -func nodeSigMsgIDs() []string { - return []string{nodeSigMsgID} -} - // nodeSigBcast handles broadcasting of K1 signatures over the lock hash via the bcast protocol. type nodeSigBcast struct { sigs [][]byte @@ -39,6 +38,7 @@ type nodeSigBcast struct { bcastFunc bcast.BroadcastFunc peers []p2p.Peer nodeIdx cluster.NodeIdx + msgID string lockHashCh chan []byte lockHashData []byte @@ -46,23 +46,23 @@ type nodeSigBcast struct { } // newNodeSigBcast returns a new instance of nodeSigBcast. -// It registers bcast handlers on bcastComp. +// It registers bcast handlers for msgID on bcastComp. func newNodeSigBcast( peers []p2p.Peer, nodeIdx cluster.NodeIdx, bcastComp *bcast.Component, + msgID string, ) *nodeSigBcast { ret := &nodeSigBcast{ sigs: make([][]byte, len(peers)), bcastFunc: bcastComp.Broadcast, peers: peers, nodeIdx: nodeIdx, + msgID: msgID, lockHashCh: make(chan []byte), } - for _, k1Sig := range nodeSigMsgIDs() { - bcastComp.RegisterMessageIDFuncs(k1Sig, ret.broadcastCallback, ret.checkMessage) - } + bcastComp.RegisterMessageIDFuncs(msgID, ret.broadcastCallback, ret.checkMessage) return ret } @@ -218,7 +218,7 @@ func (n *nodeSigBcast) exchange( PeerIndex: uint32(n.nodeIdx.PeerIdx), } - if err := n.bcastFunc(ctx, nodeSigMsgID, bcastData); err != nil { + if err := n.bcastFunc(ctx, n.msgID, bcastData); err != nil { return nil, errors.Wrap(err, "k1 lock hash signature broadcast") } diff --git a/dkg/nodesigs_internal_test.go b/dkg/nodesigs_internal_test.go index ee072146eb..24abde12ca 100644 --- a/dkg/nodesigs_internal_test.go +++ b/dkg/nodesigs_internal_test.go @@ -74,6 +74,7 @@ func TestSigsExchange(t *testing.T) { clusterPeers, cluster.NodeIdx{PeerIdx: i}, component, + nodeSigMsgID, )) } @@ -166,6 +167,7 @@ func TestSigsCallbacks(t *testing.T) { clusterPeers, cluster.NodeIdx{PeerIdx: 0}, component, + nodeSigMsgID, ) t.Run("wrong peer index, equal to ours", func(t *testing.T) { diff --git a/dkg/proposerconfig.go b/dkg/proposerconfig.go new file mode 100644 index 0000000000..fdac11a37e --- /dev/null +++ b/dkg/proposerconfig.go @@ -0,0 +1,312 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package dkg + +import ( + "context" + "encoding/json" + "fmt" + "strings" + "sync" + "time" + + k1 "github.com/decred/dcrd/dcrec/secp256k1/v4" + "github.com/libp2p/go-libp2p/core/peer" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" + + "github.com/obolnetwork/charon/app" + "github.com/obolnetwork/charon/app/errors" + "github.com/obolnetwork/charon/app/log" + "github.com/obolnetwork/charon/app/z" + "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" + "github.com/obolnetwork/charon/dkg/bcast" + dkgpb "github.com/obolnetwork/charon/dkg/dkgpb/v1" + "github.com/obolnetwork/charon/p2p" +) + +// configAgreement makes all nodes agree on one proposer config via the bcast protocol. +// An instance is single-use per ceremony: the first config received from each peer wins. +type configAgreement struct { + bcastFunc bcast.BroadcastFunc + peers []p2p.Peer + nodeIdx cluster.NodeIdx + msgID string + + mu sync.Mutex + received map[int]proposerconfig.Config +} + +// newConfigAgreement returns a new configAgreement and registers its bcast handlers for msgID on bcastComp. +// The bcast read limit of 128MB per message comfortably fits the config of thousands of validators. +func newConfigAgreement( + peers []p2p.Peer, + nodeIdx cluster.NodeIdx, + bcastComp *bcast.Component, + msgID string, +) *configAgreement { + ret := &configAgreement{ + bcastFunc: bcastComp.Broadcast, + peers: peers, + nodeIdx: nodeIdx, + msgID: msgID, + received: make(map[int]proposerconfig.Config), + } + + bcastComp.RegisterMessageIDFuncs(msgID, ret.broadcastCallback, ret.checkMessage) + + return ret +} + +// set stores the peer's normalised config, first write wins: an identical repeat is ignored and a +// differing one is an error. It is safe to use concurrently. +func (a *configAgreement) set(peerIdx int, cfg proposerconfig.Config) error { + a.mu.Lock() + defer a.mu.Unlock() + + prev, ok := a.received[peerIdx] + if !ok { + a.received[peerIdx] = cfg + return nil + } + + same, err := proposerconfig.SameConfig(prev, cfg) + if err != nil { + return err + } + + if !same { + return errors.New("conflicting proposer config from peer", z.Int("peer", peerIdx)) + } + + return nil +} + +// all returns the configs of all peers in peer order once every peer's has arrived. +func (a *configAgreement) all() ([]proposerconfig.Config, bool) { + a.mu.Lock() + defer a.mu.Unlock() + + if len(a.received) != len(a.peers) { + return nil, false + } + + res := make([]proposerconfig.Config, len(a.peers)) + for idx, cfg := range a.received { + res[idx] = cfg + } + + return res, true +} + +// broadcastCallback is the bcast.Callback of configAgreement. +func (a *configAgreement) broadcastCallback(_ context.Context, senderID peer.ID, _ string, msg proto.Message) error { + m, ok := msg.(*dkgpb.MsgProposerConfigContent) + if !ok { + return errors.New("invalid proposer config type") + } + + peerIdx := int(m.GetPeerIndex()) + if peerIdx < 0 || peerIdx >= len(a.peers) || peerIdx == a.nodeIdx.PeerIdx { + return errors.New("invalid peer index") + } + + if a.peers[peerIdx].ID != senderID { + return errors.New("sender peer ID does not match claimed peer index") + } + + var cfg proposerconfig.Config + + err := json.Unmarshal(m.GetContent(), &cfg) + if err != nil { + return errors.Wrap(err, "unmarshal proposer config", z.Int("peer", peerIdx)) + } + + norm, err := proposerconfig.Normalise(cfg) + if err != nil { + return errors.Wrap(err, "normalise proposer config", z.Int("peer", peerIdx)) + } + + return a.set(peerIdx, norm) +} + +// checkMessage is the bcast.CheckMessage of configAgreement. +func (*configAgreement) checkMessage(_ context.Context, peerID peer.ID, msgAny *anypb.Any) error { + var msg dkgpb.MsgProposerConfigContent + + err := msgAny.UnmarshalTo(&msg) + if err != nil { + return errors.Wrap(err, "proposer config request malformed", z.Str("peer_id", peerID.String())) + } + + return nil +} + +// agree broadcasts local and returns the config all peers agree on. The lock is only used to describe +// disagreements; hint ends a disagreement error with the operators' remedy. +func (a *configAgreement) agree(ctx context.Context, lock cluster.Lock, local proposerconfig.Config, hint string) (proposerconfig.Config, error) { + norm, err := proposerconfig.Normalise(local) + if err != nil { + return proposerconfig.Config{}, errors.Wrap(err, "normalise local proposer config") + } + + b, err := json.Marshal(norm) + if err != nil { + return proposerconfig.Config{}, errors.Wrap(err, "marshal proposer config") + } + + msg := &dkgpb.MsgProposerConfigContent{ + Content: b, + PeerIndex: uint32(a.nodeIdx.PeerIdx), + } + + err = a.bcastFunc(ctx, a.msgID, msg) + if err != nil { + return proposerconfig.Config{}, errors.Wrap(err, "proposer config broadcast") + } + + err = a.set(a.nodeIdx.PeerIdx, norm) + if err != nil { + return proposerconfig.Config{}, err + } + + tick := time.NewTicker(100 * time.Millisecond) + defer tick.Stop() + + for { + select { + case <-ctx.Done(): + return proposerconfig.Config{}, ctx.Err() + case <-tick.C: + cfgs, ok := a.all() + if ok { + return resolveConfigs(lock, cfgs, hint) + } + } + } +} + +// resolveConfigs returns the config all peers share, or an error describing each disagreement +// relative to peer 0, ending with hint. +func resolveConfigs(lock cluster.Lock, cfgs []proposerconfig.Config, hint string) (proposerconfig.Config, error) { + first := cfgs[0] + + var lines []string + + for i, cfg := range cfgs[1:] { + same, err := proposerconfig.SameConfig(first, cfg) + if err != nil { + return proposerconfig.Config{}, errors.Wrap(err, "compare proposer configs", z.Int("peer", i+1)) + } + + if same { + continue + } + + lines = append(lines, fmt.Sprintf("peer %d differs from peer 0:", i+1)) + + diffs := proposerconfig.Diff(lock, first, cfg) + for _, line := range diffs { + lines = append(lines, " "+line) + } + + if len(diffs) == 0 { + lines = append(lines, " configs differ outside the compared fields") + } + } + + if len(lines) > 0 { + if hint != "" { + lines = append(lines, hint) + } + + return proposerconfig.Config{}, errors.New("proposer config mismatch between operators:\n" + strings.Join(lines, "\n")) + } + + return first, nil +} + +// initialProposerConfig returns the config charon run derives with no file, with the default gas limit and no builder. +func initialProposerConfig(ctx context.Context, lock cluster.Lock, overridesFile string) (proposerconfig.Config, error) { + feeRecipientFunc, err := app.RegistrationFeeRecipientFunc(ctx, lock, overridesFile) + if err != nil { + return proposerconfig.Config{}, err + } + + doc, err := app.InitialProposerConfig(lock, proposerconfig.Seed{GasLimit: proposerconfig.DefaultGasLimit}, feeRecipientFunc) + if err != nil { + return proposerconfig.Config{}, err + } + + return doc.Config, nil +} + +// loadCarriedProposerConfig returns the config of this node's proposer config file to carry into a new lock, +// or the initial config if the file is absent. An unloadable or invalid file is an error. +func loadCarriedProposerConfig(ctx context.Context, lock cluster.Lock, nodeIdx cluster.NodeIdx, path, overridesFile string) (proposerconfig.Config, error) { + doc, err := proposerconfig.Load(path, lock, nodeIdx) + if errors.Is(err, proposerconfig.ErrNotFound) { + log.Info(ctx, "No proposer config file, carrying over one derived from the lock and overrides", z.Str("path", path)) + + return initialProposerConfig(ctx, lock, overridesFile) + } else if err != nil { + return proposerconfig.Config{}, err + } + + err = proposerconfig.Verify(doc, lock) + if err != nil { + return proposerconfig.Config{}, errors.Wrap(err, "verify proposer config file", z.Str("path", path)) + } + + return doc.Config, nil +} + +// newLockProposerConfig returns the config for the new lock with the agreed gas limit and builder: +// the agreed fee recipients of the carried lock's validators followed by newFees, in lock order. +func newLockProposerConfig(lock cluster.Lock, agreed proposerconfig.Config, carried cluster.Lock, newFees []string) (proposerconfig.Config, error) { + gasLimit, err := agreed.GasLimit() + if err != nil { + return proposerconfig.Config{}, err + } + + fees := append(agreed.FeeRecipients(carried), newFees...) + + return proposerconfig.NewConfig(lock, fees, gasLimit, agreed.DefaultConfig.Builder) +} + +// exchangeProposerConfig exchanges all operators' signatures of the lock's revision 1 proposer config with the +// config and returns the verified document. Signatures arrive in peer order, which is the lock's operator order. +func exchangeProposerConfig(ctx context.Context, caster *nodeSigBcast, key *k1.PrivateKey, lock cluster.Lock, cfg proposerconfig.Config) (proposerconfig.Document, error) { + doc := proposerconfig.Document{ + Version: proposerconfig.Version, + LockHash: lock.LockHash, + Revision: 1, + Config: cfg, + } + + hash, err := doc.Hash() + if err != nil { + return proposerconfig.Document{}, err + } + + sigs, err := caster.exchange(ctx, key, hash[:]) + if err != nil { + return proposerconfig.Document{}, errors.Wrap(err, "k1 proposer config signature exchange") + } + + if len(sigs) != len(lock.Operators) { + return proposerconfig.Document{}, errors.New("proposer config signature count mismatch", z.Int("signatures", len(sigs)), z.Int("operators", len(lock.Operators))) + } + + for i, sig := range sigs { + doc.Signatures = append(doc.Signatures, proposerconfig.Signature{Operator: i, Signature: sig}) + } + + err = proposerconfig.Verify(doc, lock) + if err != nil { + return proposerconfig.Document{}, errors.Wrap(err, "verify signed proposer config") + } + + return doc, nil +} diff --git a/dkg/proposerconfig_internal_test.go b/dkg/proposerconfig_internal_test.go new file mode 100644 index 0000000000..5c8a8ad160 --- /dev/null +++ b/dkg/proposerconfig_internal_test.go @@ -0,0 +1,550 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package dkg + +import ( + "bytes" + "context" + "encoding/hex" + "encoding/json" + "math/rand" + "os" + "path/filepath" + "slices" + "strings" + "testing" + "time" + + eth2api "github.com/attestantio/go-eth2-client/api" + eth2v1 "github.com/attestantio/go-eth2-client/api/v1" + eth2spec "github.com/attestantio/go-eth2-client/spec" + "github.com/attestantio/go-eth2-client/spec/bellatrix" + eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" + k1 "github.com/decred/dcrd/dcrec/secp256k1/v4" + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/peerstore" + "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" + + "github.com/obolnetwork/charon/app" + "github.com/obolnetwork/charon/app/k1util" + "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" + "github.com/obolnetwork/charon/core" + "github.com/obolnetwork/charon/dkg/bcast" + dkgpb "github.com/obolnetwork/charon/dkg/dkgpb/v1" + "github.com/obolnetwork/charon/eth2util/enr" + "github.com/obolnetwork/charon/eth2util/registration" + "github.com/obolnetwork/charon/p2p" + "github.com/obolnetwork/charon/tbls" + "github.com/obolnetwork/charon/testutil" +) + +const testFeeAddr = "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed" + +// newBcastComponents returns n connected bcast components and their cluster peers. +func newBcastComponents(t *testing.T, n int) ([]*bcast.Component, []p2p.Peer, []*k1.PrivateKey) { + t.Helper() + + var ( + secrets []*k1.PrivateKey + tcpNodes []host.Host + peers []peer.ID + clusterPeers []p2p.Peer + ) + + for i := range n { + secret, err := k1.GeneratePrivateKey() + require.NoError(t, err) + + secrets = append(secrets, secret) + + tcpNode := testutil.CreateHostWithIdentity(t, testutil.AvailableAddr(t), secret) + tcpNodes = append(tcpNodes, tcpNode) + peers = append(peers, tcpNode.ID()) + + e, err := enr.New(secret) + require.NoError(t, err) + + epeer, err := p2p.NewPeerFromENR(e, i) + require.NoError(t, err) + + clusterPeers = append(clusterPeers, epeer) + } + + for i := range n { + for j := range n { + tcpNodes[i].Peerstore().AddAddrs(tcpNodes[j].ID(), tcpNodes[j].Addrs(), peerstore.PermanentAddrTTL) + } + } + + comps := make([]*bcast.Component, n) + for i := range n { + comps[i] = bcast.New(tcpNodes[i], peers, secrets[i], []byte("session hash")) + } + + return comps, clusterPeers, secrets +} + +// runAgreement runs agree on all nodes with the given local configs. +func runAgreement(t *testing.T, lock cluster.Lock, locals []proposerconfig.Config) ([]proposerconfig.Config, []error) { + t.Helper() + + ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second) + defer cancel() + + comps, peers, _ := newBcastComponents(t, len(locals)) + + var ( + results = make([]proposerconfig.Config, len(locals)) + errs = make([]error, len(locals)) + eg errgroup.Group + ) + + agreements := make([]*configAgreement, len(locals)) + for i := range locals { + agreements[i] = newConfigAgreement(peers, cluster.NodeIdx{PeerIdx: i}, comps[i], proposerConfigSeedMsgID) + } + + for i := range locals { + eg.Go(func() error { + results[i], errs[i] = agreements[i].agree(ctx, lock, locals[i], "test hint") + return nil + }) + } + + require.NoError(t, eg.Wait()) + + return results, errs +} + +func testProposerConfig(t *testing.T, lock cluster.Lock, gasLimit uint64) proposerconfig.Config { + t.Helper() + + fees := make([]string, len(lock.Validators)) + for i := range fees { + fees[i] = testFeeAddr + } + + c, err := proposerconfig.NewConfig(lock, fees, gasLimit, nil) + require.NoError(t, err) + + return c +} + +func TestNodeSigBcastTwoMessageIDs(t *testing.T) { + const n = 3 + + ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second) + defer cancel() + + comps, peers, secrets := newBcastComponents(t, n) + + var ( + lockHash = bytes.Repeat([]byte{1}, 32) + confHash = bytes.Repeat([]byte{2}, 32) + lockRes = make([][][]byte, n) + confRes = make([][][]byte, n) + eg errgroup.Group + ) + + for i := range n { + lockSigs := newNodeSigBcast(peers, cluster.NodeIdx{PeerIdx: i}, comps[i], nodeSigMsgID) + confSigs := newNodeSigBcast(peers, cluster.NodeIdx{PeerIdx: i}, comps[i], proposerConfigSigMsgID) + + eg.Go(func() error { + var err error + + lockRes[i], err = lockSigs.exchange(ctx, secrets[i], lockHash) + + return err + }) + eg.Go(func() error { + var err error + + confRes[i], err = confSigs.exchange(ctx, secrets[i], confHash) + + return err + }) + } + + require.NoError(t, eg.Wait()) + + // Every node holds all signatures of each exchange, each verifying against its own hash only. + for i := range n { + require.Len(t, lockRes[i], n) + require.Len(t, confRes[i], n) + + for j := range n { + pubk, err := peers[j].PublicKey() + require.NoError(t, err) + + ok, err := k1util.Verify65(pubk, lockHash, lockRes[i][j]) + require.NoError(t, err) + require.True(t, ok) + + ok, err = k1util.Verify65(pubk, confHash, confRes[i][j]) + require.NoError(t, err) + require.True(t, ok) + } + } +} + +func TestConfigAgreementEqual(t *testing.T) { + lock, _, _ := cluster.NewForT(t, 2, 3, 4, 0, rand.New(rand.NewSource(1))) + c := testProposerConfig(t, lock, proposerconfig.DefaultGasLimit) + + results, errs := runAgreement(t, lock, []proposerconfig.Config{c, c, c, c}) + for i := range errs { + require.NoError(t, errs[i]) + require.Equal(t, c, results[i]) + } +} + +func TestConfigAgreementMismatchDiff(t *testing.T) { + lock, _, _ := cluster.NewForT(t, 2, 3, 4, 0, rand.New(rand.NewSource(1))) + a := testProposerConfig(t, lock, proposerconfig.DefaultGasLimit) + b := testProposerConfig(t, lock, 123) + + _, errs := runAgreement(t, lock, []proposerconfig.Config{a, a, b, a}) + for _, err := range errs { + require.ErrorContains(t, err, "peer 2") + require.ErrorContains(t, err, "default.gas_limit: 200000000 -> 123") + require.True(t, strings.HasSuffix(err.Error(), "\ntest hint"), err.Error()) + require.NotContains(t, err.Error(), "peer 1") + } +} + +func TestConfigAgreementNoValidators(t *testing.T) { + // Seed configs carry no validators; Diff must still work against a lock without any. + a := proposerconfig.Config{DefaultConfig: proposerconfig.Settings{FeeRecipient: testFeeAddr, GasLimit: "1"}} + b := proposerconfig.Config{DefaultConfig: proposerconfig.Settings{FeeRecipient: testFeeAddr, GasLimit: "2"}} + + _, errs := runAgreement(t, cluster.Lock{}, []proposerconfig.Config{a, b, a}) + for _, err := range errs { + require.ErrorContains(t, err, "default.gas_limit: 1 -> 2") + } +} + +func TestConfigAgreementNormalisesAddresses(t *testing.T) { + a := proposerconfig.Config{DefaultConfig: proposerconfig.Settings{FeeRecipient: testFeeAddr, GasLimit: "1"}} + b := proposerconfig.Config{DefaultConfig: proposerconfig.Settings{FeeRecipient: strings.ToLower(testFeeAddr), GasLimit: "1"}} + + _, errs := runAgreement(t, cluster.Lock{}, []proposerconfig.Config{a, b, a}) + for _, err := range errs { + require.NoError(t, err) + } +} + +func TestConfigAgreementHostileConfig(t *testing.T) { + lock, _, _ := cluster.NewForT(t, 2, 3, 4, 0, rand.New(rand.NewSource(1))) + a := testProposerConfig(t, lock, proposerconfig.DefaultGasLimit) + // Missing default fields, an entry for a pubkey outside the lock and empty maps. + b := proposerconfig.Config{ProposerConfig: map[string]proposerconfig.Settings{"0xABCD": {GasLimit: "5"}}} + c := proposerconfig.Config{} + + _, errs := runAgreement(t, lock, []proposerconfig.Config{a, b, c}) + for _, err := range errs { + require.ErrorContains(t, err, "peer 1") + require.ErrorContains(t, err, "peer 2") + } +} + +func TestConfigAgreementHashOnlyDiff(t *testing.T) { + a := proposerconfig.Config{DefaultConfig: proposerconfig.Settings{FeeRecipient: testFeeAddr, GasLimit: "1"}} + b := proposerconfig.Config{ + DefaultConfig: a.DefaultConfig, + ProposerConfig: map[string]proposerconfig.Settings{"0xabcd": {GasLimit: "5"}}, + } + + _, errs := runAgreement(t, cluster.Lock{}, []proposerconfig.Config{a, b, a}) + for _, err := range errs { + require.ErrorContains(t, err, "configs differ outside the compared fields") + } +} + +func TestConfigAgreementDuplicateFirstWins(t *testing.T) { + comps, peers, _ := newBcastComponents(t, 2) + ag := newConfigAgreement(peers, cluster.NodeIdx{PeerIdx: 0}, comps[0], proposerConfigSeedMsgID) + + send := func(gas string) error { + b, err := json.Marshal(proposerconfig.Config{DefaultConfig: proposerconfig.Settings{GasLimit: gas}}) + require.NoError(t, err) + + return ag.broadcastCallback(context.Background(), peers[1].ID, "", &dkgpb.MsgProposerConfigContent{Content: b, PeerIndex: 1}) + } + + require.NoError(t, send("1")) + require.NoError(t, send("1")) + require.ErrorContains(t, send("2"), "conflicting") + require.Equal(t, "1", ag.received[1].DefaultConfig.GasLimit) +} + +// signOverride returns the validator's registration with the fee recipient and timestamp, signed by its root key. +func signOverride(t *testing.T, lock cluster.Lock, shares [][]tbls.PrivateKey, valIdx int, fee bellatrix.ExecutionAddress, timestamp time.Time) *eth2api.VersionedSignedValidatorRegistration { + t.Helper() + + sharesMap := make(map[int]tbls.PrivateKey) + for i, share := range shares[valIdx] { + sharesMap[i+1] = share + } + + root, err := tbls.RecoverSecret(sharesMap, uint(len(shares[valIdx])), uint(lock.Threshold)) + require.NoError(t, err) + + msg := ð2v1.ValidatorRegistration{ + FeeRecipient: fee, + GasLimit: registration.DefaultGasLimit, + Timestamp: timestamp, + Pubkey: eth2p0.BLSPubKey(lock.Validators[valIdx].PubKey), + } + + sigRoot, err := registration.GetMessageSigningRoot(msg, eth2p0.Version(lock.ForkVersion)) + require.NoError(t, err) + + sig, err := tbls.Sign(root, sigRoot[:]) + require.NoError(t, err) + + return ð2api.VersionedSignedValidatorRegistration{ + Version: eth2spec.BuilderVersionV1, + V1: ð2v1.SignedValidatorRegistration{Message: msg, Signature: eth2p0.BLSSignature(sig)}, + } +} + +func TestInitialProposerConfig(t *testing.T) { + lock, _, shares := cluster.NewForT(t, 3, 3, 4, 0, rand.New(rand.NewSource(1))) + lockFees := lock.FeeRecipientAddresses() + + newer := bellatrix.ExecutionAddress{19: 0x99} + older := bellatrix.ExecutionAddress{19: 0x98} + lockTime := lock.Validators[1].BuilderRegistration.Message.Timestamp + + overrides := []*eth2api.VersionedSignedValidatorRegistration{ + signOverride(t, lock, shares, 0, newer, time.Now()), + signOverride(t, lock, shares, 1, older, lockTime.Add(-time.Hour)), + } + + b, err := json.Marshal(overrides) + require.NoError(t, err) + + overridesFile := filepath.Join(t.TempDir(), "overrides.json") + require.NoError(t, os.WriteFile(overridesFile, b, 0o644)) + + t.Run("overrides newer than the lock win", func(t *testing.T) { + cfg, err := initialProposerConfig(t.Context(), lock, overridesFile) + require.NoError(t, err) + require.Equal(t, []string{ + "0x" + hex.EncodeToString(newer[:]), + strings.ToLower(lockFees[1]), + strings.ToLower(lockFees[2]), + }, cfg.FeeRecipients(lock)) + require.Equal(t, "200000000", cfg.DefaultConfig.GasLimit) + require.Nil(t, cfg.DefaultConfig.Builder) + }) + + t.Run("absent overrides file", func(t *testing.T) { + cfg, err := initialProposerConfig(t.Context(), lock, filepath.Join(t.TempDir(), "absent.json")) + require.NoError(t, err) + require.Equal(t, lowerAddrs(lockFees), cfg.FeeRecipients(lock)) + }) + + t.Run("invalid overrides file", func(t *testing.T) { + bad := filepath.Join(t.TempDir(), "bad.json") + require.NoError(t, os.WriteFile(bad, []byte("{"), 0o644)) + + _, err := initialProposerConfig(t.Context(), lock, bad) + require.ErrorContains(t, err, "unmarshal builder registration overrides file") + }) +} + +func TestInitialProposerConfigMatchesRun(t *testing.T) { + lock, _, shares := cluster.NewForT(t, 3, 3, 4, 0, rand.New(rand.NewSource(1))) + + noRegs := lock + noRegs.Validators = slices.Clone(lock.Validators) + + for i := range noRegs.Validators { + noRegs.Validators[i].BuilderRegistration = cluster.BuilderRegistration{} + } + + b, err := json.Marshal([]*eth2api.VersionedSignedValidatorRegistration{ + signOverride(t, lock, shares, 0, bellatrix.ExecutionAddress{19: 0x99}, time.Now()), + }) + require.NoError(t, err) + + overridesFile := filepath.Join(t.TempDir(), "overrides.json") + require.NoError(t, os.WriteFile(overridesFile, b, 0o644)) + + // runFeeRecipientFunc is the builder registration service charon run derives the initial config from. + runFeeRecipientFunc := func(t *testing.T, l cluster.Lock) func(core.PubKey) string { + t.Helper() + + var regs []*eth2api.VersionedSignedValidatorRegistration + + fees := make(map[core.PubKey]string) + + for i, val := range l.Validators { + pubkey, err := core.PubKeyFromBytes(val.PubKey) + require.NoError(t, err) + + fees[pubkey] = l.FeeRecipientAddresses()[i] + + reg, err := val.Eth2Registration() + require.NoError(t, err) + + regs = append(regs, reg) + } + + svc, err := app.NewBuilderRegistrationService(t.Context(), overridesFile, eth2p0.Version(l.ForkVersion), regs, fees, nil, l.LockHash) + require.NoError(t, err) + + return svc.FeeRecipient + } + + t.Run("with registrations", func(t *testing.T) { + got, err := initialProposerConfig(t.Context(), lock, overridesFile) + require.NoError(t, err) + + want, err := app.InitialProposerConfig(lock, proposerconfig.Seed{GasLimit: proposerconfig.DefaultGasLimit}, runFeeRecipientFunc(t, lock)) + require.NoError(t, err) + require.Equal(t, want.Config, got) + }) + + t.Run("invalid registration fails as on run", func(t *testing.T) { + _, err := initialProposerConfig(t.Context(), noRegs, overridesFile) + require.ErrorContains(t, err, "convert builder registration") + }) +} + +func lowerAddrs(addrs []string) []string { + res := make([]string, 0, len(addrs)) + for _, a := range addrs { + res = append(res, strings.ToLower(a)) + } + + return res +} + +func TestLoadCarriedProposerConfig(t *testing.T) { + lock, keys, _ := cluster.NewForT(t, 2, 3, 4, 0, rand.New(rand.NewSource(1))) + nodeIdx := cluster.NodeIdx{PeerIdx: 1, ShareIdx: 2} + absent := filepath.Join(t.TempDir(), "absent.json") + + cfg := testProposerConfig(t, lock, 60_000_000) + cfg.DefaultConfig.Builder = &proposerconfig.Builder{MinBid: "0", BuilderBoostFactor: "100", MaxExecutionPayment: "0", Builders: []proposerconfig.BuilderEntry{{URL: "https://b.example.com"}}} + + signed := func(t *testing.T, signers int) proposerconfig.Document { + t.Helper() + + doc := proposerconfig.Document{Version: proposerconfig.Version, LockHash: lock.LockHash, Revision: 3, Config: cfg} + for i := range signers { + sig, err := proposerconfig.Sign(doc, keys[i]) + require.NoError(t, err) + + doc.Signatures = append(doc.Signatures, proposerconfig.Signature{Operator: i, Signature: sig}) + } + + return doc + } + + write := func(t *testing.T, doc proposerconfig.Document) string { + t.Helper() + + path := filepath.Join(t.TempDir(), "proposer-config.json") + require.NoError(t, proposerconfig.Write(path, doc, lock, nodeIdx)) + + return path + } + + t.Run("signed file", func(t *testing.T) { + got, err := loadCarriedProposerConfig(t.Context(), lock, nodeIdx, write(t, signed(t, lock.Threshold)), absent) + require.NoError(t, err) + require.Equal(t, cfg.FeeRecipients(lock), got.FeeRecipients(lock)) + require.Equal(t, cfg.DefaultConfig, got.DefaultConfig) + }) + + t.Run("revision 0 file", func(t *testing.T) { + doc := proposerconfig.Document{Version: proposerconfig.Version, LockHash: lock.LockHash, Config: cfg} + + got, err := loadCarriedProposerConfig(t.Context(), lock, nodeIdx, write(t, doc), absent) + require.NoError(t, err) + require.Equal(t, cfg.DefaultConfig, got.DefaultConfig) + }) + + t.Run("absent file is the initial config", func(t *testing.T) { + got, err := loadCarriedProposerConfig(t.Context(), lock, nodeIdx, absent, absent) + require.NoError(t, err) + + want, err := initialProposerConfig(t.Context(), lock, absent) + require.NoError(t, err) + require.Equal(t, want, got) + }) + + t.Run("invalid file", func(t *testing.T) { + _, err := loadCarriedProposerConfig(t.Context(), lock, nodeIdx, write(t, signed(t, lock.Threshold-1)), absent) + require.ErrorIs(t, err, proposerconfig.ErrInvalid) + }) + + t.Run("undecodable file", func(t *testing.T) { + path := filepath.Join(t.TempDir(), "proposer-config.json") + require.NoError(t, os.WriteFile(path, []byte("{"), 0o644)) + + _, err := loadCarriedProposerConfig(t.Context(), lock, nodeIdx, path, absent) + require.ErrorContains(t, err, "unmarshal proposer config") + }) + + t.Run("other lock", func(t *testing.T) { + doc := signed(t, lock.Threshold) + doc.LockHash = bytes.Repeat([]byte{1}, 32) + + other := lock + other.LockHash = doc.LockHash + + path := filepath.Join(t.TempDir(), "proposer-config.json") + require.NoError(t, proposerconfig.Write(path, doc, other, nodeIdx)) + + _, err := loadCarriedProposerConfig(t.Context(), lock, nodeIdx, path, absent) + require.ErrorIs(t, err, proposerconfig.ErrLockHashMismatch) + }) +} + +func TestNewLockProposerConfig(t *testing.T) { + lock, _, _ := cluster.NewForT(t, 3, 3, 4, 0, rand.New(rand.NewSource(1))) + carried := lock + carried.Validators = lock.Validators[:2] + + const ( + defaultFee = "0x00000000000000000000000000000000000000aa" + divergingFee = "0x00000000000000000000000000000000000000bb" + newFee = "0x00000000000000000000000000000000000000cc" + ) + + builder := &proposerconfig.Builder{MinBid: "1", BuilderBoostFactor: "90", MaxExecutionPayment: "2", Builders: []proposerconfig.BuilderEntry{{URL: "https://b.example.com"}}} + + agreed, err := proposerconfig.NewConfig(carried, []string{divergingFee, defaultFee}, 60_000_000, builder) + require.NoError(t, err) + + t.Run("append", func(t *testing.T) { + got, err := newLockProposerConfig(lock, agreed, carried, []string{newFee}) + require.NoError(t, err) + require.Equal(t, []string{divergingFee, defaultFee, newFee}, got.FeeRecipients(lock)) + require.Equal(t, "60000000", got.DefaultConfig.GasLimit) + require.Equal(t, builder, got.DefaultConfig.Builder) + }) + + t.Run("fresh", func(t *testing.T) { + seed := proposerconfig.Config{DefaultConfig: proposerconfig.Settings{GasLimit: "200000000"}} + + got, err := newLockProposerConfig(lock, seed, cluster.Lock{}, []string{newFee, newFee, divergingFee}) + require.NoError(t, err) + require.Equal(t, []string{newFee, newFee, divergingFee}, got.FeeRecipients(lock)) + require.Equal(t, "200000000", got.DefaultConfig.GasLimit) + require.Nil(t, got.DefaultConfig.Builder) + }) + + t.Run("fee recipient count mismatch", func(t *testing.T) { + _, err := newLockProposerConfig(lock, agreed, carried, nil) + require.ErrorContains(t, err, "fee recipient count mismatch") + }) +} diff --git a/dkg/protocol_addoperators.go b/dkg/protocol_addoperators.go index 30c2396557..9a4a41bc27 100644 --- a/dkg/protocol_addoperators.go +++ b/dkg/protocol_addoperators.go @@ -94,7 +94,7 @@ func (p *addOperatorsProtocol) PostInit(ctx context.Context, pctx *ProtocolConte // Bind broadcasts to the lock hash since it changes with every cluster mutation, // preventing replay of messages from previous ceremonies of the same cluster. pctx.Caster = bcast.New(pctx.ThisNode, pctx.PeerIDs, pctx.ENRPrivateKey, pctx.Lock.LockHash) - pctx.NodeSigCaster = newNodeSigBcast(pctx.Peers, pctx.ThisNodeIdx, pctx.Caster) + pctx.NodeSigCaster = newNodeSigBcast(pctx.Peers, pctx.ThisNodeIdx, pctx.Caster, nodeSigMsgID) newPeerIDs := pctx.PeerIDs[len(pctx.Lock.Operators):] reshareConfig := pedersen.NewReshareConfig(len(pctx.Lock.Validators), pctx.Lock.Threshold, newPeerIDs, nil) diff --git a/dkg/protocol_removeoperators.go b/dkg/protocol_removeoperators.go index c855824d81..e36bbe7ae0 100644 --- a/dkg/protocol_removeoperators.go +++ b/dkg/protocol_removeoperators.go @@ -153,7 +153,7 @@ func (p *removeOperatorsProtocol) PostInit(ctx context.Context, pctx *ProtocolCo // Bind broadcasts to the lock hash since it changes with every cluster mutation, // preventing replay of messages from previous ceremonies of the same cluster. pctx.Caster = bcast.New(pctx.ThisNode, pctx.PeerIDs, pctx.ENRPrivateKey, pctx.Lock.LockHash) - pctx.NodeSigCaster = newNodeSigBcast(pctx.Peers, pctx.ThisNodeIdx, pctx.Caster) + pctx.NodeSigCaster = newNodeSigBcast(pctx.Peers, pctx.ThisNodeIdx, pctx.Caster, nodeSigMsgID) if !p.oldNode { // SigExchanger is only created for nodes remaining in the cluster, because old nodes do not participate in signing. diff --git a/dkg/protocol_replaceoperator.go b/dkg/protocol_replaceoperator.go index 7d6dadc203..b44bade02b 100644 --- a/dkg/protocol_replaceoperator.go +++ b/dkg/protocol_replaceoperator.go @@ -112,7 +112,7 @@ func (p *replaceOperatorProtocol) PostInit(ctx context.Context, pctx *ProtocolCo // Bind broadcasts to the lock hash since it changes with every cluster mutation, // preventing replay of messages from previous ceremonies of the same cluster. pctx.Caster = bcast.New(pctx.ThisNode, pctx.PeerIDs, pctx.ENRPrivateKey, pctx.Lock.LockHash) - pctx.NodeSigCaster = newNodeSigBcast(pctx.Peers, pctx.ThisNodeIdx, pctx.Caster) + pctx.NodeSigCaster = newNodeSigBcast(pctx.Peers, pctx.ThisNodeIdx, pctx.Caster, nodeSigMsgID) // For replace operator: identify the old and new peer IDs at the replacement position. // The old operator is being removed (OldPeers), the new operator is being added (NewPeers). diff --git a/dkg/protocol_reshare.go b/dkg/protocol_reshare.go index 23f9e11d76..5dd2bad19c 100644 --- a/dkg/protocol_reshare.go +++ b/dkg/protocol_reshare.go @@ -58,7 +58,7 @@ func (p *reshareProtocol) PostInit(ctx context.Context, pctx *ProtocolContext) e // Bind broadcasts to the lock hash since it changes with every cluster mutation, // preventing replay of messages from previous ceremonies of the same cluster. pctx.Caster = bcast.New(pctx.ThisNode, pctx.PeerIDs, pctx.ENRPrivateKey, pctx.Lock.LockHash) - pctx.NodeSigCaster = newNodeSigBcast(pctx.Peers, pctx.ThisNodeIdx, pctx.Caster) + pctx.NodeSigCaster = newNodeSigBcast(pctx.Peers, pctx.ThisNodeIdx, pctx.Caster, nodeSigMsgID) pedersenReshareConfig := pedersen.NewReshareConfig(len(pctx.Lock.Validators), pctx.Lock.Threshold, nil, nil) p.config = pedersen.NewConfig(pctx.ThisPeerID, pctx.PeerMap, pctx.Lock.Threshold, pctx.Lock.DefinitionHash, pctx.Config.Timeout/6, pedersenReshareConfig) diff --git a/dkg/protocolsteps_internal_test.go b/dkg/protocolsteps_internal_test.go index ad0508ca92..b52619331a 100644 --- a/dkg/protocolsteps_internal_test.go +++ b/dkg/protocolsteps_internal_test.go @@ -195,7 +195,7 @@ func TestUpdateNodeSignaturesProtocolStep(t *testing.T) { for n := range numNodes { group.Go(func() error { caster := bcast.New(nodes[n].NodeHost, peers, nodeKeys[n], lock.DefinitionHash) - nodeSigCaster := newNodeSigBcast(allPeers, cluster.NodeIdx{PeerIdx: n, ShareIdx: n + 1}, caster) + nodeSigCaster := newNodeSigBcast(allPeers, cluster.NodeIdx{PeerIdx: n, ShareIdx: n + 1}, caster, nodeSigMsgID) step := &updateNodeSignaturesProtocolStep{} lockCopy := lock diff --git a/docs/dkg.md b/docs/dkg.md index a1de15b659..c9b0308557 100644 --- a/docs/dkg.md +++ b/docs/dkg.md @@ -66,6 +66,7 @@ No user input is required, charon does the work and outputs the following files ./charon/validator_keys/ # Folder of key shares to be backed up and moved to validator client [Back this up] ./charon/deposit_data* # JSON files of deposit data for the distributed validators ./charon/exit_data # JSON file of exit data that ethdo can broadcast +./charon/vc-config/proposer-config.json # Signed proposer config (fee recipients, gas limit, builders), change it with `charon alpha edit proposer-config` ``` ### Interruptions and restarts during a ceremony diff --git a/testutil/integration/nightly_dkg_test.go b/testutil/integration/nightly_dkg_test.go index f26d840e5a..7139b14bc0 100644 --- a/testutil/integration/nightly_dkg_test.go +++ b/testutil/integration/nightly_dkg_test.go @@ -21,6 +21,7 @@ import ( "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/app/z" "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/dkg" "github.com/obolnetwork/charon/p2p" ) @@ -90,7 +91,8 @@ func TestLongWaitDKG(t *testing.T) { TestConfig: dkg.TestConfig{ Def: &def, }, - Timeout: 10 * time.Minute, + Timeout: 10 * time.Minute, + ProposerConfigSeed: proposerconfig.Seed{GasLimit: proposerconfig.DefaultGasLimit, BuilderBoostFactor: proposerconfig.DefaultBuilderBoostFactor}, } windowTicker := time.NewTicker(window) @@ -307,7 +309,8 @@ func TestDKGWithHighValidatorsAmt(t *testing.T) { TestConfig: dkg.TestConfig{ Def: &def, }, - Timeout: 10 * time.Minute, + Timeout: 10 * time.Minute, + ProposerConfigSeed: proposerconfig.Seed{GasLimit: proposerconfig.DefaultGasLimit, BuilderBoostFactor: proposerconfig.DefaultBuilderBoostFactor}, } dir := t.TempDir() From 1698608f689cd8b935c6bd9f9c0ca8b1258efae5 Mon Sep 17 00:00:00 2001 From: kalo <24719519+KaloyanTanev@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:59:23 +0200 Subject: [PATCH 2/2] cmd: seed and write the signed proposer config --- cmd/cmd_internal_test.go | 85 ++++++++++++++ cmd/createcluster.go | 69 ++++++++++- cmd/createcluster_internal_test.go | 110 +++++++++++++++--- cmd/dkg.go | 1 + cmd/edit.go | 12 ++ cmd/edit_addoperators_internal_test.go | 2 +- cmd/edit_addvalidators.go | 8 ++ cmd/edit_addvalidators_internal_test.go | 80 ++++++++----- cmd/edit_removeoperators_internal_test.go | 2 +- cmd/edit_replaceoperator_internal_test.go | 2 +- cmd/run.go | 25 ++-- ...uster_custom_target_gas_limit_files.golden | 6 +- ...ster_custom_target_gas_limit_output.golden | 1 + ...eCluster_custom_testnet_flags_files.golden | 6 +- ...Cluster_custom_testnet_flags_output.golden | 1 + ...Cluster_four_partial_deposits_files.golden | 6 +- ...luster_four_partial_deposits_output.golden | 1 + .../TestCreateCluster_goerli_files.golden | 5 +- .../TestCreateCluster_goerli_output.golden | 1 + .../TestCreateCluster_simnet_files.golden | 6 +- .../TestCreateCluster_simnet_output.golden | 1 + ...olo_flow_definition_from_disk_files.golden | 6 +- ...lo_flow_definition_from_disk_output.golden | 1 + ..._flow_definition_from_network_files.golden | 6 +- ...flow_definition_from_network_output.golden | 1 + .../TestCreateCluster_splitkeys_files.golden | 6 +- .../TestCreateCluster_splitkeys_output.golden | 1 + ...tkeys_with_cluster_definition_files.golden | 6 +- ...keys_with_cluster_definition_output.golden | 1 + ...ient_and_withdrawal_addresses_files.golden | 5 +- ...ent_and_withdrawal_addresses_output.golden | 1 + ...eCluster_two_partial_deposits_files.golden | 6 +- ...Cluster_two_partial_deposits_output.golden | 1 + docs/configuration.md | 10 +- 34 files changed, 408 insertions(+), 73 deletions(-) diff --git a/cmd/cmd_internal_test.go b/cmd/cmd_internal_test.go index 64c1244ff4..4a83d0b19b 100644 --- a/cmd/cmd_internal_test.go +++ b/cmd/cmd_internal_test.go @@ -6,6 +6,7 @@ import ( "context" "io" "os" + "strings" "testing" "time" @@ -17,6 +18,7 @@ import ( "github.com/obolnetwork/charon/app/featureset" "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/cluster/proposerconfig" + "github.com/obolnetwork/charon/dkg" "github.com/obolnetwork/charon/p2p" "github.com/obolnetwork/charon/testutil" ) @@ -276,6 +278,89 @@ func TestProposerConfigSeedFlags(t *testing.T) { }) } +func TestDKGProposerConfigSeedFlags(t *testing.T) { + execute := func(t *testing.T, args ...string) (dkg.Config, error) { + t.Helper() + + var conf dkg.Config + + root := newRootCmd(newDKGCmd(func(_ context.Context, config dkg.Config) error { + conf = config + return nil + })) + root.SetArgs(append([]string{"dkg"}, args...)) + + return conf, root.Execute() + } + + t.Run("defaults", func(t *testing.T) { + conf, err := execute(t) + require.NoError(t, err) + require.Equal(t, proposerconfig.Seed{GasLimit: 200_000_000, BuilderBoostFactor: 100}, conf.ProposerConfigSeed) + }) + + t.Run("flags parse", func(t *testing.T) { + conf, err := execute(t, + "--proposer-config-gas-limit=60000000", + "--proposer-config-builder-urls=https://a.example.com", + "--proposer-config-builder-min-bid=1", + "--proposer-config-builder-boost-factor=90", + "--proposer-config-builder-max-execution-payment=2", + ) + require.NoError(t, err) + require.Equal(t, proposerconfig.Seed{ + GasLimit: 60_000_000, + BuilderURLs: []string{"https://a.example.com"}, + BuilderMinBid: 1, + BuilderBoostFactor: 90, + BuilderMaxExecutionPayment: 2, + NonDefault: []string{ + "proposer-config-gas-limit", "proposer-config-builder-urls", "proposer-config-builder-min-bid", + "proposer-config-builder-boost-factor", "proposer-config-builder-max-execution-payment", + }, + }, conf.ProposerConfigSeed) + }) + + t.Run("builder value without urls", func(t *testing.T) { + _, err := execute(t, "--proposer-config-builder-min-bid=1") + require.ErrorContains(t, err, "require proposer-config-builder-urls") + }) + + t.Run("usage says the values are signed", func(t *testing.T) { + cmd := newDKGCmd(nil) + for _, flag := range []string{"proposer-config-gas-limit", "proposer-config-builder-urls", "proposer-config-builder-min-bid", "proposer-config-builder-boost-factor", "proposer-config-builder-max-execution-payment"} { + usage := cmd.Flags().Lookup(flag).Usage + require.Contains(t, usage, "Signed into the cluster's initial proposer config", flag) + require.Contains(t, usage, "charon alpha edit proposer-config", flag) + require.NotContains(t, usage, "disregarded", flag) + } + }) + + t.Run("nickname still validated", func(t *testing.T) { + _, err := execute(t, "--nickname="+strings.Repeat("a", 33)) + require.ErrorContains(t, err, "--nickname exceeds 32 character limit") + }) +} + +func TestAddValidatorsProposerConfigFlags(t *testing.T) { + var conf addValidatorsConfig + + root := newRootCmd(newAddValidatorsCmd(func(_ context.Context, config addValidatorsConfig) error { + conf = config + return nil + })) + + root.SetArgs([]string{"add-validators"}) + require.NoError(t, root.Execute()) + require.Equal(t, ".charon/vc-config/proposer-config.json", conf.ProposerConfigFile) + require.Equal(t, ".charon/builder_registrations_overrides.json", conf.OverridesFile) + + root.SetArgs([]string{"add-validators", "--proposer-config-file=pc.json", "--overrides-file=o.json"}) + require.NoError(t, root.Execute()) + require.Equal(t, "pc.json", conf.ProposerConfigFile) + require.Equal(t, "o.json", conf.OverridesFile) +} + func TestFlagsToLogFields(t *testing.T) { set := pflag.NewFlagSet("test", pflag.PanicOnError) bindLokiFlags(set, &log.Config{}) diff --git a/cmd/createcluster.go b/cmd/createcluster.go index 9cc95599e7..7d94afef44 100644 --- a/cmd/createcluster.go +++ b/cmd/createcluster.go @@ -35,6 +35,7 @@ import ( "github.com/obolnetwork/charon/app/obolapi" "github.com/obolnetwork/charon/app/z" "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/core" "github.com/obolnetwork/charon/core/consensus/protocols" "github.com/obolnetwork/charon/eth2util" @@ -91,6 +92,9 @@ type clusterConfig struct { ExecutionEngineAddr string Zipped bool + + // ProposerConfigSeed seeds the gas limit and builder of the proposer config signed at revision 1. + ProposerConfigSeed proposerconfig.Seed } func newCreateClusterCmd(runFunc func(context.Context, io.Writer, clusterConfig) error) *cobra.Command { @@ -109,6 +113,7 @@ func newCreateClusterCmd(runFunc func(context.Context, io.Writer, clusterConfig) bindClusterFlags(cmd.Flags(), &conf) bindInsecureFlags(cmd.Flags(), &conf.InsecureKeys) bindNetworkFlags(cmd.Flags(), &conf.Network, &conf.testnetConfig) + bindProposerConfigSeedFlags(cmd, &conf.ProposerConfigSeed, proposerConfigSignedUsage) wrapPreRunE(cmd, func(cmd *cobra.Command, _ []string) error { thresholdPresent := cmd.Flags().Lookup("threshold").Changed @@ -166,7 +171,13 @@ func bindInsecureFlags(flags *pflag.FlagSet, insecureKeys *bool) { } func runCreateCluster(ctx context.Context, w io.Writer, conf clusterConfig) error { - var err error + // Reject a bad seed before any work: it is signed by every operator. + seed := conf.ProposerConfigSeed + + err := seed.Validate() + if err != nil { + return err + } // Map prater to goerli to ensure backwards compatibility with older cluster definitions and cluster locks. if conf.Network == eth2util.Prater { @@ -351,6 +362,11 @@ func runCreateCluster(ctx context.Context, w io.Writer, conf clusterConfig) erro lock.NodeSignatures = append(lock.NodeSignatures, nodeSig) } + proposerConfig, err := signProposerConfig(lock, def.FeeRecipientAddresses(), conf.ProposerConfigSeed, nodeKeys) + if err != nil { + return err + } + // dashboardURL is the Launchpad dashboard url for a given lock file. // If empty, either conf.Publish wasn't specified or there was a processing error in publishing // the generated lock file. @@ -367,6 +383,10 @@ func runCreateCluster(ctx context.Context, w io.Writer, conf clusterConfig) erro return err } + if err = writeProposerConfig(proposerConfig, lock, conf.ClusterDir); err != nil { + return err + } + if conf.Zipped { if err = app.BundleOutput(conf.ClusterDir, "cluster.tar.gz"); err != nil { return err @@ -718,6 +738,51 @@ func writeLock(lock cluster.Lock, clusterDir string, numNodes int) error { return nil } +// signProposerConfig returns the lock's revision 1 proposer config signed by every operator key. +func signProposerConfig(lock cluster.Lock, feeRecipients []string, seed proposerconfig.Seed, nodeKeys []*k1.PrivateKey) (proposerconfig.Document, error) { + cfg, err := proposerconfig.NewConfig(lock, feeRecipients, seed.GasLimit, seed.Builder()) + if err != nil { + return proposerconfig.Document{}, errors.Wrap(err, "proposer config") + } + + doc := proposerconfig.Document{ + Version: proposerconfig.Version, + LockHash: lock.LockHash, + Revision: 1, + Config: cfg, + } + + for i, key := range nodeKeys { + sig, err := proposerconfig.Sign(doc, key) + if err != nil { + return proposerconfig.Document{}, errors.Wrap(err, "sign proposer config", z.Int("operator", i)) + } + + doc.Signatures = append(doc.Signatures, proposerconfig.Signature{Operator: i, Signature: sig}) + } + + err = proposerconfig.Verify(doc, lock) + if err != nil { + return proposerconfig.Document{}, errors.Wrap(err, "verify signed proposer config") + } + + return doc, nil +} + +// writeProposerConfig writes the proposer config to every node's vc-config directory, keyed by its pubshares. +func writeProposerConfig(doc proposerconfig.Document, lock cluster.Lock, clusterDir string) error { + for i := range lock.Operators { + path := filepath.Join(nodeDir(clusterDir, i), "vc-config", "proposer-config.json") + + err := proposerconfig.Write(path, doc, lock, cluster.NodeIdx{PeerIdx: i, ShareIdx: i + 1}) + if err != nil { + return errors.Wrap(err, "write proposer config", z.Int("node", i)) + } + } + + return nil +} + // getValidators returns distributed validators from the provided dv public keys and keyshares. // It creates new peers from the provided config and saves validator keys to disk for each peer. func getValidators( @@ -1004,6 +1069,8 @@ func writeOutput(out io.Writer, splitKeys bool, clusterDir string, numNodes int, _, _ = sb.WriteString("│ ├─ charon-enr-private-key\tCharon networking private key for node authentication\n") _, _ = sb.WriteString("│ ├─ cluster-lock.json\t\tCluster lock defines the cluster lock file which is signed by all nodes\n") + _, _ = sb.WriteString("│ ├─ vc-config/proposer-config.json\tProposer config signed by all nodes, read by charon run and the validator clients\n") + _, _ = sb.WriteString("│ ├─ deposit-data-*.json\tDeposit data files are used to activate a Distributed Validator on the DV Launchpad\n") if keysToDisk { _, _ = sb.WriteString("│ ├─ validator_keys\t\tValidator keystores and password\n") diff --git a/cmd/createcluster_internal_test.go b/cmd/createcluster_internal_test.go index ebb8aded6f..10d3a753ec 100644 --- a/cmd/createcluster_internal_test.go +++ b/cmd/createcluster_internal_test.go @@ -25,6 +25,7 @@ import ( "github.com/obolnetwork/charon/app" "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/eth2util" "github.com/obolnetwork/charon/eth2util/deposit" "github.com/obolnetwork/charon/eth2util/keystore" @@ -337,7 +338,7 @@ func testCreateCluster(t *testing.T, conf clusterConfig, def cluster.Definition, var buf bytes.Buffer - err := runCreateCluster(context.Background(), &buf, conf) + err := createClusterT(context.Background(), &buf, conf) if err != nil { log.Error(context.Background(), "runCreateCluster error in test", err) } @@ -679,7 +680,7 @@ func TestCreateClusterInsecureKeys(t *testing.T) { SplitKeysDir: filepath.Join(t.TempDir(), "missing"), } - err := runCreateCluster(t.Context(), io.Discard, conf) + err := createClusterT(t.Context(), io.Discard, conf) require.ErrorContains(t, err, "insecure keys not supported") }) } @@ -754,7 +755,7 @@ func TestSplitKeys(t *testing.T) { var buf bytes.Buffer - err = runCreateCluster(context.Background(), &buf, test.conf) + err = createClusterT(context.Background(), &buf, test.conf) if test.expectedErrMsg != "" { require.ErrorContains(t, err, test.expectedErrMsg) } else { @@ -787,7 +788,7 @@ func TestSplitKeys(t *testing.T) { func TestMultipleAddresses(t *testing.T) { t.Run("insufficient fee recipient addresses", func(t *testing.T) { - err := runCreateCluster(context.Background(), io.Discard, clusterConfig{ + err := createClusterT(context.Background(), io.Discard, clusterConfig{ NumDVs: 4, NumNodes: 4, Threshold: 3, @@ -799,7 +800,7 @@ func TestMultipleAddresses(t *testing.T) { }) t.Run("insufficient withdrawal addresses", func(t *testing.T) { - err := runCreateCluster(context.Background(), io.Discard, clusterConfig{ + err := createClusterT(context.Background(), io.Discard, clusterConfig{ NumDVs: 1, NumNodes: 4, Threshold: 3, @@ -829,7 +830,7 @@ func TestMultipleAddresses(t *testing.T) { })) defer srv.Close() - err := runCreateCluster(context.Background(), io.Discard, clusterConfig{DefFile: srv.URL, NumNodes: minNodes, NumDVs: 2, Network: defaultNetwork}) + err := createClusterT(context.Background(), io.Discard, clusterConfig{DefFile: srv.URL, NumNodes: minNodes, NumDVs: 2, Network: defaultNetwork}) require.ErrorContains(t, err, "num_validators does not match validators length") }) } @@ -898,7 +899,7 @@ func TestTargetGasLimit(t *testing.T) { t.Run(test.name, func(t *testing.T) { var buf bytes.Buffer - err := runCreateCluster(context.Background(), &buf, test.conf) + err := createClusterT(context.Background(), &buf, test.conf) if test.expectedErrMsg != "" { require.ErrorContains(t, err, test.expectedErrMsg) } else { @@ -962,7 +963,7 @@ func TestDefinitionFileIsAuthoritative(t *testing.T) { TargetGasLimit: 60000000, Compounding: false, } - require.NoError(t, runCreateCluster(ctx, io.Discard, runConf)) + require.NoError(t, createClusterT(ctx, io.Discard, runConf)) b, err := os.ReadFile(path.Join(nodeDir(clusterDir, 0), "cluster-lock.json")) require.NoError(t, err) @@ -1063,7 +1064,7 @@ func TestKeymanager(t *testing.T) { // Run create cluster command var buf bytes.Buffer - err = runCreateCluster(context.Background(), &buf, conf) + err = createClusterT(context.Background(), &buf, conf) if err != nil { log.Error(context.Background(), "runCreateCluster error in TestKeymanager/all_successful", err) } @@ -1093,7 +1094,7 @@ func TestKeymanager(t *testing.T) { // Run create cluster command var buf bytes.Buffer - err = runCreateCluster(context.Background(), &buf, conf) + err = createClusterT(context.Background(), &buf, conf) if err != nil { log.Error(context.Background(), "runCreateCluster error in TestKeymanager/some_unsuccessful", err) } @@ -1108,7 +1109,7 @@ func TestKeymanager(t *testing.T) { incorrectConf := conf incorrectConf.KeymanagerAuthTokens = incorrectConf.KeymanagerAuthTokens[1:] - err = runCreateCluster(context.Background(), nil, incorrectConf) + err = createClusterT(context.Background(), nil, incorrectConf) require.ErrorContains(t, err, "number of --keymanager-addresses does not match number of --keymanager-auth-tokens") }) } @@ -1147,7 +1148,7 @@ func TestPublish(t *testing.T) { // Run create cluster command var buf bytes.Buffer - err := runCreateCluster(context.Background(), &buf, conf) + err := createClusterT(context.Background(), &buf, conf) if err != nil { log.Error(context.Background(), "runCreateCluster error in TestPublish/upload_successful", err) } @@ -1242,7 +1243,7 @@ func TestZipped(t *testing.T) { backupDir := t.TempDir() var buf bytes.Buffer - require.NoError(t, runCreateCluster(ctx, &buf, conf)) + require.NoError(t, createClusterT(ctx, &buf, conf)) // Backup cluster dir since bundleOutput is destructive require.NoError(t, os.CopyFS(backupDir, os.DirFS(conf.ClusterDir))) @@ -1348,3 +1349,86 @@ func newObolAPIHandler(ctx context.Context, t *testing.T, result chan<- struct{} func isAnyVersion(version string, versions ...string) bool { return slices.Contains(versions, version) } + +// defaultSeed is the default proposer config seed of charon create cluster. +var defaultSeed = proposerconfig.Seed{GasLimit: proposerconfig.DefaultGasLimit, BuilderBoostFactor: proposerconfig.DefaultBuilderBoostFactor} + +// createClusterT runs runCreateCluster with the CLI's default seed if conf has none. +func createClusterT(ctx context.Context, w io.Writer, conf clusterConfig) error { + if conf.ProposerConfigSeed.GasLimit == 0 && conf.ProposerConfigSeed.BuilderBoostFactor == 0 { + conf.ProposerConfigSeed = defaultSeed + } + + return runCreateCluster(ctx, w, conf) +} + +func TestCreateClusterZeroSeed(t *testing.T) { + dir := t.TempDir() + + err := runCreateCluster(context.Background(), io.Discard, clusterConfig{ + ClusterDir: dir, + NumNodes: 4, + Threshold: 3, + NumDVs: 1, + TargetGasLimit: 60_000_000, + Network: eth2util.Goerli.Name, + FeeRecipientAddrs: []string{feeRecipientAddr}, + WithdrawalAddrs: []string{feeRecipientAddr}, + }) + require.ErrorContains(t, err, "proposer-config-gas-limit must be greater than 0") + + entries, err := os.ReadDir(dir) + require.NoError(t, err) + require.Empty(t, entries) +} + +func TestCreateClusterProposerConfig(t *testing.T) { + dir := t.TempDir() + seed := proposerconfig.Seed{ + GasLimit: 60_000_000, + BuilderURLs: []string{"https://builder.example.com"}, + BuilderBoostFactor: 90, + } + + err := runCreateCluster(context.Background(), io.Discard, clusterConfig{ + ClusterDir: dir, + NumNodes: 4, + Threshold: 3, + NumDVs: 2, + TargetGasLimit: 60_000_000, + Network: eth2util.Goerli.Name, + FeeRecipientAddrs: []string{feeRecipientAddr}, + WithdrawalAddrs: []string{feeRecipientAddr}, + ProposerConfigSeed: seed, + }) + require.NoError(t, err) + + var lock cluster.Lock + + b, err := os.ReadFile(nodeDir(dir, 0) + "/cluster-lock.json") + require.NoError(t, err) + require.NoError(t, json.Unmarshal(b, &lock)) + + var hashes [][32]byte + + for i := range lock.Operators { + file := filepath.Join(nodeDir(dir, i), "vc-config", "proposer-config.json") + doc, err := proposerconfig.Load(file, lock, cluster.NodeIdx{PeerIdx: i, ShareIdx: i + 1}) + require.NoError(t, err) + require.NoError(t, proposerconfig.Verify(doc, lock)) + require.Equal(t, uint64(1), doc.Revision) + require.Len(t, doc.Signatures, len(lock.Operators)) + require.Equal(t, "60000000", doc.Config.DefaultConfig.GasLimit) + require.Equal(t, "https://builder.example.com", doc.Config.DefaultConfig.Builder.Builders[0].URL) + require.Equal(t, "90", doc.Config.DefaultConfig.Builder.BuilderBoostFactor) + + hash, err := doc.Hash() + require.NoError(t, err) + + hashes = append(hashes, hash) + } + + for _, h := range hashes { + require.Equal(t, hashes[0], h) + } +} diff --git a/cmd/dkg.go b/cmd/dkg.go index 5f89c2a2b5..ae58ff3feb 100644 --- a/cmd/dkg.go +++ b/cmd/dkg.go @@ -62,6 +62,7 @@ this command at the same time.`, bindPublishFlags(cmd.Flags(), &config) bindShutdownDelayFlag(cmd.Flags(), &config.ShutdownDelay) bindEth1Flag(cmd.Flags(), &config.ExecutionEngineAddr) + bindProposerConfigSeedFlags(cmd, &config.ProposerConfigSeed, proposerConfigSignedUsage) cmd.Flags().DurationVar(&config.Timeout, "timeout", defaultDKGTimeout, "Timeout for the DKG process, should be increased if DKG times out.") cmd.Flags().BoolVar(&config.Zipped, "zipped", false, "Create a tar archive compressed with gzip of the target directory after creation.") diff --git a/cmd/edit.go b/cmd/edit.go index 52f27636c5..6ebfad9faf 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -3,7 +3,12 @@ package cmd import ( + "context" + "path/filepath" + "github.com/spf13/cobra" + + "github.com/obolnetwork/charon/app/log" ) func newEditCmd(cmds ...*cobra.Command) *cobra.Command { @@ -17,3 +22,10 @@ func newEditCmd(cmds ...*cobra.Command) *cobra.Command { return root } + +// logProposerConfigOutput tells the operator the proposer config re-signed for the new lock replaces the current one. +func logProposerConfigOutput(ctx context.Context, outputDir string) { + path := filepath.Join(outputDir, "vc-config", "proposer-config.json") + + log.Info(ctx, "The proposer config was re-signed for the new lock: "+path+", it replaces your current vc-config/proposer-config.json") +} diff --git a/cmd/edit_addoperators_internal_test.go b/cmd/edit_addoperators_internal_test.go index ac13a47564..e3422ef7e9 100644 --- a/cmd/edit_addoperators_internal_test.go +++ b/cmd/edit_addoperators_internal_test.go @@ -38,7 +38,7 @@ func TestValidateAddOperatorsConfig(t *testing.T) { var buf bytes.Buffer - err := runCreateCluster(t.Context(), &buf, conf) + err := createClusterT(t.Context(), &buf, conf) require.NoError(t, err) lock, err := dkg.LoadAndVerifyClusterLock(t.Context(), path.Join(nodeDir(srcDir, 0), clusterLockFile), "", true) diff --git a/cmd/edit_addvalidators.go b/cmd/edit_addvalidators.go index 145dd49045..18a595855e 100644 --- a/cmd/edit_addvalidators.go +++ b/cmd/edit_addvalidators.go @@ -40,6 +40,9 @@ type addValidatorsConfig struct { DKG dkg.Config WithdrawalAddrs []string FeeRecipientAddrs []string + + ProposerConfigFile string + OverridesFile string } func newAddValidatorsCmd(runFunc func(context.Context, addValidatorsConfig) error) *cobra.Command { @@ -67,6 +70,8 @@ func newAddValidatorsCmd(runFunc func(context.Context, addValidatorsConfig) erro cmd.Flags().StringVar(&config.LockFilePath, "lock-file", ".charon/cluster-lock.json", "The path to the cluster lock file defining the distributed validator cluster.") cmd.Flags().StringVar(&config.ValidatorKeysDir, "validator-keys-dir", ".charon/validator_keys", "Path to the directory containing the validator private key share files and passwords.") cmd.Flags().StringVar(&config.OutputDir, "output-dir", "distributed_validator", "The destination folder for the new (combined) cluster data. Must be empty.") + cmd.Flags().StringVar(&config.ProposerConfigFile, "proposer-config-file", ".charon/vc-config/proposer-config.json", "The path to the current proposer config file, its content is carried over into the new cluster's signed one.") + cmd.Flags().StringVar(&config.OverridesFile, "overrides-file", ".charon/builder_registrations_overrides.json", "The path to the builder registration overrides file, used for the fee recipients if the proposer config file is absent.") cmd.Flags().BoolVar(&config.Unverified, "unverified", false, "If charon has no access to the existing validator keys, this flag allows the addition to proceed, but skips hashing and signing the new cluster lock data. Requires the --keymanager-address flag to import the new validator key shares. charon run must be started with --no-verify flag.") @@ -173,6 +178,8 @@ func runAddValidators(ctx context.Context, conf addValidatorsConfig) error { Unverified: conf.Unverified, ValidatorAddresses: valAddresses, DepositData: depositData, + ProposerConfigFile: conf.ProposerConfigFile, + OverridesFile: conf.OverridesFile, } if err := dkg.Run(ctx, dkgConfig); err != nil { @@ -183,6 +190,7 @@ func runAddValidators(ctx context.Context, conf addValidatorsConfig) error { log.Info(ctx, "IMPORTANT:") log.Info(ctx, "You need to shut down your node (charon and VC) and restart it with the new data directory: "+conf.OutputDir) + logProposerConfigOutput(ctx, conf.OutputDir) if conf.Unverified { log.Info(ctx, "Because you used --unverified flag, the new cluster cannot pass signatures verification.") diff --git a/cmd/edit_addvalidators_internal_test.go b/cmd/edit_addvalidators_internal_test.go index 96ac377629..9681c1128b 100644 --- a/cmd/edit_addvalidators_internal_test.go +++ b/cmd/edit_addvalidators_internal_test.go @@ -25,6 +25,7 @@ import ( "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/app/z" "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/dkg" "github.com/obolnetwork/charon/eth2util" "github.com/obolnetwork/charon/eth2util/deposit" @@ -46,20 +47,21 @@ func TestRunAddValidators(t *testing.T) { // Then it runs add-validators on each node in parallel to add 2 validators per node. // Two sub-tests are run: with the `--unverified` flag and without. conf := clusterConfig{ - ClusterDir: t.TempDir(), - Name: t.Name(), - NumNodes: 4, - Threshold: 3, - NumDVs: 3, - Network: eth2util.Hoodi.Name, - TargetGasLimit: 36000000, - FeeRecipientAddrs: []string{feeRecipientAddr, feeRecipientAddr, feeRecipientAddr}, - WithdrawalAddrs: []string{feeRecipientAddr, feeRecipientAddr, feeRecipientAddr}, + ProposerConfigSeed: defaultSeed, + ClusterDir: t.TempDir(), + Name: t.Name(), + NumNodes: 4, + Threshold: 3, + NumDVs: 3, + Network: eth2util.Hoodi.Name, + TargetGasLimit: 36000000, + FeeRecipientAddrs: []string{feeRecipientAddr, feeRecipientAddr, feeRecipientAddr}, + WithdrawalAddrs: []string{feeRecipientAddr, feeRecipientAddr, feeRecipientAddr}, } var buf bytes.Buffer - err := runCreateCluster(t.Context(), &buf, conf) + err := createClusterT(t.Context(), &buf, conf) require.NoError(t, err) entries, err := os.ReadDir(conf.ClusterDir) @@ -101,6 +103,9 @@ func TestRunAddValidators(t *testing.T) { WithdrawalAddrs: []string{feeRecipientAddr, feeRecipientAddr}, FeeRecipientAddrs: []string{feeRecipientAddr, feeRecipientAddr}, Unverified: unverified, + // Neither exists: the carried config is the initial config from the lock. + ProposerConfigFile: filepath.Join(ddir, "vc-config", "proposer-config.json"), + OverridesFile: filepath.Join(ddir, "builder_registrations_overrides.json"), DKG: dkg.Config{ P2P: p2p.Config{ Relays: []string{relayAddr}, @@ -183,6 +188,19 @@ func TestRunAddValidators(t *testing.T) { require.Len(t, dd, 2) // two default amounts: 1eth and 32eth require.Len(t, dd[0], lock.NumValidators) require.Len(t, dd[1], lock.NumValidators) + + // The proposer config is signed at revision 1 for the new lock, with --unverified too. + doc, err := proposerconfig.Load(filepath.Join(nd, "vc-config", "proposer-config.json"), lock, cluster.NodeIdx{PeerIdx: n, ShareIdx: n + 1}) + require.NoError(t, err) + require.NoError(t, proposerconfig.Verify(doc, lock)) + require.EqualValues(t, 1, doc.Revision) + require.Len(t, doc.Signatures, conf.NumNodes) + require.Equal(t, "200000000", doc.Config.DefaultConfig.GasLimit) + require.Nil(t, doc.Config.DefaultConfig.Builder) + + for _, fee := range doc.Config.FeeRecipients(lock) { + require.Equal(t, strings.ToLower(feeRecipientAddr), fee) + } } } @@ -201,15 +219,16 @@ func TestRunAddValidators(t *testing.T) { func TestRunAddValidatorsInvalidLock(t *testing.T) { conf := clusterConfig{ - ClusterDir: t.TempDir(), - Name: "test_cluster", - NumNodes: 4, - Threshold: 3, - NumDVs: 3, - Network: eth2util.Hoodi.Name, - TargetGasLimit: 36000000, - FeeRecipientAddrs: []string{feeRecipientAddr, feeRecipientAddr, feeRecipientAddr}, - WithdrawalAddrs: []string{feeRecipientAddr, feeRecipientAddr, feeRecipientAddr}, + ProposerConfigSeed: defaultSeed, + ClusterDir: t.TempDir(), + Name: "test_cluster", + NumNodes: 4, + Threshold: 3, + NumDVs: 3, + Network: eth2util.Hoodi.Name, + TargetGasLimit: 36000000, + FeeRecipientAddrs: []string{feeRecipientAddr, feeRecipientAddr, feeRecipientAddr}, + WithdrawalAddrs: []string{feeRecipientAddr, feeRecipientAddr, feeRecipientAddr}, } var ( @@ -217,7 +236,7 @@ func TestRunAddValidatorsInvalidLock(t *testing.T) { dstDir = t.TempDir() ) - err := runCreateCluster(t.Context(), &buf, conf) + err := createClusterT(t.Context(), &buf, conf) require.NoError(t, err) ddir := nodeDir(conf.ClusterDir, 0) @@ -440,20 +459,21 @@ func mustLoadTestLockFile(t *testing.T, path string) cluster.Lock { func TestRunAddValidatorsAddressValidation(t *testing.T) { conf := clusterConfig{ - ClusterDir: t.TempDir(), - Name: "test_cluster", - NumNodes: 4, - Threshold: 3, - NumDVs: 1, - Network: eth2util.Mainnet.Name, - TargetGasLimit: 36000000, - FeeRecipientAddrs: []string{validEthAddr}, - WithdrawalAddrs: []string{validEthAddr}, + ProposerConfigSeed: defaultSeed, + ClusterDir: t.TempDir(), + Name: "test_cluster", + NumNodes: 4, + Threshold: 3, + NumDVs: 1, + Network: eth2util.Mainnet.Name, + TargetGasLimit: 36000000, + FeeRecipientAddrs: []string{validEthAddr}, + WithdrawalAddrs: []string{validEthAddr}, } var buf bytes.Buffer - require.NoError(t, runCreateCluster(t.Context(), &buf, conf)) + require.NoError(t, createClusterT(t.Context(), &buf, conf)) ddir := nodeDir(conf.ClusterDir, 0) badChecksum := "0xFB6916095ca1df60bB79Ce92cE3Ea74c37c5d359" diff --git a/cmd/edit_removeoperators_internal_test.go b/cmd/edit_removeoperators_internal_test.go index fe18a60d90..3c2e155ecb 100644 --- a/cmd/edit_removeoperators_internal_test.go +++ b/cmd/edit_removeoperators_internal_test.go @@ -38,7 +38,7 @@ func TestValidateRemoveOperatorsConfig(t *testing.T) { var buf bytes.Buffer - err := runCreateCluster(t.Context(), &buf, conf) + err := createClusterT(t.Context(), &buf, conf) require.NoError(t, err) lock, err := dkg.LoadAndVerifyClusterLock(t.Context(), path.Join(nodeDir(srcDir, 0), clusterLockFile), "", true) diff --git a/cmd/edit_replaceoperator_internal_test.go b/cmd/edit_replaceoperator_internal_test.go index ee1d55d90a..dc5636145c 100644 --- a/cmd/edit_replaceoperator_internal_test.go +++ b/cmd/edit_replaceoperator_internal_test.go @@ -38,7 +38,7 @@ func TestValidateReplaceOperatorConfig(t *testing.T) { var buf bytes.Buffer - err := runCreateCluster(t.Context(), &buf, conf) + err := createClusterT(t.Context(), &buf, conf) require.NoError(t, err) lock, err := dkg.LoadAndVerifyClusterLock(t.Context(), path.Join(nodeDir(srcDir, 0), clusterLockFile), "", true) diff --git a/cmd/run.go b/cmd/run.go index 89b64aab4b..d705c8b76f 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -51,7 +51,7 @@ func newRunCmd(runFunc func(context.Context, app.Config) error, unsafe bool) *co bindPrivKeyFlag(cmd, &conf.PrivKeyFile, &conf.PrivKeyLocking) bindRunFlags(cmd, &conf) - bindProposerConfigSeedFlags(cmd, &conf.ProposerConfigSeed) + bindProposerConfigSeedFlags(cmd, &conf.ProposerConfigSeed, proposerConfigSeedUsage) bindDebugMonitoringFlags(cmd, &conf.MonitoringAddr, &conf.DebugAddr, "127.0.0.1:3620") bindNoVerifyFlag(cmd.Flags(), &conf.NoVerify) bindP2PFlags(cmd, &conf.P2P) @@ -172,8 +172,15 @@ func bindPrivKeyFlag(cmd *cobra.Command, privKeyFile *string, privkeyLockEnabled cmd.Flags().BoolVar(privkeyLockEnabled, "private-key-file-lock", false, "Enables private key locking to prevent multiple instances using the same key.") } -// bindProposerConfigSeedFlags binds the flags seeding an unsigned (revision 0) proposer config file. -func bindProposerConfigSeedFlags(cmd *cobra.Command, seed *proposerconfig.Seed) { +const ( + // proposerConfigSeedUsage ends the seeding flags' usage on charon run, which writes an unsigned file. + proposerConfigSeedUsage = "Seeds a new proposer config file only, disregarded once the cluster has a signed one. Must be identical on all nodes in the cluster." + // proposerConfigSignedUsage ends the seeding flags' usage on the commands signing the initial file. + proposerConfigSignedUsage = "Signed into the cluster's initial proposer config, must be identical on all operators. Change it later with charon alpha edit proposer-config." +) + +// bindProposerConfigSeedFlags binds the flags seeding the initial proposer config; note ends each usage. +func bindProposerConfigSeedFlags(cmd *cobra.Command, seed *proposerconfig.Seed, note string) { // seedFlag records the flag name for the PreRunE below. var names []string @@ -182,13 +189,11 @@ func bindProposerConfigSeedFlags(cmd *cobra.Command, seed *proposerconfig.Seed) return name } - const seedOnly = "Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster." - - cmd.Flags().Uint64Var(&seed.GasLimit, seedFlag("proposer-config-gas-limit"), proposerconfig.DefaultGasLimit, "Preferred target gas limit for proposed execution payloads from the gloas fork onwards. "+seedOnly) - cmd.Flags().StringSliceVar(&seed.BuilderURLs, seedFlag("proposer-config-builder-urls"), nil, "Comma separated list of builder API URLs to request execution payload bids from directly, from the gloas fork onwards. "+seedOnly) - cmd.Flags().Uint64Var(&seed.BuilderMinBid, seedFlag("proposer-config-builder-min-bid"), 0, "Minimum builder bid value in gwei, bids below it lose to the locally built payload. Requires proposer-config-builder-urls. "+seedOnly) - cmd.Flags().Uint64Var(&seed.BuilderBoostFactor, seedFlag("proposer-config-builder-boost-factor"), proposerconfig.DefaultBuilderBoostFactor, "Percentage multiplier applied to builder bid values when comparing them to the locally built payload. Requires proposer-config-builder-urls. "+seedOnly) - cmd.Flags().Uint64Var(&seed.BuilderMaxExecutionPayment, seedFlag("proposer-config-builder-max-execution-payment"), 0, "Maximum execution layer payment in gwei counted when valuing a builder bid, 0 counts no execution payment (trustless bids only). Requires proposer-config-builder-urls. "+seedOnly) + cmd.Flags().Uint64Var(&seed.GasLimit, seedFlag("proposer-config-gas-limit"), proposerconfig.DefaultGasLimit, "Preferred target gas limit for proposed execution payloads from the gloas fork onwards. "+note) + cmd.Flags().StringSliceVar(&seed.BuilderURLs, seedFlag("proposer-config-builder-urls"), nil, "Comma separated list of builder API URLs to request execution payload bids from directly, from the gloas fork onwards. "+note) + cmd.Flags().Uint64Var(&seed.BuilderMinBid, seedFlag("proposer-config-builder-min-bid"), 0, "Minimum builder bid value in gwei, bids below it lose to the locally built payload. Requires proposer-config-builder-urls. "+note) + cmd.Flags().Uint64Var(&seed.BuilderBoostFactor, seedFlag("proposer-config-builder-boost-factor"), proposerconfig.DefaultBuilderBoostFactor, "Percentage multiplier applied to builder bid values when comparing them to the locally built payload. Requires proposer-config-builder-urls. "+note) + cmd.Flags().Uint64Var(&seed.BuilderMaxExecutionPayment, seedFlag("proposer-config-builder-max-execution-payment"), 0, "Maximum execution layer payment in gwei counted when valuing a builder bid, 0 counts no execution payment (trustless bids only). Requires proposer-config-builder-urls. "+note) wrapPreRunE(cmd, func(cc *cobra.Command, _ []string) error { seed.NonDefault = nil diff --git a/cmd/testdata/TestCreateCluster_custom_target_gas_limit_files.golden b/cmd/testdata/TestCreateCluster_custom_target_gas_limit_files.golden index 9dc10f1038..113a0c83e6 100644 --- a/cmd/testdata/TestCreateCluster_custom_target_gas_limit_files.golden +++ b/cmd/testdata/TestCreateCluster_custom_target_gas_limit_files.golden @@ -8,19 +8,23 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-1eth.json", "node3/deposit-data.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_custom_target_gas_limit_output.golden b/cmd/testdata/TestCreateCluster_custom_target_gas_limit_output.golden index da2d5e3d24..4e04f22d87 100644 --- a/cmd/testdata/TestCreateCluster_custom_target_gas_limit_output.golden +++ b/cmd/testdata/TestCreateCluster_custom_target_gas_limit_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_custom_testnet_flags_files.golden b/cmd/testdata/TestCreateCluster_custom_testnet_flags_files.golden index 9dc10f1038..113a0c83e6 100644 --- a/cmd/testdata/TestCreateCluster_custom_testnet_flags_files.golden +++ b/cmd/testdata/TestCreateCluster_custom_testnet_flags_files.golden @@ -8,19 +8,23 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-1eth.json", "node3/deposit-data.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_custom_testnet_flags_output.golden b/cmd/testdata/TestCreateCluster_custom_testnet_flags_output.golden index da2d5e3d24..4e04f22d87 100644 --- a/cmd/testdata/TestCreateCluster_custom_testnet_flags_output.golden +++ b/cmd/testdata/TestCreateCluster_custom_testnet_flags_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_four_partial_deposits_files.golden b/cmd/testdata/TestCreateCluster_four_partial_deposits_files.golden index f53d1513c6..45655d20af 100644 --- a/cmd/testdata/TestCreateCluster_four_partial_deposits_files.golden +++ b/cmd/testdata/TestCreateCluster_four_partial_deposits_files.golden @@ -7,16 +7,20 @@ "node0/cluster-lock.json", "node0/deposit-data-8eth.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-8eth.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-8eth.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-8eth.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_four_partial_deposits_output.golden b/cmd/testdata/TestCreateCluster_four_partial_deposits_output.golden index da2d5e3d24..4e04f22d87 100644 --- a/cmd/testdata/TestCreateCluster_four_partial_deposits_output.golden +++ b/cmd/testdata/TestCreateCluster_four_partial_deposits_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_goerli_files.golden b/cmd/testdata/TestCreateCluster_goerli_files.golden index 2caa6c3e6b..ca0a497024 100644 --- a/cmd/testdata/TestCreateCluster_goerli_files.golden +++ b/cmd/testdata/TestCreateCluster_goerli_files.golden @@ -7,14 +7,17 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", - "node2/validator_keys" + "node2/validator_keys", + "node2/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_goerli_output.golden b/cmd/testdata/TestCreateCluster_goerli_output.golden index d337e2b595..d8448415ae 100644 --- a/cmd/testdata/TestCreateCluster_goerli_output.golden +++ b/cmd/testdata/TestCreateCluster_goerli_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-2]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_simnet_files.golden b/cmd/testdata/TestCreateCluster_simnet_files.golden index 9dc10f1038..113a0c83e6 100644 --- a/cmd/testdata/TestCreateCluster_simnet_files.golden +++ b/cmd/testdata/TestCreateCluster_simnet_files.golden @@ -8,19 +8,23 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-1eth.json", "node3/deposit-data.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_simnet_output.golden b/cmd/testdata/TestCreateCluster_simnet_output.golden index da2d5e3d24..4e04f22d87 100644 --- a/cmd/testdata/TestCreateCluster_simnet_output.golden +++ b/cmd/testdata/TestCreateCluster_simnet_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_solo_flow_definition_from_disk_files.golden b/cmd/testdata/TestCreateCluster_solo_flow_definition_from_disk_files.golden index 9dc10f1038..113a0c83e6 100644 --- a/cmd/testdata/TestCreateCluster_solo_flow_definition_from_disk_files.golden +++ b/cmd/testdata/TestCreateCluster_solo_flow_definition_from_disk_files.golden @@ -8,19 +8,23 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-1eth.json", "node3/deposit-data.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_solo_flow_definition_from_disk_output.golden b/cmd/testdata/TestCreateCluster_solo_flow_definition_from_disk_output.golden index da2d5e3d24..4e04f22d87 100644 --- a/cmd/testdata/TestCreateCluster_solo_flow_definition_from_disk_output.golden +++ b/cmd/testdata/TestCreateCluster_solo_flow_definition_from_disk_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_solo_flow_definition_from_network_files.golden b/cmd/testdata/TestCreateCluster_solo_flow_definition_from_network_files.golden index 9dc10f1038..113a0c83e6 100644 --- a/cmd/testdata/TestCreateCluster_solo_flow_definition_from_network_files.golden +++ b/cmd/testdata/TestCreateCluster_solo_flow_definition_from_network_files.golden @@ -8,19 +8,23 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-1eth.json", "node3/deposit-data.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_solo_flow_definition_from_network_output.golden b/cmd/testdata/TestCreateCluster_solo_flow_definition_from_network_output.golden index da2d5e3d24..4e04f22d87 100644 --- a/cmd/testdata/TestCreateCluster_solo_flow_definition_from_network_output.golden +++ b/cmd/testdata/TestCreateCluster_solo_flow_definition_from_network_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_splitkeys_files.golden b/cmd/testdata/TestCreateCluster_splitkeys_files.golden index 9dc10f1038..113a0c83e6 100644 --- a/cmd/testdata/TestCreateCluster_splitkeys_files.golden +++ b/cmd/testdata/TestCreateCluster_splitkeys_files.golden @@ -8,19 +8,23 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-1eth.json", "node3/deposit-data.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_splitkeys_output.golden b/cmd/testdata/TestCreateCluster_splitkeys_output.golden index 8e51f80a04..3f28d446d5 100644 --- a/cmd/testdata/TestCreateCluster_splitkeys_output.golden +++ b/cmd/testdata/TestCreateCluster_splitkeys_output.golden @@ -12,6 +12,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_splitkeys_with_cluster_definition_files.golden b/cmd/testdata/TestCreateCluster_splitkeys_with_cluster_definition_files.golden index 9dc10f1038..113a0c83e6 100644 --- a/cmd/testdata/TestCreateCluster_splitkeys_with_cluster_definition_files.golden +++ b/cmd/testdata/TestCreateCluster_splitkeys_with_cluster_definition_files.golden @@ -8,19 +8,23 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-1eth.json", "node3/deposit-data.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_splitkeys_with_cluster_definition_output.golden b/cmd/testdata/TestCreateCluster_splitkeys_with_cluster_definition_output.golden index 8e51f80a04..3f28d446d5 100644 --- a/cmd/testdata/TestCreateCluster_splitkeys_with_cluster_definition_output.golden +++ b/cmd/testdata/TestCreateCluster_splitkeys_with_cluster_definition_output.golden @@ -12,6 +12,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_test_with_fee_recipient_and_withdrawal_addresses_files.golden b/cmd/testdata/TestCreateCluster_test_with_fee_recipient_and_withdrawal_addresses_files.golden index 2caa6c3e6b..ca0a497024 100644 --- a/cmd/testdata/TestCreateCluster_test_with_fee_recipient_and_withdrawal_addresses_files.golden +++ b/cmd/testdata/TestCreateCluster_test_with_fee_recipient_and_withdrawal_addresses_files.golden @@ -7,14 +7,17 @@ "node0/deposit-data-1eth.json", "node0/deposit-data.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data.json", - "node2/validator_keys" + "node2/validator_keys", + "node2/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_test_with_fee_recipient_and_withdrawal_addresses_output.golden b/cmd/testdata/TestCreateCluster_test_with_fee_recipient_and_withdrawal_addresses_output.golden index d337e2b595..d8448415ae 100644 --- a/cmd/testdata/TestCreateCluster_test_with_fee_recipient_and_withdrawal_addresses_output.golden +++ b/cmd/testdata/TestCreateCluster_test_with_fee_recipient_and_withdrawal_addresses_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-2]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/cmd/testdata/TestCreateCluster_two_partial_deposits_files.golden b/cmd/testdata/TestCreateCluster_two_partial_deposits_files.golden index 181e3b4dd7..659e52c021 100644 --- a/cmd/testdata/TestCreateCluster_two_partial_deposits_files.golden +++ b/cmd/testdata/TestCreateCluster_two_partial_deposits_files.golden @@ -8,19 +8,23 @@ "node0/deposit-data-1eth.json", "node0/deposit-data-31eth.json", "node0/validator_keys", + "node0/vc-config", "node1/charon-enr-private-key", "node1/cluster-lock.json", "node1/deposit-data-1eth.json", "node1/deposit-data-31eth.json", "node1/validator_keys", + "node1/vc-config", "node2/charon-enr-private-key", "node2/cluster-lock.json", "node2/deposit-data-1eth.json", "node2/deposit-data-31eth.json", "node2/validator_keys", + "node2/vc-config", "node3/charon-enr-private-key", "node3/cluster-lock.json", "node3/deposit-data-1eth.json", "node3/deposit-data-31eth.json", - "node3/validator_keys" + "node3/validator_keys", + "node3/vc-config" ] \ No newline at end of file diff --git a/cmd/testdata/TestCreateCluster_two_partial_deposits_output.golden b/cmd/testdata/TestCreateCluster_two_partial_deposits_output.golden index da2d5e3d24..4e04f22d87 100644 --- a/cmd/testdata/TestCreateCluster_two_partial_deposits_output.golden +++ b/cmd/testdata/TestCreateCluster_two_partial_deposits_output.golden @@ -5,6 +5,7 @@ charon/ ├─ node[0-3]/ Directory for each node │ ├─ charon-enr-private-key Charon networking private key for node authentication │ ├─ cluster-lock.json Cluster lock defines the cluster lock file which is signed by all nodes +│ ├─ vc-config/proposer-config.json Proposer config signed by all nodes, read by charon run and the validator clients │ ├─ deposit-data-*.json Deposit data files are used to activate a Distributed Validator on the DV Launchpad │ ├─ validator_keys Validator keystores and password │ │ ├─ keystore-*.json Validator private share key for duty signing diff --git a/docs/configuration.md b/docs/configuration.md index 23078fc3dc..6e4d2edfbe 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -200,12 +200,12 @@ Flags: --private-key-file string The path to the charon enr private key file. (default ".charon/charon-enr-private-key") --private-key-file-lock Enables private key locking to prevent multiple instances using the same key. --proc-directory string Directory to look into in order to detect other stack components running on the host. Enabling this exports the command lines of detected validator clients to the monitoring endpoint and debug logs, with the values of secret-shaped flags redacted. - --proposer-config-builder-boost-factor uint Percentage multiplier applied to builder bid values when comparing them to the locally built payload. Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. (default 100) - --proposer-config-builder-max-execution-payment uint Maximum execution layer payment in gwei counted when valuing a builder bid, 0 counts no execution payment (trustless bids only). Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. - --proposer-config-builder-min-bid uint Minimum builder bid value in gwei, bids below it lose to the locally built payload. Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. - --proposer-config-builder-urls strings Comma separated list of builder API URLs to request execution payload bids from directly, from the gloas fork onwards. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. + --proposer-config-builder-boost-factor uint Percentage multiplier applied to builder bid values when comparing them to the locally built payload. Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster has a signed one. Must be identical on all nodes in the cluster. (default 100) + --proposer-config-builder-max-execution-payment uint Maximum execution layer payment in gwei counted when valuing a builder bid, 0 counts no execution payment (trustless bids only). Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster has a signed one. Must be identical on all nodes in the cluster. + --proposer-config-builder-min-bid uint Minimum builder bid value in gwei, bids below it lose to the locally built payload. Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster has a signed one. Must be identical on all nodes in the cluster. + --proposer-config-builder-urls strings Comma separated list of builder API URLs to request execution payload bids from directly, from the gloas fork onwards. Seeds a new proposer config file only, disregarded once the cluster has a signed one. Must be identical on all nodes in the cluster. --proposer-config-file string The path to the validator client proposer config file. Written from the cluster lock and the proposer-config seeding flags if absent, verified on start and reloaded when it changes otherwise. (default ".charon/vc-config/proposer-config.json") - --proposer-config-gas-limit uint Preferred target gas limit for proposed execution payloads from the gloas fork onwards. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. (default 200000000) + --proposer-config-gas-limit uint Preferred target gas limit for proposed execution payloads from the gloas fork onwards. Seeds a new proposer config file only, disregarded once the cluster has a signed one. Must be identical on all nodes in the cluster. (default 200000000) --publish-address string The URL of the remote API for background fee recipient fetching. (default "https://api.obol.tech/v1") --publish-timeout duration Timeout for accessing the remote API. (default 5m0s) --simnet-beacon-mock Enables an internal mock beacon node for running a simnet.