Skip to content

Broadcast Proposer Slashing on equivocation #14693

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

Merged

Conversation

shyam-patel-kira
Copy link
Contributor

fixes #13088

The PR implements immediate broadcasting of slashing messages when detecting equivocating blocks, helping the network react more quickly to malicious behavior without relying on the full slasher service processing.

@shyam-patel-kira shyam-patel-kira requested a review from a team as a code owner December 6, 2024 17:34
@0xalpharush
Copy link

I think this should probably be done in the gossip validation of beacon blocks for two reasons:

  1. I may not understand the spec properly but I believe signing equivocating blocks even if they're invalid should bet met with a slashing proposal
  2. There is probably no need for the slashing service to be sent a block which was already deemed equivocating and resulted in a slashing proposal being broadcast
    https://github.com/prysmaticlabs/prysm/blob/30a136f1fbd3f62b02369be9878decbfdeb3b648/beacon-chain/sync/validate_beacon_blocks.go#L84-L95

Fwiw I am just an interested bystander using this as a learning opportunity. Feel free to ignore or let me know if this is unhelpful

Copy link
Contributor

@potuz potuz left a comment

Choose a reason for hiding this comment

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

When moving this check to the right spot instead after the call to ReceiveBlock we don't have the root yet (since we only hash after we know we haven't seen the block), we should check if the signatures are different instead, as a different root will result in a different signature.

@shyam-patel-kira shyam-patel-kira changed the title [WIP] Broadcast Slashing on equivocation Broadcast Slashing on equivocation Jan 26, 2025
@shyam-patel-kira
Copy link
Contributor Author

Hey @potuz, Thanks for the review, addressed the changes that were requested

@shyam-patel-kira
Copy link
Contributor Author

shyam-patel-kira commented Mar 11, 2025

not sure why but the review got dismissed after I committed

@shyam-patel-kira shyam-patel-kira requested a review from potuz March 13, 2025 19:06
potuz
potuz previously approved these changes Mar 17, 2025
@shyam-patel-kira shyam-patel-kira changed the title Broadcast Slashing on equivocation Broadcast Proposer Slashing on equivocation Mar 20, 2025

// Verify the slashing against current state
if err := blocks.VerifyProposerSlashing(headState, slashing); err != nil {
if strings.Contains(err.Error(), "could not verify beacon block header") {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is very risky to compare errors like this because if someone modifies the original error message, this may never be true anymore. Can you extract the original message to an exported variable and use errors.Is?

Comment on lines 1 to 8
### Added
- Added immediate broadcasting of proposer slashings when equivocating blocks are detected during block processing.
- Added signature verification for proposer slashing detection.
- Added a new `HeadStateErr` for testing equivocations

### Changed
- Improved equivocation detection by comparing blocks with the same slot and proposer against the head block.
- Removed redundant slashing verification checks in favor of using existing VerifyProposerSlashing function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
### Added
- Added immediate broadcasting of proposer slashings when equivocating blocks are detected during block processing.
- Added signature verification for proposer slashing detection.
- Added a new `HeadStateErr` for testing equivocations
### Changed
- Improved equivocation detection by comparing blocks with the same slot and proposer against the head block.
- Removed redundant slashing verification checks in favor of using existing VerifyProposerSlashing function.
### Added
- Added immediate broadcasting of proposer slashings when equivocating blocks are detected during block processing.

I would include only this in the changelog because that's the only thing that really matters. Adding too many entries to a changelog fragment bloats the changelog

@@ -1495,3 +1496,225 @@ func Test_validateDenebBeaconBlock(t *testing.T) {
require.NoError(t, err)
require.ErrorIs(t, validateDenebBeaconBlock(bdb.Block()), errRejectCommitmentLen)
}

func TestDetectAndBroadcastEquivocation_NoEquivocation(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you merge all these tests into one, using t.Run for each test case? That way you can set up things like p := p2ptest.NewTestP2P(t) only once, at the start of the test, and reduce test times.

Pseudocode:

func TestDetectAndBroadcastEquivocation() {
    p := p2ptest.NewTestP2P(t)
    (...)
    t.Run("no equivocation", ...
    t.Run("equivocation detected", ...
}

@rkapka
Copy link
Contributor

rkapka commented Mar 21, 2025

@shyam-patel-kira I left a few comments

@shyam-patel-kira
Copy link
Contributor Author

@shyam-patel-kira I left a few comments

Thanks for the review @rkapka, I've pushed the changes let me know if anything needs to be changed

rkapka
rkapka previously approved these changes Apr 2, 2025
@rkapka
Copy link
Contributor

rkapka commented Apr 2, 2025

@shyam-patel-kira TestValidateBeaconBlockPubSub_SeenProposerSlot is failing

@shyam-patel-kira
Copy link
Contributor Author

@shyam-patel-kira TestValidateBeaconBlockPubSub_SeenProposerSlot is failing

fixed it

@potuz potuz added this pull request to the merge queue Apr 24, 2025
Merged via the queue into OffchainLabs:develop with commit 7887ebb Apr 24, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked Blocked by research or external factors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broadcast slashing on equivocating blocks
4 participants