Skip to content

Commit

Permalink
Spec - create validator-registration struct with gas limit (#516)
Browse files Browse the repository at this point in the history
* chore: receive full validator-registration struct instead of recreating it to allow the runner to manage the gas limit instead of beacon client

* use duty slot instead of first slot of epoch

* fix tests to store the SignedValidatorRegistration obj

* generate JSON tests

* add wrongly removed test cases

* delete get share

---------

Co-authored-by: MatheusFranco99 <[email protected]>
Co-authored-by: Gal Rogozinski <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent 4066ef0 commit 0ee2749
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 44 deletions.
Binary file modified ssv/spectest/generate/tests.json.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion ssv/spectest/tests/runner/consensus/invalid_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func InvalidSignature() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func SignersAndSignaturesWithDifferentLength() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func EmptySignature() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func NilSSVMessage() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func NoSignatures() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func NoSigners() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func NonUniqueSigners() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func ZeroSigner() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
2 changes: 1 addition & 1 deletion ssv/spectest/tests/runner/consensus/valid_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func ValidMessage() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: "no consensus phase for validator registration",
},
Expand Down
2 changes: 1 addition & 1 deletion ssv/spectest/tests/runner/full_happy_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func FullHappyFlow() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func InvalidMessageSlot() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: "no post consensus phase for validator registration",
},
Expand Down
2 changes: 1 addition & 1 deletion ssv/spectest/tests/runner/postconsensus/valid_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func ValidMessage() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: "no post consensus phase for validator registration",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func InvalidQuorumThenValidQuorum() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: expectedError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func InvalidThenQuorum() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion ssv/spectest/tests/runner/preconsensus/post_quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func PostQuorum() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
ExpectedError: "failed processing validator registration message: invalid pre-consensus message: no running duty",
},
Expand Down
2 changes: 1 addition & 1 deletion ssv/spectest/tests/runner/preconsensus/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Quorum() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func Quorum10Operators() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func Quorum13Operators() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Quorum7Operators() tests.SpecTest {
testingutils.PreConsensusValidatorRegistrationMsg(ks.Shares[1], 1), // broadcasts when starting a new duty
},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingValidatorRegistration),
testingutils.GetSSZRootNoError(testingutils.TestingSignedValidatorRegistration(ks)),
},
},
{
Expand Down
3 changes: 1 addition & 2 deletions ssv/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/attestantio/go-eth2-client/api"
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/phase0"
ssz "github.com/ferranbt/fastssz"

Expand Down Expand Up @@ -76,7 +75,7 @@ type SyncCommitteeContributionCalls interface {
// ValidatorRegistrationCalls interface has all validator registration duty specific calls
type ValidatorRegistrationCalls interface {
// SubmitValidatorRegistration submits a validator registration
SubmitValidatorRegistration(pubkey []byte, feeRecipient bellatrix.ExecutionAddress, sig phase0.BLSSignature) error
SubmitValidatorRegistration(registration *api.VersionedSignedValidatorRegistration) error
}

// VoluntaryExitCalls interface has all validator voluntary exit duty specific calls
Expand Down
34 changes: 23 additions & 11 deletions ssv/validator_registration.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ssv

import (
"github.com/attestantio/go-eth2-client/api"
v1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/phase0"
ssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"
Expand All @@ -18,6 +20,8 @@ type ValidatorRegistrationRunner struct {
signer types.BeaconSigner
operatorSigner *types.OperatorSigner
valCheck qbft.ProposedValueCheckF

gasLimit uint64
}

func NewValidatorRegistrationRunner(
Expand All @@ -27,6 +31,7 @@ func NewValidatorRegistrationRunner(
network Network,
signer types.BeaconSigner,
operatorSigner *types.OperatorSigner,
gasLimit uint64,
) (Runner, error) {

if len(share) != 1 {
Expand All @@ -44,6 +49,7 @@ func NewValidatorRegistrationRunner(
network: network,
signer: signer,
operatorSigner: operatorSigner,
gasLimit: gasLimit,
}, nil
}

Expand Down Expand Up @@ -80,14 +86,20 @@ func (r *ValidatorRegistrationRunner) ProcessPreConsensus(signedMsg *types.Parti
specSig := phase0.BLSSignature{}
copy(specSig[:], fullSig)

// Get share
share := r.GetShare()
if share == nil {
return errors.New("no share to get validator public key")
registration, err := r.calculateValidatorRegistration(r.BaseRunner.State.StartingDuty.DutySlot())
if err != nil {
return errors.Wrap(err, "could not calculate validator registration")
}

signed := &api.VersionedSignedValidatorRegistration{
Version: spec.BuilderVersionV1,
V1: &v1.SignedValidatorRegistration{
Message: registration,
Signature: specSig,
},
}

if err := r.beacon.SubmitValidatorRegistration(share.ValidatorPubKey[:],
share.FeeRecipientAddress, specSig); err != nil {
if err := r.beacon.SubmitValidatorRegistration(signed); err != nil {
return errors.Wrap(err, "could not submit validator registration")
}

Expand All @@ -107,7 +119,7 @@ func (r *ValidatorRegistrationRunner) expectedPreConsensusRootsAndDomain() ([]ss
if r.BaseRunner.State == nil || r.BaseRunner.State.StartingDuty == nil {
return nil, types.DomainError, errors.New("no running duty to compute preconsensus roots and domain")
}
vr, err := r.calculateValidatorRegistration(r.BaseRunner.State.StartingDuty)
vr, err := r.calculateValidatorRegistration(r.BaseRunner.State.StartingDuty.DutySlot())
if err != nil {
return nil, types.DomainError, errors.Wrap(err, "could not calculate validator registration")
}
Expand All @@ -120,7 +132,7 @@ func (r *ValidatorRegistrationRunner) expectedPostConsensusRootsAndDomain() ([]s
}

func (r *ValidatorRegistrationRunner) executeDuty(duty types.Duty) error {
vr, err := r.calculateValidatorRegistration(duty)
vr, err := r.calculateValidatorRegistration(duty.DutySlot())
if err != nil {
return errors.Wrap(err, "could not calculate validator registration")
}
Expand Down Expand Up @@ -167,7 +179,7 @@ func (r *ValidatorRegistrationRunner) executeDuty(duty types.Duty) error {
return nil
}

func (r *ValidatorRegistrationRunner) calculateValidatorRegistration(duty types.Duty) (*v1.ValidatorRegistration, error) {
func (r *ValidatorRegistrationRunner) calculateValidatorRegistration(slot phase0.Slot) (*v1.ValidatorRegistration, error) {

share := r.GetShare()
if share == nil {
Expand All @@ -177,11 +189,11 @@ func (r *ValidatorRegistrationRunner) calculateValidatorRegistration(duty types.
pk := phase0.BLSPubKey{}
copy(pk[:], share.ValidatorPubKey[:])

epoch := r.BaseRunner.BeaconNetwork.EstimatedEpochAtSlot(duty.DutySlot())
epoch := r.BaseRunner.BeaconNetwork.EstimatedEpochAtSlot(slot)

return &v1.ValidatorRegistration{
FeeRecipient: share.FeeRecipientAddress,
GasLimit: types.DefaultGasLimit,
GasLimit: r.gasLimit,
Timestamp: r.BaseRunner.BeaconNetwork.EpochStartTime(epoch),
Pubkey: pk,
}, nil
Expand Down
41 changes: 29 additions & 12 deletions types/testingutils/beacon_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,33 @@ func TestingValidatorRegistrationBySlot(slot phase0.Slot) *v1.ValidatorRegistrat
}
}

var TestingSignedValidatorRegistration = func(ks *TestKeySet) *v1.SignedValidatorRegistration {
vr := TestingValidatorRegistration
sig := signBeaconObject(vr, types.DomainApplicationBuilder, ks)
return &v1.SignedValidatorRegistration{
Message: vr,
Signature: sig,
}
}

var TestingSignedValidatorRegistrationWrong = func(ks *TestKeySet) *v1.SignedValidatorRegistration {
vr := TestingValidatorRegistrationWrong
sig := signBeaconObject(vr, types.DomainApplicationBuilder, ks)
return &v1.SignedValidatorRegistration{
Message: vr,
Signature: sig,
}
}

var TestingSignedValidatorRegistrationBySlot = func(ks *TestKeySet, slot phase0.Slot) *v1.SignedValidatorRegistration {
vr := TestingValidatorRegistrationBySlot(slot)
sig := signBeaconObject(vr, types.DomainApplicationBuilder, ks)
return &v1.SignedValidatorRegistration{
Message: vr,
Signature: sig,
}
}

var TestingVoluntaryExit = &phase0.VoluntaryExit{
Epoch: 0,
ValidatorIndex: TestingValidatorIndex,
Expand Down Expand Up @@ -708,18 +735,8 @@ func (bn *TestingBeaconNode) SubmitAttestations(attestations []*phase0.Attestati
return nil
}

func (bn *TestingBeaconNode) SubmitValidatorRegistration(pubkey []byte, feeRecipient bellatrix.ExecutionAddress, sig phase0.BLSSignature) error {
pk := phase0.BLSPubKey{}
copy(pk[:], pubkey)

vr := v1.ValidatorRegistration{
FeeRecipient: feeRecipient,
GasLimit: TestingValidatorRegistration.GasLimit,
Timestamp: TestingValidatorRegistration.Timestamp,
Pubkey: pk,
}

r, _ := vr.HashTreeRoot()
func (bn *TestingBeaconNode) SubmitValidatorRegistration(registration *api.VersionedSignedValidatorRegistration) error {
r, _ := registration.V1.HashTreeRoot()
bn.BroadcastedRoots = append(bn.BroadcastedRoots, r)
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions types/testingutils/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ var ConstructBaseRunnerWithShareMap = func(role types.RunnerRole, shareMap map[p
net,
km,
opSigner,
types.DefaultGasLimit,
)
case types.RoleVoluntaryExit:
runner, err = ssv.NewVoluntaryExitRunner(
Expand Down Expand Up @@ -357,6 +358,7 @@ var ConstructBaseRunner = func(role types.RunnerRole, keySet *TestKeySet) (ssv.R
net,
km,
opSigner,
types.DefaultGasLimit,
)
case types.RoleVoluntaryExit:
runner, err = ssv.NewVoluntaryExitRunner(
Expand Down

0 comments on commit 0ee2749

Please sign in to comment.