Skip to content

Commit

Permalink
fix tests + work on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelkrolevets committed Sep 15, 2023
1 parent 8935dad commit ecf4e91
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 1,491 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# with Go source code. If you know what GOPATH is then you probably
# don't need to bother with make.

.PHONY: dkgcli test clean build docker-build
.PHONY: install clean build test docker-build docker-operators docker-initiator mockgen-install

GOBIN = ./build/bin
GO ?= latest
Expand All @@ -17,7 +17,7 @@ DOCKER_IMAGE=ssv-dkg
install:
$(GOINSTALL) cmd/ssv-dkg/ssv-dkg.go
@echo "Done building."
@echo "Run dkgcli to launch the tool."
@echo "Run ssv-dkg to launch the tool."

clean:
env GO111MODULE=on go clean -cache
Expand All @@ -30,7 +30,7 @@ build:
# Recipe to run tests
test:
@echo "running tests"
go test -p 1 ./...
go test -v -p 1 ./...

# Recipe to build the Docker image
docker-build:
Expand All @@ -43,4 +43,8 @@ docker-operators:

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

mockgen-install:
go install github.com/golang/mock/[email protected]
@which mockgen || echo "Error: ensure `go env GOPATH` is added to PATH"
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ NOTE: ssv-dkg tool is using an ssv operator private key file. Encrypted and plin
#### Start a DKG-operator

```sh
ssv-dkg start-dkg-operator --privKey ./examples/operator1/encrypted_private_key.json --port 3030 --password ./password --storeShare true
ssv-dkg start-operator --privKey ./examples/operator1/encrypted_private_key.json --port 3030 --password ./password --storeShare true

### where
--privKey ./encrypted_private_key.json # path to ssv operator`s private key
Expand All @@ -62,12 +62,12 @@ storeShare: true
When using configuration file, run:
```sh
ssv-dkg start-dkg-operator
ssv-dkg start-operator
```

### Initiator

The initiator uses `init-dkg` to create the initial details needed to run DKG between all operators.
The initiator uses `init` to create the initial details needed to run DKG between all operators.

Generate initiator identity RSA key pair:

Expand All @@ -81,7 +81,7 @@ Write down `password` in any text file, for example to `./password`
Run:

```sh
ssv-dkg init-dkg \
ssv-dkg init \
--operatorIDs 1,2,3,4 \
--operatorsInfoPath ./operators_integration.json \
--owner 0x81592c3de184a3e2c0dcb5a261bc107bfa91f494 \
Expand All @@ -106,7 +106,7 @@ ssv-dkg init-dkg \
--initiatorPrivKeyPassword: ./password # path to password file to decrypt the key
```

Its also possible to use yaml configuration file `./config/initiator.yaml` for parameters. `dkgcli` will be looking for this file at `./config/` folder at a same root as the binary.
Its also possible to use yaml configuration file `./config/initiator.yaml` for parameters. `ssv-dkg` will be looking for this file at `./config/` folder at the same root as the binary.

Example:

Expand All @@ -126,7 +126,7 @@ password: ./password
When using configuration file, run:
```sh
ssv-dkg init-dkg
ssv-dkg init
```

**_NOTE: Threshold is computed automatically using 3f+1 tolerance._**
Expand All @@ -140,8 +140,8 @@ Here we explain how we secure the communication between DKG ceremony initiator a
1. Initiator is using RSA key (2048 bits) to sign init message sent to operators. Upon receiving operators verify the sig using pub key at init message. If the sig is valid, operators store this pub key for further verification of messages coming from the initiator(s).
2. Operators are using RSA key (ssv operator key - 2048 bits) to sign every message sent back to initiator.
3. Initiator verifies every message incoming from any operator using ID and Public Key provided by operators info file, then initiator creates a combined message and signs it.
4. Operators verify each of the messages of other operators participating in the ceremony and verifies initiator signature of the message.
5. During the DKG protocol execution, the BLS auth scheme is being used - G2 for its signature space and G1 for its public key
4. Operators verify each of the messages of other operators participating in the ceremony and verifies initiator`s signature of the combined message.
5. During the DKG protocol execution, the BLS auth scheme is used - G2 for its signature space and G1 for its public keys

## Architecture

Expand Down
2 changes: 1 addition & 1 deletion cli/initiator/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
}

var StartDKG = &cobra.Command{
Use: "init-dkg",
Use: "init",
Short: "Initiates a DKG protocol",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(`
Expand Down
2 changes: 1 addition & 1 deletion cli/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func init() {
}

var StartDKGOperator = &cobra.Command{
Use: "start-dkg-operator",
Use: "start-operator",
Short: "Starts an instance of DKG operator",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(`
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
entrypoint: /app
command:
[
"start-dkg-operator",
"start-operator",
"--privKey",
"/data/operator1/encrypted_private_key.json",
"--password",
Expand All @@ -27,7 +27,7 @@ services:
entrypoint: /app
command:
[
"start-dkg-operator",
"start-operator",
"--privKey",
"/data/operator2/encrypted_private_key.json",
"--password",
Expand All @@ -45,7 +45,7 @@ services:
entrypoint: /app
command:
[
"start-dkg-operator",
"start-operator",
"--privKey",
"/data/operator3/encrypted_private_key.json",
"--password",
Expand All @@ -63,7 +63,7 @@ services:
entrypoint: /app
command:
[
"start-dkg-operator",
"start-operator",
"--privKey",
"/data/operator4/encrypted_private_key.json",
"--password",
Expand All @@ -84,7 +84,7 @@ services:
entrypoint: /app
command:
[
"init-dkg",
"init",
"--operatorIDs",
"1,2,3,4",
"--operatorsInfoPath",
Expand Down
186 changes: 93 additions & 93 deletions integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,99 +92,99 @@ func TestHappyFlow(t *testing.T) {
srv3.srv.Close()
srv4.srv.Close()
})
// t.Run("test 7 operators happy flow", func(t *testing.T) {
// ops := make(map[uint64]initiator.Operator)
// srv1 := CreateOperator(t, 1)
// ops[1] = initiator.Operator{srv1.srv.URL, 1, &srv1.privKey.PublicKey}
// srv2 := CreateOperator(t, 2)
// ops[2] = initiator.Operator{srv2.srv.URL, 2, &srv2.privKey.PublicKey}
// srv3 := CreateOperator(t, 3)
// ops[3] = initiator.Operator{srv3.srv.URL, 3, &srv3.privKey.PublicKey}
// srv4 := CreateOperator(t, 4)
// ops[4] = initiator.Operator{srv4.srv.URL, 4, &srv4.privKey.PublicKey}
// srv5 := CreateOperator(t, 5)
// ops[5] = initiator.Operator{srv5.srv.URL, 5, &srv5.privKey.PublicKey}
// srv6 := CreateOperator(t, 6)
// ops[6] = initiator.Operator{srv6.srv.URL, 6, &srv6.privKey.PublicKey}
// srv7 := CreateOperator(t, 7)
// ops[7] = initiator.Operator{srv7.srv.URL, 7, &srv7.privKey.PublicKey}
// // Initiator priv key
// _, pv, err := rsaencryption.GenerateKeys()
// require.NoError(t, err)
// priv, err := rsaencryption.ConvertPemToPrivateKey(string(pv))
// clnt := initiator.New(priv, ops)
// withdraw := newEthAddress(t)
// owner := newEthAddress(t)
// depositData, ks, err := clnt.StartDKG(withdraw.Bytes(), []uint64{1, 2, 3, 4, 5, 6, 7}, [4]byte{0, 0, 0, 0}, "mainnnet", owner, 0)
// require.NoError(t, err)
// sharesDataSigned, err := hex.DecodeString(ks.Payload.Readable.Shares[2:])
// require.NoError(t, err)
// pubkeyraw, err := hex.DecodeString(ks.Payload.Readable.PublicKey[2:])
// require.NoError(t, err)
// testSharesData(t, ops, []*rsa.PrivateKey{srv1.privKey, srv2.privKey, srv3.privKey, srv4.privKey, srv5.privKey, srv6.privKey, srv7.privKey}, sharesDataSigned, pubkeyraw, owner, 0)
// testDepositData(t, depositData, withdraw.Bytes(), owner, 0)
// srv1.srv.Close()
// srv2.srv.Close()
// srv3.srv.Close()
// srv4.srv.Close()
// srv5.srv.Close()
// srv6.srv.Close()
// srv7.srv.Close()
// })
// t.Run("test 12 operators happy flow", func(t *testing.T) {
// ops := make(map[uint64]initiator.Operator)
// srv1 := CreateOperator(t, 1)
// ops[1] = initiator.Operator{srv1.srv.URL, 1, &srv1.privKey.PublicKey}
// srv2 := CreateOperator(t, 2)
// ops[2] = initiator.Operator{srv2.srv.URL, 2, &srv2.privKey.PublicKey}
// srv3 := CreateOperator(t, 3)
// ops[3] = initiator.Operator{srv3.srv.URL, 3, &srv3.privKey.PublicKey}
// srv4 := CreateOperator(t, 4)
// ops[4] = initiator.Operator{srv4.srv.URL, 4, &srv4.privKey.PublicKey}
// srv5 := CreateOperator(t, 5)
// ops[5] = initiator.Operator{srv5.srv.URL, 5, &srv5.privKey.PublicKey}
// srv6 := CreateOperator(t, 6)
// ops[6] = initiator.Operator{srv6.srv.URL, 6, &srv6.privKey.PublicKey}
// srv7 := CreateOperator(t, 7)
// ops[7] = initiator.Operator{srv7.srv.URL, 7, &srv7.privKey.PublicKey}
// srv8 := CreateOperator(t, 8)
// ops[8] = initiator.Operator{srv8.srv.URL, 8, &srv8.privKey.PublicKey}
// srv9 := CreateOperator(t, 9)
// ops[9] = initiator.Operator{srv9.srv.URL, 9, &srv9.privKey.PublicKey}
// srv10 := CreateOperator(t, 10)
// ops[10] = initiator.Operator{srv10.srv.URL, 10, &srv10.privKey.PublicKey}
// srv11 := CreateOperator(t, 11)
// ops[11] = initiator.Operator{srv11.srv.URL, 11, &srv11.privKey.PublicKey}
// srv12 := CreateOperator(t, 12)
// ops[12] = initiator.Operator{srv12.srv.URL, 12, &srv12.privKey.PublicKey}
// // Initiator priv key
// _, pv, err := rsaencryption.GenerateKeys()
// require.NoError(t, err)
// priv, err := rsaencryption.ConvertPemToPrivateKey(string(pv))
// clnt := initiator.New(priv, ops)
// withdraw := newEthAddress(t)
// owner := newEthAddress(t)
// depositData, ks, err := clnt.StartDKG(withdraw.Bytes(), []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, [4]byte{0, 0, 0, 0}, "mainnnet", owner, 0)
// require.NoError(t, err)
// sharesDataSigned, err := hex.DecodeString(ks.Payload.Readable.Shares[2:])
// require.NoError(t, err)
// pubkeyraw, err := hex.DecodeString(ks.Payload.Readable.PublicKey[2:])
// require.NoError(t, err)
// testSharesData(t, ops, []*rsa.PrivateKey{srv1.privKey, srv2.privKey, srv3.privKey, srv4.privKey, srv5.privKey, srv6.privKey, srv7.privKey, srv8.privKey, srv9.privKey, srv10.privKey, srv11.privKey, srv12.privKey}, sharesDataSigned, pubkeyraw, owner, 0)
// testDepositData(t, depositData, withdraw.Bytes(), owner, 0)
// srv1.srv.Close()
// srv2.srv.Close()
// srv3.srv.Close()
// srv4.srv.Close()
// srv5.srv.Close()
// srv6.srv.Close()
// srv7.srv.Close()
// srv8.srv.Close()
// srv9.srv.Close()
// srv10.srv.Close()
// srv11.srv.Close()
// srv12.srv.Close()
// })
t.Run("test 7 operators happy flow", func(t *testing.T) {
ops := make(map[uint64]initiator.Operator)
srv1 := CreateOperator(t, 1)
ops[1] = initiator.Operator{srv1.srv.URL, 1, &srv1.privKey.PublicKey}
srv2 := CreateOperator(t, 2)
ops[2] = initiator.Operator{srv2.srv.URL, 2, &srv2.privKey.PublicKey}
srv3 := CreateOperator(t, 3)
ops[3] = initiator.Operator{srv3.srv.URL, 3, &srv3.privKey.PublicKey}
srv4 := CreateOperator(t, 4)
ops[4] = initiator.Operator{srv4.srv.URL, 4, &srv4.privKey.PublicKey}
srv5 := CreateOperator(t, 5)
ops[5] = initiator.Operator{srv5.srv.URL, 5, &srv5.privKey.PublicKey}
srv6 := CreateOperator(t, 6)
ops[6] = initiator.Operator{srv6.srv.URL, 6, &srv6.privKey.PublicKey}
srv7 := CreateOperator(t, 7)
ops[7] = initiator.Operator{srv7.srv.URL, 7, &srv7.privKey.PublicKey}
// Initiator priv key
_, pv, err := rsaencryption.GenerateKeys()
require.NoError(t, err)
priv, err := rsaencryption.ConvertPemToPrivateKey(string(pv))
clnt := initiator.New(priv, ops)
withdraw := newEthAddress(t)
owner := newEthAddress(t)
depositData, ks, err := clnt.StartDKG(withdraw.Bytes(), []uint64{1, 2, 3, 4, 5, 6, 7}, [4]byte{0, 0, 0, 0}, "mainnnet", owner, 0)
require.NoError(t, err)
sharesDataSigned, err := hex.DecodeString(ks.Payload.Readable.Shares[2:])
require.NoError(t, err)
pubkeyraw, err := hex.DecodeString(ks.Payload.Readable.PublicKey[2:])
require.NoError(t, err)
testSharesData(t, ops, []*rsa.PrivateKey{srv1.privKey, srv2.privKey, srv3.privKey, srv4.privKey, srv5.privKey, srv6.privKey, srv7.privKey}, sharesDataSigned, pubkeyraw, owner, 0)
testDepositData(t, depositData, withdraw.Bytes(), owner, 0)
srv1.srv.Close()
srv2.srv.Close()
srv3.srv.Close()
srv4.srv.Close()
srv5.srv.Close()
srv6.srv.Close()
srv7.srv.Close()
})
t.Run("test 12 operators happy flow", func(t *testing.T) {
ops := make(map[uint64]initiator.Operator)
srv1 := CreateOperator(t, 1)
ops[1] = initiator.Operator{srv1.srv.URL, 1, &srv1.privKey.PublicKey}
srv2 := CreateOperator(t, 2)
ops[2] = initiator.Operator{srv2.srv.URL, 2, &srv2.privKey.PublicKey}
srv3 := CreateOperator(t, 3)
ops[3] = initiator.Operator{srv3.srv.URL, 3, &srv3.privKey.PublicKey}
srv4 := CreateOperator(t, 4)
ops[4] = initiator.Operator{srv4.srv.URL, 4, &srv4.privKey.PublicKey}
srv5 := CreateOperator(t, 5)
ops[5] = initiator.Operator{srv5.srv.URL, 5, &srv5.privKey.PublicKey}
srv6 := CreateOperator(t, 6)
ops[6] = initiator.Operator{srv6.srv.URL, 6, &srv6.privKey.PublicKey}
srv7 := CreateOperator(t, 7)
ops[7] = initiator.Operator{srv7.srv.URL, 7, &srv7.privKey.PublicKey}
srv8 := CreateOperator(t, 8)
ops[8] = initiator.Operator{srv8.srv.URL, 8, &srv8.privKey.PublicKey}
srv9 := CreateOperator(t, 9)
ops[9] = initiator.Operator{srv9.srv.URL, 9, &srv9.privKey.PublicKey}
srv10 := CreateOperator(t, 10)
ops[10] = initiator.Operator{srv10.srv.URL, 10, &srv10.privKey.PublicKey}
srv11 := CreateOperator(t, 11)
ops[11] = initiator.Operator{srv11.srv.URL, 11, &srv11.privKey.PublicKey}
srv12 := CreateOperator(t, 12)
ops[12] = initiator.Operator{srv12.srv.URL, 12, &srv12.privKey.PublicKey}
// Initiator priv key
_, pv, err := rsaencryption.GenerateKeys()
require.NoError(t, err)
priv, err := rsaencryption.ConvertPemToPrivateKey(string(pv))
clnt := initiator.New(priv, ops)
withdraw := newEthAddress(t)
owner := newEthAddress(t)
depositData, ks, err := clnt.StartDKG(withdraw.Bytes(), []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, [4]byte{0, 0, 0, 0}, "mainnnet", owner, 0)
require.NoError(t, err)
sharesDataSigned, err := hex.DecodeString(ks.Payload.Readable.Shares[2:])
require.NoError(t, err)
pubkeyraw, err := hex.DecodeString(ks.Payload.Readable.PublicKey[2:])
require.NoError(t, err)
testSharesData(t, ops, []*rsa.PrivateKey{srv1.privKey, srv2.privKey, srv3.privKey, srv4.privKey, srv5.privKey, srv6.privKey, srv7.privKey, srv8.privKey, srv9.privKey, srv10.privKey, srv11.privKey, srv12.privKey}, sharesDataSigned, pubkeyraw, owner, 0)
testDepositData(t, depositData, withdraw.Bytes(), owner, 0)
srv1.srv.Close()
srv2.srv.Close()
srv3.srv.Close()
srv4.srv.Close()
srv5.srv.Close()
srv6.srv.Close()
srv7.srv.Close()
srv8.srv.Close()
srv9.srv.Close()
srv10.srv.Close()
srv11.srv.Close()
srv12.srv.Close()
})
}

func testSharesData(t *testing.T, ops map[uint64]initiator.Operator, keys []*rsa.PrivateKey, sharesData []byte, validatorPublicKey []byte, owner common.Address, nonce uint16) {
Expand Down
9 changes: 4 additions & 5 deletions pkgs/dkg/drand.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

"github.com/attestantio/go-eth2-client/spec/phase0"
eth2_key_manager_core "github.com/bloxapp/eth2-key-manager/core"
"github.com/bloxapp/ssv-dkg/pkgs/board"
"github.com/bloxapp/ssv-dkg/pkgs/crypto"
"github.com/bloxapp/ssv-dkg/pkgs/utils"
"github.com/bloxapp/ssv-dkg/pkgs/wire"
ssvspec_types "github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv/utils/rsaencryption"
"github.com/drand/kyber"
Expand All @@ -23,11 +27,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"

"github.com/bloxapp/ssv-dkg/pkgs/board"
"github.com/bloxapp/ssv-dkg/pkgs/crypto"
"github.com/bloxapp/ssv-dkg/pkgs/utils"
"github.com/bloxapp/ssv-dkg/pkgs/wire"
)

const (
Expand Down
Loading

0 comments on commit ecf4e91

Please sign in to comment.