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

Interface for LocalCosigner #67

Closed
wants to merge 137 commits into from
Closed
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
f5d4886
Add files via upload
nitronit Mar 21, 2022
48d1cc5
Merge pull request #1 from rcommodum/rcommodum-interface-patch
nitronit Mar 21, 2022
bb47ccb
Create codeql-analysis.yml
nitronit Mar 23, 2022
387b500
Merge branch 'strangelove-ventures:main' into main
nitronit Mar 23, 2022
b70378a
Entangle the Threshold Validator - Test not done
nitronit Apr 30, 2022
64c2aad
entangled the threshold validator. Test not refactored.
nitronit Apr 30, 2022
f6cf311
Merge pull request #4 from strangelove-ventures/main
nitronit Apr 30, 2022
307072f
Test looks to be passed now.
nitronit May 6, 2022
592aaea
commented the print statements
nitronit May 6, 2022
1472223
delete puml files
nitronit May 6, 2022
0a2086e
Merge branch 'strangelove-ventures:main' into main
nitronit May 6, 2022
f313cac
Take Mutex from local signer to cosigner level
nitronit May 23, 2022
c767a2e
Merge branch 'strangelove-ventures:main' into entangle-threshold-signer
nitronit May 23, 2022
0e428cc
Merge pull request #6 from nitronit/entangle-threshold-signer
nitronit May 23, 2022
e564fcb
Delete .DS_Store
nitronit May 23, 2022
9e4fa20
Delete out directory
nitronit May 23, 2022
627d8c7
Updating some documentation and comments
nitronit May 24, 2022
1ee5bc5
update
nitronit May 24, 2022
987648b
gitignore
nitronit May 24, 2022
9e95bd7
Merge branch 'strangelove-ventures:main' into doc_update
nitronit May 24, 2022
61c7113
Delete .DS_Store
nitronit May 24, 2022
113e6ba
Delete out directory
nitronit May 24, 2022
01fe48e
Update .gitignore
nitronit May 24, 2022
4870fdd
Update glossary.md
nitronit May 24, 2022
ac0b330
Merge pull request #8 from nitronit/doc_update
nitronit May 24, 2022
4c442fe
linting updates
nitronit May 24, 2022
2f25116
linting
nitronit May 24, 2022
c0bff54
test
nitronit May 24, 2022
2f3d97c
test
nitronit May 25, 2022
9c8138b
test
nitronit May 25, 2022
3d0129f
Add files via upload
nitronit May 26, 2022
64244f9
Merge pull request #9 from nitronit/nitronit-patch
nitronit May 26, 2022
c43edc7
test
nitronit May 26, 2022
b090ed3
update readme
nitronit May 26, 2022
bf2c8bc
Working through the comments.
nitronit Jun 5, 2022
fc1b39b
Merge branch 'main' into entangle-threshold-signer
nitronit Jun 5, 2022
66c5215
Merge pull request #10 from nitronit/entangle-threshold-signer
nitronit Jun 5, 2022
21fc29a
Some minor re-workings and cleaning
nitronit Jun 21, 2022
f07b40d
Interfaces for configs on the signer level.
nitronit Jul 17, 2022
c6989b9
Merge pull request #11 from nitronit/entangle-threshold-signer
nitronit Jul 17, 2022
e414aeb
factorizing out localsigner config and update test
nitronit Jul 30, 2022
3b0bd1c
Merge pull request #12 from nitronit/entangle-threshold-signer
nitronit Jul 30, 2022
8d3be72
Few minor adjustments
nitronit Aug 2, 2022
86c7956
Minor Updates
nitronit Aug 2, 2022
de5c077
Merge pull request #13 from nitronit/entangle-threshold-signer
nitronit Aug 2, 2022
4e91a4f
Merge branch 'main' into main
nitronit Aug 2, 2022
8ad0b9a
Merge pull request #14 from nitronit/main
nitronit Aug 2, 2022
22359d8
gitignor pruning
nitronit Aug 20, 2022
17b66fe
gitignore pruning
nitronit Aug 20, 2022
ad1756a
linting and comments fixes etc
nitronit Aug 20, 2022
bedf522
Update the from polylabs to unit410
nitronit Aug 20, 2022
7440441
Merge pull request #15 from nitronit/entangle-threshold-signer
nitronit Aug 20, 2022
ce52309
license fix.
nitronit Aug 20, 2022
d179b6d
Merge pull request #16 from nitronit/entangle-threshold-signer
nitronit Aug 20, 2022
36a9271
Merge branch 'main' into main
nitronit Aug 21, 2022
4001463
Add files via upload
nitronit Aug 21, 2022
26615da
Fix the switch case so default signer is SoftSign else horcrux_test.go
nitronit Aug 22, 2022
921743b
Merge pull request #17 from nitronit/entangle-threshold-signer
nitronit Aug 22, 2022
a97b16b
small updates
nitronit Aug 22, 2022
e5e8660
small changes
nitronit Aug 22, 2022
a569fec
Merge pull request #18 from nitronit/entangle-threshold-signer
nitronit Aug 22, 2022
88d2bb2
Delete .DS_Store
nitronit Aug 22, 2022
5bc6f9b
Delete .DS_Store
nitronit Aug 22, 2022
e00b031
gofmt
nitronit Aug 22, 2022
19f1fe6
Merge pull request #19 from nitronit/entangle-threshold-signer
nitronit Aug 22, 2022
82ea2e2
Update .gitignore
nitronit Aug 22, 2022
8439b3a
finally
nitronit Aug 22, 2022
37f3f86
Merge pull request #20 from nitronit/entangle-threshold-signer
nitronit Aug 22, 2022
da1aa8d
Slightly small changes for fixes etc and clarity.
nitronit Aug 24, 2022
a3134ba
mainly some config updates
nitronit Aug 26, 2022
9d6780a
lint
nitronit Aug 26, 2022
198efae
Merge pull request #21 from nitronit/entangled-version-2
nitronit Aug 26, 2022
5d5d0ee
small fixes
nitronit Aug 26, 2022
ca8ecb3
Merge pull request #22 from nitronit/entangled-version-2
nitronit Aug 26, 2022
f3eaea6
lint
nitronit Aug 27, 2022
0de6f85
linter is killing me :)
nitronit Aug 27, 2022
4f4b83c
Merge pull request #23 from nitronit/entangled-version-2
nitronit Aug 27, 2022
9ccb3de
lint
nitronit Aug 27, 2022
7e14c99
test
nitronit Aug 27, 2022
adca665
lets set
nitronit Aug 27, 2022
00f8eef
oh lint
nitronit Aug 27, 2022
4be59c3
test
nitronit Aug 27, 2022
830f9df
If not now when(!)
nitronit Aug 28, 2022
39f787a
Fixed some config intermediate types, comments and added check for t/…
nitronit Sep 1, 2022
9ae7dbe
Fix correct check in n/2 >= t
nitronit Sep 1, 2022
79c00ac
Fixed some threshold test and added threshold parameters t to tests.
nitronit Sep 3, 2022
c9579aa
replace io/ioutil which is depreciated
nitronit Sep 3, 2022
79fe0b5
Update lint.yml
nitronit Sep 3, 2022
7897016
workflow changes
nitronit Sep 4, 2022
99fcc7b
Remove signer.Config, signer.LocalCosignerConfig, LocalHSMsignThresho…
agouin Sep 6, 2022
13f9401
Make threshold signer source of truth for cosigner ID
agouin Sep 7, 2022
e8b9653
Merge pull request #27 from strangelove-ventures/andrew/config_cleanup
nitronit Sep 8, 2022
504741e
Merge pull request #28 from strangelove-ventures/main
nitronit Sep 8, 2022
077da1b
Gitfix and license fix
nitronit Sep 8, 2022
94ac3e0
empty commit
nitronit Sep 8, 2022
2cb0948
Git license fix
nitronit Sep 8, 2022
b3180db
Merged upstream with main
nitronit Sep 13, 2022
689c079
Added the modified signer to take async.
nitronit Sep 13, 2022
7d5b6ef
Main origin merge (#30)
nitronit Sep 13, 2022
eecfaa7
Merge branch 'main' of https://github.com/strangelove-ventures/horcru…
nitronit Sep 13, 2022
9aee3c4
Merge branch 'main' into main_origin_merge
nitronit Sep 13, 2022
f26ddb8
Merge pull request #32 from nitronit/main_origin_merge
nitronit Sep 13, 2022
3aa257f
Update glossary.md
nitronit Sep 13, 2022
b4f86e0
Some updates to @mark-rushakoff review.
nitronit Sep 13, 2022
bf1efe1
HRS/T
nitronit Sep 13, 2022
778943c
Threshold signer interface
nitronit Sep 16, 2022
f3c2749
local cosigner fix
nitronit Sep 16, 2022
4b62d14
fixed some minor renaming package
nitronit Sep 16, 2022
38e0da7
fix switch to casting
nitronit Sep 16, 2022
f9504a2
fixes to @mark-rushakoff comments
nitronit Sep 16, 2022
6b30c2e
remove scope introducing block
nitronit Sep 16, 2022
fa890ba
go renaming fixes
nitronit Sep 16, 2022
76b6a71
keep up with small pr.
nitronit Sep 16, 2022
aaf9488
fixed: TODO check true here is correct for async
nitronit Sep 16, 2022
ec4e74e
Removed scope-introducing blocks
nitronit Sep 20, 2022
4655ae3
Update threshold_signer_soft.go
nitronit Sep 20, 2022
1d9454b
go lint fix
nitronit Sep 20, 2022
ebc9259
Merge pull request #34 from strangelove-ventures/main
nitronit Sep 23, 2022
f8b544b
Merge pull request #35 from strangelove-ventures/main
nitronit Sep 23, 2022
3d53760
not all is fixed but most.
nitronit Oct 15, 2022
fada662
Merge branch 'strangelove-ventures:main' into threshold_small_pr
nitronit Oct 16, 2022
716fd8e
Fix the unreadabillity setting slots.
nitronit Oct 17, 2022
d90e991
Merge pull request #36 from strangelove-ventures/main
nitronit Oct 19, 2022
69b260e
Update threshold_signer_soft.go
nitronit Oct 19, 2022
9329cec
lint fix
nitronit Oct 20, 2022
000a3ef
Merge branch 'strangelove-ventures:main' into threshold_small_pr
nitronit Oct 21, 2022
6e4231a
Merge pull request #37 from strangelove-ventures/main
nitronit Oct 24, 2022
25c0770
Minor corrections and fixes
nitronit Oct 31, 2022
2c08ca9
Merge branch 'threshold_small_pr' of https://github.com/nitronit/horc…
nitronit Oct 31, 2022
5570e50
Merge branch 'strangelove-ventures:main' into threshold_small_pr
nitronit Nov 1, 2022
52e7dcc
Variable cleaning up.
nitronit Nov 7, 2022
667c204
Merge branch 'strangelove-ventures:main' into threshold_small_pr
nitronit Nov 15, 2022
87ca34d
Merge branch 'main' into threshold_small_pr
nitronit Nov 22, 2022
35539a0
Create comparison.md
nitronit Nov 24, 2022
fbb8464
Merge pull request #38 from nitronit/threshold_small_pr
nitronit Nov 29, 2022
1c5038c
Local Cosigner and Config changes
nitronit Dec 2, 2022
7c2ab19
test
nitronit Jan 25, 2023
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Multi-party computation using threshold signatures is able to provide high-avail

For more on how the Horcrux MPC signing flow works, see [`docs/signing.md`](/docs/signing.md)

![Screenshot from 2022-03-07 18-09-49](https://user-images.githubusercontent.com/6722152/157145772-8557b4b5-a0cc-4073-8834-86afda1900fc.png)
![Screenshot from 2022-03-07 18-09-49](docs/pics/horcrux.png)
nitronit marked this conversation as resolved.
Show resolved Hide resolved


## Raft
Expand Down
62 changes: 47 additions & 15 deletions cmd/horcrux/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/signer"
tmlog "github.com/tendermint/tendermint/libs/log"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -76,7 +77,7 @@ func initCmd() *cobra.Command {
}
if cs {
p, _ := cmdFlags.GetString("peers")
threshold, _ := cmdFlags.GetInt("threshold")
threshold, _ := cmdFlags.GetUint8("threshold")
timeout, _ := cmdFlags.GetString("timeout")
peers, err := peersFromFlag(p)
if err != nil {
Expand Down Expand Up @@ -104,7 +105,7 @@ func initCmd() *cobra.Command {
ChainID: cid,
CosignerConfig: &CosignerConfig{
Threshold: threshold,
Shares: len(peers) + 1,
Shares: uint8(len(peers)) + 1,
P2PListen: listen,
Peers: peers,
Timeout: timeout,
Expand Down Expand Up @@ -160,7 +161,7 @@ func initCmd() *cobra.Command {
cmd.Flags().BoolP("cosigner", "c", false, "set to initialize a cosigner node, requires --peers and --threshold")
cmd.Flags().StringP("peers", "p", "", "cosigner peer addresses in format tcp://{addr}:{port}|{share-id} \n"+
"(i.e. \"tcp://node-1:2222|2,tcp://node-2:2222|3\")")
cmd.Flags().IntP("threshold", "t", 0, "indicate number of signatures required for threshold signature")
cmd.Flags().Uint8P("threshold", "t", 0, "indicate number of signatures required for threshold signature")
cmd.Flags().StringP("listen", "l", "", "listen address of the signer")
cmd.Flags().StringP("keyfile", "k", "",
"priv val key file path (full key for single signer, or key share for cosigner)")
Expand Down Expand Up @@ -190,9 +191,9 @@ func validateCosignerConfig(cfg DiskConfig) error {
if cfg.CosignerConfig == nil {
return fmt.Errorf("cosigner config can't be empty")
}
if len(cfg.CosignerConfig.Peers)+1 < cfg.CosignerConfig.Threshold {
return fmt.Errorf("number of peers + 1 (%d) must be greater than threshold (%d)",
len(cfg.CosignerConfig.Peers)+1, cfg.CosignerConfig.Threshold)
if float32(len(cfg.CosignerConfig.Peers))/float32(2) >= float32(cfg.CosignerConfig.Threshold) {
return fmt.Errorf("the threshold, t = (%d) must be greater than, 'peers/2' = (%.1f)",
cfg.CosignerConfig.Threshold, float32(len(cfg.CosignerConfig.Peers))/2)
}

_, err := time.ParseDuration(cfg.CosignerConfig.Timeout)
Expand Down Expand Up @@ -399,10 +400,11 @@ func setSharesCmd() *cobra.Command {
"3",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
numShares, err := strconv.Atoi(args[0])
numSharesParsed, err := strconv.ParseUint(args[0], 10, 8)
if err != nil {
return err
}
numShares := uint8(numSharesParsed)
if err := validateCosignerPeers(config.Config.CosignerConfig.Peers, numShares); err != nil {
return err
}
Expand Down Expand Up @@ -534,11 +536,12 @@ func (c RuntimeConfig) writeConfigFile() error {
}

type CosignerConfig struct {
Threshold int `json:"threshold" yaml:"threshold"`
Shares int `json:"shares" yaml:"shares"`
P2PListen string `json:"p2p-listen" yaml:"p2p-listen"`
Peers []CosignerPeer `json:"peers" yaml:"peers"`
Timeout string `json:"rpc-timeout" yaml:"rpc-timeout"`
Threshold uint8 `json:"threshold" yaml:"threshold"`
Shares uint8 `json:"shares" yaml:"shares"`
P2PListen string `json:"p2p-listen" yaml:"p2p-listen"`
Peers []CosignerPeer `json:"peers" yaml:"peers"`
Timeout string `json:"rpc-timeout" yaml:"rpc-timeout"`
SignerType string `json:"signer-type" yaml:"signer-type"`
}

func (c *DiskConfig) CosignerPeers() (out []signer.CosignerConfig) {
Expand All @@ -548,28 +551,57 @@ func (c *DiskConfig) CosignerPeers() (out []signer.CosignerConfig) {
return
}

func (c *DiskConfig) KeyAndThresholdSigner(logger tmlog.Logger) (signer.CosignerKey, signer.ThresholdSigner, error) {
switch c.CosignerConfig.SignerType {
case "hsm", "HSM":
logger.Info("Cosigning with HSM")
return signer.CosignerKey{}, signer.NewThresholdSignerHSM(), nil
default:

keyFilePath := config.keyFilePath(true)
if _, err := os.Stat(keyFilePath); os.IsNotExist(err) {
return signer.CosignerKey{}, nil, fmt.Errorf("private key share doesn't exist at path(%s)", keyFilePath)
}
key, err := signer.LoadCosignerKey(keyFilePath)
if err != nil {
return signer.CosignerKey{}, nil, fmt.Errorf("error reading cosigner key: %s", err)
nitronit marked this conversation as resolved.
Show resolved Hide resolved
}
logger.Info("Cosigning with soft key",
"file", keyFilePath,
"id", key.ID,
"threshold", c.CosignerConfig.Threshold,
"total", c.CosignerConfig.Shares,
)
return key, signer.NewThresholdSignerSoft(
key,
c.CosignerConfig.Threshold,
c.CosignerConfig.Shares,
), nil
}
}

type CosignerPeer struct {
ShareID int `json:"share-id" yaml:"share-id"`
P2PAddr string `json:"p2p-addr" yaml:"p2p-addr"`
}

func validateCosignerPeers(peers []CosignerPeer, shares int) error {
func validateCosignerPeers(peers []CosignerPeer, shares uint8) error {
// Check IDs to make sure none are duplicated
if dupl := duplicatePeers(peers); len(dupl) != 0 {
return fmt.Errorf("found duplicate share IDs in args: %v", dupl)
}

// Make sure that the peers' IDs match the number of shares.
for _, peer := range peers {
if peer.ShareID < 1 || peer.ShareID > shares {
if peer.ShareID < 1 || peer.ShareID > int(shares) {
Copy link
Member

Choose a reason for hiding this comment

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

If the shares have been switched to uint8 everywhere else, why isn't ShareID a uint8 now too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because ShareID, peers etc is int.

Would be good in the future to decide which int type to use. And I assume that
The current way is not a great design choice. Maybe should be added to issues or some kind of roadmap?

return fmt.Errorf("peer ID %v in args is out of range, must be between 1 and %v",
peer.ShareID, shares)
}
}

// Check that no more than {num-shares}-1 peers are in the peer list, assuming
// the remaining peer ID is the ID the local node is configured with.
if len(peers) == shares {
if len(peers) == int(shares) {
return fmt.Errorf("too many peers (%v+local node = %v) for the specified number of key shares (%v)",
len(peers), len(peers)+1, shares)
}
Expand Down
16 changes: 15 additions & 1 deletion cmd/horcrux/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ func TestConfigInitCmd(t *testing.T) {
},
expectErr: true,
},
{
name: "invalid threshold setting",
home: tmpHome + "_invalid_threshold_setting",
args: []string{
chainID,
"tcp://10.168.0.1:1234",
"-c",
"-p", "tcp://10.168.1.2:2222|2,tcp://10.168.1.3:2222|3",
"-t", "1", // t =< p/2, should be t > p/2
"-l", "tcp://10.168.1.1:2222",
"--timeout", "1500ms",
},
expectErr: true,
},
}

for _, tc := range tcs {
Expand Down Expand Up @@ -627,7 +641,7 @@ func TestSetShares(t *testing.T) {
tcs := []struct {
name string
args []string
expectShares int
expectShares uint8
expectErr bool
}{ // Do NOT change the order of the test cases!
{
Expand Down
59 changes: 22 additions & 37 deletions cmd/horcrux/cmd/cosigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,34 +120,24 @@ func StartCosignerCmd() *cobra.Command {
pv types.PrivValidator
chainID = config.Config.ChainID
logger = tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)).With("module", "validator")
cfg signer.Config
)

cfg = signer.Config{
Mode: "mpc",
PrivValKeyFile: config.keyFilePath(true),
PrivValStateDir: config.StateDir,
ChainID: config.Config.ChainID,
CosignerThreshold: config.Config.CosignerConfig.Threshold,
ListenAddress: config.Config.CosignerConfig.P2PListen,
Nodes: config.Config.Nodes(),
Cosigners: config.Config.CosignerPeers(),
}
nodes := config.Config.Nodes()
cfgCosigners := config.Config.CosignerPeers()

if err = cfg.KeyFileExists(); err != nil {
return err
// Initialize the localsigner (ThresholdEdSignature) of choice.
key, thresholdSigner, err := config.Config.KeyAndThresholdSigner(logger)
if err != nil {
panic(err)
nitronit marked this conversation as resolved.
Show resolved Hide resolved
}

logger.Info("Tendermint Validator", "mode", cfg.Mode,
"priv-key", cfg.PrivValKeyFile, "priv-state-dir", cfg.PrivValStateDir)
logger.Info("Tendermint Validator",
"mode", "mpc",
"priv-state-dir", config.StateDir,
"threshold-signer", thresholdSigner.Type())

var val types.PrivValidator

key, err := signer.LoadCosignerKey(cfg.PrivValKeyFile)
if err != nil {
return fmt.Errorf("error reading cosigner key: %s", err)
}

// ok to auto initialize on disk since the cosigner share is the one that actually
// protects against double sign - this exists as a cache for the final signature
signState, err := signer.LoadOrCreateSignState(config.privValStateFile(chainID))
Expand All @@ -162,15 +152,15 @@ func StartCosignerCmd() *cobra.Command {
panic(err)
}

cosigners := []signer.Cosigner{}
var cosigners []signer.Cosigner

// add ourselves as a peer so localcosigner can handle GetEphSecPart requests
peers := []signer.CosignerPeer{{
ID: key.ID,
PublicKey: key.RSAKey.PublicKey,
}}

for _, cosignerConfig := range cfg.Cosigners {
for _, cosignerConfig := range cfgCosigners {
cosigner := signer.NewRemoteCosigner(cosignerConfig.ID, cosignerConfig.Address)
cosigners = append(cosigners, cosigner)

Expand All @@ -185,18 +175,12 @@ func StartCosignerCmd() *cobra.Command {
})
}

total := len(cfg.Cosigners) + 1
localCosignerConfig := signer.LocalCosignerConfig{
CosignerKey: key,
SignState: &shareSignState,
RsaKey: key.RSAKey,
Address: cfg.ListenAddress,
Peers: peers,
Total: uint8(total),
Threshold: uint8(cfg.CosignerThreshold),
}

localCosigner := signer.NewLocalCosigner(localCosignerConfig)
// Initialize the localCosigner. The localCosigner "embeds" the local signer
localCosigner := signer.NewLocalCosigner(
config.Config.CosignerConfig.P2PListen,
peers, &shareSignState,
thresholdSigner,
)

timeout, err := time.ParseDuration(config.Config.CosignerConfig.Timeout)
if err != nil {
Expand All @@ -213,15 +197,16 @@ func StartCosignerCmd() *cobra.Command {

// Start RAFT store listener
raftStore := signer.NewRaftStore(nodeID,
raftDir, cfg.ListenAddress, timeout, logger, localCosigner, cosigners)
raftDir, config.Config.CosignerConfig.P2PListen, timeout, logger, localCosigner, cosigners)
if err := raftStore.Start(); err != nil {
log.Fatalf("Error starting raft store: %v\n", err)
}
services = append(services, raftStore)

// Initialize the Threshold validator. The Threshold validator "embeds" the local cosigner
val = signer.NewThresholdValidator(&signer.ThresholdValidatorOpt{
Pubkey: key.PubKey,
Threshold: cfg.CosignerThreshold,
Threshold: int(config.Config.CosignerConfig.Threshold),
SignState: signState,
Cosigner: localCosigner,
Peers: cosigners,
Expand All @@ -239,7 +224,7 @@ func StartCosignerCmd() *cobra.Command {
}
logger.Info("Signer", "address", pubkey.Address())

services, err = signer.StartRemoteSigners(services, logger, cfg.ChainID, pv, cfg.Nodes)
services, err = signer.StartRemoteSigners(services, logger, config.Config.ChainID, pv, nodes)
if err != nil {
panic(err)
}
Expand Down
22 changes: 8 additions & 14 deletions cmd/horcrux/cmd/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,20 @@ func StartSignerCmd() *cobra.Command {
pv types.PrivValidator
chainID = config.Config.ChainID
logger = tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)).With("module", "validator")
cfg signer.Config
)

cfg = signer.Config{
Mode: "single",
PrivValKeyFile: config.keyFilePath(false),
PrivValStateDir: config.StateDir,
ChainID: config.Config.ChainID,
Nodes: config.Config.Nodes(),
}
privValKeyFile := config.keyFilePath(false)
nodes := config.Config.Nodes()

if err = cfg.KeyFileExists(); err != nil {
return err
if _, err := os.Stat(privValKeyFile); os.IsNotExist(err) {
log.Fatalf("private key share doesn't exist at path(%s)", privValKeyFile)
nitronit marked this conversation as resolved.
Show resolved Hide resolved
}

logger.Info("Tendermint Validator", "mode", cfg.Mode,
"priv-key", cfg.PrivValKeyFile, "priv-state-dir", cfg.PrivValStateDir)
logger.Info("Tendermint Validator", "mode", "single",
"priv-key", privValKeyFile, "priv-state-dir", config.StateDir)

pv = &signer.PvGuard{
PrivValidator: privval.LoadFilePVEmptyState(cfg.PrivValKeyFile, config.privValStateFile(chainID)),
PrivValidator: privval.LoadFilePVEmptyState(privValKeyFile, config.privValStateFile(chainID)),
}

pubkey, err := pv.GetPubKey()
Expand All @@ -72,7 +66,7 @@ func StartSignerCmd() *cobra.Command {
}
logger.Info("Signer", "pubkey", pubkey)

services, err = signer.StartRemoteSigners(services, logger, cfg.ChainID, pv, cfg.Nodes)
services, err = signer.StartRemoteSigners(services, logger, config.Config.ChainID, pv, nodes)
if err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/horcrux/cmd/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestStateSetCmd(t *testing.T) {
"-c",
"-p", "tcp://10.168.1.2:2222|2,tcp://10.168.1.3:2222|3",
"-l", "tcp://10.168.1.1:2222",
"-t", "2",
"--timeout", "1500ms",
})
err = cmd.Execute()
Expand Down
9 changes: 9 additions & 0 deletions docs/glossary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Glossary - WORK IN PROGRESS

- In cryptography, a **nonce** (number once) is an arbitrary number that can be used just once in a cryptographic communication.

- A cryptographic key is called **ephemeral** if it is generated for each execution of a key establishment process.

- **Threshold signatures** allow for splitting a private key into n secret shares. To sign a message, at least some threshold of the shareholders need to coordinate and provide their individual signatures using their share. These individual signatures combine to form a single valid signature.

- **Robust schemes** ensure that so long as t participants correctly follow the protocol, the protocol is guaranteed to complete successfully, even if a subset of participants (at most n − t) contribute malformed shares.
Binary file added docs/pics/horcrux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 0 additions & 21 deletions signer/Config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package signer

import (
"fmt"
"os"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -23,24 +20,6 @@ type CosignerConfig struct {
Address string
}

type Config struct {
Mode string
PrivValKeyFile string
PrivValStateDir string
ChainID string
CosignerThreshold int
ListenAddress string
Nodes []NodeConfig
Cosigners []CosignerConfig
}

func (cfg *Config) KeyFileExists() error {
if _, err := os.Stat(cfg.PrivValKeyFile); os.IsNotExist(err) {
return fmt.Errorf("private key share doesn't exist at path(%s)", cfg.PrivValKeyFile)
}
return nil
}

func PubKey(bech32BasePrefix string, pubKey crypto.PubKey) (string, error) {
if bech32BasePrefix != "" {
pubkey, err := cryptocodec.FromTmPubKeyInterface(pubKey)
Expand Down
Loading