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

Verify Slashing Signatures Before Putting Into Blocks #5071

Merged
merged 27 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
62effe8
rem slasher proto
rauljordan Mar 3, 2020
e44fea7
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 5, 2020
3b5a515
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 5, 2020
aabb910
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 5, 2020
202e7d2
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 5, 2020
5adf2af
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 5, 2020
86eb6aa
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 6, 2020
ff839d3
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 6, 2020
3720d41
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 9, 2020
b695a33
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 10, 2020
8cb66a8
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 10, 2020
a9b3168
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 10, 2020
d2ca3b1
Merge branch 'master' of github.com:prysmaticlabs/prysm
rauljordan Mar 11, 2020
3931e0d
verify slashing
rauljordan Mar 11, 2020
55486a1
added in test for pending att slashing
rauljordan Mar 11, 2020
8347415
tests starting to apss
rauljordan Mar 11, 2020
8bdfc40
sig failed verify regression test
rauljordan Mar 11, 2020
7f87a9b
tests passing for ops pool
rauljordan Mar 11, 2020
c287271
Update beacon-chain/operations/slashings/service.go
rauljordan Mar 11, 2020
b2d63d5
Merge refs/heads/master into verify-slash-sig
prylabs-bulldozer[bot] Mar 11, 2020
a588e88
verify on insert
rauljordan Mar 11, 2020
71d91ce
tests starting to pass
rauljordan Mar 11, 2020
4247111
all code paths fixed
rauljordan Mar 11, 2020
78c3502
imports
rauljordan Mar 11, 2020
1aaa213
fix build
rauljordan Mar 11, 2020
87dbb4d
fix rpc errors
rauljordan Mar 12, 2020
d34b8e8
Merge refs/heads/master into verify-slash-sig
prylabs-bulldozer[bot] Mar 12, 2020
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
7 changes: 5 additions & 2 deletions beacon-chain/operations/slashings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state:go_default_library",
"//shared/params:go_default_library",
"//shared/sliceutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@io_opencensus_go//trace:go_default_library",
],
)

Expand All @@ -30,9 +33,9 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//beacon-chain/state:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
],
Expand Down
12 changes: 12 additions & 0 deletions beacon-chain/operations/slashings/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
)

var (
numPendingAttesterSlashingFailedSigVerify = promauto.NewCounter(
prometheus.CounterOpts{
Name: "pending_attester_slashing_fail_sig_verify_total",
Help: "Times an pending attester slashing fails sig verification",
},
)
numPendingAttesterSlashings = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "num_pending_attester_slashings",
Expand All @@ -24,6 +30,12 @@ var (
Help: "Times an attester slashing for an already slashed validator is received",
},
)
numPendingProposerSlashingFailedSigVerify = promauto.NewCounter(
prometheus.CounterOpts{
Name: "pending_proposer_slashing_fail_sig_verify_total",
Help: "Times an pending proposer slashing fails sig verification",
},
)
numPendingProposerSlashings = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "num_pending_proposer_slashings",
Expand Down
42 changes: 37 additions & 5 deletions beacon-chain/operations/slashings/service.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package slashings

import (
"errors"
"context"
"fmt"
"sort"

"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
"go.opencensus.io/trace"
)

