Web3signer: Bellatrix Block (#10590)

* initial commit

* fixing bazel

* removing extra space

* adding blindedbeaconblock

* adding unit tests

* fixing bazel build

* switching to switch statement

* fixing function parameters

* fixing ineffectual err error

* deleting unused files

* updating web3signer version to support bellatrix

* adding metrics

* testing longer run

* changing log level to help find errors

* changing logging back to all to better understand the issue

* testing better way to get public keys for web3signer on validator

* fixing bazel

* rolling back changes

* missed rolling back 1 thing

* adding flag back in

* adding comments back in

* testing lower participation

* adding logs to see web3signer keys for comparison

* fix bazel

* adding more logs temporariliy

* switching hex utility function

* web3signer doesn't support deposits, so changing this

* rolling back unintended unit test

* rolling back some changes for debugging

* Update validator/keymanager/remote-web3signer/v1/web3signer_types.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update testing/endtoend/components/web3remotesigner.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update testing/endtoend/endtoend_test.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update testing/endtoend/endtoend_test.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* fixing merge conflict

* Update validator/keymanager/remote-web3signer/v1/requests.go

* Update testing/endtoend/endtoend_test.go

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>

* Update validator/keymanager/remote-web3signer/v1/requests.go

Co-authored-by: terencechain <terence@prysmaticlabs.com>

* prysm doesn't currently support deposits for web3signer

* reverting back to old implementation

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: terencechain <terence@prysmaticlabs.com>
This commit is contained in:
james-prysm
2022-05-18 11:20:20 -04:00
committed by GitHub
parent 9fab9df61e
commit b38e4ddc3e
13 changed files with 225 additions and 37 deletions

View File

@@ -20,7 +20,7 @@ import (
"github.com/prysmaticlabs/prysm/validator/keymanager"
remote_utils "github.com/prysmaticlabs/prysm/validator/keymanager/remote-utils"
"github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/internal"
v1 "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1"
web3signerv1 "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1"
log "github.com/sirupsen/logrus"
)
@@ -113,7 +113,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
}
switch request.Object.(type) {
case *validatorpb.SignRequest_Block:
bockSignRequest, err := v1.GetBlockSignRequest(request, genesisValidatorsRoot)
bockSignRequest, err := web3signerv1.GetBlockSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
@@ -123,7 +123,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
blockSignRequestsTotal.Inc()
return json.Marshal(bockSignRequest)
case *validatorpb.SignRequest_AttestationData:
attestationSignRequest, err := v1.GetAttestationSignRequest(request, genesisValidatorsRoot)
attestationSignRequest, err := web3signerv1.GetAttestationSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
@@ -133,7 +133,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
attestationSignRequestsTotal.Inc()
return json.Marshal(attestationSignRequest)
case *validatorpb.SignRequest_AggregateAttestationAndProof:
aggregateAndProofSignRequest, err := v1.GetAggregateAndProofSignRequest(request, genesisValidatorsRoot)
aggregateAndProofSignRequest, err := web3signerv1.GetAggregateAndProofSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
@@ -143,7 +143,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
aggregateAndProofSignRequestsTotal.Inc()
return json.Marshal(aggregateAndProofSignRequest)
case *validatorpb.SignRequest_Slot:
aggregationSlotSignRequest, err := v1.GetAggregationSlotSignRequest(request, genesisValidatorsRoot)
aggregationSlotSignRequest, err := web3signerv1.GetAggregationSlotSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
@@ -153,22 +153,35 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
aggregationSlotSignRequestsTotal.Inc()
return json.Marshal(aggregationSlotSignRequest)
case *validatorpb.SignRequest_BlockV2:
blocv2AltairSignRequest, err := v1.GetBlockV2AltairSignRequest(request, genesisValidatorsRoot)
blockv2AltairSignRequest, err := web3signerv1.GetBlockV2AltairSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blocv2AltairSignRequest); err != nil {
if err = validator.StructCtx(ctx, blockv2AltairSignRequest); err != nil {
return nil, err
}
blockV2SignRequestsTotal.Inc()
return json.Marshal(blocv2AltairSignRequest)
// TODO(#10053): Need to add support for merge blocks.
/*
case *validatorpb.SignRequest_BlockV3:
return "BLOCK_V3", nil
*/
return json.Marshal(blockv2AltairSignRequest)
case *validatorpb.SignRequest_BlockV3:
blockv2BellatrixSignRequest, err := web3signerv1.GetBlockV2BellatrixSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blockv2BellatrixSignRequest); err != nil {
return nil, err
}
blockV3SignRequestsTotal.Inc()
return json.Marshal(blockv2BellatrixSignRequest)
case *validatorpb.SignRequest_BlindedBlockV3:
blindedBlockv2SignRequest, err := web3signerv1.GetBlockV2BellatrixSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blindedBlockv2SignRequest); err != nil {
return nil, err
}
blindedblockV3SignRequestsTotal.Inc()
return json.Marshal(blindedBlockv2SignRequest)
// We do not support "DEPOSIT" type.
/*
case *validatorpb.:
@@ -176,7 +189,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
*/
case *validatorpb.SignRequest_Epoch:
randaoRevealSignRequest, err := v1.GetRandaoRevealSignRequest(request, genesisValidatorsRoot)
randaoRevealSignRequest, err := web3signerv1.GetRandaoRevealSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
@@ -186,7 +199,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
randaoRevealSignRequestsTotal.Inc()
return json.Marshal(randaoRevealSignRequest)
case *validatorpb.SignRequest_Exit:
voluntaryExitRequest, err := v1.GetVoluntaryExitSignRequest(request, genesisValidatorsRoot)
voluntaryExitRequest, err := web3signerv1.GetVoluntaryExitSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
@@ -196,7 +209,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
voluntaryExitSignRequestsTotal.Inc()
return json.Marshal(voluntaryExitRequest)
case *validatorpb.SignRequest_SyncMessageBlockRoot:
syncCommitteeMessageRequest, err := v1.GetSyncCommitteeMessageSignRequest(request, genesisValidatorsRoot)
syncCommitteeMessageRequest, err := web3signerv1.GetSyncCommitteeMessageSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
@@ -206,7 +219,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
syncCommitteeMessageSignRequestsTotal.Inc()
return json.Marshal(syncCommitteeMessageRequest)
case *validatorpb.SignRequest_SyncAggregatorSelectionData:
syncCommitteeSelectionProofRequest, err := v1.GetSyncCommitteeSelectionProofSignRequest(request, genesisValidatorsRoot)
syncCommitteeSelectionProofRequest, err := web3signerv1.GetSyncCommitteeSelectionProofSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
@@ -216,7 +229,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
syncCommitteeSelectionProofSignRequestsTotal.Inc()
return json.Marshal(syncCommitteeSelectionProofRequest)
case *validatorpb.SignRequest_ContributionAndProof:
contributionAndProofRequest, err := v1.GetSyncCommitteeContributionAndProofSignRequest(request, genesisValidatorsRoot)
contributionAndProofRequest, err := web3signerv1.GetSyncCommitteeContributionAndProofSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}

View File

@@ -34,6 +34,14 @@ var (
Name: "remote_web3signer_block_v2_sign_requests_total",
Help: "Total number of block v2 sign requests",
})
blockV3SignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_block_v3_sign_requests_total",
Help: "Total number of block v3 sign requests",
})
blindedblockV3SignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_blinded_block_v3_sign_requests_total",
Help: "Total number of blinded block v3 sign requests",
})
randaoRevealSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_randao_reveal_sign_requests_total",
Help: "Total number of randao reveal sign requests",

View File

@@ -10,7 +10,9 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1",
visibility = ["//visibility:public"],
deps = [
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library",
"//network/forks:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/validator-client:go_default_library",

View File

@@ -10,6 +10,7 @@ go_library(
"//config/fieldparams:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/validator-client:go_default_library",
"//testing/util:go_default_library",
"//validator/keymanager/remote-web3signer/v1:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",

View File

@@ -8,6 +8,7 @@ import (
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/testing/util"
v1 "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1"
)
@@ -326,6 +327,24 @@ func GetMockSignRequest(t string) *validatorpb.SignRequest {
},
SigningSlot: 0,
}
case "BLOCK_V2_BELLATRIX":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlockV3{
BlockV3: util.HydrateBeaconBlockBellatrix(&eth.BeaconBlockBellatrix{}),
},
}
case "BLOCK_V2_BLINDED_BELLATRIX":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlindedBlockV3{
BlindedBlockV3: util.HydrateBlindedBeaconBlockBellatrix(&eth.BlindedBeaconBlockBellatrix{}),
},
}
case "RANDAO_REVEAL":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
@@ -461,6 +480,24 @@ func MockBlockV2AltairSignRequest() *v1.BlockV2AltairSignRequest {
}
}
func MockBlockV2BellatrixSignRequest(bodyRoot string) *v1.BlockV2BellatrixSignRequest {
return &v1.BlockV2BellatrixSignRequest{
Type: "BLOCK_V2",
ForkInfo: MockForkInfo(),
SigningRoot: hexutil.Encode(make([]byte, fieldparams.RootLength)),
BeaconBlock: &v1.BeaconBlockBellatrixBlockV2{
Version: "BELLATRIX",
BlockHeader: &v1.BeaconBlockHeader{
Slot: "0",
ProposerIndex: "0",
ParentRoot: hexutil.Encode(make([]byte, fieldparams.RootLength)),
StateRoot: hexutil.Encode(make([]byte, fieldparams.RootLength)),
BodyRoot: bodyRoot,
},
},
}
}
// MockRandaoRevealSignRequest is a mock implementation of the RandaoRevealSignRequest.
func MockRandaoRevealSignRequest() *v1.RandaoRevealSignRequest {
return &v1.RandaoRevealSignRequest{

View File

@@ -5,6 +5,8 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
)
@@ -216,6 +218,9 @@ func GetSyncCommitteeMessageSignRequest(request *validatorpb.SignRequest, genesi
// GetSyncCommitteeSelectionProofSignRequest maps the request for signing type SYNC_COMMITTEE_SELECTION_PROOF.
func GetSyncCommitteeSelectionProofSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*SyncCommitteeSelectionProofSignRequest, error) {
if request == nil {
return nil, errors.New("nil sign request provided")
}
syncCommitteeSelectionProof, ok := request.Object.(*validatorpb.SignRequest_SyncAggregatorSelectionData)
if !ok {
return nil, errors.New("failed to cast request object to sync committee selection proof")
@@ -241,6 +246,9 @@ func GetSyncCommitteeSelectionProofSignRequest(request *validatorpb.SignRequest,
// GetSyncCommitteeContributionAndProofSignRequest maps the request for signing type SYNC_COMMITTEE_CONTRIBUTION_AND_PROOF.
func GetSyncCommitteeContributionAndProofSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*SyncCommitteeContributionAndProofSignRequest, error) {
if request == nil {
return nil, errors.New("nil sign request provided")
}
syncCommitteeContributionAndProof, ok := request.Object.(*validatorpb.SignRequest_ContributionAndProof)
if !ok {
return nil, errors.New("failed to cast request object to sync committee contribution and proof")
@@ -263,3 +271,66 @@ func GetSyncCommitteeContributionAndProofSignRequest(request *validatorpb.SignRe
ContributionAndProof: contribution,
}, nil
}
// GetBlockV2BellatrixSignRequest maps the request for signing type BLOCK_V2_BELLATRIX.
// note: web3signer uses blockv2 instead of block v3 for signing type
func GetBlockV2BellatrixSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockV2BellatrixSignRequest, error) {
if request == nil {
return nil, errors.New("nil sign request provided")
}
var b interfaces.BeaconBlock
switch request.Object.(type) {
case *validatorpb.SignRequest_BlindedBlockV3:
blindedBlockV3, ok := request.Object.(*validatorpb.SignRequest_BlindedBlockV3)
if !ok {
return nil, errors.New("failed to cast request object to blinded block v3")
}
if blindedBlockV3 == nil {
return nil, errors.New("invalid sign request - blindedBlockV3 is nil")
}
beaconBlock, err := wrapper.WrappedBeaconBlock(blindedBlockV3.BlindedBlockV3)
if err != nil {
return nil, err
}
b = beaconBlock
case *validatorpb.SignRequest_BlockV3:
blockV3Bellatrix, ok := request.Object.(*validatorpb.SignRequest_BlockV3)
if !ok {
return nil, errors.New("failed to cast request object to block v3 bellatrix")
}
if blockV3Bellatrix == nil {
return nil, errors.New("invalid sign request: blockV3Bellatrix is nil")
}
beaconBlock, err := wrapper.WrappedBeaconBlock(blockV3Bellatrix.BlockV3)
if err != nil {
return nil, err
}
b = beaconBlock
default:
return nil, errors.New("invalid sign request - invalid object type")
}
fork, err := MapForkInfo(request.SigningSlot, genesisValidatorsRoot)
if err != nil {
return nil, err
}
beaconBlockHeader, err := interfaces.BeaconBlockHeaderFromBlockInterface(b)
if err != nil {
return nil, err
}
return &BlockV2BellatrixSignRequest{
Type: "BLOCK_V2",
ForkInfo: fork,
SigningRoot: hexutil.Encode(request.SigningRoot),
BeaconBlock: &BeaconBlockBellatrixBlockV2{
Version: "BELLATRIX",
BlockHeader: &BeaconBlockHeader{
Slot: fmt.Sprint(beaconBlockHeader.Slot),
ProposerIndex: fmt.Sprint(beaconBlockHeader.ProposerIndex),
ParentRoot: hexutil.Encode(beaconBlockHeader.ParentRoot),
StateRoot: hexutil.Encode(beaconBlockHeader.StateRoot),
BodyRoot: hexutil.Encode(beaconBlockHeader.BodyRoot),
},
},
}, nil
}

View File

@@ -358,3 +358,47 @@ func TestGetVoluntaryExitSignRequest(t *testing.T) {
})
}
}
func TestGetBlockV3BellatrixSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.BlockV2BellatrixSignRequest
wantErr bool
}{
{
name: "Happy Path Test non blinded",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BELLATRIX"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BellatrixSignRequest("0xcd7c49966ebe72b1214e6d4733adf6bf06935c5fbc3b3ad08e84e3085428b82f"),
wantErr: false,
},
{
name: "Happy Path Test blinded",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BLINDED_BELLATRIX"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BellatrixSignRequest("0xbabb9c2d10dd3f16dc50e31fd6eb270c9c5e95a6dcb5a1eb34389ef28194285b"),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetBlockV2BellatrixSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetBlockV2BellatrixSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBlockV2AltairSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}

View File

@@ -42,6 +42,14 @@ type BlockV2AltairSignRequest struct {
BeaconBlock *BeaconBlockAltairBlockV2 `json:"beacon_block" validate:"required"`
}
// BlockV2BellatrixSignRequest is a request object for web3signer sign api for supporting Bellatrix fork.
type BlockV2BellatrixSignRequest struct {
Type string `json:"type" validate:"required"`
ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
SigningRoot string `json:"signingRoot"`
BeaconBlock *BeaconBlockBellatrixBlockV2 `json:"beacon_block" validate:"required"`
}
// BlockV2SignRequest is a request object for web3signer sign api.
type BlockV2SignRequest struct {
Type string `json:"type" validate:"required"`
@@ -264,6 +272,12 @@ type BeaconBlockBodyAltair struct {
SyncAggregate *SyncAggregate `json:"sync_aggregate"`
}
// BeaconBlockBellatrixBlockV2 a field of BlockV2BellatrixSignRequest.
type BeaconBlockBellatrixBlockV2 struct {
Version string `json:"version"`
BlockHeader *BeaconBlockHeader `json:"block_header"`
}
// SyncAggregate is a sub property of BeaconBlockBodyAltair.
type SyncAggregate struct {
SyncCommitteeBits string `json:"sync_committee_bits"` /* SSZ hexadecimal string */