mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Slasher: Fixes double votes false positive and attester slashings duplication. (#13596)
* `Test_processAttestations`: Remove duplicated tests. * Sort indexed attestations by data root. * `processAttestations`: Don't return duplicate slashings anymore. Fix https://github.com/prysmaticlabs/prysm/issues/13592. * `AttesterDoubleVote`: Rename fields. * Detect double votes in different batches. In order to do that: 1. Each attestation of the batch is tested against the other attestations of the batch. 2. Each attestation of the batch is tested against the content of the database. 2. Attestations are saved into the database. Fixes https://github.com/prysmaticlabs/prysm/issues/13590.
This commit is contained in:
@@ -32,6 +32,7 @@ go_library(
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package simulator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"math"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/signing"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
|
||||
@@ -88,10 +90,31 @@ func (s *Simulator) generateAttestationsForSlot(
|
||||
}
|
||||
slashableAtt.Signature = aggSig.Marshal()
|
||||
slashedIndices = append(slashedIndices, slashableAtt.AttestingIndices...)
|
||||
slashings = append(slashings, ðpb.AttesterSlashing{
|
||||
|
||||
attDataRoot, err := att.Data.HashTreeRoot()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "cannot compte `att` hash tree root")
|
||||
}
|
||||
|
||||
slashableAttDataRoot, err := slashableAtt.Data.HashTreeRoot()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "cannot compte `slashableAtt` hash tree root")
|
||||
}
|
||||
|
||||
slashing := ðpb.AttesterSlashing{
|
||||
Attestation_1: att,
|
||||
Attestation_2: slashableAtt,
|
||||
})
|
||||
}
|
||||
|
||||
// Ensure the attestation with the lower data root is the first attestation.
|
||||
if bytes.Compare(attDataRoot[:], slashableAttDataRoot[:]) > 0 {
|
||||
slashing = ðpb.AttesterSlashing{
|
||||
Attestation_1: slashableAtt,
|
||||
Attestation_2: att,
|
||||
}
|
||||
}
|
||||
|
||||
slashings = append(slashings, slashing)
|
||||
attestations = append(attestations, slashableAtt)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user