Skip to content

Commit

Permalink
review feedback and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
james-prysm committed Jan 15, 2025
1 parent 5239021 commit a8b19b7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
3 changes: 3 additions & 0 deletions changelog/james-prysm_remote-signer-electra.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Remote signer electra fork support.
8 changes: 5 additions & 3 deletions validator/keymanager/remote-web3signer/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/io/file"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
validatorpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/validator/accounts/petnames"
"github.com/prysmaticlabs/prysm/v5/validator/keymanager"
"github.com/prysmaticlabs/prysm/v5/validator/keymanager/remote-web3signer/internal"
Expand Down Expand Up @@ -405,9 +406,10 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
case *validatorpb.SignRequest_AttestationData:
return handleAttestationData(ctx, validator, request, genesisValidatorsRoot)
case *validatorpb.SignRequest_AggregateAttestationAndProof:
// TODO: update to V2 sometime after release
return handleAggregateAttestationAndProof(ctx, validator, request, genesisValidatorsRoot)
case *validatorpb.SignRequest_AggregateAttestationAndProofElectra:
return handleAggregateAttestationAndProofV2Electra(ctx, validator, request, genesisValidatorsRoot)
return handleAggregateAttestationAndProofV2(ctx, version.Electra, validator, request, genesisValidatorsRoot)
case *validatorpb.SignRequest_Slot:
return handleAggregationSlot(ctx, validator, request, genesisValidatorsRoot)
case *validatorpb.SignRequest_BlockAltair:
Expand Down Expand Up @@ -488,8 +490,8 @@ func handleAggregateAttestationAndProof(ctx context.Context, validator *validato
return json.Marshal(aggregateAndProofSignRequest)
}

func handleAggregateAttestationAndProofV2Electra(ctx context.Context, validator *validator.Validate, request *validatorpb.SignRequest, genesisValidatorsRoot []byte) ([]byte, error) {
aggregateAndProofSignRequestV2, err := types.GetAggregateAndProofV2ElectraSignRequest(request, genesisValidatorsRoot)
func handleAggregateAttestationAndProofV2(ctx context.Context, fork int, validator *validator.Validate, request *validatorpb.SignRequest, genesisValidatorsRoot []byte) ([]byte, error) {
aggregateAndProofSignRequestV2, err := types.GetAggregateAndProofV2SignRequest(fork, request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions validator/keymanager/remote-web3signer/keymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ func TestKeymanager_Sign(t *testing.T) {
want: desiredSig,
wantErr: false,
},
{
name: "AGGREGATE_AND_PROOF_V2",
args: args{
request: mock.GetMockSignRequest("AGGREGATE_AND_PROOF_V2"),
},
want: desiredSig,
wantErr: false,
},
{
name: "ATTESTATION",
args: args{
Expand Down
27 changes: 27 additions & 0 deletions validator/keymanager/remote-web3signer/types/mock/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ func GetMockSignRequest(t string) *validatorpb.SignRequest {
},
SigningSlot: 0,
}
case "AGGREGATE_AND_PROOF_V2":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_AggregateAttestationAndProofElectra{
AggregateAttestationAndProofElectra: &eth.AggregateAttestationAndProofElectra{
AggregatorIndex: 0,
Aggregate: &eth.AttestationElectra{
AggregationBits: bitfield.Bitlist{0b1101},
Data: &eth.AttestationData{
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
Source: &eth.Checkpoint{
Root: make([]byte, fieldparams.RootLength),
},
Target: &eth.Checkpoint{
Root: make([]byte, fieldparams.RootLength),
},
},
Signature: make([]byte, 96),
CommitteeBits: bitfield.Bitvector64{0x01},
},
SelectionProof: make([]byte, fieldparams.BLSSignatureLength),
},
},
SigningSlot: 0,
}
case "ATTESTATION":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
Expand Down
12 changes: 7 additions & 5 deletions validator/keymanager/remote-web3signer/types/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package types

import (
"fmt"
"strings"

"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
validatorpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)

// GetBlockSignRequest maps the request for signing type BLOCK.
Expand Down Expand Up @@ -88,8 +90,8 @@ func GetAggregateAndProofSignRequest(request *validatorpb.SignRequest, genesisVa
}, nil
}

// GetAggregateAndProofV2ElectraSignRequest maps the request for signing type AGGREGATE_AND_PROOF_V2 on Electra changes.
func GetAggregateAndProofV2ElectraSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*AggregateAndProofV2ElectraSignRequest, error) {
// GetAggregateAndProofV2SignRequest maps the request for signing type AGGREGATE_AND_PROOF_V2 on Electra changes.
func GetAggregateAndProofV2SignRequest(v int, request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*AggregateAndProofV2SignRequest, error) {
aggregateAttestationAndProof, ok := request.Object.(*validatorpb.SignRequest_AggregateAttestationAndProofElectra)
if !ok {
return nil, errors.New("failed to cast request object to aggregate attestation and proof")
Expand All @@ -105,12 +107,12 @@ func GetAggregateAndProofV2ElectraSignRequest(request *validatorpb.SignRequest,
if err != nil {
return nil, err
}
return &AggregateAndProofV2ElectraSignRequest{
return &AggregateAndProofV2SignRequest{
Type: "AGGREGATE_AND_PROOF_V2",
ForkInfo: fork,
SigningRoot: request.SigningRoot,
AggregateAndProof: &AggregateAndProofV2Electra{
Version: "ELECTRA",
AggregateAndProof: &AggregateAndProofV2{
Version: strings.ToUpper(version.String(v)),
Data: aggregateAndProof,
},
}, nil
Expand Down
18 changes: 9 additions & 9 deletions validator/keymanager/remote-web3signer/types/web3signer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ type AggregateAndProofSignRequest struct {
AggregateAndProof *AggregateAndProof `json:"aggregate_and_proof" validate:"required"`
}

// AggregateAndProofV2ElectraSignRequest is a request object for web3signer sign api.
type AggregateAndProofV2ElectraSignRequest struct {
Type string `json:"type" validate:"required"`
ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
SigningRoot hexutil.Bytes `json:"signingRoot"`
AggregateAndProof *AggregateAndProofV2Electra `json:"aggregate_and_proof" validate:"required"`
// AggregateAndProofV2SignRequest is a request object for web3signer sign api.
type AggregateAndProofV2SignRequest struct {
Type string `json:"type" validate:"required"`
ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
SigningRoot hexutil.Bytes `json:"signingRoot"`
AggregateAndProof *AggregateAndProofV2 `json:"aggregate_and_proof" validate:"required"`
}

// AggregateAndProofV2Electra is a wrapper object for AggregateAndProofV2ElectraSignRequest
type AggregateAndProofV2Electra struct {
// AggregateAndProofV2 is a wrapper object for AggregateAndProofV2SignRequest
type AggregateAndProofV2 struct {
Version string `json:"version" validate:"required"`
Data *AggregateAndProofElectra `json:"data" validate:"required"`
Data *AggregateAndProofElectra `json:"data" validate:"required"` // specifies Electra for now
}

// AttestationSignRequest is a request object for web3signer sign api.
Expand Down

0 comments on commit a8b19b7

Please sign in to comment.