diff --git a/validator/rpc/slashing_test.go b/validator/rpc/slashing_test.go index ca841e08393..6cb91448a01 100644 --- a/validator/rpc/slashing_test.go +++ b/validator/rpc/slashing_test.go @@ -112,6 +112,9 @@ func TestExportSlashingProtection_Preconditions(t *testing.T) { defer func() { require.NoError(t, validatorDB.Close()) }() + genesisValidatorsRoot := [32]byte{1} + err = validatorDB.SaveGenesisValidatorsRoot(ctx, genesisValidatorsRoot[:]) + require.NoError(t, err) _, err = s.ExportSlashingProtection(ctx, &empty.Empty{}) require.NoError(t, err) diff --git a/validator/slashing-protection/local/standard-protection-format/export.go b/validator/slashing-protection/local/standard-protection-format/export.go index 68c20849276..5b23a2b08b9 100644 --- a/validator/slashing-protection/local/standard-protection-format/export.go +++ b/validator/slashing-protection/local/standard-protection-format/export.go @@ -22,6 +22,11 @@ func ExportStandardProtectionJSON(ctx context.Context, validatorDB db.Database) if err != nil { return nil, errors.Wrap(err, "could not get genesis validators root from DB") } + if genesisValidatorsRoot == nil || bytes.Equal(genesisValidatorsRoot, params.BeaconConfig().ZeroHash[:]) { + return nil, errors.New( + "genesis validators root is empty, perhaps you are not connected to your beacon node", + ) + } genesisRootHex, err := rootToHexString(genesisValidatorsRoot) if err != nil { return nil, errors.Wrap(err, "could not convert genesis validators root to hex string") diff --git a/validator/slashing-protection/local/standard-protection-format/export_test.go b/validator/slashing-protection/local/standard-protection-format/export_test.go index b07e88b7e5d..105bb27b3e6 100644 --- a/validator/slashing-protection/local/standard-protection-format/export_test.go +++ b/validator/slashing-protection/local/standard-protection-format/export_test.go @@ -12,6 +12,21 @@ import ( "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" ) +func TestExportStandardProtectionJSON_EmptyGenesisRoot(t *testing.T) { + ctx := context.Background() + pubKeys := [][48]byte{ + {1}, + } + validatorDB := dbtest.SetupDB(t, pubKeys) + _, err := ExportStandardProtectionJSON(ctx, validatorDB) + require.ErrorContains(t, "genesis validators root is empty", err) + genesisValidatorsRoot := [32]byte{1} + err = validatorDB.SaveGenesisValidatorsRoot(ctx, genesisValidatorsRoot[:]) + require.NoError(t, err) + _, err = ExportStandardProtectionJSON(ctx, validatorDB) + require.NoError(t, err) +} + func Test_getSignedAttestationsByPubKey(t *testing.T) { t.Run("OK", func(t *testing.T) { pubKeys := [][48]byte{ diff --git a/validator/slashing-protection/local/standard-protection-format/round_trip_test.go b/validator/slashing-protection/local/standard-protection-format/round_trip_test.go index f2005274512..85ee42731c8 100644 --- a/validator/slashing-protection/local/standard-protection-format/round_trip_test.go +++ b/validator/slashing-protection/local/standard-protection-format/round_trip_test.go @@ -86,7 +86,7 @@ func TestImportExport_RoundTrip_SkippedAttestationEpochs(t *testing.T) { GenesisValidatorsRoot string `json:"genesis_validators_root"` }{ InterchangeFormatVersion: format.InterchangeFormatVersion, - GenesisValidatorsRoot: fmt.Sprintf("%#x", [32]byte{}), + GenesisValidatorsRoot: fmt.Sprintf("%#x", [32]byte{1}), }, Data: []*format.ProtectionData{ {