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

Re-sign and re-share using proofs and EIP1271 signature #100

Merged
merged 39 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2fe1d0f
initial resigning
pavelkrolevets Apr 8, 2024
f329be8
add routes + flow
pavelkrolevets Apr 22, 2024
6a8f698
working resigning with result validation
pavelkrolevets Apr 23, 2024
c71c54b
fix tests
pavelkrolevets Apr 23, 2024
49ee5e9
add integration tests for resiging
pavelkrolevets Apr 24, 2024
192e714
update integration tests to use cli commands
pavelkrolevets Apr 25, 2024
798333c
initial spec alignment + reshare module
pavelkrolevets Jun 7, 2024
db83ed4
working resharing
pavelkrolevets Jun 11, 2024
323a9de
add EIP1271 owner signature verification
pavelkrolevets Jun 13, 2024
b07da73
update resharing + add docker demo for resharing
pavelkrolevets Jun 14, 2024
2b994c0
add reshare threshold + integration tests
pavelkrolevets Jun 19, 2024
94c75d9
add threshold integration tests
pavelkrolevets Jun 20, 2024
49a58fb
fix logic at message processing
pavelkrolevets Jun 21, 2024
7cf7e54
add eip1271 sig integration tests
pavelkrolevets Jun 21, 2024
01449eb
add eip1271 sig verification to resign + integration/docker tests
pavelkrolevets Jun 24, 2024
d160313
add eip1271 sig resign test + bulk tests
pavelkrolevets Jun 24, 2024
cf71c67
fix/update unit + integration tests
pavelkrolevets Jun 25, 2024
2ab1d07
Merge branch 'unstable' into re-sharing
pavelkrolevets Jun 25, 2024
e3599e9
update tests + fix bls set
pavelkrolevets Jun 26, 2024
a805153
PR comments resolved #1
pavelkrolevets Aug 21, 2024
66aa776
PR comments resolved #2
pavelkrolevets Aug 21, 2024
69a6564
PR comments resolved #3
pavelkrolevets Aug 21, 2024
2588104
PR comments resolved #4
pavelkrolevets Aug 21, 2024
67f0d5d
Merge branch 're-sign' into re-sharing
pavelkrolevets Aug 22, 2024
9de0d2e
PR comments resolved #5
pavelkrolevets Aug 22, 2024
48e52ed
PR comments resolved #6
pavelkrolevets Aug 23, 2024
a6600b4
fix tests + docker build update
pavelkrolevets Aug 23, 2024
30421ef
update CI
pavelkrolevets Aug 26, 2024
b596736
fix test
pavelkrolevets Aug 26, 2024
b7507a8
lint
pavelkrolevets Aug 26, 2024
7b5def5
add more reshare integration tests
pavelkrolevets Aug 26, 2024
07857e5
go 1.23
pavelkrolevets Aug 26, 2024
94936c0
add unit tests for join/disjoin sets of operators
pavelkrolevets Sep 1, 2024
cd66782
lint
pavelkrolevets Sep 1, 2024
f28b9cd
add proofs validation before sending + more reshare threshold integra…
pavelkrolevets Sep 1, 2024
928a72f
fix unit tests
pavelkrolevets Sep 2, 2024
0f675a5
lint
pavelkrolevets Sep 2, 2024
9af8315
fix review comments
MatusKysel Sep 2, 2024
2c789e9
remove typo and unused struct
MatusKysel Sep 2, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/go-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.23"

- name: Build
run: go build -v ./...

- name: Test
run: go test ./... -timeout 3600s
run: go run gotest.tools/gotestsum@latest --format pkgname -- -timeout=3600s ./...

