diff --git a/ssv/spectest/tests/runner/consensus/future_msg.go b/ssv/spectest/tests/runner/consensus/future_msg.go index bb6441d88..fe7cbac86 100644 --- a/ssv/spectest/tests/runner/consensus/future_msg.go +++ b/ssv/spectest/tests/runner/consensus/future_msg.go @@ -1,6 +1,8 @@ package consensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" @@ -71,10 +73,10 @@ func FutureMessage() tests.SpecTest { { Name: "proposer", Runner: testingutils.ProposerRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ testingutils.SSVMsgProposer( - futureMsgF(testingutils.TestProposerWithJustificationsConsensusData(ks), testingutils.ProposerMsgID), + futureMsgF(testingutils.TestProposerWithJustificationsConsensusDataV(ks, spec.DataVersionBellatrix), testingutils.ProposerMsgID), nil), }, PostDutyRunnerStateRoot: "32dd1d1d7a4c34bb7dafc0866f69eb49f6a0a23755b135f83ad14d12e39fff82", @@ -84,10 +86,10 @@ func FutureMessage() tests.SpecTest { { Name: "proposer (blinded block)", Runner: testingutils.ProposerBlindedBlockRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ testingutils.SSVMsgProposer( - futureMsgF(testingutils.TestProposerBlindedWithJustificationsConsensusData(ks), testingutils.ProposerMsgID), + futureMsgF(testingutils.TestProposerBlindedWithJustificationsConsensusDataV(ks, spec.DataVersionBellatrix), testingutils.ProposerMsgID), nil), }, PostDutyRunnerStateRoot: "58b946451dc5ccbd52fbc9e6bbe0ac888253d1708be018a3ff0b07762dd28891", diff --git a/ssv/spectest/tests/runner/consensus/invalid_decided_value.go b/ssv/spectest/tests/runner/consensus/invalid_decided_value.go index b121eccac..a1a59b2b2 100644 --- a/ssv/spectest/tests/runner/consensus/invalid_decided_value.go +++ b/ssv/spectest/tests/runner/consensus/invalid_decided_value.go @@ -1,10 +1,12 @@ package consensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/herumi/bls-eth-go-binary/bls" + "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" "github.com/bloxapp/ssv-spec/types/testingutils" - "github.com/herumi/bls-eth-go-binary/bls" ) // InvalidDecidedValue tests an invalid decided value ConsensusData.Validate() != nil (unknown duty role) @@ -98,11 +100,11 @@ func InvalidDecidedValue() tests.SpecTest { { Name: "proposer", Runner: testingutils.ProposerRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsg(ks.Shares[1], ks.Shares[1], 1, 1)), - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsg(ks.Shares[2], ks.Shares[2], 2, 2)), - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsg(ks.Shares[3], ks.Shares[3], 3, 3)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsgV(ks.Shares[1], ks.Shares[1], 1, 1, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsgV(ks.Shares[2], ks.Shares[2], 2, 2, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsgV(ks.Shares[3], ks.Shares[3], 3, 3, spec.DataVersionBellatrix)), testingutils.SSVMsgProposer( testingutils.TestingCommitMultiSignerMessageWithIdentifierAndFullData( @@ -114,7 +116,7 @@ func InvalidDecidedValue() tests.SpecTest { }, PostDutyRunnerStateRoot: "69a1c7fc8cbd3cc8d7aa6cfb4493f849e08df3bb37c218d88eee97e87044b810", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), }, ExpectedError: expectedErr, }, @@ -123,9 +125,9 @@ func InvalidDecidedValue() tests.SpecTest { Runner: testingutils.ProposerBlindedBlockRunner(ks), Duty: &testingutils.TestingProposerDuty, Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsg(ks.Shares[1], ks.Shares[1], 1, 1)), - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsg(ks.Shares[2], ks.Shares[2], 2, 2)), - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsg(ks.Shares[3], ks.Shares[3], 3, 3)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsgV(ks.Shares[1], ks.Shares[1], 1, 1, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsgV(ks.Shares[2], ks.Shares[2], 2, 2, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentSignerMsgV(ks.Shares[3], ks.Shares[3], 3, 3, spec.DataVersionBellatrix)), testingutils.SSVMsgProposer( testingutils.TestingCommitMultiSignerMessageWithIdentifierAndFullData( @@ -137,7 +139,7 @@ func InvalidDecidedValue() tests.SpecTest { }, PostDutyRunnerStateRoot: "cec247510f2c061613cf71cca2a343cc02ac1488cf2f6150f0b7b7787aff7fb3", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), }, ExpectedError: expectedErr, }, diff --git a/ssv/spectest/tests/runner/duties/newduty/decided.go b/ssv/spectest/tests/runner/duties/newduty/decided.go index b2b13178a..5f1ca6ace 100644 --- a/ssv/spectest/tests/runner/duties/newduty/decided.go +++ b/ssv/spectest/tests/runner/duties/newduty/decided.go @@ -1,6 +1,8 @@ package newduty import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" @@ -57,11 +59,11 @@ func PostDecided() tests.SpecTest { }, { Name: "proposer", - Runner: finishRunner(testingutils.ProposerRunner(ks), &testingutils.TestingProposerDutyNextEpoch), - Duty: &testingutils.TestingProposerDutyNextEpoch, + Runner: finishRunner(testingutils.ProposerRunner(ks), testingutils.TestingProposerDutyNextEpochV(spec.DataVersionBellatrix)), + Duty: testingutils.TestingProposerDutyNextEpochV(spec.DataVersionBellatrix), PostDutyRunnerStateRoot: "8bb7114ca6cb9d4247a2fc955e9c881f9c1909752a0f330270251dfaa52adcc3", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoNextEpochMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoNextEpochMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, }, { diff --git a/ssv/spectest/tests/runner/full_happy_flow.go b/ssv/spectest/tests/runner/full_happy_flow.go index 815a2c115..a74c8f8c1 100644 --- a/ssv/spectest/tests/runner/full_happy_flow.go +++ b/ssv/spectest/tests/runner/full_happy_flow.go @@ -3,6 +3,7 @@ package runner import ( "encoding/hex" + "github.com/attestantio/go-eth2-client/spec" ssz "github.com/ferranbt/fastssz" "github.com/bloxapp/ssv-spec/qbft" @@ -101,42 +102,42 @@ func FullHappyFlow() tests.SpecTest { { Name: "proposer", Runner: testingutils.ProposerRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: append( - testingutils.SSVDecidingMsgs(testingutils.TestProposerConsensusData, ks, types.BNRoleProposer), // consensus + testingutils.SSVDecidingMsgsV(testingutils.TestProposerConsensusDataV(spec.DataVersionBellatrix), ks, types.BNRoleProposer), // consensus []*types.SSVMessage{ // post consensus - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsg(ks.Shares[1], 1)), - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsg(ks.Shares[2], 2)), - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsg(ks.Shares[3], 3)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[2], 2, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[3], 3, spec.DataVersionBellatrix)), }..., ), - PostDutyRunnerStateRoot: fullHappyFlowProposerSC().Root(), // "76812c0f14ff09067547e9528730749b0c0090d1a4872689a0b8480d7b538884", - PostDutyRunnerState: fullHappyFlowProposerSC().ExpectedState, + PostDutyRunnerStateRoot: fullHappyFlowProposerSCV(spec.DataVersionBellatrix).Root(), // "76812c0f14ff09067547e9528730749b0c0090d1a4872689a0b8480d7b538884", + PostDutyRunnerState: fullHappyFlowProposerSCV(spec.DataVersionBellatrix).ExpectedState, OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), - testingutils.PostConsensusProposerMsg(ks.Shares[1], 1), + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), + testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), }, BeaconBroadcastedRoots: []string{ - getSSZRootNoError(testingutils.TestingSignedBeaconBlock(ks)), + getSSZRootNoError(testingutils.TestingSignedBeaconBlockV(ks, spec.DataVersionBellatrix)), }, }, { Name: "proposer blinded block", Runner: testingutils.ProposerBlindedBlockRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: append( - testingutils.SSVDecidingMsgs(testingutils.TestProposerBlindedBlockConsensusData, ks, types.BNRoleProposer), // consensus + testingutils.SSVDecidingMsgsV(testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionBellatrix), ks, types.BNRoleProposer), // consensus []*types.SSVMessage{ // post consensus - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsg(ks.Shares[1], 1)), - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsg(ks.Shares[2], 2)), - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsg(ks.Shares[3], 3)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[2], 2, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[3], 3, spec.DataVersionBellatrix)), }..., ), - PostDutyRunnerStateRoot: fullHappyFlowBlindedProposerSC().Root(), // "90755cc41b814519fd9fdd14bc82d239997ba51340c297f25f5f1552f27f66c7", - PostDutyRunnerState: fullHappyFlowBlindedProposerSC().ExpectedState, + PostDutyRunnerStateRoot: fullHappyFlowBlindedProposerSCV(spec.DataVersionBellatrix).Root(), // "90755cc41b814519fd9fdd14bc82d239997ba51340c297f25f5f1552f27f66c7", + PostDutyRunnerState: fullHappyFlowBlindedProposerSCV(spec.DataVersionBellatrix).ExpectedState, OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), - testingutils.PostConsensusProposerMsg(ks.Shares[1], 1), + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), + testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), }, BeaconBroadcastedRoots: []string{ getSSZRootNoError(testingutils.TestingSignedBeaconBlock(ks)), diff --git a/ssv/spectest/tests/runner/full_happy_flow_sc.go b/ssv/spectest/tests/runner/full_happy_flow_sc.go index ddf0a109a..bf9bc9025 100644 --- a/ssv/spectest/tests/runner/full_happy_flow_sc.go +++ b/ssv/spectest/tests/runner/full_happy_flow_sc.go @@ -8,18 +8,18 @@ import ( ssvcomparable "github.com/bloxapp/ssv-spec/ssv/spectest/comparable" "github.com/bloxapp/ssv-spec/types" "github.com/bloxapp/ssv-spec/types/testingutils" - typescomparable "github.com/bloxapp/ssv-spec/types/testingutils/comparable" + "github.com/bloxapp/ssv-spec/types/testingutils/comparable" ) // fullHappyFlowSyncCommitteeContributionSC returns state comparison object for the FullHappyFlow SyncCommitteeContribution spec test -func fullHappyFlowSyncCommitteeContributionSC() *typescomparable.StateComparison { +func fullHappyFlowSyncCommitteeContributionSC() *comparable.StateComparison { ks := testingutils.Testing4SharesSet() - return &typescomparable.StateComparison{ + return &comparable.StateComparison{ ExpectedState: func() types.Root { ret := testingutils.SyncCommitteeContributionRunner(ks) ret.GetBaseRunner().State = &ssv.State{ Finished: true, - DecidedValue: typescomparable.FixIssue178(testingutils.TestSyncCommitteeContributionConsensusData, spec.DataVersionPhase0), + DecidedValue: comparable.FixIssue178(testingutils.TestSyncCommitteeContributionConsensusData, spec.DataVersionPhase0), StartingDuty: &testingutils.TestSyncCommitteeContributionConsensusData.Duty, PreConsensusContainer: ssvcomparable.SetMessagesInContainer( ssv.NewPartialSigContainer(3), @@ -33,7 +33,7 @@ func fullHappyFlowSyncCommitteeContributionSC() *typescomparable.StateComparison }), } ret.GetBaseRunner().State.RunningInstance = &qbft.Instance{ - StartValue: typescomparable.NoErrorEncoding(typescomparable.FixIssue178(testingutils.TestSyncCommitteeContributionConsensusData, spec.DataVersionBellatrix)), + StartValue: comparable.NoErrorEncoding(comparable.FixIssue178(testingutils.TestSyncCommitteeContributionConsensusData, spec.DataVersionBellatrix)), State: &qbft.State{ Share: testingutils.TestingShare(testingutils.Testing4SharesSet()), ID: ret.GetBaseRunner().QBFTController.Identifier, @@ -50,7 +50,7 @@ func fullHappyFlowSyncCommitteeContributionSC() *typescomparable.StateComparison DecidedValue: testingutils.TestSyncCommitteeContributionConsensusDataByts, }, } - typescomparable.SetMessages( + comparable.SetMessages( ret.GetBaseRunner().State.RunningInstance, testingutils.SSVDecidingMsgs(testingutils.TestSyncCommitteeContributionConsensusData, ks, types.BNRoleSyncCommitteeContribution)[3:10], ) @@ -61,14 +61,14 @@ func fullHappyFlowSyncCommitteeContributionSC() *typescomparable.StateComparison } // fullHappyFlowSyncCommitteeSC returns state comparison object for the FullHappyFlow SyncCommittee spec test -func fullHappyFlowSyncCommitteeSC() *typescomparable.StateComparison { +func fullHappyFlowSyncCommitteeSC() *comparable.StateComparison { ks := testingutils.Testing4SharesSet() - return &typescomparable.StateComparison{ + return &comparable.StateComparison{ ExpectedState: func() types.Root { ret := testingutils.SyncCommitteeRunner(ks) ret.GetBaseRunner().State = &ssv.State{ Finished: true, - DecidedValue: typescomparable.FixIssue178(testingutils.TestSyncCommitteeConsensusData, spec.DataVersionPhase0), + DecidedValue: comparable.FixIssue178(testingutils.TestSyncCommitteeConsensusData, spec.DataVersionPhase0), StartingDuty: &testingutils.TestSyncCommitteeConsensusData.Duty, PreConsensusContainer: ssvcomparable.SetMessagesInContainer( ssv.NewPartialSigContainer(3), @@ -82,7 +82,7 @@ func fullHappyFlowSyncCommitteeSC() *typescomparable.StateComparison { }), } ret.GetBaseRunner().State.RunningInstance = &qbft.Instance{ - StartValue: typescomparable.NoErrorEncoding(testingutils.TestSyncCommitteeConsensusData), + StartValue: comparable.NoErrorEncoding(testingutils.TestSyncCommitteeConsensusData), State: &qbft.State{ Share: testingutils.TestingShare(testingutils.Testing4SharesSet()), ID: ret.GetBaseRunner().QBFTController.Identifier, @@ -99,7 +99,7 @@ func fullHappyFlowSyncCommitteeSC() *typescomparable.StateComparison { DecidedValue: testingutils.TestSyncCommitteeConsensusDataByts, }, } - typescomparable.SetMessages( + comparable.SetMessages( ret.GetBaseRunner().State.RunningInstance, testingutils.SSVDecidingMsgs(testingutils.TestSyncCommitteeConsensusData, ks, types.BNRoleSyncCommittee)[0:7], ) @@ -110,14 +110,14 @@ func fullHappyFlowSyncCommitteeSC() *typescomparable.StateComparison { } // fullHappyFlowAggregatorSC returns state comparison object for the FullHappyFlow Aggregator spec test -func fullHappyFlowAggregatorSC() *typescomparable.StateComparison { +func fullHappyFlowAggregatorSC() *comparable.StateComparison { ks := testingutils.Testing4SharesSet() - return &typescomparable.StateComparison{ + return &comparable.StateComparison{ ExpectedState: func() types.Root { ret := testingutils.AggregatorRunner(ks) ret.GetBaseRunner().State = &ssv.State{ Finished: true, - DecidedValue: typescomparable.FixIssue178(testingutils.TestAggregatorConsensusData, spec.DataVersionPhase0), + DecidedValue: comparable.FixIssue178(testingutils.TestAggregatorConsensusData, spec.DataVersionPhase0), StartingDuty: &testingutils.TestAggregatorConsensusData.Duty, PreConsensusContainer: ssvcomparable.SetMessagesInContainer( ssv.NewPartialSigContainer(3), @@ -131,7 +131,7 @@ func fullHappyFlowAggregatorSC() *typescomparable.StateComparison { }), } ret.GetBaseRunner().State.RunningInstance = &qbft.Instance{ - StartValue: typescomparable.NoErrorEncoding(testingutils.TestAggregatorConsensusData), + StartValue: comparable.NoErrorEncoding(testingutils.TestAggregatorConsensusData), State: &qbft.State{ Share: testingutils.TestingShare(testingutils.Testing4SharesSet()), ID: ret.GetBaseRunner().QBFTController.Identifier, @@ -148,7 +148,7 @@ func fullHappyFlowAggregatorSC() *typescomparable.StateComparison { DecidedValue: testingutils.TestAggregatorConsensusDataByts, }, } - typescomparable.SetMessages( + comparable.SetMessages( ret.GetBaseRunner().State.RunningInstance, testingutils.SSVDecidingMsgs(testingutils.TestAggregatorConsensusData, ks, types.BNRoleAggregator)[3:10], ) @@ -158,29 +158,32 @@ func fullHappyFlowAggregatorSC() *typescomparable.StateComparison { } } -// fullHappyFlowProposerSC returns state comparison object for the FullHappyFlow Proposer spec test -func fullHappyFlowProposerSC() *typescomparable.StateComparison { +// fullHappyFlowProposerSCV returns state comparison object for the FullHappyFlow Proposer versioned spec test +func fullHappyFlowProposerSCV(version spec.DataVersion) *comparable.StateComparison { ks := testingutils.Testing4SharesSet() - return &typescomparable.StateComparison{ + cd := testingutils.TestProposerConsensusDataV(version) + cdBytes := testingutils.TestProposerConsensusDataBytsV(version) + + return &comparable.StateComparison{ ExpectedState: func() types.Root { ret := testingutils.ProposerRunner(ks) ret.GetBaseRunner().State = &ssv.State{ Finished: true, - DecidedValue: typescomparable.FixIssue178(testingutils.TestProposerConsensusData, spec.DataVersionBellatrix), - StartingDuty: &testingutils.TestProposerConsensusData.Duty, + DecidedValue: comparable.FixIssue178(cd, version), + StartingDuty: &cd.Duty, PreConsensusContainer: ssvcomparable.SetMessagesInContainer( ssv.NewPartialSigContainer(3), - testingutils.SSVDecidingMsgs(testingutils.TestProposerConsensusData, ks, types.BNRoleProposer)[0:3]), + testingutils.SSVDecidingMsgs(cd, ks, types.BNRoleProposer)[0:3]), PostConsensusContainer: ssvcomparable.SetMessagesInContainer( ssv.NewPartialSigContainer(3), []*types.SSVMessage{ - testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusProposerMsg(ks.Shares[1], 1)), - testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusProposerMsg(ks.Shares[2], 2)), - testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusProposerMsg(ks.Shares[3], 3)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, version)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[2], 2, version)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[3], 3, version)), }), } ret.GetBaseRunner().State.RunningInstance = &qbft.Instance{ - StartValue: typescomparable.NoErrorEncoding(testingutils.TestProposerConsensusData), + StartValue: comparable.NoErrorEncoding(cd), State: &qbft.State{ Share: testingutils.TestingShare(testingutils.Testing4SharesSet()), ID: ret.GetBaseRunner().QBFTController.Identifier, @@ -189,17 +192,17 @@ func fullHappyFlowProposerSC() *typescomparable.StateComparison { ProposalAcceptedForCurrentRound: testingutils.TestingProposalMessageWithIdentifierAndFullData( ks.Shares[1], types.OperatorID(1), ret.GetBaseRunner().QBFTController.Identifier, - testingutils.TestProposerConsensusDataByts, + cdBytes, ), LastPreparedRound: 1, - LastPreparedValue: testingutils.TestProposerConsensusDataByts, + LastPreparedValue: cdBytes, Decided: true, - DecidedValue: testingutils.TestProposerConsensusDataByts, + DecidedValue: cdBytes, }, } - typescomparable.SetMessages( + comparable.SetMessages( ret.GetBaseRunner().State.RunningInstance, - testingutils.SSVDecidingMsgs(testingutils.TestProposerConsensusData, ks, types.BNRoleProposer)[3:10], + testingutils.SSVDecidingMsgs(cd, ks, types.BNRoleProposer)[3:10], ) ret.GetBaseRunner().QBFTController.StoredInstances = append(ret.GetBaseRunner().QBFTController.StoredInstances, ret.GetBaseRunner().State.RunningInstance) return ret @@ -207,29 +210,32 @@ func fullHappyFlowProposerSC() *typescomparable.StateComparison { } } -// fullHappyFlowBlindedProposerSC returns state comparison object for the FullHappyFlow BlindedProposer spec test -func fullHappyFlowBlindedProposerSC() *typescomparable.StateComparison { +// fullHappyFlowBlindedProposerSCV returns state comparison object for the FullHappyFlow BlindedProposer versioned spec test +func fullHappyFlowBlindedProposerSCV(version spec.DataVersion) *comparable.StateComparison { ks := testingutils.Testing4SharesSet() - return &typescomparable.StateComparison{ + cd := testingutils.TestProposerBlindedBlockConsensusDataV(version) + cdBytes := testingutils.TestProposerBlindedBlockConsensusDataBytsV(version) + + return &comparable.StateComparison{ ExpectedState: func() types.Root { ret := testingutils.ProposerBlindedBlockRunner(ks) ret.GetBaseRunner().State = &ssv.State{ Finished: true, - DecidedValue: typescomparable.FixIssue178(testingutils.TestProposerBlindedBlockConsensusData, spec.DataVersionBellatrix), - StartingDuty: &testingutils.TestProposerConsensusData.Duty, + DecidedValue: comparable.FixIssue178(cd, version), + StartingDuty: &testingutils.TestProposerConsensusDataV(version).Duty, PreConsensusContainer: ssvcomparable.SetMessagesInContainer( ssv.NewPartialSigContainer(3), - testingutils.SSVDecidingMsgs(testingutils.TestProposerBlindedBlockConsensusData, ks, types.BNRoleProposer)[0:3]), + testingutils.SSVDecidingMsgs(cd, ks, types.BNRoleProposer)[0:3]), PostConsensusContainer: ssvcomparable.SetMessagesInContainer( ssv.NewPartialSigContainer(3), []*types.SSVMessage{ - testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusProposerMsg(ks.Shares[1], 1)), - testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusProposerMsg(ks.Shares[2], 2)), - testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusProposerMsg(ks.Shares[3], 3)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, version)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[2], 2, version)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[3], 3, version)), }), } ret.GetBaseRunner().State.RunningInstance = &qbft.Instance{ - StartValue: typescomparable.NoErrorEncoding(testingutils.TestProposerBlindedBlockConsensusData), + StartValue: comparable.NoErrorEncoding(cd), State: &qbft.State{ Share: testingutils.TestingShare(testingutils.Testing4SharesSet()), ID: ret.GetBaseRunner().QBFTController.Identifier, @@ -238,17 +244,17 @@ func fullHappyFlowBlindedProposerSC() *typescomparable.StateComparison { ProposalAcceptedForCurrentRound: testingutils.TestingProposalMessageWithIdentifierAndFullData( ks.Shares[1], types.OperatorID(1), ret.GetBaseRunner().QBFTController.Identifier, - testingutils.TestProposerBlindedBlockConsensusDataByts, + cdBytes, ), LastPreparedRound: 1, - LastPreparedValue: testingutils.TestProposerBlindedBlockConsensusDataByts, + LastPreparedValue: cdBytes, Decided: true, - DecidedValue: testingutils.TestProposerBlindedBlockConsensusDataByts, + DecidedValue: cdBytes, }, } - typescomparable.SetMessages( + comparable.SetMessages( ret.GetBaseRunner().State.RunningInstance, - testingutils.SSVDecidingMsgs(testingutils.TestProposerBlindedBlockConsensusData, ks, types.BNRoleProposer)[3:10], + testingutils.SSVDecidingMsgs(cd, ks, types.BNRoleProposer)[3:10], ) ret.GetBaseRunner().QBFTController.StoredInstances = append(ret.GetBaseRunner().QBFTController.StoredInstances, ret.GetBaseRunner().State.RunningInstance) return ret @@ -257,14 +263,14 @@ func fullHappyFlowBlindedProposerSC() *typescomparable.StateComparison { } // fullHappyFlowAttesterSC returns state comparison object for the FullHappyFlow Attester spec test -func fullHappyFlowAttesterSC() *typescomparable.StateComparison { +func fullHappyFlowAttesterSC() *comparable.StateComparison { ks := testingutils.Testing4SharesSet() - return &typescomparable.StateComparison{ + return &comparable.StateComparison{ ExpectedState: func() types.Root { ret := testingutils.AttesterRunner(ks) ret.GetBaseRunner().State = &ssv.State{ Finished: true, - DecidedValue: typescomparable.FixIssue178(testingutils.TestAttesterConsensusData, spec.DataVersionPhase0), + DecidedValue: comparable.FixIssue178(testingutils.TestAttesterConsensusData, spec.DataVersionPhase0), StartingDuty: &testingutils.TestAttesterConsensusData.Duty, PreConsensusContainer: ssvcomparable.SetMessagesInContainer( ssv.NewPartialSigContainer(3), @@ -278,7 +284,7 @@ func fullHappyFlowAttesterSC() *typescomparable.StateComparison { }), } ret.GetBaseRunner().State.RunningInstance = &qbft.Instance{ - StartValue: typescomparable.NoErrorEncoding(testingutils.TestAttesterConsensusData), + StartValue: comparable.NoErrorEncoding(testingutils.TestAttesterConsensusData), State: &qbft.State{ Share: testingutils.TestingShare(testingutils.Testing4SharesSet()), ID: ret.GetBaseRunner().QBFTController.Identifier, @@ -295,7 +301,7 @@ func fullHappyFlowAttesterSC() *typescomparable.StateComparison { DecidedValue: testingutils.TestAttesterConsensusDataByts, }, } - typescomparable.SetMessages( + comparable.SetMessages( ret.GetBaseRunner().State.RunningInstance, testingutils.SSVDecidingMsgs(testingutils.TestAttesterConsensusData, ks, types.BNRoleAttester)[0:7], ) @@ -306,9 +312,9 @@ func fullHappyFlowAttesterSC() *typescomparable.StateComparison { } // fullHappyFlowValidatorRegistrationSC returns state comparison object for the FullHappyFlow ValidatorRegistration spec test -func fullHappyFlowValidatorRegistrationSC() *typescomparable.StateComparison { +func fullHappyFlowValidatorRegistrationSC() *comparable.StateComparison { ks := testingutils.Testing4SharesSet() - return &typescomparable.StateComparison{ + return &comparable.StateComparison{ ExpectedState: func() types.Root { ret := testingutils.ValidatorRegistrationRunner(ks) ret.GetBaseRunner().State = &ssv.State{ diff --git a/ssv/spectest/tests/runner/postconsensus/duplicate_msg_different_roots.go b/ssv/spectest/tests/runner/postconsensus/duplicate_msg_different_roots.go index dc4d6b126..4869258c8 100644 --- a/ssv/spectest/tests/runner/postconsensus/duplicate_msg_different_roots.go +++ b/ssv/spectest/tests/runner/postconsensus/duplicate_msg_different_roots.go @@ -1,6 +1,8 @@ package postconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" @@ -54,13 +56,13 @@ func DuplicateMsgDifferentRoots() tests.SpecTest { Name: "proposer", Runner: decideRunner( testingutils.ProposerRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsg(ks.Shares[1], 1)), - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongProposerMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "79dea0905cae233ecfaabdf8468351ea1c88d2684009176eb4a4d3e91823e74c", OutputMessages: []*types.SignedPartialSignatureMessage{}, @@ -72,13 +74,13 @@ func DuplicateMsgDifferentRoots() tests.SpecTest { Name: "proposer (blinded block)", Runner: decideRunner( testingutils.ProposerBlindedBlockRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerBlindedBlockConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsg(ks.Shares[1], 1)), - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongProposerMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "b57fb84140f2785ed05295d294271ab6636116f8cd013d8e9a060f47976dfe3d", OutputMessages: []*types.SignedPartialSignatureMessage{}, diff --git a/ssv/spectest/tests/runner/postconsensus/invalid_beacon_sig.go b/ssv/spectest/tests/runner/postconsensus/invalid_beacon_sig.go index 62bf33329..30c16d240 100644 --- a/ssv/spectest/tests/runner/postconsensus/invalid_beacon_sig.go +++ b/ssv/spectest/tests/runner/postconsensus/invalid_beacon_sig.go @@ -1,6 +1,8 @@ package postconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" @@ -52,12 +54,12 @@ func InvalidBeaconSignature() tests.SpecTest { Name: "proposer", Runner: decideRunner( testingutils.ProposerRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongSigProposerMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongSigProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "ff213af6f0bf2350bb37f48021c137dd5552b1c25cb5c6ebd0c1d27debf6080e", OutputMessages: []*types.SignedPartialSignatureMessage{}, @@ -69,12 +71,12 @@ func InvalidBeaconSignature() tests.SpecTest { Name: "proposer (blinded block)", Runner: decideRunner( testingutils.ProposerBlindedBlockRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerBlindedBlockConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionBellatrix), ), Duty: &testingutils.TestingProposerDuty, Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongSigProposerMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongSigProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "9b4524d5100835df4d71d0a1e559acdc33d541c44a746ebda115c5e7f3eaa85a", OutputMessages: []*types.SignedPartialSignatureMessage{}, diff --git a/ssv/spectest/tests/runner/postconsensus/invalid_msg_slot.go b/ssv/spectest/tests/runner/postconsensus/invalid_msg_slot.go index 8742536e0..5595c9867 100644 --- a/ssv/spectest/tests/runner/postconsensus/invalid_msg_slot.go +++ b/ssv/spectest/tests/runner/postconsensus/invalid_msg_slot.go @@ -1,6 +1,8 @@ package postconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" @@ -16,6 +18,11 @@ func InvalidMessageSlot() tests.SpecTest { return msg } + invalidateSlotV := func(msg *types.SignedPartialSignatureMessage, version spec.DataVersion) *types.SignedPartialSignatureMessage { + msg.Message.Slot = testingutils.TestingInvalidDutySlotV(version) + return msg + } + return &tests.MultiMsgProcessingSpecTest{ Name: "post consensus invalid msg slot", Tests: []*tests.MsgProcessingSpecTest{ @@ -57,12 +64,12 @@ func InvalidMessageSlot() tests.SpecTest { Name: "proposer", Runner: decideRunner( testingutils.ProposerRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, invalidateSlot(testingutils.PostConsensusProposerMsg(ks.Shares[1], 1))), + testingutils.SSVMsgProposer(nil, invalidateSlotV(testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "ff213af6f0bf2350bb37f48021c137dd5552b1c25cb5c6ebd0c1d27debf6080e", OutputMessages: []*types.SignedPartialSignatureMessage{}, @@ -74,12 +81,12 @@ func InvalidMessageSlot() tests.SpecTest { Name: "proposer (blinded block)", Runner: decideRunner( testingutils.ProposerBlindedBlockRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerBlindedBlockConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, invalidateSlot(testingutils.PostConsensusProposerMsg(ks.Shares[1], 1))), + testingutils.SSVMsgProposer(nil, invalidateSlotV(testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "9b4524d5100835df4d71d0a1e559acdc33d541c44a746ebda115c5e7f3eaa85a", OutputMessages: []*types.SignedPartialSignatureMessage{}, diff --git a/ssv/spectest/tests/runner/postconsensus/too_few_roots.go b/ssv/spectest/tests/runner/postconsensus/too_few_roots.go index d52b771f2..583a59fbb 100644 --- a/ssv/spectest/tests/runner/postconsensus/too_few_roots.go +++ b/ssv/spectest/tests/runner/postconsensus/too_few_roots.go @@ -1,6 +1,8 @@ package postconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" @@ -52,12 +54,12 @@ func TooFewRoots() tests.SpecTest { Name: "proposer", Runner: decideRunner( testingutils.ProposerRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerTooFewRootsMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerTooFewRootsMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "ff213af6f0bf2350bb37f48021c137dd5552b1c25cb5c6ebd0c1d27debf6080e", OutputMessages: []*types.SignedPartialSignatureMessage{}, @@ -69,12 +71,12 @@ func TooFewRoots() tests.SpecTest { Name: "proposer (blinded block)", Runner: decideRunner( testingutils.ProposerBlindedBlockRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerBlindedBlockConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerTooFewRootsMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerTooFewRootsMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "9b4524d5100835df4d71d0a1e559acdc33d541c44a746ebda115c5e7f3eaa85a", OutputMessages: []*types.SignedPartialSignatureMessage{}, diff --git a/ssv/spectest/tests/runner/postconsensus/too_many_roots.go b/ssv/spectest/tests/runner/postconsensus/too_many_roots.go index ddaf81ba4..22be470d5 100644 --- a/ssv/spectest/tests/runner/postconsensus/too_many_roots.go +++ b/ssv/spectest/tests/runner/postconsensus/too_many_roots.go @@ -1,6 +1,8 @@ package postconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" @@ -52,12 +54,12 @@ func TooManyRoots() tests.SpecTest { Name: "proposer", Runner: decideRunner( testingutils.ProposerRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerTooManyRootsMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerTooManyRootsMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "ff213af6f0bf2350bb37f48021c137dd5552b1c25cb5c6ebd0c1d27debf6080e", OutputMessages: []*types.SignedPartialSignatureMessage{}, @@ -69,12 +71,12 @@ func TooManyRoots() tests.SpecTest { Name: "proposer (blinded block)", Runner: decideRunner( testingutils.ProposerBlindedBlockRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerBlindedBlockConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerTooManyRootsMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerTooManyRootsMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "9b4524d5100835df4d71d0a1e559acdc33d541c44a746ebda115c5e7f3eaa85a", OutputMessages: []*types.SignedPartialSignatureMessage{}, diff --git a/ssv/spectest/tests/runner/postconsensus/unknown_signer.go b/ssv/spectest/tests/runner/postconsensus/unknown_signer.go index 2cec27d25..253d8e402 100644 --- a/ssv/spectest/tests/runner/postconsensus/unknown_signer.go +++ b/ssv/spectest/tests/runner/postconsensus/unknown_signer.go @@ -1,6 +1,8 @@ package postconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" @@ -52,12 +54,12 @@ func UnknownSigner() tests.SpecTest { Name: "proposer", Runner: decideRunner( testingutils.ProposerRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusSigProposerWrongBeaconSignerMsg(ks.Shares[1], 5, 5)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusSigProposerWrongBeaconSignerMsgV(ks.Shares[1], 5, 5, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "ff213af6f0bf2350bb37f48021c137dd5552b1c25cb5c6ebd0c1d27debf6080e", OutputMessages: []*types.SignedPartialSignatureMessage{}, @@ -69,12 +71,12 @@ func UnknownSigner() tests.SpecTest { Name: "proposer (blinded block)", Runner: decideRunner( testingutils.ProposerBlindedBlockRunner(ks), - &testingutils.TestingProposerDuty, - testingutils.TestProposerBlindedBlockConsensusData, + testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), + testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionBellatrix), ), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PostConsensusSigProposerWrongBeaconSignerMsg(ks.Shares[1], 5, 5)), + testingutils.SSVMsgProposer(nil, testingutils.PostConsensusSigProposerWrongBeaconSignerMsgV(ks.Shares[1], 5, 5, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "9b4524d5100835df4d71d0a1e559acdc33d541c44a746ebda115c5e7f3eaa85a", OutputMessages: []*types.SignedPartialSignatureMessage{}, diff --git a/ssv/spectest/tests/runner/pre_consensus_justifications/invalid_msg_type.go b/ssv/spectest/tests/runner/pre_consensus_justifications/invalid_msg_type.go index b397f0818..38a1d5365 100644 --- a/ssv/spectest/tests/runner/pre_consensus_justifications/invalid_msg_type.go +++ b/ssv/spectest/tests/runner/pre_consensus_justifications/invalid_msg_type.go @@ -15,7 +15,7 @@ func InvalidMsgType() tests.SpecTest { fullData, _ := obj.Encode() root, _ := qbft.HashDataRoot(fullData) msg := &qbft.Message{ - MsgType: qbft.PrepareMsgType, //invalid, qbft.ProposeMsgType expected + MsgType: qbft.PrepareMsgType, //invalid, qbft.ProposeMsgType expected Height: 1, Round: qbft.FirstRound, Identifier: id, diff --git a/ssv/spectest/tests/runner/pre_consensus_justifications/invalid_slot.go b/ssv/spectest/tests/runner/pre_consensus_justifications/invalid_slot.go index e45f2b049..1f21a479e 100644 --- a/ssv/spectest/tests/runner/pre_consensus_justifications/invalid_slot.go +++ b/ssv/spectest/tests/runner/pre_consensus_justifications/invalid_slot.go @@ -1,6 +1,8 @@ package pre_consensus_justifications import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" @@ -11,12 +13,7 @@ import ( func InvalidSlot() tests.SpecTest { ks := testingutils.Testing4SharesSet() - msgF := func(obj *types.ConsensusData, id []byte) *qbft.SignedMessage { - // change slot - if len(obj.PreConsensusJustifications) > 0 { - obj.PreConsensusJustifications[0].Message.Slot = testingutils.TestingDutySlot2 - } - + signedMsg := func(obj *types.ConsensusData, id []byte) *qbft.SignedMessage { fullData, _ := obj.Encode() root, _ := qbft.HashDataRoot(fullData) msg := &qbft.Message{ @@ -32,6 +29,22 @@ func InvalidSlot() tests.SpecTest { return signed } + msgF := func(obj *types.ConsensusData, id []byte) *qbft.SignedMessage { + // change slot + if len(obj.PreConsensusJustifications) > 0 { + obj.PreConsensusJustifications[0].Message.Slot = testingutils.TestingDutySlot2 + } + return signedMsg(obj, id) + } + + msgFV := func(obj *types.ConsensusData, id []byte) *qbft.SignedMessage { + // change slot + if len(obj.PreConsensusJustifications) > 0 { + obj.PreConsensusJustifications[0].Message.Slot = testingutils.TestingInvalidDutySlotV(obj.Version) + } + return signedMsg(obj, id) + } + expectedErr := "failed processing consensus message: invalid pre-consensus justification: invalid partial sig slot" return &tests.MultiMsgProcessingSpecTest{ @@ -66,26 +79,26 @@ func InvalidSlot() tests.SpecTest { { Name: "randao", Runner: decideFirstHeight(testingutils.ProposerRunner(ks)), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(msgF(testingutils.TestProposerWithJustificationsConsensusData(ks), testingutils.ProposerMsgID), nil), + testingutils.SSVMsgProposer(msgFV(testingutils.TestProposerWithJustificationsConsensusDataV(ks, spec.DataVersionBellatrix), testingutils.ProposerMsgID), nil), }, PostDutyRunnerStateRoot: "2754fc7ced14fb15f3f18556bb6b837620287cbbfbf908abafa5a0533fc4bc5f", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: expectedErr, }, { Name: "randao (blinded block)", Runner: decideFirstHeight(testingutils.ProposerBlindedBlockRunner(ks)), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(msgF(testingutils.TestProposerBlindedWithJustificationsConsensusData(ks), testingutils.ProposerMsgID), nil), + testingutils.SSVMsgProposer(msgF(testingutils.TestProposerBlindedWithJustificationsConsensusDataV(ks, spec.DataVersionBellatrix), testingutils.ProposerMsgID), nil), }, PostDutyRunnerStateRoot: "6bd59da9f817b8e40112e58231e36738b9d021db4416c9eeec1dd0236a5362e2", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: expectedErr, }, diff --git a/ssv/spectest/tests/runner/preconsensus/invalid_beacon_sig.go b/ssv/spectest/tests/runner/preconsensus/invalid_beacon_sig.go index 70a9038a2..df1092b49 100644 --- a/ssv/spectest/tests/runner/preconsensus/invalid_beacon_sig.go +++ b/ssv/spectest/tests/runner/preconsensus/invalid_beacon_sig.go @@ -1,6 +1,8 @@ package preconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" "github.com/bloxapp/ssv-spec/types/testingutils" @@ -41,26 +43,26 @@ func InvalidBeaconSignature() tests.SpecTest { { Name: "randao", Runner: testingutils.ProposerRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoWrongBeaconSigMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoWrongBeaconSigMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "56eafcb33392ded888a0fefe30ba49e52aa00ab36841cb10c9dc1aa2935af347", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: "failed processing randao message: invalid pre-consensus message: could not verify Beacon partial Signature: wrong signature", }, { Name: "randao (blinded block)", Runner: testingutils.ProposerBlindedBlockRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoWrongBeaconSigMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoWrongBeaconSigMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "2ce3241658f324f352c77909f4043934eedf38e939ae638c5ce6acf28e965646", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: "failed processing randao message: invalid pre-consensus message: could not verify Beacon partial Signature: wrong signature", }, diff --git a/ssv/spectest/tests/runner/preconsensus/invalid_expected_root.go b/ssv/spectest/tests/runner/preconsensus/invalid_expected_root.go index ce407fe5e..ca8bacd1a 100644 --- a/ssv/spectest/tests/runner/preconsensus/invalid_expected_root.go +++ b/ssv/spectest/tests/runner/preconsensus/invalid_expected_root.go @@ -1,6 +1,8 @@ package preconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" "github.com/bloxapp/ssv-spec/types/testingutils" @@ -41,26 +43,26 @@ func InvalidExpectedRoot() tests.SpecTest { { Name: "randao", Runner: testingutils.ProposerRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentEpochMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentEpochMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "56eafcb33392ded888a0fefe30ba49e52aa00ab36841cb10c9dc1aa2935af347", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: "failed processing randao message: invalid pre-consensus message: wrong signing root", }, { Name: "randao (blinded block)", Runner: testingutils.ProposerBlindedBlockRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentEpochMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoDifferentEpochMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "2ce3241658f324f352c77909f4043934eedf38e939ae638c5ce6acf28e965646", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: "failed processing randao message: invalid pre-consensus message: wrong signing root", }, diff --git a/ssv/spectest/tests/runner/preconsensus/too_few_roots.go b/ssv/spectest/tests/runner/preconsensus/too_few_roots.go index 19e2d56d3..963414429 100644 --- a/ssv/spectest/tests/runner/preconsensus/too_few_roots.go +++ b/ssv/spectest/tests/runner/preconsensus/too_few_roots.go @@ -1,6 +1,8 @@ package preconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" "github.com/bloxapp/ssv-spec/types/testingutils" @@ -41,26 +43,26 @@ func TooFewRoots() tests.SpecTest { { Name: "randao", Runner: testingutils.ProposerRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoTooFewRootsMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoTooFewRootsMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "56eafcb33392ded888a0fefe30ba49e52aa00ab36841cb10c9dc1aa2935af347", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: "failed processing randao message: invalid pre-consensus message: SignedPartialSignatureMessage invalid: no PartialSignatureMessages messages", }, { Name: "randao (blinded block)", Runner: testingutils.ProposerBlindedBlockRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoTooFewRootsMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoTooFewRootsMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "2ce3241658f324f352c77909f4043934eedf38e939ae638c5ce6acf28e965646", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: "failed processing randao message: invalid pre-consensus message: SignedPartialSignatureMessage invalid: no PartialSignatureMessages messages", }, diff --git a/ssv/spectest/tests/runner/preconsensus/too_many_roots.go b/ssv/spectest/tests/runner/preconsensus/too_many_roots.go index 4f0f6f1af..83b8be08a 100644 --- a/ssv/spectest/tests/runner/preconsensus/too_many_roots.go +++ b/ssv/spectest/tests/runner/preconsensus/too_many_roots.go @@ -1,6 +1,8 @@ package preconsensus import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/bloxapp/ssv-spec/ssv/spectest/tests" "github.com/bloxapp/ssv-spec/types" "github.com/bloxapp/ssv-spec/types/testingutils" @@ -41,26 +43,26 @@ func TooManyRoots() tests.SpecTest { { Name: "randao", Runner: testingutils.ProposerRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoTooManyRootsMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoTooManyRootsMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "56eafcb33392ded888a0fefe30ba49e52aa00ab36841cb10c9dc1aa2935af347", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: "failed processing randao message: invalid pre-consensus message: wrong expected roots count", }, { Name: "randao (blinded block)", Runner: testingutils.ProposerBlindedBlockRunner(ks), - Duty: &testingutils.TestingProposerDuty, + Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix), Messages: []*types.SSVMessage{ - testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoTooManyRootsMsg(ks.Shares[1], 1)), + testingutils.SSVMsgProposer(nil, testingutils.PreConsensusRandaoTooManyRootsMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)), }, PostDutyRunnerStateRoot: "2ce3241658f324f352c77909f4043934eedf38e939ae638c5ce6acf28e965646", OutputMessages: []*types.SignedPartialSignatureMessage{ - testingutils.PreConsensusRandaoMsg(ks.Shares[1], 1), // broadcasts when starting a new duty + testingutils.PreConsensusRandaoMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix), // broadcasts when starting a new duty }, ExpectedError: "failed processing randao message: invalid pre-consensus message: wrong expected roots count", }, diff --git a/types/testingutils/beacon_node.go b/types/testingutils/beacon_node.go index 75bb979f4..8a9c3baac 100644 --- a/types/testingutils/beacon_node.go +++ b/types/testingutils/beacon_node.go @@ -499,7 +499,15 @@ func (bn *TestingBeaconNode) SubmitAttestation(attestation *phase0.Attestation) // GetBeaconBlock returns beacon block by the given slot and committee index func (bn *TestingBeaconNode) GetBeaconBlock(slot phase0.Slot, committeeIndex phase0.CommitteeIndex, graffiti, randao []byte) (ssz.Marshaler, spec.DataVersion, error) { - return TestingBeaconBlock, spec.DataVersionBellatrix, nil + version := VersionBySlot(slot) + + switch version { + case spec.DataVersionBellatrix: + vBlk := TestingBeaconBlockV(version) + return vBlk.Bellatrix, version, nil + default: + panic("unsupported version") + } } // SubmitBeaconBlock submit the block to the node @@ -544,7 +552,15 @@ func (bn *TestingBeaconNode) SubmitBeaconBlock(block *spec.VersionedBeaconBlock, // GetBlindedBeaconBlock returns blinded beacon block by the given slot and committee index func (bn *TestingBeaconNode) GetBlindedBeaconBlock(slot phase0.Slot, committeeIndex phase0.CommitteeIndex, graffiti, randao []byte) (ssz.Marshaler, spec.DataVersion, error) { - return TestingBlindedBeaconBlock, spec.DataVersionBellatrix, nil + version := VersionBySlot(slot) + + switch version { + case spec.DataVersionBellatrix: + vBlk := TestingBlindedBeaconBlockV(version) + return vBlk.Bellatrix, version, nil + default: + panic("unsupported version") + } } // SubmitBlindedBeaconBlock submit the blinded block to the node diff --git a/types/testingutils/beacon_node_versioned.go b/types/testingutils/beacon_node_versioned.go new file mode 100644 index 000000000..69a40df21 --- /dev/null +++ b/types/testingutils/beacon_node_versioned.go @@ -0,0 +1,181 @@ +package testingutils + +import ( + "github.com/attestantio/go-eth2-client/api" + "github.com/attestantio/go-eth2-client/spec" + "github.com/attestantio/go-eth2-client/spec/bellatrix" + "github.com/attestantio/go-eth2-client/spec/phase0" + ssz "github.com/ferranbt/fastssz" + + "github.com/bloxapp/ssv-spec/types" +) + +const ( + // ForkSlotCapella taken from https://github.com/ethereum/consensus-specs/blob/1c424d76eddbacae3cbffed8276264b46951456b/specs/capella/fork.md?plain=1#L30 + ForkSlotCapella = 6209536 // Epoch(194048) + // TestingDutySlotBellatrix keeping this value to not break the test roots + TestingDutySlotBellatrix = 12 + TestingDutySlotBellatrixNextEpoch = 50 + TestingDutySlotBellatrixInvalid = 50 +) + +var TestingBeaconBlockV = func(version spec.DataVersion) *spec.VersionedBeaconBlock { + switch version { + case spec.DataVersionBellatrix: + return &spec.VersionedBeaconBlock{ + Version: version, + Bellatrix: TestingBeaconBlock, + } + default: + panic("unsupported version") + } +} + +var TestingBeaconBlockBytesV = func(version spec.DataVersion) []byte { + var ret []byte + vBlk := TestingBeaconBlockV(version) + if vBlk.IsEmpty() { + panic("empty block") + } + + switch version { + case spec.DataVersionBellatrix: + ret, _ = vBlk.Bellatrix.MarshalSSZ() + + default: + panic("unsupported version") + } + + return ret +} + +var TestingBlindedBeaconBlockV = func(version spec.DataVersion) *api.VersionedBlindedBeaconBlock { + switch version { + case spec.DataVersionBellatrix: + return &api.VersionedBlindedBeaconBlock{ + Version: version, + Bellatrix: TestingBlindedBeaconBlock, + } + default: + panic("unsupported version") + } +} + +var TestingBlindedBeaconBlockBytesV = func(version spec.DataVersion) []byte { + var ret []byte + vBlk := TestingBlindedBeaconBlockV(version) + if vBlk.IsEmpty() { + panic("empty block") + } + + switch version { + case spec.DataVersionBellatrix: + ret, _ = vBlk.Bellatrix.MarshalSSZ() + + default: + panic("unsupported version") + } + + return ret +} + +var TestingWrongBeaconBlockV = func(version spec.DataVersion) *spec.VersionedBeaconBlock { + blkByts := TestingBeaconBlockBytesV(version) + + switch version { + case spec.DataVersionBellatrix: + ret := &bellatrix.BeaconBlock{} + if err := ret.UnmarshalSSZ(blkByts); err != nil { + panic(err.Error()) + } + ret.Slot = 100 + return &spec.VersionedBeaconBlock{ + Version: version, + Bellatrix: ret, + } + + default: + panic("unsupported version") + } +} + +var TestingSignedBeaconBlockV = func(ks *TestKeySet, version spec.DataVersion) ssz.HashRoot { + vBlk := TestingBeaconBlockV(version) + if vBlk.IsEmpty() { + panic("empty block") + } + + switch version { + case spec.DataVersionBellatrix: + return &bellatrix.SignedBeaconBlock{ + Message: vBlk.Bellatrix, + Signature: signBeaconObject(vBlk.Bellatrix, types.DomainProposer, ks), + } + + default: + panic("unsupported version") + } +} + +var VersionBySlot = func(slot phase0.Slot) spec.DataVersion { + if slot < ForkSlotCapella { + return spec.DataVersionBellatrix + } + return spec.DataVersionCapella +} + +var TestingProposerDutyV = func(version spec.DataVersion) *types.Duty { + duty := &types.Duty{ + Type: types.BNRoleProposer, + PubKey: TestingValidatorPubKey, + ValidatorIndex: TestingValidatorIndex, + // ISSUE 233: We are initializing unused struct fields here + CommitteeIndex: 3, + CommitteesAtSlot: 36, + CommitteeLength: 128, + ValidatorCommitteeIndex: 11, + } + + switch version { + case spec.DataVersionBellatrix: + duty.Slot = TestingDutySlotBellatrix + + default: + panic("unsupported version") + } + + return duty +} + +var TestingProposerDutyNextEpochV = func(version spec.DataVersion) *types.Duty { + duty := &types.Duty{ + Type: types.BNRoleProposer, + PubKey: TestingValidatorPubKey, + ValidatorIndex: TestingValidatorIndex, + // ISSUE 233: We are initializing unused struct fields here + CommitteeIndex: 3, + CommitteesAtSlot: 36, + CommitteeLength: 128, + ValidatorCommitteeIndex: 11, + } + + switch version { + case spec.DataVersionBellatrix: + duty.Slot = TestingDutySlotBellatrixNextEpoch + + default: + panic("unsupported version") + } + + return duty +} + +var TestingInvalidDutySlotV = func(version spec.DataVersion) phase0.Slot { + switch version { + case spec.DataVersionBellatrix: + return TestingDutySlotBellatrixInvalid + + default: + panic("unsupported version") + } +} diff --git a/types/testingutils/runner_versioned.go b/types/testingutils/runner_versioned.go new file mode 100644 index 000000000..148ec63b2 --- /dev/null +++ b/types/testingutils/runner_versioned.go @@ -0,0 +1,53 @@ +package testingutils + +import ( + "github.com/bloxapp/ssv-spec/qbft" + "github.com/bloxapp/ssv-spec/types" +) + +var SSVDecidingMsgsV = func(consensusData *types.ConsensusData, ks *TestKeySet, role types.BeaconRole) []*types.SSVMessage { + id := types.NewMsgID(TestingSSVDomainType, TestingValidatorPubKey[:], role) + + ssvMsgF := func(qbftMsg *qbft.SignedMessage, partialSigMsg *types.SignedPartialSignatureMessage) *types.SSVMessage { + var byts []byte + var msgType types.MsgType + if partialSigMsg != nil { + msgType = types.SSVPartialSignatureMsgType + byts, _ = partialSigMsg.Encode() + } else { + msgType = types.SSVConsensusMsgType + byts, _ = qbftMsg.Encode() + } + + return &types.SSVMessage{ + MsgType: msgType, + MsgID: id, + Data: byts, + } + } + + // pre consensus msgs + base := make([]*types.SSVMessage, 0) + if role == types.BNRoleProposer { + for i := uint64(1); i <= ks.Threshold; i++ { + base = append(base, ssvMsgF(nil, PreConsensusRandaoMsgV(ks.Shares[types.OperatorID(i)], types.OperatorID(i), consensusData.Version))) + } + } + if role == types.BNRoleAggregator { + for i := uint64(1); i <= ks.Threshold; i++ { + base = append(base, ssvMsgF(nil, PreConsensusSelectionProofMsg(ks.Shares[types.OperatorID(i)], ks.Shares[types.OperatorID(i)], types.OperatorID(i), types.OperatorID(i)))) + } + } + if role == types.BNRoleSyncCommitteeContribution { + for i := uint64(1); i <= ks.Threshold; i++ { + base = append(base, ssvMsgF(nil, PreConsensusContributionProofMsg(ks.Shares[types.OperatorID(i)], ks.Shares[types.OperatorID(i)], types.OperatorID(i), types.OperatorID(i)))) + } + } + + // consensus and post consensus + qbftMsgs := DecidingMsgsForHeight(consensusData, id[:], qbft.FirstHeight, ks) + for _, msg := range qbftMsgs { + base = append(base, ssvMsgF(msg, nil)) + } + return base +} diff --git a/types/testingutils/ssv_msgs.go b/types/testingutils/ssv_msgs.go index f9b32788e..50ffcedb3 100644 --- a/types/testingutils/ssv_msgs.go +++ b/types/testingutils/ssv_msgs.go @@ -2,13 +2,15 @@ package testingutils import ( "crypto/sha256" - spec2 "github.com/attestantio/go-eth2-client/spec" + + "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair" "github.com/attestantio/go-eth2-client/spec/bellatrix" - spec "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/herumi/bls-eth-go-binary/bls" + "github.com/bloxapp/ssv-spec/qbft" "github.com/bloxapp/ssv-spec/types" - "github.com/herumi/bls-eth-go-binary/bls" ) var TestingSSVDomainType = types.V3Testnet @@ -52,7 +54,7 @@ var TestAggregatorConsensusDataByts, _ = TestAggregatorConsensusData.Encode() var TestProposerConsensusData = &types.ConsensusData{ Duty: TestingProposerDuty, - Version: spec2.DataVersionBellatrix, + Version: spec.DataVersionBellatrix, DataSSZ: TestingBeaconBlockBytes, } var TestProposerConsensusDataByts, _ = TestProposerConsensusData.Encode() @@ -65,7 +67,7 @@ var TestAttesterWithJustificationsConsensusData = func(ks *TestKeySet) *types.Co return &types.ConsensusData{ Duty: TestingAttesterDuty, - Version: spec2.DataVersionBellatrix, + Version: spec.DataVersionBellatrix, PreConsensusJustifications: justif, DataSSZ: TestingAttestationDataBytes, } @@ -80,7 +82,7 @@ var TestSyncCommitteeWithJustificationsConsensusData = func(ks *TestKeySet) *typ return &types.ConsensusData{ Duty: TestingSyncCommitteeDuty, - Version: spec2.DataVersionBellatrix, + Version: spec.DataVersionBellatrix, PreConsensusJustifications: justif, DataSSZ: TestingSyncCommitteeBlockRoot[:], } @@ -94,7 +96,7 @@ var TestProposerWithJustificationsConsensusData = func(ks *TestKeySet) *types.Co return &types.ConsensusData{ Duty: TestingProposerDuty, - Version: spec2.DataVersionBellatrix, + Version: spec.DataVersionBellatrix, PreConsensusJustifications: justif, DataSSZ: TestingBeaconBlockBytes, } @@ -108,7 +110,7 @@ var TestProposerBlindedWithJustificationsConsensusData = func(ks *TestKeySet) *t return &types.ConsensusData{ Duty: TestingProposerDuty, - Version: spec2.DataVersionBellatrix, + Version: spec.DataVersionBellatrix, PreConsensusJustifications: justif, DataSSZ: TestingBlindedBeaconBlockBytes, } @@ -116,9 +118,10 @@ var TestProposerBlindedWithJustificationsConsensusData = func(ks *TestKeySet) *t var TestProposerBlindedBlockConsensusData = &types.ConsensusData{ Duty: TestingProposerDuty, - Version: spec2.DataVersionBellatrix, + Version: spec.DataVersionBellatrix, DataSSZ: TestingBlindedBeaconBlockBytes, } + var TestProposerBlindedBlockConsensusDataByts, _ = TestProposerBlindedBlockConsensusData.Encode() var TestSyncCommitteeConsensusData = &types.ConsensusData{ @@ -365,7 +368,7 @@ var postConsensusBeaconBlockMsg = func( if wrongBeaconSig { sig, root, _ = signer.SignBeaconObject(block, d, Testing7SharesSet().ValidatorPK.Serialize(), types.DomainProposer) } - blsSig := spec.BLSSignature{} + blsSig := phase0.BLSSignature{} copy(blsSig[:], sig) signed := bellatrix.SignedBeaconBlock{ @@ -479,7 +482,7 @@ var randaoMsg = func( sk *bls.SecretKey, id types.OperatorID, wrongRoot bool, - epoch spec.Epoch, + epoch phase0.Epoch, msgCnt int, wrongBeaconSig bool, ) *types.SignedPartialSignatureMessage { @@ -536,7 +539,7 @@ var PreConsensusSelectionProofTooFewRootsMsg = func(msgSK, beaconSK *bls.SecretK return selectionProofMsg(msgSK, beaconSK, msgID, beaconID, TestingDutySlot, TestingDutySlot, 0, false) } -var PreConsensusCustomSlotSelectionProofMsg = func(msgSK, beaconSK *bls.SecretKey, msgID, beaconID types.OperatorID, slot spec.Slot) *types.SignedPartialSignatureMessage { +var PreConsensusCustomSlotSelectionProofMsg = func(msgSK, beaconSK *bls.SecretKey, msgID, beaconID types.OperatorID, slot phase0.Slot) *types.SignedPartialSignatureMessage { return selectionProofMsg(msgSK, beaconSK, msgID, beaconID, slot, TestingDutySlot, 1, false) } @@ -552,7 +555,7 @@ var TestSelectionProofWithJustificationsConsensusData = func(ks *TestKeySet) *ty return &types.ConsensusData{ Duty: TestingAggregatorDuty, - Version: spec2.DataVersionBellatrix, + Version: spec.DataVersionBellatrix, PreConsensusJustifications: justif, DataSSZ: TestingAggregateAndProofBytes, } @@ -563,8 +566,8 @@ var selectionProofMsg = func( beaconsk *bls.SecretKey, id types.OperatorID, beaconid types.OperatorID, - slot spec.Slot, - msgSlot spec.Slot, + slot phase0.Slot, + msgSlot phase0.Slot, msgCnt int, wrongBeaconSig bool, ) *types.SignedPartialSignatureMessage { @@ -619,7 +622,7 @@ var validatorRegistrationMsg = func( id, beaconID types.OperatorID, msgCnt int, wrongRoot bool, - epoch spec.Epoch, + epoch phase0.Epoch, wrongBeaconSig bool, ) *types.SignedPartialSignatureMessage { signer := NewTestingKeyManager() @@ -856,7 +859,7 @@ var PreConsensusContributionProofNextEpochMsg = func(msgSK, beaconSK *bls.Secret return contributionProofMsg(msgSK, beaconSK, msgID, beaconID, TestingDutySlot2, TestingDutySlot2, false, false) } -var PreConsensusCustomSlotContributionProofMsg = func(msgSK, beaconSK *bls.SecretKey, msgID, beaconID types.OperatorID, slot spec.Slot) *types.SignedPartialSignatureMessage { +var PreConsensusCustomSlotContributionProofMsg = func(msgSK, beaconSK *bls.SecretKey, msgID, beaconID types.OperatorID, slot phase0.Slot) *types.SignedPartialSignatureMessage { return contributionProofMsg(msgSK, beaconSK, msgID, beaconID, slot, TestingDutySlot, false, false) } @@ -875,7 +878,7 @@ var TestContributionProofWithJustificationsConsensusData = func(ks *TestKeySet) return &types.ConsensusData{ Duty: TestingSyncCommitteeContributionDuty, - Version: spec2.DataVersionBellatrix, + Version: spec.DataVersionBellatrix, PreConsensusJustifications: justif, DataSSZ: TestingContributionsDataBytes, } @@ -916,8 +919,8 @@ var PreConsensusContributionProofTooFewRootsMsg = func(msgSK, beaconSK *bls.Secr var contributionProofMsg = func( sk, beaconsk *bls.SecretKey, id, beaconid types.OperatorID, - slot spec.Slot, - msgSlot spec.Slot, + slot phase0.Slot, + msgSlot phase0.Slot, wrongMsgOrder bool, wrongBeaconSig bool, ) *types.SignedPartialSignatureMessage { @@ -927,7 +930,7 @@ var contributionProofMsg = func( msgs := make([]*types.PartialSignatureMessage, 0) for index := range TestingContributionProofIndexes { - subnet, _ := beacon.SyncCommitteeSubnetID(spec.CommitteeIndex(index)) + subnet, _ := beacon.SyncCommitteeSubnetID(phase0.CommitteeIndex(index)) data := &altair.SyncAggregatorSelectionData{ Slot: slot, SubcommitteeIndex: subnet, @@ -1025,7 +1028,7 @@ var PostConsensusSigSyncCommitteeContributionWrongSignerMsg = func(sk *bls.Secre var postConsensusSyncCommitteeContributionMsg = func( sk *bls.SecretKey, id types.OperatorID, - validatorIndex spec.ValidatorIndex, + validatorIndex phase0.ValidatorIndex, keySet *TestKeySet, wrongRoot bool, wrongBeaconSig bool, diff --git a/types/testingutils/ssv_msgs_versioned.go b/types/testingutils/ssv_msgs_versioned.go new file mode 100644 index 000000000..12b4bfc2a --- /dev/null +++ b/types/testingutils/ssv_msgs_versioned.go @@ -0,0 +1,263 @@ +package testingutils + +import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/herumi/bls-eth-go-binary/bls" + + "github.com/bloxapp/ssv-spec/types" +) + +var TestProposerConsensusDataV = func(version spec.DataVersion) *types.ConsensusData { + duty := TestingProposerDutyV(version) + return &types.ConsensusData{ + Duty: *duty, + Version: version, + DataSSZ: TestingBeaconBlockBytesV(version), + } +} + +var TestProposerConsensusDataBytsV = func(version spec.DataVersion) []byte { + cd := TestProposerConsensusDataV(version) + byts, _ := cd.Encode() + return byts +} + +var TestProposerWithJustificationsConsensusDataV = func(ks *TestKeySet, version spec.DataVersion) *types.ConsensusData { + justif := make([]*types.SignedPartialSignatureMessage, 0) + for i := uint64(0); i <= ks.Threshold; i++ { + justif = append(justif, PreConsensusRandaoMsgV(ks.Shares[i+1], i+1, version)) + } + + cd := TestProposerConsensusDataV(version) + cd.PreConsensusJustifications = justif + return cd +} + +var TestProposerBlindedWithJustificationsConsensusDataV = func(ks *TestKeySet, version spec.DataVersion) *types.ConsensusData { + justif := make([]*types.SignedPartialSignatureMessage, 0) + for i := uint64(0); i <= ks.Threshold; i++ { + justif = append(justif, PreConsensusRandaoMsgV(ks.Shares[i+1], i+1, version)) + } + + cd := TestProposerBlindedBlockConsensusDataV(version) + cd.PreConsensusJustifications = justif + return cd +} + +var TestProposerBlindedBlockConsensusDataV = func(version spec.DataVersion) *types.ConsensusData { + return &types.ConsensusData{ + Duty: *TestingProposerDutyV(version), + Version: version, + DataSSZ: TestingBlindedBeaconBlockBytesV(version), + } +} + +var TestProposerBlindedBlockConsensusDataBytsV = func(version spec.DataVersion) []byte { + cd := TestProposerBlindedBlockConsensusDataV(version) + byts, _ := cd.Encode() + return byts +} + +var PostConsensusProposerMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return postConsensusBeaconBlockMsgV(sk, id, false, false, version) +} + +var PostConsensusProposerTooManyRootsMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + ret := postConsensusBeaconBlockMsgV(sk, id, false, false, version) + ret.Message.Messages = append(ret.Message.Messages, ret.Message.Messages[0]) + + msg := &types.PartialSignatureMessages{ + Type: types.PostConsensusPartialSig, + Slot: TestingProposerDutyV(version).Slot, + Messages: ret.Message.Messages, + } + + sig, _ := NewTestingKeyManager().SignRoot(msg, types.PartialSignatureType, sk.GetPublicKey().Serialize()) + return &types.SignedPartialSignatureMessage{ + Message: *msg, + Signature: sig, + Signer: id, + } +} + +var PostConsensusProposerTooFewRootsMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + msg := &types.PartialSignatureMessages{ + Type: types.PostConsensusPartialSig, + Slot: TestingProposerDutyV(version).Slot, + Messages: []*types.PartialSignatureMessage{}, + } + + sig, _ := NewTestingKeyManager().SignRoot(msg, types.PartialSignatureType, sk.GetPublicKey().Serialize()) + return &types.SignedPartialSignatureMessage{ + Message: *msg, + Signature: sig, + Signer: id, + } +} + +var PostConsensusWrongProposerMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return postConsensusBeaconBlockMsgV(sk, id, true, false, version) +} + +var PostConsensusWrongSigProposerMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return postConsensusBeaconBlockMsgV(sk, id, false, true, version) +} + +var PostConsensusSigProposerWrongBeaconSignerMsgV = func(sk *bls.SecretKey, id, beaconSigner types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + ret := postConsensusBeaconBlockMsgV(sk, beaconSigner, false, true, version) + ret.Signer = id + return ret +} + +var postConsensusBeaconBlockMsgV = func( + sk *bls.SecretKey, + id types.OperatorID, + wrongRoot bool, + wrongBeaconSig bool, + version spec.DataVersion, +) *types.SignedPartialSignatureMessage { + signer := NewTestingKeyManager() + beacon := NewTestingBeaconNode() + + var root phase0.Root + var err error + if wrongRoot { + blk := TestingWrongBeaconBlockV(version) + root, err = blk.Root() + } else { + blk := TestingBeaconBlockV(version) + root, err = blk.Root() + } + if err != nil { + panic(err) + } + hashRoot := types.SSZ32Bytes(root) + + d, _ := beacon.DomainData(1, types.DomainProposer) // epoch doesn't matter here, hard coded + sig, root, _ := signer.SignBeaconObject(hashRoot, d, sk.GetPublicKey().Serialize(), types.DomainProposer) + if wrongBeaconSig { + sig, root, _ = signer.SignBeaconObject(hashRoot, d, Testing7SharesSet().ValidatorPK.Serialize(), types.DomainProposer) + } + blsSig := phase0.BLSSignature{} + copy(blsSig[:], sig) + + msgs := types.PartialSignatureMessages{ + Type: types.PostConsensusPartialSig, + Slot: TestingProposerDutyV(version).Slot, + Messages: []*types.PartialSignatureMessage{ + { + PartialSignature: blsSig[:], + SigningRoot: root, + Signer: id, + }, + }, + } + msgSig, _ := signer.SignRoot(msgs, types.PartialSignatureType, sk.GetPublicKey().Serialize()) + return &types.SignedPartialSignatureMessage{ + Message: msgs, + Signature: msgSig, + Signer: id, + } +} + +var PreConsensusRandaoMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return randaoMsgV(sk, id, false, TestingDutyEpoch, 1, false, version) +} + +// PreConsensusRandaoNextEpochMsgV testing for a second duty start +var PreConsensusRandaoNextEpochMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return randaoMsgV(sk, id, false, TestingDutyEpoch2, 1, false, version) +} + +var PreConsensusRandaoDifferentEpochMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return randaoMsgV(sk, id, false, TestingDutyEpoch+1, 1, false, version) +} + +var PreConsensusRandaoTooManyRootsMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return randaoMsgV(sk, id, false, TestingDutyEpoch, 2, false, version) +} + +var PreConsensusRandaoTooFewRootsMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return randaoMsgV(sk, id, false, TestingDutyEpoch, 0, false, version) +} + +var PreConsensusRandaoNoMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return randaoMsgV(sk, id, false, TestingDutyEpoch, 0, false, version) +} + +var PreConsensusRandaoWrongBeaconSigMsgV = func(sk *bls.SecretKey, id types.OperatorID, version spec.DataVersion) *types.SignedPartialSignatureMessage { + return randaoMsgV(sk, id, false, TestingDutyEpoch, 1, true, version) +} + +var PreConsensusRandaoDifferentSignerMsgV = func( + msgSigner, randaoSigner *bls.SecretKey, + msgSignerID, + randaoSignerID types.OperatorID, + version spec.DataVersion, +) *types.SignedPartialSignatureMessage { + signer := NewTestingKeyManager() + beacon := NewTestingBeaconNode() + d, _ := beacon.DomainData(TestingDutyEpoch, types.DomainRandao) + signed, root, _ := signer.SignBeaconObject(types.SSZUint64(TestingDutyEpoch), d, randaoSigner.GetPublicKey().Serialize(), types.DomainRandao) + + msg := types.PartialSignatureMessages{ + Type: types.RandaoPartialSig, + Slot: TestingProposerDutyV(version).Slot, + Messages: []*types.PartialSignatureMessage{ + { + PartialSignature: signed[:], + SigningRoot: root, + Signer: randaoSignerID, + }, + }, + } + sig, _ := signer.SignRoot(msg, types.PartialSignatureType, msgSigner.GetPublicKey().Serialize()) + return &types.SignedPartialSignatureMessage{ + Message: msg, + Signature: sig, + Signer: msgSignerID, + } +} + +var randaoMsgV = func( + sk *bls.SecretKey, + id types.OperatorID, + wrongRoot bool, + epoch phase0.Epoch, + msgCnt int, + wrongBeaconSig bool, + version spec.DataVersion, +) *types.SignedPartialSignatureMessage { + signer := NewTestingKeyManager() + beacon := NewTestingBeaconNode() + d, _ := beacon.DomainData(epoch, types.DomainRandao) + signed, root, _ := signer.SignBeaconObject(types.SSZUint64(epoch), d, sk.GetPublicKey().Serialize(), types.DomainRandao) + if wrongBeaconSig { + signed, root, _ = signer.SignBeaconObject(types.SSZUint64(TestingDutyEpoch), d, Testing7SharesSet().ValidatorPK.Serialize(), types.DomainRandao) + } + + msgs := types.PartialSignatureMessages{ + Type: types.RandaoPartialSig, + Slot: TestingProposerDutyV(version).Slot, + Messages: []*types.PartialSignatureMessage{}, + } + for i := 0; i < msgCnt; i++ { + msg := &types.PartialSignatureMessage{ + PartialSignature: signed[:], + SigningRoot: root, + Signer: id, + } + if wrongRoot { + msg.SigningRoot = [32]byte{} + } + msgs.Messages = append(msgs.Messages, msg) + } + + sig, _ := signer.SignRoot(msgs, types.PartialSignatureType, sk.GetPublicKey().Serialize()) + return &types.SignedPartialSignatureMessage{ + Message: msgs, + Signature: sig, + Signer: id, + } +}