Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions ssv/spectest/all_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ var AllTests = []tests.TestF{
valcheckattestations.SourceHigherThanTarget,
valcheckattestations.UnmatchedTargetEpoch,
valcheckattestations.UnmatchedSourceEpoch,
valcheckattestations.UnmatchedTargetRoot,
valcheckattestations.UnmatchedSourceRoot,
valcheckattestations.BeaconVoteDataNil,
valcheckattestations.Valid,
valcheckattestations.MinoritySlashable,
Expand Down

This file was deleted.

This file was deleted.

33 changes: 17 additions & 16 deletions ssv/spectest/tests/valcheck/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type SpecTest struct {
RunnerRole types.RunnerRole
DutySlot phase0.Slot // DutySlot is used only for the RoleCommittee since the BeaconVoteValueCheckF requires the duty's slot
Input []byte
ExpectedSource phase0.Checkpoint // Specify expected source epoch for beacon vote value check
ExpectedTarget phase0.Checkpoint // Specify expected target epoch for beacon vote value check
ExpectedSource phase0.Checkpoint // Specify expected source epoch for beacon vote value check
ExpectedTarget phase0.Checkpoint // Specify expected target epoch for beacon vote value check
SlashableSlots map[string][]phase0.Slot // map share pk to a list of slashable slots
ShareValidatorsPK []types.ShareValidatorPK `json:"ShareValidatorsPK,omitempty"` // Optional. Specify validators shares for beacon vote value check
ExpectedErrorCode int
Expand Down Expand Up @@ -63,7 +63,8 @@ func (test *SpecTest) valCheckF(signer types.BeaconSigner) qbft.ProposedValueChe
}
switch test.RunnerRole {
case types.RoleCommittee:
return ssv.BeaconVoteValueCheckF(signer, test.DutySlot, shareValidatorsPK, &test.ExpectedSource, &test.ExpectedTarget)
return ssv.BeaconVoteValueCheckF(signer, test.DutySlot, shareValidatorsPK, test.ExpectedSource.Epoch,
test.ExpectedTarget.Epoch)
case types.RoleProposer:
return ssv.ProposerValueCheckF(signer, test.Network, pubKeyBytes, testingutils.TestingValidatorIndex, nil)
case types.RoleAggregator:
Expand Down Expand Up @@ -118,19 +119,19 @@ func NewSpecTest(
anyError bool,
) *SpecTest {
return &SpecTest{
Name: name,
Type: "Value check: validations for input of different runner roles",
Documentation: documentation,
Network: network,
RunnerRole: role,
DutySlot: dutySlot,
Input: input,
ExpectedSource: expectedSource,
ExpectedTarget: expectedTarget,
SlashableSlots: slashableSlots,
ShareValidatorsPK: shareValidatorsPK,
ExpectedErrorCode: expectedErrorCode,
AnyError: anyError,
Name: name,
Type: "Value check: validations for input of different runner roles",
Documentation: documentation,
Network: network,
RunnerRole: role,
DutySlot: dutySlot,
Input: input,
ExpectedSource: expectedSource,
ExpectedTarget: expectedTarget,
SlashableSlots: slashableSlots,
ShareValidatorsPK: shareValidatorsPK,
ExpectedErrorCode: expectedErrorCode,
AnyError: anyError,
}
}

Expand Down

This file was deleted.

This file was deleted.

24 changes: 12 additions & 12 deletions ssv/value_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package ssv
import (
"bytes"
"fmt"
"math"
"reflect"

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/pkg/errors"
"math"

"github.com/ssvlabs/ssv-spec/qbft"
"github.com/ssvlabs/ssv-spec/types"
Expand Down Expand Up @@ -43,8 +41,8 @@ func BeaconVoteValueCheckF(
signer types.BeaconSigner,
slot phase0.Slot,
sharePublicKeys []types.ShareValidatorPK,
expectedSource *phase0.Checkpoint,
expectedTarget *phase0.Checkpoint,
expectedSource phase0.Epoch,
expectedTarget phase0.Epoch,
) qbft.ProposedValueCheckF {
return func(data []byte) error {
bv := types.BeaconVote{}
Expand All @@ -56,14 +54,16 @@ func BeaconVoteValueCheckF(
return types.NewError(types.AttestationSourceNotLessThanTargetErrorCode, "attestation data source >= target")
}

if !reflect.DeepEqual(bv.Source, expectedSource) {
return types.NewError(types.CheckpointMismatch, fmt.Sprintf("attestation data source checkpoint %v does not match expected %v",
bv.Source, expectedSource))
if bv.Source.Epoch != expectedSource {
return types.NewError(types.CheckpointMismatch,
fmt.Sprintf("attestation data source checkpoint %d does not match expected %d",
bv.Source.Epoch, expectedSource))
}

if !reflect.DeepEqual(bv.Target, expectedTarget) {
return types.NewError(types.CheckpointMismatch, fmt.Sprintf("attestation data target checkpoint %v does not match expected %v",
bv.Target, expectedTarget))

if bv.Target.Epoch != expectedTarget {
return types.NewError(types.CheckpointMismatch,
fmt.Sprintf("attestation data target checkpoint %d does not match expected %d",
bv.Target.Epoch, expectedTarget))
}

attestationData := &phase0.AttestationData{
Expand Down
4 changes: 2 additions & 2 deletions types/testingutils/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var ConstructBaseRunnerWithShareMap = func(role types.RunnerRole, shareMap map[p
switch role {
case types.RoleCommittee:
valCheck = ssv.BeaconVoteValueCheckF(km, TestingDutySlot,
sharePubKeys, TestBeaconVote.Source, TestBeaconVote.Target)
sharePubKeys, TestBeaconVote.Source.Epoch, TestBeaconVote.Target.Epoch)
case types.RoleProposer:
valCheck = ssv.ProposerValueCheckF(km, types.BeaconTestNetwork,
(types.ValidatorPK)(shareInstance.ValidatorPubKey), shareInstance.ValidatorIndex, shareInstance.SharePubKey)
Expand Down Expand Up @@ -272,7 +272,7 @@ var ConstructBaseRunner = func(role types.RunnerRole, keySet *TestKeySet) (ssv.R
switch role {
case types.RoleCommittee:
valCheck = ssv.BeaconVoteValueCheckF(km, TestingDutySlot,
[]types.ShareValidatorPK{share.SharePubKey}, TestBeaconVote.Source, TestBeaconVote.Target)
[]types.ShareValidatorPK{share.SharePubKey}, TestBeaconVote.Source.Epoch, TestBeaconVote.Target.Epoch)
case types.RoleProposer:
valCheck = ssv.ProposerValueCheckF(km, types.BeaconTestNetwork,
(types.ValidatorPK)(TestingValidatorPubKey), TestingValidatorIndex, share.SharePubKey)
Expand Down