diff --git a/beacon-chain/rpc/eth/beacon/BUILD.bazel b/beacon-chain/rpc/eth/beacon/BUILD.bazel index 110dd27e3e..462966a868 100644 --- a/beacon-chain/rpc/eth/beacon/BUILD.bazel +++ b/beacon-chain/rpc/eth/beacon/BUILD.bazel @@ -72,6 +72,7 @@ go_library( go_test( name = "go_default_test", srcs = [ + "handlers_equivocation_test.go", "handlers_pool_test.go", "handlers_state_test.go", "handlers_test.go", diff --git a/beacon-chain/rpc/eth/beacon/handlers.go b/beacon-chain/rpc/eth/beacon/handlers.go index 349ada614c..541b79d663 100644 --- a/beacon-chain/rpc/eth/beacon/handlers.go +++ b/beacon-chain/rpc/eth/beacon/handlers.go @@ -701,7 +701,7 @@ func (s *Server) publishBlockSSZ(ctx context.Context, w http.ResponseWriter, r * // Validate and optionally broadcast sidecars on equivocation. if err := s.validateBroadcast(ctx, r, genericBlock); err != nil { if errors.Is(err, errEquivocatedBlock) { - b, err := blocks.NewSignedBeaconBlock(genericBlock) + b, err := blocks.NewSignedBeaconBlock(genericBlock.Block) if err != nil { httputil.HandleError(w, err.Error(), http.StatusBadRequest) return @@ -855,7 +855,7 @@ func (s *Server) publishBlock(ctx context.Context, w http.ResponseWriter, r *htt // Validate and optionally broadcast sidecars on equivocation. if err := s.validateBroadcast(ctx, r, genericBlock); err != nil { if errors.Is(err, errEquivocatedBlock) { - b, err := blocks.NewSignedBeaconBlock(genericBlock) + b, err := blocks.NewSignedBeaconBlock(genericBlock.Block) if err != nil { httputil.HandleError(w, err.Error(), http.StatusBadRequest) return diff --git a/beacon-chain/rpc/eth/beacon/handlers_equivocation_test.go b/beacon-chain/rpc/eth/beacon/handlers_equivocation_test.go new file mode 100644 index 0000000000..f0e47b7d80 --- /dev/null +++ b/beacon-chain/rpc/eth/beacon/handlers_equivocation_test.go @@ -0,0 +1,35 @@ +package beacon + +import ( + "encoding/json" + "testing" + + "github.com/OffchainLabs/prysm/v6/api/server/structs" + rpctesting "github.com/OffchainLabs/prysm/v6/beacon-chain/rpc/eth/shared/testing" + "github.com/OffchainLabs/prysm/v6/consensus-types/blocks" + "github.com/OffchainLabs/prysm/v6/testing/require" +) + +// TestBlocks_NewSignedBeaconBlock_EquivocationFix tests that blocks.NewSignedBeaconBlock +// correctly handles the fixed case where genericBlock.Block is passed instead of genericBlock +func TestBlocks_NewSignedBeaconBlock_EquivocationFix(t *testing.T) { + // Parse the Phase0 JSON block + var block structs.SignedBeaconBlock + err := json.Unmarshal([]byte(rpctesting.Phase0Block), &block) + require.NoError(t, err) + + // Convert to generic format + genericBlock, err := block.ToGeneric() + require.NoError(t, err) + + // Test the FIX: pass genericBlock.Block instead of genericBlock + // This is what our fix changed in handlers.go line 704 and 858 + _, err = blocks.NewSignedBeaconBlock(genericBlock.Block) + require.NoError(t, err, "NewSignedBeaconBlock should work with genericBlock.Block") + + // Test the BROKEN version: pass genericBlock directly (this should fail) + _, err = blocks.NewSignedBeaconBlock(genericBlock) + if err == nil { + t.Errorf("NewSignedBeaconBlock should fail with whole genericBlock but succeeded") + } +} \ No newline at end of file diff --git a/changelog/ttsao_fix-equivocation-block-field.md b/changelog/ttsao_fix-equivocation-block-field.md new file mode 100644 index 0000000000..4a0630b6c8 --- /dev/null +++ b/changelog/ttsao_fix-equivocation-block-field.md @@ -0,0 +1,3 @@ +### Fixed + +- Fixed NewSignedBeaconBlock calls to use Block field for proper equivocation handling