Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Secp256k1 - #14

Merged
larskuhtz merged 8 commits into
mainfrom
secp256k1
Sep 15, 2023
Merged

Secp256k1#14
larskuhtz merged 8 commits into
mainfrom
secp256k1

Conversation

@larskuhtz

Copy link
Copy Markdown
Collaborator

No description provided.

@larskuhtz
larskuhtz marked this pull request as ready for review September 4, 2023 16:10
Comment thread src-secp256k1/Crypto/Secp256k1/Internal.hs Outdated
Comment thread ethereum.cabal
GHC==9.2.4
GHC==9.0.2
GHC==8.10.7
, GHC==9.4.2

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.

add GHC 9.6.2?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That is included in #17, which can be merged as soon as chainweb-node supports aeson-2.2, which is currently blocked on haskell-servant/servant#1695.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't know much about the cryptography but overall the code LGTM.

natToBytesInternal l n = go l n []
where
go 0 _ = id
go i m = let (a, b) = quotRem m 256 in go (i - 1) a . (int b :)

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.

not: put a bang on i to make GHC more likely to make this tail recursive/for the int to unpack

where
r = a .^ ((pC + 1) `quot` 4)

-- | Not sure if this is faster. TODO benchmark it.

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.

There is a TODO for benchmarks here, but the above comment said that it's been benchmarked. Could you amend the comments to reconcile this?

-- | Recover public key for curve Secp256k1.
--
-- The chance that `secondKey` is needed (i.e. there are two solution for the x
-- coordinate) is \(2^{128}\). Do we need to cover that case or can we just

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.

I think you mean the inverse of this.

(sk, pk) <- genKey
(r, s, isOddY, isSecondKey) <- sign sk msgDigest
return
$ classify isOddY "isOddY"

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.

nice QuickCheck-fu 👍

@chessai

chessai commented Sep 15, 2023

Copy link
Copy Markdown
Contributor

Approved, but left a few comments of some small things I would like to see changed.

I'm not an expert on the cryptography here either, but the math makes sense to me. Reading the references helped.

Comment thread src-secp256k1/Crypto/Secp256k1/Internal.hs Outdated
Comment thread src-secp256k1/Crypto/Secp256k1/Internal.hs
Comment thread src-secp256k1/Crypto/Secp256k1/Internal.hs Outdated
Comment thread src-secp256k1/Crypto/Secp256k1/Internal.hs Outdated
@larskuhtz
larskuhtz merged commit 987435c into main Sep 15, 2023
@larskuhtz
larskuhtz deleted the secp256k1 branch September 15, 2023 16:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants