Skip to content

Commit 8f5ddfc

Browse files
Spec - Relax Majority Protection Rules (#589)
* Remove full checkpoint comparisons from value check * generate jsons * Update ssv/value_check.go Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 91ceedb commit 8f5ddfc

File tree

8 files changed

+31
-174
lines changed

8 files changed

+31
-174
lines changed

ssv/spectest/all_tests.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ var AllTests = []tests.TestF{
171171
valcheckattestations.SourceHigherThanTarget,
172172
valcheckattestations.UnmatchedTargetEpoch,
173173
valcheckattestations.UnmatchedSourceEpoch,
174-
valcheckattestations.UnmatchedTargetRoot,
175-
valcheckattestations.UnmatchedSourceRoot,
176174
valcheckattestations.BeaconVoteDataNil,
177175
valcheckattestations.Valid,
178176
valcheckattestations.MinoritySlashable,

ssv/spectest/generate/tests/valcheck.SpecTest_attestation_value_check_unmatched_source_root.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

ssv/spectest/generate/tests/valcheck.SpecTest_attestation_value_check_unmatched_target_root.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

ssv/spectest/tests/valcheck/test.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ type SpecTest struct {
2121
RunnerRole types.RunnerRole
2222
DutySlot phase0.Slot // DutySlot is used only for the RoleCommittee since the BeaconVoteValueCheckF requires the duty's slot
2323
Input []byte
24-
ExpectedSource phase0.Checkpoint // Specify expected source epoch for beacon vote value check
25-
ExpectedTarget phase0.Checkpoint // Specify expected target epoch for beacon vote value check
24+
ExpectedSource phase0.Checkpoint // Specify expected source epoch for beacon vote value check
25+
ExpectedTarget phase0.Checkpoint // Specify expected target epoch for beacon vote value check
2626
SlashableSlots map[string][]phase0.Slot // map share pk to a list of slashable slots
2727
ShareValidatorsPK []types.ShareValidatorPK `json:"ShareValidatorsPK,omitempty"` // Optional. Specify validators shares for beacon vote value check
2828
ExpectedErrorCode int
@@ -63,7 +63,8 @@ func (test *SpecTest) valCheckF(signer types.BeaconSigner) qbft.ProposedValueChe
6363
}
6464
switch test.RunnerRole {
6565
case types.RoleCommittee:
66-
return ssv.BeaconVoteValueCheckF(signer, test.DutySlot, shareValidatorsPK, &test.ExpectedSource, &test.ExpectedTarget)
66+
return ssv.BeaconVoteValueCheckF(signer, test.DutySlot, shareValidatorsPK, test.ExpectedSource.Epoch,
67+
test.ExpectedTarget.Epoch)
6768
case types.RoleProposer:
6869
return ssv.ProposerValueCheckF(signer, test.Network, pubKeyBytes, testingutils.TestingValidatorIndex, nil)
6970
case types.RoleAggregator:
@@ -118,19 +119,19 @@ func NewSpecTest(
118119
anyError bool,
119120
) *SpecTest {
120121
return &SpecTest{
121-
Name: name,
122-
Type: "Value check: validations for input of different runner roles",
123-
Documentation: documentation,
124-
Network: network,
125-
RunnerRole: role,
126-
DutySlot: dutySlot,
127-
Input: input,
128-
ExpectedSource: expectedSource,
129-
ExpectedTarget: expectedTarget,
130-
SlashableSlots: slashableSlots,
131-
ShareValidatorsPK: shareValidatorsPK,
132-
ExpectedErrorCode: expectedErrorCode,
133-
AnyError: anyError,
122+
Name: name,
123+
Type: "Value check: validations for input of different runner roles",
124+
Documentation: documentation,
125+
Network: network,
126+
RunnerRole: role,
127+
DutySlot: dutySlot,
128+
Input: input,
129+
ExpectedSource: expectedSource,
130+
ExpectedTarget: expectedTarget,
131+
SlashableSlots: slashableSlots,
132+
ShareValidatorsPK: shareValidatorsPK,
133+
ExpectedErrorCode: expectedErrorCode,
134+
AnyError: anyError,
134135
}
135136
}
136137

ssv/spectest/tests/valcheck/valcheckattestations/unmatched_source_root.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

ssv/spectest/tests/valcheck/valcheckattestations/unmatched_target_root.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

ssv/value_check.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package ssv
33
import (
44
"bytes"
55
"fmt"
6-
"math"
7-
"reflect"
8-
96
"github.com/attestantio/go-eth2-client/spec/phase0"
107
"github.com/pkg/errors"
8+
"math"
119

1210
"github.com/ssvlabs/ssv-spec/qbft"
1311
"github.com/ssvlabs/ssv-spec/types"
@@ -43,8 +41,8 @@ func BeaconVoteValueCheckF(
4341
signer types.BeaconSigner,
4442
slot phase0.Slot,
4543
sharePublicKeys []types.ShareValidatorPK,
46-
expectedSource *phase0.Checkpoint,
47-
expectedTarget *phase0.Checkpoint,
44+
expectedSource phase0.Epoch,
45+
expectedTarget phase0.Epoch,
4846
) qbft.ProposedValueCheckF {
4947
return func(data []byte) error {
5048
bv := types.BeaconVote{}
@@ -56,14 +54,16 @@ func BeaconVoteValueCheckF(
5654
return types.NewError(types.AttestationSourceNotLessThanTargetErrorCode, "attestation data source >= target")
5755
}
5856

59-
if !reflect.DeepEqual(bv.Source, expectedSource) {
60-
return types.NewError(types.CheckpointMismatch, fmt.Sprintf("attestation data source checkpoint %v does not match expected %v",
61-
bv.Source, expectedSource))
57+
if bv.Source.Epoch != expectedSource {
58+
return types.NewError(types.CheckpointMismatch,
59+
fmt.Sprintf("attestation data source checkpoint %d does not match expected %d",
60+
bv.Source.Epoch, expectedSource))
6261
}
63-
64-
if !reflect.DeepEqual(bv.Target, expectedTarget) {
65-
return types.NewError(types.CheckpointMismatch, fmt.Sprintf("attestation data target checkpoint %v does not match expected %v",
66-
bv.Target, expectedTarget))
62+
63+
if bv.Target.Epoch != expectedTarget {
64+
return types.NewError(types.CheckpointMismatch,
65+
fmt.Sprintf("attestation data target checkpoint %d does not match expected %d",
66+
bv.Target.Epoch, expectedTarget))
6767
}
6868

6969
attestationData := &phase0.AttestationData{

types/testingutils/runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ var ConstructBaseRunnerWithShareMap = func(role types.RunnerRole, shareMap map[p
118118
switch role {
119119
case types.RoleCommittee:
120120
valCheck = ssv.BeaconVoteValueCheckF(km, TestingDutySlot,
121-
sharePubKeys, TestBeaconVote.Source, TestBeaconVote.Target)
121+
sharePubKeys, TestBeaconVote.Source.Epoch, TestBeaconVote.Target.Epoch)
122122
case types.RoleProposer:
123123
valCheck = ssv.ProposerValueCheckF(km, types.BeaconTestNetwork,
124124
(types.ValidatorPK)(shareInstance.ValidatorPubKey), shareInstance.ValidatorIndex, shareInstance.SharePubKey)
@@ -272,7 +272,7 @@ var ConstructBaseRunner = func(role types.RunnerRole, keySet *TestKeySet) (ssv.R
272272
switch role {
273273
case types.RoleCommittee:
274274
valCheck = ssv.BeaconVoteValueCheckF(km, TestingDutySlot,
275-
[]types.ShareValidatorPK{share.SharePubKey}, TestBeaconVote.Source, TestBeaconVote.Target)
275+
[]types.ShareValidatorPK{share.SharePubKey}, TestBeaconVote.Source.Epoch, TestBeaconVote.Target.Epoch)
276276
case types.RoleProposer:
277277
valCheck = ssv.ProposerValueCheckF(km, types.BeaconTestNetwork,
278278
(types.ValidatorPK)(TestingValidatorPubKey), TestingValidatorIndex, share.SharePubKey)

0 commit comments

Comments
 (0)