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:
Manu NALEPA
2024-02-12 18:35:22 +01:00
committed by GitHub
parent 5e74c798d4
commit 06a5548424
11 changed files with 345 additions and 309 deletions

View File

@@ -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",
],
)

View File

@@ -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, &ethpb.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 := &ethpb.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 = &ethpb.AttesterSlashing{
Attestation_1: slashableAtt,
Attestation_2: att,
}
}
slashings = append(slashings, slashing)
attestations = append(attestations, slashableAtt)
}
}