Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast Slashing on equivocation #14693

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
682677c
Add equivocation detection logic; broadcast slashing immediately on e…
shyam-patel-kira Dec 6, 2024
4861bed
nit: comments
shyam-patel-kira Dec 6, 2024
98f0bc3
Merge branch 'develop' into broadcast-equivocating-blocks
shyam-patel-kira Dec 6, 2024
8858503
Merge branch 'prysmaticlabs:develop' into broadcast-equivocating-blocks
shyam-patel-kira Jan 25, 2025
8d7270e
move equivocation detection to validateBeaconBlockPubSub
shyam-patel-kira Jan 25, 2025
f14cacb
include broadcasting logic within the helper function
shyam-patel-kira Jan 25, 2025
a3797e6
fix lint
shyam-patel-kira Jan 26, 2025
1bfc38e
Add unit tests for equivocation detection
shyam-patel-kira Jan 26, 2025
e915e42
remove comment that are not required
shyam-patel-kira Jan 26, 2025
b8989d3
Add changelog file
shyam-patel-kira Jan 26, 2025
bfa3b9a
Merge branch 'develop' of https://github.com/shyam-patel-kira/prysm i…
shyam-patel-kira Jan 30, 2025
b9b9cde
Add descriptive comment for detectAndBroadcastEquivocation
shyam-patel-kira Jan 30, 2025
9609bef
Merge branch 'develop' of https://github.com/prysmaticlabs/prysm into…
shyam-patel-kira Jan 30, 2025
cdb8935
Merge branch 'develop' of https://github.com/shyam-patel-kira/prysm i…
shyam-patel-kira Feb 2, 2025
95cb35d
Merge branch 'develop' of https://github.com/shyam-patel-kira/prysm i…
shyam-patel-kira Feb 3, 2025
7acef84
Merge branch 'broadcast-equivocating-blocks' of https://github.com/sh…
shyam-patel-kira Feb 3, 2025
462f569
use head block instead of block cache for equivocation detection
shyam-patel-kira Feb 3, 2025
1709546
add more equivocation unit tests; update a mock to include HeadState …
shyam-patel-kira Feb 3, 2025
bdec36f
Merge branch 'develop' of https://github.com/prysmaticlabs/prysm into…
shyam-patel-kira Feb 6, 2025
d80fb4b
Merge branch 'develop' of https://github.com/shyam-patel-kira/prysm i…
shyam-patel-kira Feb 7, 2025
0f174be
Merge branch 'develop' of https://github.com/shyam-patel-kira/prysm i…
shyam-patel-kira Feb 10, 2025
e6ce574
update the order of the checks
shyam-patel-kira Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func (s *Service) postBlockProcess(cfg *postBlockProcessConfig) error {
defer reportProcessingTime(startTime)
defer reportAttestationInclusion(cfg.roblock.Block())

// Check for equivocation before inserting into fork choice
slashing, slashingErr := s.detectEquivocatingBlock(cfg.ctx, cfg.roblock)
shyam-patel-kira marked this conversation as resolved.
Show resolved Hide resolved
if slashingErr != nil {
return errors.Wrap(slashingErr, "could not detect equivocating block")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably log instead of returning and preventing FCU? could not check for block equivocation seems more accurate

}

if slashing != nil {
shyam-patel-kira marked this conversation as resolved.
Show resolved Hide resolved
if err := s.broadcastProposerSlashing(cfg.ctx, slashing); err != nil {
log.WithError(err).Error("Could not broadcast proposer slashing")
}

// Also insert into slashing pool
if err := s.cfg.SlashingPool.InsertProposerSlashing(cfg.ctx, cfg.postState, slashing); err != nil {
log.WithError(err).Error("Could not insert proposer slashing into pool")
}
}

err := s.cfg.ForkChoiceStore.InsertNode(ctx, cfg.postState, cfg.roblock)
if err != nil {
// Do not use parent context in the event it deadlined
Expand Down Expand Up @@ -706,3 +723,11 @@ func (s *Service) rollbackBlock(ctx context.Context, blockRoot [32]byte) {
log.WithError(err).Errorf("Could not delete block with block root %#x", blockRoot)
}
}

func (s *Service) broadcastProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error {
if features.Get().DisableBroadcastSlashings {
return nil
}

return s.cfg.P2p.Broadcast(ctx, slashing)
}
47 changes: 47 additions & 0 deletions beacon-chain/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,50 @@
}
go slots.CountdownToGenesis(ctx, genesisTime, uint64(gState.NumValidators()), gRoot)
}

func (s *Service) detectEquivocatingBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock) (*ethpb.ProposerSlashing, error) {
// Get the incoming block's header
header1, err := block.Header()
if err != nil {
return nil, errors.Wrap(err, "could not get header from incoming block")
}

s.headLock.RLock()
headBlock, err := s.headBlock()
if err != nil {
s.headLock.RUnlock()
return nil, errors.Wrap(err, "could not get head block")
}
s.headLock.RUnlock()

// Get the head block's header
header2, err := headBlock.Header()
if err != nil {
return nil, errors.Wrap(err, "could not get header from head block")
}

// Check for equivocation:
if header1.Header.Slot == header2.Header.Slot &&
header1.Header.ProposerIndex == header2.Header.ProposerIndex {

Check failure on line 607 in beacon-chain/blockchain/service.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary leading newline (whitespace)

header1Root, err := header1.Header.HashTreeRoot()
shyam-patel-kira marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, errors.Wrap(err, "could not hash header 1")
}

header2Root, err := header2.Header.HashTreeRoot()
shyam-patel-kira marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, errors.Wrap(err, "could not hash header 2")
}

// Different header roots means equivocation
if header1Root != header2Root {
return &ethpb.ProposerSlashing{
Header_1: header1,
Header_2: header2,
}, nil
}
}

return nil, nil
}
Loading