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

Web3Signer: Object Mapper and Types #10061

Merged
merged 22 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
952e937
initial commit
james-prysm Jan 7, 2022
33c2a26
fixing some types and renaming file
james-prysm Jan 7, 2022
95f1993
initial map function commit and moving to a v1 folder
james-prysm Jan 7, 2022
98615a0
adding in remaining mapper functions and comments for types and initi…
james-prysm Jan 10, 2022
d3e02b2
adding readme
james-prysm Jan 10, 2022
014d16a
fixing unit tests and errors caught
james-prysm Jan 10, 2022
554c55a
fixed a few missed properties and names
james-prysm Jan 11, 2022
2d44b6a
Merge branch 'develop' into web3signer-types
james-prysm Jan 11, 2022
1bcb0b7
updating error handling to be more descriptive
james-prysm Jan 11, 2022
39cb7b7
Merge branch 'develop' into web3signer-types
james-prysm Jan 11, 2022
5a0a40c
Update validator/keymanager/remote-web3signer/client_test.go
james-prysm Jan 11, 2022
112d4b0
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jan 11, 2022
148ab0a
Update validator/keymanager/remote-web3signer/v1/custom_mappers.go
james-prysm Jan 11, 2022
655ca36
Update validator/keymanager/remote-web3signer/v1/custom_mappers.go
james-prysm Jan 11, 2022
638a626
fixing comments
james-prysm Jan 11, 2022
f6d86f4
fixing comments
james-prysm Jan 11, 2022
cd325f9
adding more error checks
james-prysm Jan 11, 2022
25ead3a
Merge branch 'develop' into web3signer-types
james-prysm Jan 11, 2022
147b938
Update validator/keymanager/remote-web3signer/client.go
rauljordan Jan 11, 2022
c52f411
fmt and bazel build
rauljordan Jan 11, 2022
0e96c61
fixing unit tests
james-prysm Jan 11, 2022
846d3cd
lint needed
rauljordan Jan 11, 2022
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
2 changes: 2 additions & 0 deletions validator/keymanager/remote-web3signer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//crypto/bls:go_default_library",
"//encoding/bytesutil:go_default_library",
"//proto/prysm/v1alpha1/validator-client:go_default_library",
"//validator/keymanager/remote-web3signer/v1:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand All @@ -35,6 +36,7 @@ go_test(
"//encoding/bytesutil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/validator-client:go_default_library",
"//validator/keymanager/remote-web3signer/v1:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
],
Expand Down
56 changes: 56 additions & 0 deletions validator/keymanager/remote-web3signer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Web3Signer

Web3Signer is a popular remote signer tool by Consensys to allow users to store validation keys outside the validation
client and signed without the vc knowing the private keys. Web3Signer Specs are found by
searching `Consensys' Web3Signer API specification`

issue: https://github.com/prysmaticlabs/prysm/issues/9994

## Support

WIP

## Features

### CLI

WIP

### API

- Get Public keys: returns all public keys currently stored with web3signer excluding newly added keys if reload keys
was not run.
- Sign: Signs a message with a given public key. There are several types of messages that can be signed ( web3signer
type to prysm type):
- BLOCK <- *validatorpb.SignRequest_Block
- ATTESTATION <- *validatorpb.SignRequest_AttestationData
- AGGREGATE_AND_PROOF <- *validatorpb.SignRequest_AggregateAttestationAndProof
- AGGREGATION_SLOT <- *validatorpb.SignRequest_Slot
- BLOCK_V2 <- *validatorpb.SignRequest_BlockV2
- BLOCK_V3 <- *validatorpb.SignRequest_BlockV3
- DEPOSIT <- not supported
- RANDAO_REVEAL <- *validatorpb.SignRequest_Epoch
- VOLUNTARY_EXIT <- *validatorpb.SignRequest_Exit
- SYNC_COMMITTEE_MESSAGE <- *validatorpb.SignRequest_SyncMessageBlockRoot
- SYNC_COMMITTEE_SELECTION_PROOF <- *validatorpb.SignRequest_SyncAggregatorSelectionData
- SYNC_COMMITTEE_CONTRIBUTION_AND_PROOF <- *validatorpb.SignRequest_ContributionAndProof
- Reload Keys: reloads all public keys from the web3signer.
- Get Server Status: returns OK if the web3signer is ok.

## Files Added and Files Changed

- Files Added:
- validator/keymanager/remote-web3signer package

- Files Modified:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually part of the cli pr so please ignore this section, it was just to keep track of file changes as we might want to refactor this in the future

