Skip to content

feat(account-lib): add support for secp256k1 curve TSS#2256

Merged
tylerlevine merged 1 commit into
masterfrom
BG-47402-add-support-for-secp-256-k-1-curve
May 20, 2022
Merged

feat(account-lib): add support for secp256k1 curve TSS#2256
tylerlevine merged 1 commit into
masterfrom
BG-47402-add-support-for-secp-256-k-1-curve

Conversation

@sachushajiabraham

@sachushajiabraham sachushajiabraham commented May 5, 2022

Copy link
Copy Markdown
Contributor

this change adds support for secp256k1 curve for MPC / TSS and also changes verify function in ed25519 to return boolean

TICKET:BG-47402

@codecov

codecov Bot commented May 5, 2022

Copy link
Copy Markdown

Codecov Report

Merging #2256 (7467f8c) into master (b65e861) will increase coverage by 84.16%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           master    #2256       +/-   ##
===========================================
+ Coverage        0   84.16%   +84.16%     
===========================================
  Files           0      174      +174     
  Lines           0     7788     +7788     
  Branches        0     1219     +1219     
===========================================
+ Hits            0     6555     +6555     
- Misses          0      826      +826     
- Partials        0      407      +407     
Flag Coverage Δ
unit 84.16% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
modules/account-lib/src/mpc/curves/ed25519.ts 91.66% <100.00%> (ø)
modules/account-lib/src/mpc/curves/index.ts 100.00% <100.00%> (ø)
modules/account-lib/src/mpc/curves/secp256k1.ts 100.00% <100.00%> (ø)
modules/account-lib/src/mpc/tss.ts 96.49% <100.00%> (ø)
modules/account-lib/src/mpc/util.ts 100.00% <100.00%> (ø)
modules/account-lib/src/coin/xtz/address.ts 100.00% <0.00%> (ø)
...t-lib/src/coin/near/walletInitializationBuilder.ts 50.00% <0.00%> (ø)
modules/account-lib/src/coin/algo/txnSchema.ts 86.95% <0.00%> (ø)
modules/account-lib/src/coin/algo/utils.ts 78.51% <0.00%> (ø)
...dules/account-lib/src/coin/cspr/delegateBuilder.ts 85.71% <0.00%> (ø)
... and 168 more

@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from 4cbf25f to c07e63d Compare May 5, 2022 17:08
Comment thread modules/account-lib/src/mpc/curves/secp256k1.ts Outdated
@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from c07e63d to 1e911c4 Compare May 5, 2022 17:28
Comment thread modules/account-lib/src/mpc/curves/secp256k1.ts Outdated
Comment thread modules/account-lib/src/mpc/curves/secp256k1.ts Outdated
@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch 4 times, most recently from 71e5536 to fb4f5e0 Compare May 9, 2022 10:32

@tylerlevine tylerlevine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How come we're implementing these primitive curve operations in account-lib instead of using a dependency for these that's already in the utxo-lib dependency tree (eg, noble-secp256k1 or a pre-wasm version of tiny-secp256k1)?

@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from fb4f5e0 to 7e13be3 Compare May 9, 2022 17:38
@sachushajiabraham sachushajiabraham changed the title feat(account-lib): add support for secp256k1 curve feat(account-lib): add support for secp256k1 curve TSS May 9, 2022
@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from 7e13be3 to 70fd762 Compare May 9, 2022 18:40
@sachushajiabraham

sachushajiabraham commented May 10, 2022

Copy link
Copy Markdown
Contributor Author

Hi @tylerlevine , the implementations are for the basic scalar operations over that finite field , for point operations we will be making use of noble-secp256k1 or tiny-secp256k1 or any suitable library. Still finalising on it
cc: @johnoliverdriscoll

@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from 70fd762 to 5f70eb7 Compare May 11, 2022 11:01
@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from 5f70eb7 to 3c1ba89 Compare May 11, 2022 11:25
@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch 8 times, most recently from a9d067d to 4f1c91c Compare May 12, 2022 19:21
@sachushajiabraham sachushajiabraham marked this pull request as ready for review May 12, 2022 19:31
@sachushajiabraham sachushajiabraham requested review from a team, barathcj and wesgraham May 12, 2022 19:31
@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch 3 times, most recently from d2f2cff to be548a0 Compare May 19, 2022 19:37

@brandonblack brandonblack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couple of minor things left. Looking very clean.

Comment thread modules/account-lib/src/mpc/curves/secp256k1.ts Outdated
Comment thread modules/account-lib/src/mpc/curves/secp256k1.ts Outdated
@brandonblack

brandonblack commented May 19, 2022 via email

Copy link
Copy Markdown
Contributor

Comment thread modules/account-lib/src/mpc/curves/secp256k1.ts Outdated
@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from be548a0 to 52aec81 Compare May 19, 2022 20:24
brandonblack
brandonblack previously approved these changes May 19, 2022
@brandonblack

Copy link
Copy Markdown
Contributor

I believe that Paul on noble-secp is working on adding the build products to his tree similar to how I have them in my fork, so we should be able to move to the mainline soon. Not sure on his plans for a release. Until then, I think it is OK to depend on one commit off mainline with the build products checked in. We should probably update to use the commit hash that we're happy with rather than the branch though.

brandonblack
brandonblack previously approved these changes May 19, 2022

@tylerlevine tylerlevine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

almost there. Thanks for providing in-depth review on this @brandonblack

Comment thread modules/account-lib/package.json Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why return a buffer? What do the return values mean? Please add a doc comment if it's not going to return a boolean.

@sachushajiabraham sachushajiabraham May 20, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From the docs I looked up and reading through testcases, sodium.crypto_sign_open returns the original message if the signature is valid. I have added a comment for clarity @tylerlevine

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@joey-bai just want to bring your attention to this change to the verify function to have it follow same base parameters as ECDSA to have the message also passed to verify after discussing with @johnoliverdriscoll , I have a feeling that this could break some places, double checking with you. I think it would make sense to have it return as a boolean value if it verifies the signature correctly if there is no specific reason to return the actual message if signature is valid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense - i agree that boolean makes it more more clear how to use the output of this func

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated to have it as boolean

@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from 92d7824 to 9e495d7 Compare May 20, 2022 06:34
joey-bai
joey-bai previously approved these changes May 20, 2022

@joey-bai joey-bai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

overall LGTM.

you may also want to get input from @johnoliverdriscoll, who implemented ed25519 + tss

@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch 3 times, most recently from 12ead8d to c17e289 Compare May 20, 2022 17:42
this change adds support for secp256k1 curve and also
changes verify function in ed25519 to return boolean

TICKET:BG-47402
@sachushajiabraham sachushajiabraham force-pushed the BG-47402-add-support-for-secp-256-k-1-curve branch from c17e289 to 7467f8c Compare May 20, 2022 18:47

@tylerlevine tylerlevine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

one nit but feel free to handle in follow up. Nice work 👍

Comment thread modules/account-lib/src/mpc/curves/ed25519.ts
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.

7 participants