commit e96bc5f24230d6658c927c6ba0a12061e345070d parent ea1a6a7c2e5c3cfd7573ee4988aaa6bed7e71586 Author: Jared Tobin <jared@jtobin.io> Date: Sat, 10 Oct 2026 13:02:13 +0400 lib: require a compressed prefix in point BOLT #1 Appendix B rejects a node_id with a 0x04 prefix as an invalid point. Check for 0x02/0x03 in addition to the length. Diffstat:
| M | lib/Lightning/Protocol/BOLT1/Prim.hs | | | 10 | +++++++--- |
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/Lightning/Protocol/BOLT1/Prim.hs b/lib/Lightning/Protocol/BOLT1/Prim.hs @@ -194,11 +194,15 @@ instance NFData Point -- | Construct a 'Point' from a 33-byte 'BS.ByteString'. -- --- Returns 'Nothing' if the input is not exactly 33 bytes. +-- Returns 'Nothing' if the input is not exactly 33 bytes, or does not +-- begin with a compressed-encoding prefix (0x02 or 0x03). The curve +-- equation is not checked. point :: BS.ByteString -> Maybe Point point !bs - | BS.length bs == 33 = Just (Point bs) - | otherwise = Nothing + | BS.length bs == 33 + , let !h = BS.index bs 0 + , h == 0x02 || h == 0x03 = Just (Point bs) + | otherwise = Nothing {-# INLINE point #-} -- | Extract the raw bytes from a 'Point'.