secp256k1

Pure Haskell Schnorr, ECDSA on the elliptic curve secp256k1 (docs.ppad.tech/secp256k1).
git clone git://git.ppad.tech/secp256k1.git
Log | Files | Refs | README | LICENSE

commit 52214de15457f96370063bf3791797c384d64f2a
parent 7ec20de4316921667116e4b14403e85f1a22dc81
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat,  1 Aug 2026 12:33:22 -0230

lib: take the point prefix byte totally

parse_point read byte zero with BU.unsafeIndex, relying on laziness to
avoid the read on inputs shorter than 33 bytes. That holds only
because readWord8OffAddr# is can_fail and so not ok-for-speculation,
which is a property of GHC's primop table rather than anything the
code states. BS.uncons is O(1) and total.

Diffstat:
Mlib/Crypto/Curve/Secp256k1.hs | 11++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/Crypto/Curve/Secp256k1.hs b/lib/Crypto/Curve/Secp256k1.hs @@ -896,13 +896,14 @@ parse_int256 bs = do parse_point :: BS.ByteString -> Maybe Projective parse_point bs | len == 32 = _parse_bip0340 bs - | len == 33 = _parse_compressed h t - | len == 65 = _parse_uncompressed h t - | otherwise = Nothing + | otherwise = case BS.uncons bs of + Nothing -> Nothing + Just (h, t) + | len == 33 -> _parse_compressed h t + | len == 65 -> _parse_uncompressed h t + | otherwise -> Nothing where len = BS.length bs - h = BU.unsafeIndex bs 0 -- lazy - t = BS.drop 1 bs -- input is guaranteed to be 32B in length _parse_bip0340 :: BS.ByteString -> Maybe Projective