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

Prysm V4: Web3signer changes for capella #12001

Merged
merged 7 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions testing/endtoend/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ lighthouse_archive_name = "lighthouse-%s-x86_64-unknown-linux-gnu-portable.tar.g
def e2e_deps():
http_archive(
name = "web3signer",
urls = ["https://artifacts.consensys.net/public/web3signer/raw/names/web3signer.tar.gz/versions/22.8.1/web3signer-22.8.1.tar.gz"],
sha256 = "ec888222484c4d1b6203bd6d248890adf713f8bf47fb362fb36e8d47a98cb401",
urls = ["https://artifacts.consensys.net/public/web3signer/raw/names/web3signer.tar.gz/versions/23.2.1/web3signer-23.2.1.tar.gz"],
sha256 = "652f88bce1945f1c8ad3943b20c7c9adba730b2e4a5b9dec13a695c41f3e2ff1",
build_file = "@prysm//testing/endtoend:web3signer.BUILD",
strip_prefix = "web3signer-22.8.1",
strip_prefix = "web3signer-23.2.1",
)

http_archive(
Expand Down
26 changes: 23 additions & 3 deletions validator/keymanager/remote-web3signer/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
blockAltairSignRequestsTotal.Inc()
return json.Marshal(blockv2AltairSignRequest)
case *validatorpb.SignRequest_BlockBellatrix:
blockv2BellatrixSignRequest, err := web3signerv1.GetBlockBellatrixSignRequest(request, genesisValidatorsRoot)
blockv2BellatrixSignRequest, err := web3signerv1.GetBlockV2BlindedSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
Expand All @@ -173,15 +173,35 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
blockBellatrixSignRequestsTotal.Inc()
return json.Marshal(blockv2BellatrixSignRequest)
case *validatorpb.SignRequest_BlindedBlockBellatrix:
blindedBlockv2SignRequest, err := web3signerv1.GetBlockBellatrixSignRequest(request, genesisValidatorsRoot)
blindedBlockv2SignRequest, err := web3signerv1.GetBlockV2BlindedSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blindedBlockv2SignRequest); err != nil {
return nil, err
}
blindedblockBellatrixSignRequestsTotal.Inc()
blindedBlockBellatrixSignRequestsTotal.Inc()
return json.Marshal(blindedBlockv2SignRequest)
case *validatorpb.SignRequest_BlockCapella:
blockv2CapellaSignRequest, err := web3signerv1.GetBlockV2BlindedSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blockv2CapellaSignRequest); err != nil {
return nil, err
}
blockCapellaSignRequestsTotal.Inc()
return json.Marshal(blockv2CapellaSignRequest)
case *validatorpb.SignRequest_BlindedBlockCapella:
blindedBlockv2CapellaSignRequest, err := web3signerv1.GetBlockV2BlindedSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blindedBlockv2CapellaSignRequest); err != nil {
return nil, err
}
blindedBlockCapellaSignRequestsTotal.Inc()
return json.Marshal(blindedBlockv2CapellaSignRequest)
// We do not support "DEPOSIT" type.
/*
case *validatorpb.:
Expand Down
10 changes: 9 additions & 1 deletion validator/keymanager/remote-web3signer/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ var (
Name: "remote_web3signer_block_bellatrix_sign_requests_total",
Help: "Total number of block bellatrix sign requests",
})
blindedblockBellatrixSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
blindedBlockBellatrixSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_blinded_block_bellatrix_sign_requests_total",
Help: "Total number of blinded block bellatrix sign requests",
})
blockCapellaSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_block_capella_sign_requests_total",
Help: "Total number of block capella sign requests",
})
blindedBlockCapellaSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_blinded_block_capella_sign_requests_total",
Help: "Total number of block capella sign requests",
})
randaoRevealSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_randao_reveal_sign_requests_total",
Help: "Total number of randao reveal sign requests",
Expand Down
26 changes: 22 additions & 4 deletions validator/keymanager/remote-web3signer/v1/mock/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,24 @@ func GetMockSignRequest(t string) *validatorpb.SignRequest {
BlindedBlockBellatrix: util.HydrateBlindedBeaconBlockBellatrix(&eth.BlindedBeaconBlockBellatrix{}),
},
}
case "BLOCK_V2_CAPELLA":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlockCapella{
BlockCapella: util.HydrateBeaconBlockCapella(&eth.BeaconBlockCapella{}),
},
}
case "BLOCK_V2_BLINDED_CAPELLA":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlindedBlockCapella{
BlindedBlockCapella: util.HydrateBlindedBeaconBlockCapella(&eth.BlindedBeaconBlockCapella{}),
},
}
case "RANDAO_REVEAL":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
Expand Down Expand Up @@ -495,13 +513,13 @@ func MockBlockV2AltairSignRequest() *v1.BlockAltairSignRequest {
}
}

func MockBlockV2BellatrixSignRequest(bodyRoot []byte) *v1.BlockBellatrixSignRequest {
return &v1.BlockBellatrixSignRequest{
func MockBlockV2BlindedSignRequest(bodyRoot []byte, version string) *v1.BlockV2BlindedSignRequest {
return &v1.BlockV2BlindedSignRequest{
Type: "BLOCK_V2",
ForkInfo: MockForkInfo(),
SigningRoot: make([]byte, fieldparams.RootLength),
BeaconBlock: &v1.BeaconBlockBellatrixBlockV2{
Version: "BELLATRIX",
BeaconBlock: &v1.BeaconBlockV2Blinded{
Version: version,
BlockHeader: &v1.BeaconBlockHeader{
Slot: "0",
ProposerIndex: "0",
Expand Down
48 changes: 40 additions & 8 deletions validator/keymanager/remote-web3signer/v1/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,40 +271,72 @@ func GetSyncCommitteeContributionAndProofSignRequest(request *validatorpb.SignRe
}, nil
}

// GetBlockBellatrixSignRequest maps the request for signing type BLOCK_V2_BELLATRIX.
func GetBlockBellatrixSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockBellatrixSignRequest, error) {
// GetBlockV2BlindedSignRequest maps the request for signing types
// Supports Bellatrix and Capella
func GetBlockV2BlindedSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockV2BlindedSignRequest, error) {
if request == nil {
return nil, errors.New("nil sign request provided")
}
var b interfaces.ReadOnlyBeaconBlock
var version string
switch request.Object.(type) {
case *validatorpb.SignRequest_BlindedBlockBellatrix:
version = "BELLATRIX"
blindedBlockBellatrix, ok := request.Object.(*validatorpb.SignRequest_BlindedBlockBellatrix)
if !ok {
return nil, errors.New("failed to cast request object to blinded block bellatrix")
}
if blindedBlockBellatrix == nil {
return nil, errors.New("invalid sign request - blindedBlockBellatrix is nil")
return nil, errors.New("invalid sign request - blinded bellatrix block is nil")
}
beaconBlock, err := blocks.NewBeaconBlock(blindedBlockBellatrix.BlindedBlockBellatrix)
if err != nil {
return nil, err
}
b = beaconBlock
case *validatorpb.SignRequest_BlockBellatrix:
version = "BELLATRIX"
blockBellatrix, ok := request.Object.(*validatorpb.SignRequest_BlockBellatrix)
if !ok {
return nil, errors.New("failed to cast request object to block v3 bellatrix")
return nil, errors.New("failed to cast request object to bellatrix block")
}

if blockBellatrix == nil {
return nil, errors.New("invalid sign request: blockBellatrix is nil")
return nil, errors.New("invalid sign request: bellatrix block is nil")
}
beaconBlock, err := blocks.NewBeaconBlock(blockBellatrix.BlockBellatrix)
if err != nil {
return nil, err
}
b = beaconBlock
case *validatorpb.SignRequest_BlockCapella:
version = "CAPELLA"
blockCapella, ok := request.Object.(*validatorpb.SignRequest_BlockCapella)
if !ok {
return nil, errors.New("failed to cast request object to capella block")
}
if blockCapella == nil {
return nil, errors.New("invalid sign request: capella block is nil")
}
beaconBlock, err := blocks.NewBeaconBlock(blockCapella.BlockCapella)
if err != nil {
return nil, err
}
b = beaconBlock
case *validatorpb.SignRequest_BlindedBlockCapella:
version = "CAPELLA"
blindedBlockCapella, ok := request.Object.(*validatorpb.SignRequest_BlindedBlockCapella)
if !ok {
return nil, errors.New("failed to cast request object to blinded capella block")
}
if blindedBlockCapella == nil {
return nil, errors.New("invalid sign request: blinded capella block is nil")
}
beaconBlock, err := blocks.NewBeaconBlock(blindedBlockCapella.BlindedBlockCapella)
if err != nil {
return nil, err
}
b = beaconBlock
default:
return nil, errors.New("invalid sign request - invalid object type")
}
Expand All @@ -316,12 +348,12 @@ func GetBlockBellatrixSignRequest(request *validatorpb.SignRequest, genesisValid
if err != nil {
return nil, err
}
return &BlockBellatrixSignRequest{
return &BlockV2BlindedSignRequest{
Type: "BLOCK_V2",
ForkInfo: fork,
SigningRoot: request.SigningRoot,
BeaconBlock: &BeaconBlockBellatrixBlockV2{
Version: "BELLATRIX",
BeaconBlock: &BeaconBlockV2Blinded{
Version: version,
BlockHeader: &BeaconBlockHeader{
Slot: fmt.Sprint(beaconBlockHeader.Slot),
ProposerIndex: fmt.Sprint(beaconBlockHeader.ProposerIndex),
Expand Down
48 changes: 37 additions & 11 deletions validator/keymanager/remote-web3signer/v1/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,53 +361,79 @@ func TestGetVoluntaryExitSignRequest(t *testing.T) {
}
}

func TestGetBlockBellatrixSignRequest(t *testing.T) {
func TestGetBlockV2BlindedSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.BlockBellatrixSignRequest
want *v1.BlockV2BlindedSignRequest
wantErr bool
}{
{
name: "Happy Path Test non blinded",
name: "Happy Path Test non blinded Bellatrix",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BELLATRIX"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BellatrixSignRequest(func(t *testing.T) []byte {
want: mock.MockBlockV2BlindedSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0xcd7c49966ebe72b1214e6d4733adf6bf06935c5fbc3b3ad08e84e3085428b82f")
require.NoError(t, err)
return bytevalue
}(t)),
}(t), "BELLATRIX"),
wantErr: false,
},
{
name: "Happy Path Test blinded",
name: "Happy Path Test blinded Bellatrix",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BLINDED_BELLATRIX"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BellatrixSignRequest(func(t *testing.T) []byte {
want: mock.MockBlockV2BlindedSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0xbabb9c2d10dd3f16dc50e31fd6eb270c9c5e95a6dcb5a1eb34389ef28194285b")
require.NoError(t, err)
return bytevalue
}(t)),
}(t), "BELLATRIX"),
wantErr: false,
},
{
name: "Happy Path Test non blinded Capella",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_CAPELLA"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BlindedSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0x74b4bb048d39c75f175fbb2311062eb9867d79b712907f39544fcaf2d7e1b433")
require.NoError(t, err)
return bytevalue
}(t), "CAPELLA"),
wantErr: false,
},
{
name: "Happy Path Test blinded Capella",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BLINDED_CAPELLA"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BlindedSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0x54797f27f45a91d2cf4d73e509c62e464d648ec34e07ddba946adee742039e76")
require.NoError(t, err)
return bytevalue
}(t), "CAPELLA"),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetBlockBellatrixSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
got, err := v1.GetBlockV2BlindedSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetBlockBellatrixSignRequest() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("GetBlockV2BlindedSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBlockAltairSignRequest() got = %v, want %v", got, tt.want)
t.Errorf("GetBlockV2BlindedSignRequest() got = %v, want %v", got, tt.want)
}
})
}
Expand Down
18 changes: 10 additions & 8 deletions validator/keymanager/remote-web3signer/v1/web3signer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ type BlockAltairSignRequest struct {
BeaconBlock *BeaconBlockAltairBlockV2 `json:"beacon_block" validate:"required"`
}

// BlockBellatrixSignRequest is a request object for web3signer sign api for supporting Bellatrix fork.
type BlockBellatrixSignRequest struct {
Type string `json:"type" validate:"required"`
ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
SigningRoot hexutil.Bytes `json:"signingRoot"`
BeaconBlock *BeaconBlockBellatrixBlockV2 `json:"beacon_block" validate:"required"`
// BlockV2BlindedSignRequest is a request object for web3signer sign api
// Supports Bellatrix(merge) and Capella
type BlockV2BlindedSignRequest struct {
Type string `json:"type" validate:"required"`
ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
SigningRoot hexutil.Bytes `json:"signingRoot"`
BeaconBlock *BeaconBlockV2Blinded `json:"beacon_block" validate:"required"`
}

// DepositSignRequest Not currently supported by Prysm.
Expand Down Expand Up @@ -275,8 +276,9 @@ type BeaconBlockBodyAltair struct {
SyncAggregate *SyncAggregate `json:"sync_aggregate"`
}

// BeaconBlockBellatrixBlockV2 a field of BlockBellatrixSignRequest.
type BeaconBlockBellatrixBlockV2 struct {
// BeaconBlockV2Blinded a field of BlockV2BlindedSignRequest.
// Supports Bellatrix(merge) and Capella
type BeaconBlockV2Blinded struct {
Version string `json:"version" enum:"true"`
BlockHeader *BeaconBlockHeader `json:"block_header"`
}
Expand Down