// NewPool returns an initialized attester slashing and proposer slashing pool.
Expand All @@ -23,9 +26,11 @@ func NewPool() *Pool {

// PendingAttesterSlashings returns attester slashings that are able to be included into a block.
// This method will not return more than the block enforced MaxAttesterSlashings.
func (p *Pool) PendingAttesterSlashings() []*ethpb.AttesterSlashing {
func (p *Pool) PendingAttesterSlashings(ctx context.Context) []*ethpb.AttesterSlashing {
p.lock.RLock()
defer p.lock.RUnlock()
ctx, span := trace.StartSpan(ctx, "operations.PendingAttesterSlashing")
defer span.End()

// Update prom metric.
numPendingAttesterSlashings.Set(float64(len(p.pendingAttesterSlashing)))
Expand All @@ -37,13 +42,15 @@ func (p *Pool) PendingAttesterSlashings() []*ethpb.AttesterSlashing {
break
}
if included[slashing.validatorToSlash] {
p.pendingAttesterSlashing = append(p.pendingAttesterSlashing[:i], p.pendingAttesterSlashing[i+1:]...)
continue
}
attSlashing := slashing.attesterSlashing
slashedVal := sliceutil.IntersectionUint64(attSlashing.Attestation_1.AttestingIndices, attSlashing.Attestation_2.AttestingIndices)
for _, idx := range slashedVal {
included[idx] = true
}

pending = append(pending, attSlashing)
}

Expand All @@ -52,9 +59,11 @@ func (p *Pool) PendingAttesterSlashings() []*ethpb.AttesterSlashing {

// PendingProposerSlashings returns proposer slashings that are able to be included into a block.
// This method will not return more than the block enforced MaxProposerSlashings.
func (p *Pool) PendingProposerSlashings() []*ethpb.ProposerSlashing {
func (p *Pool) PendingProposerSlashings(ctx context.Context) []*ethpb.ProposerSlashing {
p.lock.RLock()
defer p.lock.RUnlock()
ctx, span := trace.StartSpan(ctx, "operations.PendingProposerSlashing")
defer span.End()

// Update prom metric.
numPendingProposerSlashings.Set(float64(len(p.pendingProposerSlashing)))
Expand All @@ -71,9 +80,20 @@ func (p *Pool) PendingProposerSlashings() []*ethpb.ProposerSlashing {

// InsertAttesterSlashing into the pool. This method is a no-op if the attester slashing already exists in the pool,
// has been included into a block recently, or the validator is already exited.
func (p *Pool) InsertAttesterSlashing(state *beaconstate.BeaconState, slashing *ethpb.AttesterSlashing) error {
func (p *Pool) InsertAttesterSlashing(
ctx context.Context,
state *beaconstate.BeaconState,
slashing *ethpb.AttesterSlashing,
) error {
p.lock.Lock()
defer p.lock.Unlock()
ctx, span := trace.StartSpan(ctx, "operations.InsertAttesterSlashing")
defer span.End()

if err := blocks.VerifyAttesterSlashing(ctx, state, slashing); err != nil {
numPendingAttesterSlashingFailedSigVerify.Inc()
return errors.Wrap(err, "could not verify attester slashing")
}

slashedVal := sliceutil.IntersectionUint64(slashing.Attestation_1.AttestingIndices, slashing.Attestation_2.AttestingIndices)
for _, val := range slashedVal {
Expand Down Expand Up @@ -115,9 +135,21 @@ func (p *Pool) InsertAttesterSlashing(state *beaconstate.BeaconState, slashing *

// InsertProposerSlashing into the pool. This method is a no-op if the pending slashing already exists,
// has been included recently, the validator is already exited, or the validator was already slashed.
func (p *Pool) InsertProposerSlashing(state *beaconstate.BeaconState, slashing *ethpb.ProposerSlashing) error {
func (p *Pool) InsertProposerSlashing(
ctx context.Context,
state *beaconstate.BeaconState,
slashing *ethpb.ProposerSlashing,
) error {
p.lock.Lock()
defer p.lock.Unlock()
ctx, span := trace.StartSpan(ctx, "operations.InsertProposerSlashing")
defer span.End()

if err := blocks.VerifyProposerSlashing(state, slashing); err != nil {
numPendingAttesterSlashingFailedSigVerify.Inc()
Copy link
Contributor

Choose a reason for hiding this comment

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

Good call with the metrics

return errors.Wrap(err, "could not verify proposer slashing")
}

idx := slashing.ProposerIndex
ok, err := p.validatorSlashingPreconditionCheck(state, idx)
if err != nil {
Expand Down
Loading