From 23994518690870ede7d131212604561438126cd9 Mon Sep 17 00:00:00 2001 From: Md Amaan <114795592+Redidacove@users.noreply.github.com> Date: Mon, 26 Aug 2024 22:20:29 +0530 Subject: [PATCH] Hardcoded GenesisValidatorsRoot (#14365) * hardcoded GenesisValidatorsRoot * added in mainnet.config * updated desc * added it in all testnets * minor change * added roots instead of empty and fn to compute byte32 from hex * added in e2e testnet_config * fixed test * minor fix * removed fn and added bytes output directly * Add test for genesis validator root mainnet value * removed root from minimal and testnet * removed root * Update CHANGELOG.md * Fix bazel package visiblity --------- Co-authored-by: Preston Van Loon Co-authored-by: Preston Van Loon --- CHANGELOG.md | 1 + beacon-chain/state/genesis/BUILD.bazel | 5 ++++- config/params/BUILD.bazel | 1 + config/params/config.go | 1 + config/params/config_test.go | 13 +++++++++++++ config/params/mainnet_config.go | 1 + config/params/testnet_holesky_config.go | 1 + config/params/testnet_sepolia_config.go | 1 + 8 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2329b9765a..939bfbd523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve - Electra: Add electra objects to beacon API. - Electra: Updated block publishing beacon APIs to support Electra. - "Submitted builder validator registration settings for custom builders" log message moved to debug level. +- config: Genesis validator root is now hardcoded in params.BeaconConfig() ### Deprecated diff --git a/beacon-chain/state/genesis/BUILD.bazel b/beacon-chain/state/genesis/BUILD.bazel index 41948e5b64..2c5a225e98 100644 --- a/beacon-chain/state/genesis/BUILD.bazel +++ b/beacon-chain/state/genesis/BUILD.bazel @@ -8,7 +8,10 @@ go_library( ], embedsrcs = ["mainnet.ssz.snappy"], importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/genesis", - visibility = ["//beacon-chain/db:__subpackages__"], + visibility = [ + "//beacon-chain/db:__subpackages__", + "//config/params:__pkg__", + ], deps = [ "//beacon-chain/state:go_default_library", "//beacon-chain/state/state-native:go_default_library", diff --git a/config/params/BUILD.bazel b/config/params/BUILD.bazel index e97f4d1f9f..35660c89b9 100644 --- a/config/params/BUILD.bazel +++ b/config/params/BUILD.bazel @@ -62,6 +62,7 @@ go_test( gotags = ["develop"], tags = ["CI_race_detection"], deps = [ + "//beacon-chain/state/genesis:go_default_library", "//consensus-types/primitives:go_default_library", "//encoding/bytesutil:go_default_library", "//io/file:go_default_library", diff --git a/config/params/config.go b/config/params/config.go index 69f7193df1..5f9e37f0df 100644 --- a/config/params/config.go +++ b/config/params/config.go @@ -128,6 +128,7 @@ type BeaconChainConfig struct { DomainConsolidation [4]byte `yaml:"DOMAIN_CONSOLIDATION" spec:"true"` // Prysm constants. + GenesisValidatorsRoot [32]byte // GenesisValidatorsRoot is the root hash of the genesis validators. GweiPerEth uint64 // GweiPerEth is the amount of gwei corresponding to 1 eth. BLSSecretKeyLength int // BLSSecretKeyLength defines the expected length of BLS secret keys in bytes. BLSPubkeyLength int // BLSPubkeyLength defines the expected length of BLS public keys in bytes. diff --git a/config/params/config_test.go b/config/params/config_test.go index 52cb4b23e5..6e29127f0a 100644 --- a/config/params/config_test.go +++ b/config/params/config_test.go @@ -1,9 +1,11 @@ package params_test import ( + "bytes" "sync" "testing" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/genesis" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/testing/require" @@ -92,3 +94,14 @@ func TestConfig_WithinDAPeriod(t *testing.T) { }) } } + +func TestConfigGenesisValidatorRoot(t *testing.T) { + g, err := genesis.State(params.MainnetName) + require.NoError(t, err) + + gvr := g.GenesisValidatorsRoot() + + if !bytes.Equal(gvr, params.BeaconConfig().GenesisValidatorsRoot[:]) { + t.Fatal("mainnet params genesis validator root does not match the mainnet genesis state value") + } +} diff --git a/config/params/mainnet_config.go b/config/params/mainnet_config.go index 1131c9823b..334aec572c 100644 --- a/config/params/mainnet_config.go +++ b/config/params/mainnet_config.go @@ -174,6 +174,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{ DomainConsolidation: bytesutil.Uint32ToBytes4(0x0B000000), // Prysm constants. + GenesisValidatorsRoot: [32]byte{75, 54, 61, 185, 78, 40, 97, 32, 215, 110, 185, 5, 52, 15, 221, 78, 84, 191, 233, 240, 107, 243, 63, 246, 207, 90, 210, 127, 81, 27, 254, 149}, GweiPerEth: 1000000000, BLSSecretKeyLength: 32, BLSPubkeyLength: 48, diff --git a/config/params/testnet_holesky_config.go b/config/params/testnet_holesky_config.go index 66bf9bd23f..03cefd8988 100644 --- a/config/params/testnet_holesky_config.go +++ b/config/params/testnet_holesky_config.go @@ -26,6 +26,7 @@ func HoleskyConfig() *BeaconChainConfig { cfg.MinGenesisTime = 1695902100 cfg.GenesisDelay = 300 cfg.ConfigName = HoleskyName + cfg.GenesisValidatorsRoot = [32]byte{145, 67, 170, 124, 97, 90, 127, 113, 21, 226, 182, 170, 195, 25, 192, 53, 41, 223, 130, 66, 174, 112, 95, 186, 157, 243, 155, 121, 197, 159, 168, 177} cfg.GenesisForkVersion = []byte{0x01, 0x01, 0x70, 0x00} cfg.SecondsPerETH1Block = 14 cfg.DepositChainID = 17000 diff --git a/config/params/testnet_sepolia_config.go b/config/params/testnet_sepolia_config.go index 0df3e1e51d..353c874be7 100644 --- a/config/params/testnet_sepolia_config.go +++ b/config/params/testnet_sepolia_config.go @@ -26,6 +26,7 @@ func SepoliaConfig() *BeaconChainConfig { cfg.MinGenesisTime = 1655647200 cfg.GenesisDelay = 86400 cfg.MinGenesisActiveValidatorCount = 1300 + cfg.GenesisValidatorsRoot = [32]byte{216, 234, 23, 31, 60, 148, 174, 162, 30, 188, 66, 161, 237, 97, 5, 42, 207, 63, 146, 9, 192, 14, 78, 251, 170, 221, 172, 9, 237, 155, 128, 120} cfg.ConfigName = SepoliaName cfg.GenesisForkVersion = []byte{0x90, 0x00, 0x00, 0x69} cfg.SecondsPerETH1Block = 14