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 2 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
149 changes: 80 additions & 69 deletions signer/local_cosigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ type CosignerGetEphemeralSecretPartRequest struct {
}

type LocalCosignerConfig struct {
CosignerKey CosignerKey
SignState *SignState
RsaKey rsa.PrivateKey
Peers []CosignerPeer
Address string
RaftAddress string
Total uint8
Threshold uint8
CosignerKey CosignerKey
SignState *SignState
RsaKey rsa.PrivateKey
Peers []CosignerPeer
Address string
RaftAddress string
Total uint8
Threshold uint8
ThresholdEd25519Signature ThresholdEd25519Signature
}

type PeerMetadata struct {
Expand All @@ -85,8 +86,8 @@ type HrsMetadata struct {

// LocalCosigner responds to sign requests using their share key
// The cosigner maintains a watermark to avoid double-signing
//
// LocalCosigner signing is thread saafe
// TODO: Clarify what you mean with cosinger here.
// LocalCosigner signing is thread safe
type LocalCosigner struct {
pubKeyBytes []byte
key CosignerKey
Expand All @@ -106,6 +107,8 @@ type LocalCosigner struct {
peers map[int]CosignerPeer

address string

thresholdEd25519SignatureImplementation ThresholdEd25519Signature
}

func (cosigner *LocalCosigner) SaveLastSignedState(signState SignStateConsensus) error {
Expand All @@ -114,14 +117,15 @@ func (cosigner *LocalCosigner) SaveLastSignedState(signState SignStateConsensus)

func NewLocalCosigner(cfg LocalCosignerConfig) *LocalCosigner {
agouin marked this conversation as resolved.
Show resolved Hide resolved
cosigner := &LocalCosigner{
key: cfg.CosignerKey,
lastSignState: cfg.SignState,
rsaKey: cfg.RsaKey,
hrsMeta: make(map[HRSTKey]HrsMetadata),
peers: make(map[int]CosignerPeer),
total: cfg.Total,
threshold: cfg.Threshold,
address: cfg.Address,
key: cfg.CosignerKey,
lastSignState: cfg.SignState,
rsaKey: cfg.RsaKey,
hrsMeta: make(map[HRSTKey]HrsMetadata),
agouin marked this conversation as resolved.
Show resolved Hide resolved
peers: make(map[int]CosignerPeer),
total: cfg.Total,
threshold: cfg.Threshold,
address: cfg.Address,
thresholdEd25519SignatureImplementation: cfg.ThresholdEd25519Signature,
}

for _, peer := range cfg.Peers {
Expand All @@ -146,15 +150,67 @@ func (cosigner *LocalCosigner) GetID() int {
return cosigner.key.ID
}

// GetAddress returns the RPC URL of the cosigner
// GetAddress returns the GRPC URL of the cosigner
// Implements Cosigner interface
func (cosigner *LocalCosigner) GetAddress() string {
return cosigner.address
}

// Sign the sign request using the cosigner's share
// Return the signed bytes or an error
// GetEphemeralSecretParts
// Implements Cosigner interface
func (cosigner *LocalCosigner) GetEphemeralSecretParts(
hrst HRSTKey) (*CosignerEphemeralSecretPartsResponse, error) {
res := &CosignerEphemeralSecretPartsResponse{
EncryptedSecrets: make([]CosignerEphemeralSecretPart, 0, len(cosigner.peers)-1),
}
for _, peer := range cosigner.peers {
if peer.ID == cosigner.GetID() {
continue
}
secretPart, err := cosigner.getEphemeralSecretPart(CosignerGetEphemeralSecretPartRequest{
agouin marked this conversation as resolved.
Show resolved Hide resolved
ID: peer.ID,
Height: hrst.Height,
Round: hrst.Round,
Step: hrst.Step,
Timestamp: time.Unix(0, hrst.Timestamp),
})

if err != nil {
return nil, err
}

res.EncryptedSecrets = append(res.EncryptedSecrets, secretPart)
}
return res, nil
}

// SetEphemeralSecretPartsAndSign
// Implements Cosigner interface
func (cosigner *LocalCosigner) SetEphemeralSecretPartsAndSign(
req CosignerSetEphemeralSecretPartsAndSignRequest) (*CosignerSignResponse, error) {
for _, secretPart := range req.EncryptedSecrets {
err := cosigner.setEphemeralSecretPart(CosignerSetEphemeralSecretPartRequest{
agouin marked this conversation as resolved.
Show resolved Hide resolved
SourceID: secretPart.SourceID,
SourceEphemeralSecretPublicKey: secretPart.SourceEphemeralSecretPublicKey,
EncryptedSharePart: secretPart.EncryptedSharePart,
SourceSig: secretPart.SourceSig,
Height: req.HRST.Height,
Round: req.HRST.Round,
Step: req.HRST.Step,
Timestamp: time.Unix(0, req.HRST.Timestamp),
})
if err != nil {
return nil, err
}
}

res, err := cosigner.sign(CosignerSignRequest{req.SignBytes})
agouin marked this conversation as resolved.
Show resolved Hide resolved
return &res, err
}

// sign the sign request using the cosigner's share
// Return the signed bytes or an error
// Implements Cosigner interface # Comment is this really true? Doesnt it implement ThresholdEd25519Signature
func (cosigner *LocalCosigner) sign(req CosignerSignRequest) (CosignerSignResponse, error) {
agouin marked this conversation as resolved.
Show resolved Hide resolved
cosigner.lastSignStateMutex.Lock()
defer cosigner.lastSignStateMutex.Unlock()
Expand Down Expand Up @@ -250,6 +306,7 @@ func (cosigner *LocalCosigner) sign(req CosignerSignRequest) (CosignerSignRespon
return res, nil
}

// Implements ThresholdEd25519Signature interface
func (cosigner *LocalCosigner) dealShares(req CosignerGetEphemeralSecretPartRequest) (HrsMetadata, error) {
agouin marked this conversation as resolved.
Show resolved Hide resolved
hrsKey := HRSTKey{
Height: req.Height,
Expand Down Expand Up @@ -284,34 +341,9 @@ func (cosigner *LocalCosigner) dealShares(req CosignerGetEphemeralSecretPartRequ

}

func (cosigner *LocalCosigner) GetEphemeralSecretParts(
hrst HRSTKey) (*CosignerEphemeralSecretPartsResponse, error) {
res := &CosignerEphemeralSecretPartsResponse{
EncryptedSecrets: make([]CosignerEphemeralSecretPart, 0, len(cosigner.peers)-1),
}
for _, peer := range cosigner.peers {
if peer.ID == cosigner.GetID() {
continue
}
secretPart, err := cosigner.getEphemeralSecretPart(CosignerGetEphemeralSecretPartRequest{
ID: peer.ID,
Height: hrst.Height,
Round: hrst.Round,
Step: hrst.Step,
Timestamp: time.Unix(0, hrst.Timestamp),
})

if err != nil {
return nil, err
}

res.EncryptedSecrets = append(res.EncryptedSecrets, secretPart)
}
return res, nil
}

// Get the ephemeral secret part for an ephemeral share
// The ephemeral secret part is encrypted for the receiver
// Implements ThresholdEd25519Signature interface
func (cosigner *LocalCosigner) getEphemeralSecretPart(
agouin marked this conversation as resolved.
Show resolved Hide resolved
req CosignerGetEphemeralSecretPartRequest) (CosignerEphemeralSecretPart, error) {
res := CosignerEphemeralSecretPart{}
Expand Down Expand Up @@ -393,6 +425,7 @@ func (cosigner *LocalCosigner) getEphemeralSecretPart(
}

// Store an ephemeral secret share part provided by another cosigner
// Implements ThresholdEd25519Signature interface
func (cosigner *LocalCosigner) setEphemeralSecretPart(req CosignerSetEphemeralSecretPartRequest) error {
agouin marked this conversation as resolved.
Show resolved Hide resolved

// Verify the source signature
Expand Down Expand Up @@ -464,25 +497,3 @@ func (cosigner *LocalCosigner) setEphemeralSecretPart(req CosignerSetEphemeralSe
meta.Peers[req.SourceID-1].EphemeralSecretPublicKey = req.SourceEphemeralSecretPublicKey
return nil
}

func (cosigner *LocalCosigner) SetEphemeralSecretPartsAndSign(
req CosignerSetEphemeralSecretPartsAndSignRequest) (*CosignerSignResponse, error) {
for _, secretPart := range req.EncryptedSecrets {
err := cosigner.setEphemeralSecretPart(CosignerSetEphemeralSecretPartRequest{
SourceID: secretPart.SourceID,
SourceEphemeralSecretPublicKey: secretPart.SourceEphemeralSecretPublicKey,
EncryptedSharePart: secretPart.EncryptedSharePart,
SourceSig: secretPart.SourceSig,
Height: req.HRST.Height,
Round: req.HRST.Round,
Step: req.HRST.Step,
Timestamp: time.Unix(0, req.HRST.Timestamp),
})
if err != nil {
return nil, err
}
}

res, err := cosigner.sign(CosignerSignRequest{req.SignBytes})
return &res, err
}
6 changes: 3 additions & 3 deletions signer/remote_cosigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (cosigner *RemoteCosigner) GetID() int {
}

// GetAddress returns the P2P URL of the remote cosigner
// Implements the cosigner interface
// Implements the Cosigner interface
func (cosigner *RemoteCosigner) GetAddress() string {
return cosigner.address
}
Expand All @@ -61,7 +61,7 @@ func (cosigner *RemoteCosigner) getGRPCClient() (proto.CosignerGRPCClient, *grpc
return proto.NewCosignerGRPCClient(conn), conn, nil
}

// Implements the cosigner interface
// GetEphemeralSecretParts implements the Cosigner interface
func (cosigner *RemoteCosigner) GetEphemeralSecretParts(
req HRSTKey) (*CosignerEphemeralSecretPartsResponse, error) {
client, conn, err := cosigner.getGRPCClient()
Expand All @@ -82,7 +82,7 @@ func (cosigner *RemoteCosigner) GetEphemeralSecretParts(
}, nil
}

// Implements the cosigner interface
// SetEphemeralSecretPartsAndSign implements the Cosigner interface
func (cosigner *RemoteCosigner) SetEphemeralSecretPartsAndSign(
req CosignerSetEphemeralSecretPartsAndSignRequest) (*CosignerSignResponse, error) {
client, conn, err := cosigner.getGRPCClient()
Expand Down
12 changes: 12 additions & 0 deletions signer/threshold_ed25519_signature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package signer

// Interface for which is used by local Signer
type ThresholdEd25519Signature interface {
dealShares(req CosignerGetEphemeralSecretPartRequest) (HrsMetadata, error)

getEphemeralSecretPart(req CosignerGetEphemeralSecretPartRequest) (CosignerEphemeralSecretPart, error)

setEphemeralSecretPart(req CosignerSetEphemeralSecretPartRequest) error

sign(req CosignerSignRequest) (CosignerSignResponse, error)
}