- name: Critic
run: go install -v github.com/go-critic/go-critic/cmd/gocritic@latest && gocritic check ./...
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
bin/
.vscode/
examples/*/output/*
integration_test/output

######## Node
# Logs
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use golang base image
FROM golang:1.20-alpine3.18 as build
FROM golang:1.23.0-alpine3.20 as build

WORKDIR /ssv-dkg

Expand Down Expand Up @@ -27,7 +27,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
./cmd/ssv-dkg

# Final stage
FROM alpine:3.18
FROM alpine:3.20
WORKDIR /ssv-dkg

# Install openssl
Expand Down
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ build:
# Recipe to run tests
test:
@echo "running tests"
go run gotest.tools/gotestsum@latest --format testname
go run gotest.tools/gotestsum@latest --format pkgname --jsonfile test-output.log -- -timeout=3600s ./...

# Recipe to build the Docker image
docker-build-image:
Expand All @@ -40,16 +40,28 @@ docker-build-image:

docker-demo-operators:
@echo "Running operators in docker demo"
docker-compose up --build operator1 operator2 operator3 operator4 operator5 operator6 operator7 operator8
docker-compose up --build operator1 operator2 operator3 operator4 operator5 operator6 operator7 operator8 operator9 operator10 operator11 operator12 operator13

docker-demo-initiator:
@echo "Running initiator in docker demo"
docker-compose up --build initiator

docker-demo-resign:
@echo "Running re-sign ceremony in docker demo"
docker-compose up --build resign

docker-demo-reshare:
@echo "Running re-share ceremony in docker demo"
docker-compose up --build reshare

docker-demo-ping:
@echo "Running ping operators in docker demo"
docker-compose up --build ping

docker-demo-ethnode:
@echo "Running ethereum node in docker demo"
docker-compose up --build ethnode

docker-operator:
@echo "Running operator docker, make sure to update ./examples/operator1/congig/config.yaml"
docker run \
Expand Down
4 changes: 4 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func init() {
RootCmd.AddCommand(operator.StartDKGOperator)
RootCmd.AddCommand(initiator.HealthCheck)
RootCmd.AddCommand(verify.Verify)
RootCmd.AddCommand(initiator.StartResigning)
RootCmd.AddCommand(initiator.StartReshare)
}

// RootCmd represents the root command of DKG-tool CLI
Expand All @@ -32,6 +34,8 @@ func Execute(appName, version string) {
RootCmd.Version = version
initiator.HealthCheck.Version = version
initiator.StartDKG.Version = version
initiator.StartResigning.Version = version
initiator.StartReshare.Version = version
operator.StartDKGOperator.Version = version
if err := RootCmd.Execute(); err != nil {
log.Fatal("failed to execute root command", zap.Error(err))
Expand Down
31 changes: 31 additions & 0 deletions cli/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
const (
withdrawAddress = "withdrawAddress"
operatorIDs = "operatorIDs"
newOperatorIDs = "newOperatorIDs"
operatorsInfo = "operatorsInfo"
operatorsInfoPath = "operatorsInfoPath"
privKey = "privKey"
Expand All @@ -29,6 +30,10 @@ const (
clientCACertPath = "clientCACertPath"
serverTLSCertPath = "serverTLSCertPath"
serverTLSKeyPath = "serverTLSKeyPath"
proofsFilePath = "proofsFilePath"
ethKeystorePath = "ethKeystorePath"
ethKeystorePass = "ethKeystorePass"
ethEndpointURL = "ethEndpointURL"
)

// WithdrawAddressFlag adds withdraw address flag to the command
Expand All @@ -41,6 +46,11 @@ func OperatorIDsFlag(c *cobra.Command) {
AddPersistentStringSliceFlag(c, operatorIDs, []string{"1", "2", "3"}, "Operator IDs", false)
}

// newOperatorIDsFlag adds new operators IDs flag to the command
func NewOperatorIDsFlag(c *cobra.Command) {
AddPersistentStringSliceFlag(c, newOperatorIDs, []string{"1", "2", "3"}, "New operator IDs for resharing ceremony", false)
}

// OperatorsInfoFlag adds path to operators' ifo file flag to the command
func OperatorsInfoFlag(c *cobra.Command) {
AddPersistentStringFlag(c, operatorsInfo, "", "Raw JSON string operators' public keys, IDs and IPs file e.g. `{ 1: { publicKey: XXX, id: 1, ip: 10.0.0.1:3033 }`", false)
Expand Down Expand Up @@ -136,6 +146,27 @@ func OperatorIDFlag(c *cobra.Command) {
AddPersistentIntFlag(c, operatorID, 0, "Operator ID", false)
}

// ProofsFilePath add file path to proofs flag to the command
func ProofsFilePath(c *cobra.Command) {
AddPersistentStringFlag(c, proofsFilePath, "proofs.json", "Path to proofs file", false)
}

// KeystoreFilePath
func KeystoreFilePath(c *cobra.Command) {
AddPersistentStringFlag(c, ethKeystorePath, "keystore.json", "Path to ethereum keystore json file", false)
}

// KeystoreFilePass
func KeystoreFilePass(c *cobra.Command) {
AddPersistentStringFlag(c, ethKeystorePass, "", "Password to decrypt ethereum keystore json file", false)
}


// EthEndpointURL
func EthEndpointURL(c *cobra.Command) {
AddPersistentStringFlag(c, ethEndpointURL, "http://127.0.0.1:8545", "Ethereum node endpoint URL", false)
}

// AddPersistentStringFlag adds a string flag to the command
func AddPersistentStringFlag(c *cobra.Command, flag, value, description string, isRequired bool) {
req := ""
Expand Down
21 changes: 10 additions & 11 deletions cli/initiator/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"fmt"
"log"

"github.com/sourcegraph/conc/pool"
"github.com/spf13/cobra"
"go.uber.org/zap"

e2m_core "github.com/bloxapp/eth2-key-manager/core"
cli_utils "github.com/bloxapp/ssv-dkg/cli/utils"
"github.com/bloxapp/ssv-dkg/pkgs/crypto"
"github.com/bloxapp/ssv-dkg/pkgs/initiator"
"github.com/bloxapp/ssv-dkg/pkgs/wire"
"github.com/sourcegraph/conc/pool"
"github.com/spf13/cobra"
"go.uber.org/zap"

spec "github.com/ssvlabs/dkg-spec"
)

const (
Expand Down Expand Up @@ -62,10 +62,9 @@ var StartDKG = &cobra.Command{
if err != nil {
logger.Fatal("😥 Failed to load operators: ", zap.Error(err))
}
logger.Info("🔑 opening initiator RSA private key file")
ethnetwork := e2m_core.MainNetwork
if cli_utils.Network != "now_test_network" {
ethnetwork = e2m_core.NetworkFromString(cli_utils.Network)
ethNetwork := e2m_core.NetworkFromString(cli_utils.Network)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should make this fail on invalid input (now it fails silently with unknown outcomes)

if ethNetwork == "" {
logger.Fatal("😥 Cant recognize eth network")
}
// start the ceremony
ctx := context.Background()
Expand All @@ -79,10 +78,10 @@ var StartDKG = &cobra.Command{
return nil, err
}
// Create a new ID.
id := crypto.NewID()
id := spec.NewID()
nonce := cli_utils.Nonce + uint64(i)
// Perform the ceremony.
depositData, keyShares, proofs, err := dkgInitiator.StartDKG(id, cli_utils.WithdrawAddress.Bytes(), operatorIDs, ethnetwork, cli_utils.OwnerAddress, nonce)
depositData, keyShares, proofs, err := dkgInitiator.StartDKG(id, cli_utils.WithdrawAddress.Bytes(), operatorIDs, ethNetwork, cli_utils.OwnerAddress, nonce)
if err != nil {
return nil, err
}
Expand Down
125 changes: 125 additions & 0 deletions cli/initiator/reshare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package initiator

import (
"fmt"
"log"
"os"
"path/filepath"

e2m_core "github.com/bloxapp/eth2-key-manager/core"
cli_utils "github.com/bloxapp/ssv-dkg/cli/utils"
"github.com/bloxapp/ssv-dkg/pkgs/initiator"
"github.com/bloxapp/ssv-dkg/pkgs/wire"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/spf13/cobra"
"go.uber.org/zap"

spec "github.com/ssvlabs/dkg-spec"
)

func init() {
cli_utils.SetReshareFlags(StartReshare)
}

var StartReshare = &cobra.Command{
Use: "reshare",
Short: "Reshare an existing key to new operators",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println(`
▓█████▄ ██ ▄█▀ ▄████ ██▀███ ▓█████ ██████ ██░ ██ ▄▄▄ ██▀███ ▓█████
▒██▀ ██▌ ██▄█▒ ██▒ ▀█▒ ▓██ ▒ ██▒▓█ ▀ ▒██ ▒ ▓██░ ██▒▒████▄ ▓██ ▒ ██▒▓█ ▀
░██ █▌▓███▄░ ▒██░▄▄▄░ ▓██ ░▄█ ▒▒███ ░ ▓██▄ ▒██▀▀██░▒██ ▀█▄ ▓██ ░▄█ ▒▒███
░▓█▄ ▌▓██ █▄ ░▓█ ██▓ ▒██▀▀█▄ ▒▓█ ▄ ▒ ██▒░▓█ ░██ ░██▄▄▄▄██ ▒██▀▀█▄ ▒▓█ ▄
░▒████▓ ▒██▒ █▄░▒▓███▀▒ ░██▓ ▒██▒░▒████▒▒██████▒▒░▓█▒░██▓ ▓█ ▓██▒░██▓ ▒██▒░▒████▒
▒▒▓ ▒ ▒ ▒▒ ▓▒ ░▒ ▒ ░ ▒▓ ░▒▓░░░ ▒░ ░▒ ▒▓▒ ▒ ░ ▒ ░░▒░▒ ▒▒ ▓▒█░░ ▒▓ ░▒▓░░░ ▒░ ░
░ ▒ ▒ ░ ░▒ ▒░ ░ ░ ░▒ ░ ▒░ ░ ░ ░░ ░▒ ░ ░ ▒ ░▒░ ░ ▒ ▒▒ ░ ░▒ ░ ▒░ ░ ░ ░
░ ░ ░ ░ ░░ ░ ░ ░ ░ ░░ ░ ░ ░ ░ ░ ░ ░░ ░ ░ ▒ ░░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
░`)
if err := cli_utils.SetViperConfig(cmd); err != nil {
return err
}
if err := cli_utils.BindReshareFlags(cmd); err != nil {
return err
}
logger, err := cli_utils.SetGlobalLogger(cmd, "dkg-initiator")
if err != nil {
return err
}
defer func() {
if err := cli_utils.Sync(logger); err != nil {
log.Printf("Failed to sync logger: %v", err)
}
}()
logger.Info("🪛 Initiator`s", zap.String("Version", cmd.Version))
opMap, err := cli_utils.LoadOperators(logger)
if err != nil {
logger.Fatal("😥 Failed to load operators: ", zap.Error(err))
}
oldOperatorIDs, err := cli_utils.StingSliceToUintArray(cli_utils.OperatorIDs)
if err != nil {
logger.Fatal("😥 Failed to load participants: ", zap.Error(err))
}
newOperatorIDs, err := cli_utils.StingSliceToUintArray(cli_utils.NewOperatorIDs)
if err != nil {
logger.Fatal("😥 Failed to load new participants: ", zap.Error(err))
}
// create a new ID for resharing
id := spec.NewID()
// create initiator instance
dkgInitiator, err := initiator.New(opMap.Clone(), logger, cmd.Version, cli_utils.ClientCACertPath)
if err != nil {
return err
}
signedProofs, err := wire.LoadProofs(cli_utils.ProofsFilePath)
if err != nil {
logger.Fatal("😥 Failed to read proofs json file:", zap.Error(err))
}
ethNetwork := e2m_core.NetworkFromString(cli_utils.Network)
if ethNetwork == "" {
logger.Fatal("😥 Cant recognize eth network")
}
// Open ethereum keystore
jsonBytes, err := os.ReadFile(cli_utils.KeystorePath)
if err != nil {
return err
}
keyStorePassword, err := os.ReadFile(filepath.Clean(cli_utils.KeystorePass))
if err != nil {
return fmt.Errorf("😥 Error reading password file: %s", err)
}
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
if err != nil {
return err
}
// Start the ceremony
depositData, keyShares, proof, err := dkgInitiator.StartResharing(id, oldOperatorIDs, newOperatorIDs, signedProofs[0], sk.PrivateKey, ethNetwork, cli_utils.WithdrawAddress[:], cli_utils.OwnerAddress, cli_utils.Nonce)
if err != nil {
logger.Fatal("😥 Failed to initiate DKG ceremony: ", zap.Error(err))
}
var depositDataArr []*wire.DepositDataCLI
var keySharesArr []*wire.KeySharesCLI
var proofs [][]*wire.SignedProof
depositDataArr = append(depositDataArr, depositData)
keySharesArr = append(keySharesArr, keyShares)
proofs = append(proofs, proof)
// Save results
logger.Info("🎯 All data is validated.")
if err := cli_utils.WriteResults(
logger,
depositDataArr,
keySharesArr,
proofs,
false,
1,
cli_utils.OwnerAddress,
cli_utils.Nonce,
cli_utils.WithdrawAddress,
cli_utils.OutputPath,
); err != nil {
logger.Fatal("Could not save results", zap.Error(err))
}
logger.Info("🚀 Resharing ceremony completed")
return nil
},
}
Loading
Loading