Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validator registration request bug: reusing public keys #10883

Merged
merged 4 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
var validatorToFeeRecipients []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer
var registerValidatorRequests []*ethpb.ValidatorRegistrationV1
// need to check for pubkey to validator index mappings
for _, key := range pubkeys {
for i, key := range pubkeys {
skipAppendToFeeRecipientArray := false
feeRecipient := common.HexToAddress(params.BeaconConfig().EthBurnAddressHex)
gasLimit := params.BeaconConfig().DefaultBuilderGasLimit
Expand Down Expand Up @@ -1042,7 +1042,7 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
FeeRecipient: feeRecipient[:],
GasLimit: gasLimit,
Timestamp: uint64(time.Now().UTC().Unix()),
Pubkey: key[:],
Pubkey: pubkeys[i][:],
})

}
Expand Down
172 changes: 89 additions & 83 deletions validator/client/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
err string
}{
{
name: " Happy Path",
name: " Happy Path proposer config not nil",
validatorSetter: func(t *testing.T) *validator {

v := validator{
Expand All @@ -1543,88 +1543,84 @@ func TestValidator_PushProposerSettings(t *testing.T) {
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
useWeb: false,
interopKeysConfig: &local.InteropKeymanagerConfig{
NumValidatorKeys: 1,
NumValidatorKeys: 2,
Offset: 1,
},
genesisTime: 0,
}
// set bellatrix as current epoch
params.BeaconConfig().BellatrixForkEpoch = 0
err := v.WaitForKeymanagerInitialization(ctx)
require.NoError(t, err)
config := make(map[[fieldparams.BLSPubkeyLength]byte]*validator_service_config.ProposerOption)
km, err := v.Keymanager()
require.NoError(t, err)
keys, err := km.FetchValidatingPublicKeys(ctx)
require.NoError(t, err)
v.ProposerSettings = &validator_service_config.ProposerSettings{
ProposeConfig: nil,
DefaultConfig: &validator_service_config.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
},
}
client.EXPECT().ValidatorIndex(
ctx, // ctx
&ethpb.ValidatorIndexRequest{PublicKey: keys[0][:]},
).Return(&ethpb.ValidatorIndexResponse{
Index: 1,
}, nil)
client.EXPECT().ValidatorIndex(
ctx, // ctx
&ethpb.ValidatorIndexRequest{PublicKey: keys[1][:]},
).Return(&ethpb.ValidatorIndexResponse{
Index: 2,
}, nil)
client.EXPECT().PrepareBeaconProposer(gomock.Any(), &ethpb.PrepareBeaconProposerRequest{
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
{FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(), ValidatorIndex: 1},
{FeeRecipient: common.HexToAddress(defaultFeeHex).Bytes(), ValidatorIndex: 2},
},
}).Return(nil, nil)
config[keys[0]] = &validator_service_config.ProposerOption{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
GasLimit: uint64(40000000),
}
v.ProposerSettings = &validator_service_config.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validator_service_config.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
GasLimit: uint64(35000000),
},
}
nodeClient.EXPECT().GetGenesis(
gomock.Any(),
&emptypb.Empty{},
).Return(
).Times(2).Return(
&ethpb.Genesis{GenesisTime: timestamppb.Now()}, nil)

client.EXPECT().DomainData(
gomock.Any(),
gomock.Any(),
).Return(
).Times(2).Return(
&ethpb.DomainResponse{
SignatureDomain: make([]byte, 32),
},
nil)
client.EXPECT().SubmitValidatorRegistration(
gomock.Any(),
gomock.Any(),
).Return(&empty.Empty{}, nil)
client.EXPECT().PrepareBeaconProposer(gomock.Any(), &ethpb.PrepareBeaconProposerRequest{
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
{FeeRecipient: common.HexToAddress(defaultFeeHex).Bytes(), ValidatorIndex: 1},
},
}).Return(nil, nil)
).Times(2).Return(&empty.Empty{}, nil)
return &v
},
feeRecipientMap: map[types.ValidatorIndex]string{
1: defaultFeeHex,
1: "0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9",
2: defaultFeeHex,
},
mockExpectedRequests: []ExpectedValidatorRegistration{

{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(),
GasLimit: uint64(40000000),
},
{
FeeRecipient: byteValueAddress,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
GasLimit: uint64(35000000),
},
},
},
{
name: " Skip if no config",
validatorSetter: func(t *testing.T) *validator {

v := validator{
validatorClient: client,
db: db,
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
useWeb: false,
interopKeysConfig: &local.InteropKeymanagerConfig{
NumValidatorKeys: 1,
Offset: 1,
},
}
err := v.WaitForKeymanagerInitialization(ctx)
require.NoError(t, err)
return &v
},
},
{
name: " Happy Path validator index not found in cache",
name: " Happy Path",
validatorSetter: func(t *testing.T) *validator {

v := validator{
Expand All @@ -1637,19 +1633,23 @@ func TestValidator_PushProposerSettings(t *testing.T) {
NumValidatorKeys: 1,
Offset: 1,
},
genesisTime: 0,
}
// set bellatrix as current epoch
params.BeaconConfig().BellatrixForkEpoch = 0
err := v.WaitForKeymanagerInitialization(ctx)
require.NoError(t, err)
km, err := v.Keymanager()
require.NoError(t, err)
keys, err := km.FetchValidatingPublicKeys(ctx)
require.NoError(t, err)
v.ProposerSettings = &validator_service_config.ProposerSettings{
ProposeConfig: nil,
DefaultConfig: &validator_service_config.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
},
}
km, err := v.Keymanager()
require.NoError(t, err)
keys, err := km.FetchValidatingPublicKeys(ctx)
require.NoError(t, err)
client.EXPECT().ValidatorIndex(
ctx, // ctx
&ethpb.ValidatorIndexRequest{PublicKey: keys[0][:]},
Expand Down Expand Up @@ -1692,7 +1692,26 @@ func TestValidator_PushProposerSettings(t *testing.T) {
},
},
{
name: " Happy Path proposer config not nil",
name: " Skip if no config",
validatorSetter: func(t *testing.T) *validator {

v := validator{
validatorClient: client,
db: db,
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
useWeb: false,
interopKeysConfig: &local.InteropKeymanagerConfig{
NumValidatorKeys: 1,
Offset: 1,
},
}
err := v.WaitForKeymanagerInitialization(ctx)
require.NoError(t, err)
return &v
},
},
{
name: " Happy Path validator index not found in cache",
validatorSetter: func(t *testing.T) *validator {

v := validator{
Expand All @@ -1702,13 +1721,18 @@ func TestValidator_PushProposerSettings(t *testing.T) {
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
useWeb: false,
interopKeysConfig: &local.InteropKeymanagerConfig{
NumValidatorKeys: 2,
NumValidatorKeys: 1,
Offset: 1,
},
}
err := v.WaitForKeymanagerInitialization(ctx)
require.NoError(t, err)
config := make(map[[fieldparams.BLSPubkeyLength]byte]*validator_service_config.ProposerOption)
v.ProposerSettings = &validator_service_config.ProposerSettings{
ProposeConfig: nil,
DefaultConfig: &validator_service_config.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
},
}
km, err := v.Keymanager()
require.NoError(t, err)
keys, err := km.FetchValidatingPublicKeys(ctx)
Expand All @@ -1719,62 +1743,38 @@ func TestValidator_PushProposerSettings(t *testing.T) {
).Return(&ethpb.ValidatorIndexResponse{
Index: 1,
}, nil)
client.EXPECT().ValidatorIndex(
ctx, // ctx
&ethpb.ValidatorIndexRequest{PublicKey: keys[1][:]},
).Return(&ethpb.ValidatorIndexResponse{
Index: 2,
}, nil)
client.EXPECT().PrepareBeaconProposer(gomock.Any(), &ethpb.PrepareBeaconProposerRequest{
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
{FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(), ValidatorIndex: 1},
{FeeRecipient: common.HexToAddress(defaultFeeHex).Bytes(), ValidatorIndex: 2},
},
}).Return(nil, nil)
config[keys[0]] = &validator_service_config.ProposerOption{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
GasLimit: uint64(40000000),
}
v.ProposerSettings = &validator_service_config.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validator_service_config.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
GasLimit: uint64(35000000),
},
}
nodeClient.EXPECT().GetGenesis(
gomock.Any(),
&emptypb.Empty{},
).Times(2).Return(
).Return(
&ethpb.Genesis{GenesisTime: timestamppb.Now()}, nil)

client.EXPECT().DomainData(
gomock.Any(),
gomock.Any(),
).Times(2).Return(
).Return(
&ethpb.DomainResponse{
SignatureDomain: make([]byte, 32),
},
nil)
client.EXPECT().SubmitValidatorRegistration(
gomock.Any(),
gomock.Any(),
).Times(2).Return(&empty.Empty{}, nil)
).Return(&empty.Empty{}, nil)
client.EXPECT().PrepareBeaconProposer(gomock.Any(), &ethpb.PrepareBeaconProposerRequest{
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
{FeeRecipient: common.HexToAddress(defaultFeeHex).Bytes(), ValidatorIndex: 1},
},
}).Return(nil, nil)
return &v
},
feeRecipientMap: map[types.ValidatorIndex]string{
1: "0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9",
2: defaultFeeHex,
1: defaultFeeHex,
},
mockExpectedRequests: []ExpectedValidatorRegistration{

{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(),
GasLimit: uint64(40000000),
},
{
FeeRecipient: byteValueAddress,
GasLimit: uint64(35000000),
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
},
},
},
Expand Down Expand Up @@ -1980,6 +1980,12 @@ func TestValidator_PushProposerSettings(t *testing.T) {
require.Equal(t, tt.mockExpectedRequests[i].GasLimit, request.GasLimit)
require.Equal(t, hexutil.Encode(tt.mockExpectedRequests[i].FeeRecipient), hexutil.Encode(request.FeeRecipient))
}
// check if Pubkeys are always unique
var unique = make(map[string]bool)
for _, request := range registerValidatorRequests {
require.Equal(t, unique[common.BytesToAddress(request.Pubkey).Hex()], false)
unique[common.BytesToAddress(request.Pubkey).Hex()] = true
}
require.Equal(t, len(tt.mockExpectedRequests), len(registerValidatorRequests))
}
if err := v.PushProposerSettings(ctx, km); tt.err != "" {
Expand Down