validator registration request bug: reusing public keys (#10883)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
james-prysm 2022-06-15 13:26:05 -04:00 committed by GitHub
parent 7b38f8b8fc
commit 838963c9f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 89 deletions

View File

@ -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
@ -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][:],
})
}

View File

@ -1532,6 +1532,93 @@ func TestValidator_PushProposerSettings(t *testing.T) {
mockExpectedRequests []ExpectedValidatorRegistration
err string
}{
{
name: " Happy Path proposer config not nil",
validatorSetter: func(t *testing.T) *validator {
v := validator{
validatorClient: client,
node: nodeClient,
db: db,
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
useWeb: false,
interopKeysConfig: &local.InteropKeymanagerConfig{
NumValidatorKeys: 2,
Offset: 1,
},
}
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)
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{},
).Times(2).Return(
&ethpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
client.EXPECT().DomainData(
gomock.Any(),
gomock.Any(),
).Times(2).Return(
&ethpb.DomainResponse{
SignatureDomain: make([]byte, 32),
},
nil)
client.EXPECT().SubmitValidatorRegistration(
gomock.Any(),
gomock.Any(),
).Times(2).Return(&empty.Empty{}, nil)
return &v
},
feeRecipientMap: map[types.ValidatorIndex]string{
1: "0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9",
2: defaultFeeHex,
},
mockExpectedRequests: []ExpectedValidatorRegistration{
{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(),
GasLimit: uint64(40000000),
},
{
FeeRecipient: byteValueAddress,
GasLimit: uint64(35000000),
},
},
},
{
name: " Happy Path",
validatorSetter: func(t *testing.T) *validator {
@ -1691,93 +1778,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
},
},
},
{
name: " Happy Path proposer config not nil",
validatorSetter: func(t *testing.T) *validator {
v := validator{
validatorClient: client,
node: nodeClient,
db: db,
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
useWeb: false,
interopKeysConfig: &local.InteropKeymanagerConfig{
NumValidatorKeys: 2,
Offset: 1,
},
}
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)
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{},
).Times(2).Return(
&ethpb.Genesis{GenesisTime: timestamppb.Now()}, nil)
client.EXPECT().DomainData(
gomock.Any(),
gomock.Any(),
).Times(2).Return(
&ethpb.DomainResponse{
SignatureDomain: make([]byte, 32),
},
nil)
client.EXPECT().SubmitValidatorRegistration(
gomock.Any(),
gomock.Any(),
).Times(2).Return(&empty.Empty{}, nil)
return &v
},
feeRecipientMap: map[types.ValidatorIndex]string{
1: "0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9",
2: defaultFeeHex,
},
mockExpectedRequests: []ExpectedValidatorRegistration{
{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(),
GasLimit: uint64(40000000),
},
{
FeeRecipient: byteValueAddress,
GasLimit: uint64(35000000),
},
},
},
{
name: " proposer config not nil but fee recipient empty ",
validatorSetter: func(t *testing.T) *validator {
@ -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 != "" {