mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Web3Signer: Validator Registration (#10964)
* initial commit * adjusting logic to match web3signer specifications * making Epoch mandatory * fixing unit test * rolling back some changes on slots * fixing unit tests * testing enable validator registration * adding validator registration to configs * fixing prefix * fixing shasum * rolling back e2e validator registration until fully supported * updating web3signer version * changing types based on feedback
This commit is contained in:
@@ -238,6 +238,16 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
|
||||
}
|
||||
syncCommitteeContributionAndProofSignRequestsTotal.Inc()
|
||||
return json.Marshal(contributionAndProofRequest)
|
||||
case *validatorpb.SignRequest_Registration:
|
||||
validatorRegistrationRequest, err := web3signerv1.GetValidatorRegistrationSignRequest(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = validator.StructCtx(ctx, validatorRegistrationRequest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
validatorRegistrationSignRequestsTotal.Inc()
|
||||
return json.Marshal(validatorRegistrationRequest)
|
||||
default:
|
||||
return nil, fmt.Errorf("web3signer sign request type %T not supported", request.Object)
|
||||
}
|
||||
|
||||
@@ -163,6 +163,14 @@ func TestKeymanager_Sign(t *testing.T) {
|
||||
want: desiredSig,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "VALIDATOR_REGISTRATION",
|
||||
args: args{
|
||||
request: mock.GetMockSignRequest("VALIDATOR_REGISTRATION"),
|
||||
},
|
||||
want: desiredSig,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
@@ -62,4 +62,8 @@ var (
|
||||
Name: "remote_web3signer_sync_committee_contribution_and_proof_sign_requests_total",
|
||||
Help: "Total number of sync committee contribution and proof sign requests",
|
||||
})
|
||||
validatorRegistrationSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "remote_web3signer_validator_registration_sign_requests_total",
|
||||
Help: "Total number of validator registration sign requests",
|
||||
})
|
||||
)
|
||||
|
||||
@@ -411,6 +411,21 @@ func GetMockSignRequest(t string) *validatorpb.SignRequest {
|
||||
},
|
||||
SigningSlot: 0,
|
||||
}
|
||||
case "VALIDATOR_REGISTRATION":
|
||||
return &validatorpb.SignRequest{
|
||||
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
|
||||
SigningRoot: make([]byte, fieldparams.RootLength),
|
||||
SignatureDomain: make([]byte, 4),
|
||||
Object: &validatorpb.SignRequest_Registration{
|
||||
Registration: ð.ValidatorRegistrationV1{
|
||||
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength),
|
||||
GasLimit: uint64(0),
|
||||
Timestamp: uint64(0),
|
||||
Pubkey: make([]byte, fieldparams.BLSSignatureLength),
|
||||
},
|
||||
},
|
||||
SigningSlot: 0,
|
||||
}
|
||||
default:
|
||||
fmt.Printf("Web3signer sign request type: %v not found", t)
|
||||
return nil
|
||||
@@ -559,6 +574,20 @@ func MockVoluntaryExitSignRequest() *v1.VoluntaryExitSignRequest {
|
||||
}
|
||||
}
|
||||
|
||||
// MockValidatorRegistrationSignRequest is a mock implementation of the ValidatorRegistrationSignRequest.
|
||||
func MockValidatorRegistrationSignRequest() *v1.ValidatorRegistrationSignRequest {
|
||||
return &v1.ValidatorRegistrationSignRequest{
|
||||
Type: "VALIDATOR_REGISTRATION",
|
||||
SigningRoot: make([]byte, fieldparams.RootLength),
|
||||
ValidatorRegistration: &v1.ValidatorRegistration{
|
||||
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength),
|
||||
GasLimit: fmt.Sprint(0),
|
||||
Timestamp: fmt.Sprint(0),
|
||||
Pubkey: make([]byte, fieldparams.BLSSignatureLength),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -334,3 +334,25 @@ func GetBlockV2BellatrixSignRequest(request *validatorpb.SignRequest, genesisVal
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetValidatorRegistrationSignRequest maps the request for signing type VALIDATOR_REGISTRATION.
|
||||
func GetValidatorRegistrationSignRequest(request *validatorpb.SignRequest) (*ValidatorRegistrationSignRequest, error) {
|
||||
if request == nil {
|
||||
return nil, errors.New("nil sign request provided")
|
||||
}
|
||||
validatorRegistrationRequest, ok := request.Object.(*validatorpb.SignRequest_Registration)
|
||||
if !ok {
|
||||
return nil, errors.New("failed to cast request object to validator registration")
|
||||
}
|
||||
registration := validatorRegistrationRequest.Registration
|
||||
return &ValidatorRegistrationSignRequest{
|
||||
Type: "VALIDATOR_REGISTRATION",
|
||||
SigningRoot: request.SigningRoot,
|
||||
ValidatorRegistration: &ValidatorRegistration{
|
||||
FeeRecipient: registration.FeeRecipient,
|
||||
GasLimit: fmt.Sprint(registration.GasLimit),
|
||||
Timestamp: fmt.Sprint(registration.Timestamp),
|
||||
Pubkey: registration.Pubkey,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -402,3 +402,36 @@ func TestGetBlockV3BellatrixSignRequest(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetValidatorRegistrationSignRequest(t *testing.T) {
|
||||
type args struct {
|
||||
request *validatorpb.SignRequest
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *v1.ValidatorRegistrationSignRequest
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Happy Path Test",
|
||||
args: args{
|
||||
request: mock.GetMockSignRequest("VALIDATOR_REGISTRATION"),
|
||||
},
|
||||
want: mock.MockValidatorRegistrationSignRequest(),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := v1.GetValidatorRegistrationSignRequest(tt.args.request)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("GetValidatorRegistrationSignRequest() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetValidatorRegistrationSignRequest() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
/* Web3Signer Specs are found by searching Consensys' Web3Signer API specification*/
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
)
|
||||
|
||||
// AggregationSlotSignRequest is a request object for web3signer sign api.
|
||||
type AggregationSlotSignRequest struct {
|
||||
Type string `json:"type" validate:"required"`
|
||||
@@ -101,6 +105,13 @@ type SyncCommitteeContributionAndProofSignRequest struct {
|
||||
ContributionAndProof *ContributionAndProof `json:"contribution_and_proof" validate:"required"`
|
||||
}
|
||||
|
||||
// ValidatorRegistrationSignRequest a request object for web3signer sign api.
|
||||
type ValidatorRegistrationSignRequest struct {
|
||||
Type string `json:"type" validate:"required"`
|
||||
SigningRoot hexutil.Bytes `json:"signingRoot"`
|
||||
ValidatorRegistration *ValidatorRegistration `json:"validator_registration" validate:"required"`
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// sub properties of Sign Requests /////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -324,6 +335,14 @@ type SyncCommitteeContribution struct {
|
||||
Signature string `json:"signature"` /* 96 byte hexadecimal string */
|
||||
}
|
||||
|
||||
// ValidatorRegistration a sub property of ValidatorRegistrationSignRequest
|
||||
type ValidatorRegistration struct {
|
||||
FeeRecipient hexutil.Bytes `json:"fee_recipient" validate:"required"` /* 42 hexadecimal string */
|
||||
GasLimit string `json:"gas_limit" validate:"required"` /* uint64 */
|
||||
Timestamp string `json:"timestamp" validate:"required"` /* uint64 */
|
||||
Pubkey hexutil.Bytes `json:"pubkey" validate:"required"` /* bls hexadecimal string */
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user