Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@zhelnov
Copy link
Contributor

@zhelnov zhelnov commented Feb 18, 2023

This PR is adding functionality for private key recovery from multi-party DKG results (shares and BK's). It may be useful in case all parties agreed to "exit" HTSS process and wants to receive single private key to work with further, like emergency case for some services providing HTSS are down.

This implementation tested for both EcDSA (secp265k1 and secp256r1) and EDDSA (ed25519) algo's with threshold considering (3/3, 2/3 DKG quorums).

I'm about to cover hierarchical scenarios too (involving different BK's Rank values) and write some readme for that tool, but would be nice to hear from maintainers if this whole thing correct and makes sense as part of Alice lib. @markya0616 @cychuang0924 what do you think?

(UPD 28.02.2023 added EDDSA tests)

Before submitting a pull request, please make sure the following is done:

Checklist

  • Fork the repository and create your new branch from master.
  • Please mention the name of community in Pull Request title.
  • Git Commit Messages
    • Use the present tense (Also in Pull Request title): "Add feature" not "Added feature"
    • Use the imperative mood (Also in Pull Request title): "Move cursor to..." not "Moves cursor to..."
    • Use rebase to squash/fixup dummy/unnecessary commits into only one commit.

@codecov
Copy link

codecov bot commented Feb 19, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (09a854b) 76.77% compared to head (d555cf1) 76.85%.

Files Patch % Lines
crypto/tss/recovery/recover_private_key.go 93.54% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #239      +/-   ##
==========================================
+ Coverage   76.77%   76.85%   +0.07%     
==========================================
  Files         145      146       +1     
  Lines       11326    11357      +31     
==========================================
+ Hits         8696     8728      +32     
+ Misses       1869     1868       -1     
  Partials      761      761              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zhelnov zhelnov force-pushed the ecdsa-private-key-recovery branch from 90bace1 to b1f96b1 Compare February 28, 2023 17:49
@zhelnov zhelnov changed the title crypto/tss/ecdsa: add private key recovery algorithm from dkg results crypto/tss/recovery: add private key recovery from dkg results Feb 28, 2023
@cychuang0924
Copy link
Contributor

cychuang0924 commented Mar 1, 2023

Hi zhelnov,

Thanks for your PR. We will check it in this week!

Sincerely

privKeyBigInt.Mod(privKeyBigInt, fieldOrder)

pubKey := ecpointgrouplaw.NewBase(curve).ScalarMult(privKeyBigInt)
privKey := &ecdsa.PrivateKey{
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check the public generating by this private and the public key owned by all participants, which are the same ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, i just added ECpoint pubkey param to recovery function and check if public generated from our recovered private key is equal to provided one. It'll not affect recovery flow, but it will be some kind of fuse to protect against incorrect recovery.

Also i rewrote tests on ginkgo/gomega tools.

@zhelnov zhelnov force-pushed the ecdsa-private-key-recovery branch from b1f96b1 to 52912a7 Compare March 6, 2023 16:28
bk *birkhoffinterpolation.BkParameter
}

func RecoverPrivateKey(curve elliptic.Curve, threshold uint32, pubKey *ecpointgrouplaw.ECPoint, peers []RecoveryPeer) (*ecdsa.PrivateKey, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A point to consider here: i chose to describe function arguments in NewDkg/NewSigner arguments style to keep it simple and unambiguous. But i suppose actual use case of such function may be that library user provides array of DKG results. I have higher-level function that accepts such array and does necessary validation (BKs/Pubkey/Threshold consistency in each array entry for example to check its same peer quorum results) but not sure if it makes sense to keep that logic as part of Alice. Altough i'll be happy to add such function here if it makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's acceptable for this version. Your consideration is meaningful.

@zhelnov zhelnov requested a review from cychuang0924 March 6, 2023 16:40
cychuang0924
cychuang0924 previously approved these changes Mar 7, 2023
@cychuang0924
Copy link
Contributor

Hi zhelnov,

Thanks for your PR. The PR will be merged until @markya0616 reviewed it.

@zhelnov
Copy link
Contributor Author

zhelnov commented Apr 6, 2023

Hi! A tiny addition i feel like i should mention. Unlike EcDSA, where recovered big.Int is actually a private key, it seems for EDDSA we're just getting so called scalar, which is not the private key. Furthermore, according to EDDSA RFC https://www.rfc-editor.org/rfc/rfc8032#section-3.3 scalar is derivative of source private key by hashing. As hashing is irreversible operation, unfortunately we cant recover original EDDSA private key and best we can get is scalar. Despite we still can sign something using scalar with library like github.com/decred/dcrd/dcrec/edwards.

@zhelnov
Copy link
Contributor Author

zhelnov commented Apr 6, 2023

I just rebased it with upstream

@zhelnov zhelnov force-pushed the ecdsa-private-key-recovery branch from 9a25eaa to 1af96c7 Compare September 12, 2023 18:55
@zhelnov
Copy link
Contributor Author

zhelnov commented Sep 12, 2023

@cychuang0924 @markya0616 hello! Is any change this PR will be merged? Still would be useful to have this packed into Alice.

@zhelnov zhelnov force-pushed the ecdsa-private-key-recovery branch from 1af96c7 to 1d3e7db Compare September 13, 2023 12:10
@cychuang0924 cychuang0924 merged commit 9ec2bc7 into getamis:master Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants