mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
Compute correct domain for validator registration (#10894)
Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
This commit is contained in:
parent
2dfe291cf9
commit
88f8dbecc8
@ -42,7 +42,6 @@ go_test(
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//testing/util:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_google_gofuzz//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -3,7 +3,6 @@ package signing
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
@ -11,17 +10,19 @@ var ErrNilRegistration = errors.New("nil signed registration")
|
||||
|
||||
// VerifyRegistrationSignature verifies the signature of a validator's registration.
|
||||
func VerifyRegistrationSignature(
|
||||
e types.Epoch,
|
||||
f *ethpb.Fork,
|
||||
sr *ethpb.SignedValidatorRegistrationV1,
|
||||
genesisRoot []byte,
|
||||
) error {
|
||||
if sr == nil || sr.Message == nil {
|
||||
return ErrNilRegistration
|
||||
}
|
||||
|
||||
d := params.BeaconConfig().DomainApplicationBuilder
|
||||
sd, err := Domain(f, e, d, genesisRoot)
|
||||
// Per spec, we want the fork version and genesis validator to be nil.
|
||||
// Which is genesis value and zero by default.
|
||||
sd, err := ComputeDomain(
|
||||
d,
|
||||
nil, /* fork version */
|
||||
nil /* genesis val root */)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/testing/util"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
func TestVerifyRegistrationSignature(t *testing.T) {
|
||||
@ -23,22 +21,22 @@ func TestVerifyRegistrationSignature(t *testing.T) {
|
||||
Timestamp: uint64(time.Now().Unix()),
|
||||
Pubkey: sk.PublicKey().Marshal(),
|
||||
}
|
||||
st, _ := util.DeterministicGenesisState(t, 1)
|
||||
d := params.BeaconConfig().DomainApplicationBuilder
|
||||
e := slots.ToEpoch(st.Slot())
|
||||
sig, err := signing.ComputeDomainAndSign(st, e, reg, d, sk)
|
||||
domain, err := signing.ComputeDomain(d, nil, nil)
|
||||
require.NoError(t, err)
|
||||
sr, err := signing.ComputeSigningRoot(reg, domain)
|
||||
require.NoError(t, err)
|
||||
sk.Sign(sr[:]).Marshal()
|
||||
|
||||
sReg := ðpb.SignedValidatorRegistrationV1{
|
||||
Message: reg,
|
||||
Signature: sig,
|
||||
Signature: sk.Sign(sr[:]).Marshal(),
|
||||
}
|
||||
f := st.Fork()
|
||||
g := st.GenesisValidatorsRoot()
|
||||
require.NoError(t, signing.VerifyRegistrationSignature(e, f, sReg, g))
|
||||
require.NoError(t, signing.VerifyRegistrationSignature(sReg))
|
||||
|
||||
sReg.Signature = []byte("bad")
|
||||
require.ErrorIs(t, signing.VerifyRegistrationSignature(e, f, sReg, g), signing.ErrSigFailedToVerify)
|
||||
require.ErrorIs(t, signing.VerifyRegistrationSignature(sReg), signing.ErrSigFailedToVerify)
|
||||
|
||||
sReg.Message = nil
|
||||
require.ErrorIs(t, signing.VerifyRegistrationSignature(e, f, sReg, g), signing.ErrNilRegistration)
|
||||
require.ErrorIs(t, signing.VerifyRegistrationSignature(sReg), signing.ErrNilRegistration)
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
@ -58,20 +57,18 @@ func signValidatorRegistration(
|
||||
signer signingFunc,
|
||||
reg *ethpb.ValidatorRegistrationV1,
|
||||
) ([]byte, error) {
|
||||
req := ðpb.DomainRequest{
|
||||
Epoch: slots.ToEpoch(slot),
|
||||
Domain: params.BeaconConfig().DomainApplicationBuilder[:],
|
||||
}
|
||||
|
||||
domain, err := validatorClient.DomainData(ctx, req)
|
||||
// Per spec, we want the fork version and genesis validator to be nil.
|
||||
// Which is genesis value and zero by default.
|
||||
d, err := signing.ComputeDomain(
|
||||
params.BeaconConfig().DomainApplicationBuilder,
|
||||
nil, /* fork version */
|
||||
nil /* genesis val root */)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, domainDataErr)
|
||||
}
|
||||
if domain == nil {
|
||||
return nil, errors.New(domainDataErr)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r, err := signing.ComputeSigningRoot(reg, domain.SignatureDomain)
|
||||
r, err := signing.ComputeSigningRoot(reg, d)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, signingRootErr)
|
||||
}
|
||||
@ -79,7 +76,7 @@ func signValidatorRegistration(
|
||||
sig, err := signer(ctx, &validatorpb.SignRequest{
|
||||
PublicKey: reg.Pubkey,
|
||||
SigningRoot: r[:],
|
||||
SignatureDomain: domain.SignatureDomain,
|
||||
SignatureDomain: d,
|
||||
Object: &validatorpb.SignRequest_Registration{Registration: reg},
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -32,11 +32,6 @@ func TestSubmitValidatorRegistration(t *testing.T) {
|
||||
GetGenesis(gomock.Any(), &emptypb.Empty{}).
|
||||
Return(ðpb.Genesis{GenesisTime: ti}, nil)
|
||||
|
||||
m.validatorClient.EXPECT().DomainData(
|
||||
gomock.Any(), // ctx
|
||||
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
||||
).Times(1).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)
|
||||
|
||||
m.validatorClient.EXPECT().
|
||||
SubmitValidatorRegistration(gomock.Any(), ðpb.SignedValidatorRegistrationV1{
|
||||
Message: reg,
|
||||
@ -46,31 +41,6 @@ func TestSubmitValidatorRegistration(t *testing.T) {
|
||||
require.NoError(t, nil, SubmitValidatorRegistration(ctx, m.validatorClient, m.nodeClient, m.signfunc, reg))
|
||||
}
|
||||
|
||||
func TestSubmitValidatorRegistration_InvalidDomain(t *testing.T) {
|
||||
_, m, validatorKey, finish := setup(t)
|
||||
defer finish()
|
||||
|
||||
ctx := context.Background()
|
||||
reg := ðpb.ValidatorRegistrationV1{
|
||||
FeeRecipient: bytesutil.PadTo([]byte("fee"), 20),
|
||||
GasLimit: 123456,
|
||||
Timestamp: uint64(time.Now().Unix()),
|
||||
Pubkey: validatorKey.PublicKey().Marshal(),
|
||||
}
|
||||
|
||||
genesisTime := ×tamppb.Timestamp{}
|
||||
m.nodeClient.EXPECT().
|
||||
GetGenesis(gomock.Any(), &emptypb.Empty{}).
|
||||
Return(ðpb.Genesis{GenesisTime: genesisTime}, nil)
|
||||
|
||||
m.validatorClient.EXPECT().DomainData(
|
||||
gomock.Any(), // ctx
|
||||
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
||||
).Times(1).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, errors.New(domainDataErr))
|
||||
|
||||
require.ErrorContains(t, domainDataErr, SubmitValidatorRegistration(ctx, m.validatorClient, m.nodeClient, m.signfunc, reg))
|
||||
}
|
||||
|
||||
func TestSubmitValidatorRegistration_CantSign(t *testing.T) {
|
||||
_, m, validatorKey, finish := setup(t)
|
||||
defer finish()
|
||||
@ -88,11 +58,6 @@ func TestSubmitValidatorRegistration_CantSign(t *testing.T) {
|
||||
GetGenesis(gomock.Any(), &emptypb.Empty{}).
|
||||
Return(ðpb.Genesis{GenesisTime: genesisTime}, nil)
|
||||
|
||||
m.validatorClient.EXPECT().DomainData(
|
||||
gomock.Any(), // ctx
|
||||
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
||||
).Times(1).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)
|
||||
|
||||
m.validatorClient.EXPECT().
|
||||
SubmitValidatorRegistration(gomock.Any(), ðpb.SignedValidatorRegistrationV1{
|
||||
Message: reg,
|
||||
@ -113,23 +78,10 @@ func Test_signValidatorRegistration(t *testing.T) {
|
||||
Timestamp: uint64(time.Now().Unix()),
|
||||
Pubkey: validatorKey.PublicKey().Marshal(),
|
||||
}
|
||||
m.validatorClient.EXPECT().DomainData(
|
||||
gomock.Any(), // ctx
|
||||
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
||||
).Times(1).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)
|
||||
_, err := signValidatorRegistration(
|
||||
ctx,
|
||||
1,
|
||||
m.validatorClient, m.signfunc, reg)
|
||||
require.NoError(t, err)
|
||||
|
||||
m.validatorClient.EXPECT().DomainData(
|
||||
gomock.Any(), // ctx
|
||||
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
||||
).Times(1).Return(nil, errors.New(domainDataErr) /*err*/)
|
||||
_, err = signValidatorRegistration(
|
||||
ctx,
|
||||
1,
|
||||
m.validatorClient, m.signfunc, reg)
|
||||
require.ErrorContains(t, domainDataErr, err)
|
||||
}
|
||||
|
@ -403,14 +403,6 @@ func TestWaitMultipleActivation_LogsActivationEpochOK(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -474,14 +466,6 @@ func TestWaitActivation_NotAllValidatorsActivatedOK(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -1588,15 +1572,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
&emptypb.Empty{},
|
||||
).Times(2).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Times(2).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -1662,14 +1637,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -1749,14 +1716,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -1826,14 +1785,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -1945,14 +1896,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
|
@ -114,14 +114,6 @@ func TestWaitActivation_StreamSetupFails_AttemptsToReconnect(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -181,14 +173,6 @@ func TestWaitForActivation_ReceiveErrorFromStream_AttemptsReconnection(t *testin
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -244,14 +228,6 @@ func TestWaitActivation_LogsActivationEpochOK(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -312,14 +288,6 @@ func TestWaitForActivation_Exiting(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -386,14 +354,6 @@ func TestWaitForActivation_RefetchKeys(t *testing.T) {
|
||||
).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -484,14 +444,6 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) {
|
||||
).Times(2).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Times(2).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -592,14 +544,6 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) {
|
||||
).Times(2).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Times(2).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -686,14 +630,6 @@ func TestWaitForActivation_RemoteKeymanager(t *testing.T) {
|
||||
&emptypb.Empty{},
|
||||
).Times(2).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Times(2).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@ -789,14 +725,6 @@ func TestWaitForActivation_RemoteKeymanager(t *testing.T) {
|
||||
).Times(2).Return(
|
||||
ðpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
|
||||
|
||||
client.EXPECT().DomainData(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Times(2).Return(
|
||||
ðpb.DomainResponse{
|
||||
SignatureDomain: make([]byte, 32),
|
||||
},
|
||||
nil)
|
||||
client.EXPECT().SubmitValidatorRegistration(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
|
Loading…
Reference in New Issue
Block a user