- modified: cmd/validator/flags/flags.go
- modified: validator/accounts/accounts_backup.go
- modified: validator/accounts/accounts_list.go
- modified: validator/accounts/iface/wallet.go
- modified: validator/accounts/userprompt/prompt.go
- modified: validator/accounts/wallet/wallet.go
- modified: validator/accounts/wallet_create.go
- modified: validator/client/runner.go
- modified: validator/client/validator.go
- modified: validator/keymanager/remote-web3signer/keymanager.go
- modified: validator/keymanager/types.go
35 changes: 6 additions & 29 deletions validator/keymanager/remote-web3signer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/crypto/bls"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
v1 "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1"
)

const (
Expand Down Expand Up @@ -47,35 +48,11 @@ func newApiClient(baseEndpoint string) (*apiClient, error) {
}, nil
}

// SignRequest is a request object for web3signer sign api.
type SignRequest struct {
Type string `json:"type"`
ForkInfo *ForkInfo `json:"fork_info"`
SigningRoot string `json:"signingRoot"`
AggregationSlot *AggregationSlot `json:"aggregation_slot"`
}

// ForkInfo a sub property object of the Sign request,in the future before bellatrix to remove the need to send the entire block body and just use the block_body_root.
type ForkInfo struct {
Fork *Fork `json:"fork"`
GenesisValidatorsRoot string `json:"genesis_validators_root"`
}

// Fork a sub property of ForkInfo.
type Fork struct {
PreviousVersion string `json:"previous_version"`
CurrentVersion string `json:"current_version"`
Epoch string `json:"epoch"`
}

// AggregationSlot a sub property of SignRequest.
type AggregationSlot struct {
Slot string `json:"slot"`
}

// signResponse the response object of the web3signer sign api.
type signResponse struct {
Signature string `json:"signature"`
Type string `json:"type"`
ForkInfo *v1.ForkInfo `json:"fork_info"`
SigningRoot string `json:"signingRoot"`
AggregationSlot *v1.AggregationSlot `json:"aggregation_slot"`
}

// Sign is a wrapper method around the web3signer sign api.
Expand All @@ -95,7 +72,7 @@ func (client *apiClient) Sign(_ context.Context, pubKey string, request *SignReq
if resp.StatusCode == 412 {
return nil, errors.Wrap(err, "signing operation failed due to slashing protection rules")
}
signResp := &signResponse{}
signResp := &v1.SignResponse{}
if err := client.unmarshalResponse(resp.Body, &signResp); err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions validator/keymanager/remote-web3signer/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"testing"

v1 "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1"
"github.com/stretchr/testify/assert"
)

Expand All @@ -22,17 +23,17 @@ func (m *mockTransport) RoundTrip(*http.Request) (*http.Response, error) {
}

func getClientMockSignRequest() *SignRequest {
forkData := &Fork{
forkData := &v1.Fork{
PreviousVersion: "",
CurrentVersion: "",
Epoch: "",
}
forkInfoData := &ForkInfo{
forkInfoData := &v1.ForkInfo{
Fork: forkData,
GenesisValidatorsRoot: "",
}

AggregationSlotData := &AggregationSlot{Slot: ""}
AggregationSlotData := &v1.AggregationSlot{Slot: ""}
// remember to replace signing root with hex encoding remove 0x
web3SignerRequest := SignRequest{
Type: "foo",
Expand Down
7 changes: 4 additions & 3 deletions validator/keymanager/remote-web3signer/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/async/event"
"github.com/prysmaticlabs/prysm/crypto/bls"
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
v1 "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1"
)

// SetupConfig includes configuration values for initializing.
Expand Down Expand Up @@ -85,16 +86,16 @@ func (km *Keymanager) Sign(ctx context.Context, request *validatorpb.SignRequest
return nil, err
}

forkData := &Fork{
forkData := &v1.Fork{
PreviousVersion: hexutil.Encode(request.Fork.PreviousVersion),
CurrentVersion: hexutil.Encode(request.Fork.CurrentVersion),
Epoch: fmt.Sprint(request.Fork.Epoch),
}
forkInfoData := &ForkInfo{
forkInfoData := &v1.ForkInfo{
Fork: forkData,
GenesisValidatorsRoot: hexutil.Encode(km.genesisValidatorsRoot),
}
aggregationSlotData := &AggregationSlot{Slot: fmt.Sprint(request.AggregationSlot)}
aggregationSlotData := &v1.AggregationSlot{Slot: fmt.Sprint(request.AggregationSlot)}
web3SignerRequest := SignRequest{
Type: signRequestType,
ForkInfo: forkInfoData,
Expand Down
32 changes: 32 additions & 0 deletions validator/keymanager/remote-web3signer/v1/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@prysm//tools/go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"custom_mappers.go",
"mocks.go",
"web3signer_types.go",
],
importpath = "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1",
visibility = ["//visibility:public"],
deps = [
"//config/fieldparams:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = ["custom_mappers_test.go"],
embed = [":go_default_library"],
deps = [
"//config/fieldparams:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/util:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
],
)
Loading