Skip to content

Commit

Permalink
Merge pull request #17 from serokell/lierdakil/chore-update-ghc-9.8
Browse files Browse the repository at this point in the history
[INT-224] Update for GHC 9.8 compatibility
  • Loading branch information
lierdakil authored Dec 30, 2023
2 parents e3f4d0c + ba54103 commit e9fc587
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 53 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
stack: ["2.9.3"]
stack: ["2.13.1"]
# Remember to update the `tested-with` section of `package.yaml`.
resolver: ["lts", "nightly"]
resolver: ["lts-21", "lts", "nightly"]

steps:
- name: Get compiler version
Expand All @@ -189,9 +189,11 @@ jobs:
stack-version: ${{ matrix.stack }}

- uses: actions/cache@v3
name: Cache ~/.stack
name: Cache ~/.stack and cabal store
with:
path: ~/.stack
path: |
~/.stack
${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ runner.os }}-${{ steps.ghcver.outputs.ghcver }}-stack

- name: Set stack config
Expand All @@ -201,7 +203,6 @@ jobs:
stack config set resolver ${{ matrix.resolver }}
- name: Configure for Weeder
if: ${{ steps.ghcver.outputs.ghcver == '9.4.5' }}
run: |
echo 'ghc-options: { "$locals": -fwrite-ide-info }' >> stack.yaml
Expand All @@ -212,12 +213,10 @@ jobs:
--ghc-options '-Werror' \
--haddock --no-haddock-deps
- name: Weeder
if: ${{ steps.ghcver.outputs.ghcver == '9.4.5' }}
- name: Weeder for GHC 9.6
if: ${{ startsWith(steps.ghcver.outputs.ghcver, '9.6') }}
run: |
wget https://github.com/lierdakil/weeder2-static/releases/download/v2.5.0-1/weeder.gz
gunzip weeder.gz
chmod +x weeder
cabal install --installdir "$PWD" weeder
./weeder
- name: Stack test
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
- SPDX-License-Identifier: MPL-2.0
-->

## v0.0.3

* Minor tweaks for GHC 9.8 compatibility.
* Types `Point` and `Affine` now have `PointKind` parameter be role `nominal`, as coercing those between point types will break invariants.
* Bundled blst version bumped to v0.3.11.

## v0.0.2

* Prevent inlining of foreign calls. This fixes a potential efficiency issue,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

HsBLST is low-level Haskell bindings and a high-level interface to [BLST](https://github.com/supranational/blst) -- a multilingual BLS12-381 signature library.

This package includes sources from v0.3.10 version of BLST, licensed under
This package includes sources from v0.3.11 version of BLST, licensed under
[Apache License 2.0](https://github.com/supranational/blst/blob/master/LICENSE)

## Build Instructions [](#hsblst)
Expand Down
2 changes: 1 addition & 1 deletion c-source
Submodule c-source updated 161 files
27 changes: 15 additions & 12 deletions hsblst.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cabal-version: 1.12
cabal-version: 3.0

-- This file has been generated from package.yaml by hpack version 0.34.4.
--
-- see: https://github.com/sol/hpack

name: hsblst
version: 0.0.2
version: 0.0.3
synopsis: Haskell bindings to BLST
description: HsBLST is low-level Haskell bindings and a high-level interface to [BLST](https://github.com/supranational/blst) -- a multilingual BLS12-381 signature library.
category: Cryptography
Expand All @@ -20,6 +20,7 @@ build-type: Simple
tested-with:
GHC == 9.4.8
, GHC == 9.6.3
, GHC == 9.8.1
extra-source-files:
README.md
CHANGELOG.md
Expand Down Expand Up @@ -98,6 +99,7 @@ extra-source-files:
c-source/src/client_min_pk.c
c-source/src/client_min_sig.c
c-source/src/consts.c
c-source/src/cpuid.c
c-source/src/e1.c
c-source/src/e2.c
c-source/src/exp.c
Expand All @@ -109,6 +111,7 @@ extra-source-files:
c-source/src/map_to_g2.c
c-source/src/multi_scalar.c
c-source/src/pairing.c
c-source/src/pentaroot.c
c-source/src/rb_tree.c
c-source/src/recip.c
c-source/src/server.c
Expand All @@ -121,6 +124,7 @@ extra-source-files:
c-source/src/errors.h
c-source/src/fields.h
c-source/src/no_asm.h
c-source/src/pentaroot-addchain.h
c-source/src/point.h
c-source/src/recip-addchain.h
c-source/src/sha256.h
Expand Down Expand Up @@ -200,16 +204,15 @@ library
c-source/bindings
c-sources:
c-source/src/server.c
c-source/build/assembly.S
build-tools:
c2hs
build-depends:
base >=4.15.1.0 && <4.19
, deepseq >=1.4.5.0 && <1.5
base >=4.17 && <4.20
, deepseq >=1.4.5.0 && <1.5.1
, memory >=0.16.0 && <0.19
if impl(ghc >= 9.2)
ghc-options: -Wno-missing-kind-signatures
default-language: Haskell2010
asm-sources: c-source/build/assembly.S
build-tool-depends: c2hs:c2hs

test-suite hsblst-test
type: exitcode-stdio-1.0
Expand Down Expand Up @@ -275,14 +278,14 @@ test-suite hsblst-test
build-tool-depends:
tasty-discover:tasty-discover
build-depends:
base >=4.15.1.0 && <4.19
, bytestring >=0.10.12.1 && <0.12
, hex-text >=0.1.0.6 && <0.2
base >=4.17 && <4.20
, base16-bytestring ==1.0.*
, bytestring >=0.10.12.1 && <0.13
, hsblst
, memory >=0.16.0 && <0.19
, tasty >=1.4.2.1 && <1.5
, tasty >=1.4.2.1 && <1.6
, tasty-hunit >=0.10.0.3 && <0.11
, text >=1.2.5.0 && <1.3 || >=2.0.1 && <2.1
, text >=1.2.5.0 && <1.3 || >=2.0.1 && <2.1 || >=2.1 && <2.2
if impl(ghc >= 9.2)
ghc-options: -Wno-missing-kind-signatures
if impl(ghc < 9.4)
Expand Down
23 changes: 14 additions & 9 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: CC0-1.0

name: hsblst
version: 0.0.2
version: 0.0.3
author: Serokell <[email protected]>
github: serokell/hsblst

Expand All @@ -17,9 +17,13 @@ copyright: 2022 Serokell <https://serokell.io>
license-file: LICENSE
license: MPL-2.0

verbatim:
cabal-version: 3.0

tested-with:
- GHC == 9.4.8
- GHC == 9.6.3
- GHC == 9.8.1

default-extensions:
- AllowAmbiguousTypes
Expand Down Expand Up @@ -102,18 +106,19 @@ extra-source-files:
- c-source/README.md

dependencies:
- base >=4.15.1.0 && <4.19
- base >=4.17 && <4.20
- memory >=0.16.0 && <0.19

library:
source-dirs: src
include-dirs: c-source/bindings
build-tools: c2hs:c2hs
dependencies:
- deepseq ^>=1.4.5.0
- deepseq >=1.4.5.0 && < 1.5.1
c-sources:
- c-source/src/server.c
- c-source/build/assembly.S
verbatim:
build-tool-depends: c2hs:c2hs
asm-sources: c-source/build/assembly.S

tests:
hsblst-test:
Expand All @@ -133,8 +138,8 @@ tests:

dependencies:
- hsblst
- bytestring >=0.10.12.1 && <0.12
- hex-text ^>=0.1.0.6
- tasty ^>=1.4.2.1
- bytestring >=0.10.12.1 && <0.13
- base16-bytestring ^>=1.0
- tasty >=1.4.2.1 && <1.6
- tasty-hunit ^>=0.10.0.3
- text ^>=1.2.5.0 || ^>=2.0.1
- text ^>=1.2.5.0 || ^>=2.0.1 || ^>= 2.1
1 change: 1 addition & 0 deletions src/Crypto/BLST/Internal/Bindings.chs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <blst.h>

{-# OPTIONS_HADDOCK not-home #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | Lower-level bindings. Functions starting with @blst_@ are raw c2hs
-- bindings. Others are slightly higher level wrappers around those bindings.
Expand Down
3 changes: 3 additions & 0 deletions src/Crypto/BLST/Internal/Bindings/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- SPDX-License-Identifier: MPL-2.0

{-# OPTIONS_HADDOCK not-home #-}
{-# LANGUAGE RoleAnnotations #-}

-- | Types for lower-level bindings
module Crypto.BLST.Internal.Bindings.Types
Expand Down Expand Up @@ -29,13 +30,15 @@ instance Demote 'P2 where demote = P2
type SizeOf :: Type -> Nat
type family SizeOf t

type role Point nominal
-- | Point representation.
newtype Point (a :: PointKind) = Point ( SizedByteArray (SizeOf (Point a)) Bytes )
deriving stock (Show, Eq)

instance NFData (Point a) where
rnf = rnf @Bytes . unSizedByteArray . coerce

type role Affine nominal
-- | Affine point representation.
newtype Affine (a :: PointKind) = Affine { unAffine :: SizedByteArray (SizeOf (Affine a)) Bytes }
deriving stock (Show, Eq)
Expand Down
3 changes: 3 additions & 0 deletions src/Crypto/BLST/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- SPDX-License-Identifier: MPL-2.0

{-# OPTIONS_HADDOCK not-home #-}
{-# LANGUAGE RoleAnnotations #-}

-- | Types used for the high-level interface.
module Crypto.BLST.Internal.Types
Expand Down Expand Up @@ -35,6 +36,7 @@ newtype SecretKey = SecretKey Scalar

type instance ByteSize 'Serialize SecretKey = SkSerializeSize

type role PublicKey nominal
-- | Public key representation.
type PublicKey :: Curve -> Type
newtype PublicKey c = PublicKey (Affine (CurveToPkPoint c))
Expand All @@ -44,6 +46,7 @@ newtype PublicKey c = PublicKey (Affine (CurveToPkPoint c))
type instance ByteSize 'Serialize (PublicKey c) = SerializedSize (CurveToPkPoint c)
type instance ByteSize 'Compress (PublicKey c) = CompressedSize (CurveToPkPoint c)

type role Signature nominal phantom
-- | Signature representation.
type Signature :: Curve -> EncodeMethod -> Type
newtype Signature c m = Signature (Affine (CurveToMsgPoint c))
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
# SPDX-License-Identifier: CC0-1.0

resolver: lts-21.22
resolver: lts-22.4
packages: ['.']
8 changes: 4 additions & 4 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
packages: []
snapshots:
- completed:
sha256: afd5ba64ab602cabc2d3942d3d7e7dd6311bc626dcb415b901eaf576cb62f0ea
size: 640060
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/22.yaml
original: lts-21.22
sha256: 8b211c5a6aad3787e023dfddaf7de7868968e4f240ecedf14ad1c5b2199046ca
size: 714097
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/4.yaml
original: lts-22.4
11 changes: 6 additions & 5 deletions test/Test/BLST/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,28 @@ import Data.ByteArray (Bytes)
import Data.ByteArray qualified as BA
import Data.ByteArray.Sized (SizedByteArray)
import Data.ByteArray.Sized qualified as AS
import Data.Maybe (fromJust, fromMaybe)
import Data.ByteString.Base16 qualified as B16
import Data.Maybe (fromMaybe)
import Data.Proxy (Proxy(..))
import Data.Text (Text, unpack)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import GHC.TypeNats (KnownNat, natVal)
import System.IO.Unsafe (unsafePerformIO)
import Text.Hex (decodeHex, encodeHex)

import Crypto.BLST.Internal.Bindings qualified as B
import Crypto.BLST.Internal.Classy qualified as C

fromHex :: forall n. (KnownNat n) => Text -> SizedByteArray n Bytes
fromHex arg = AS.convert
. fromMaybe (error $ "Expected " <> show (natVal @n Proxy) <> " bytes got " <> unpack arg)
. AS.sizedByteArray . fromJust . decodeHex
. AS.sizedByteArray . B16.decodeLenient . encodeUtf8
$ arg

fromHex' :: BA.ByteArray a => Text -> a
fromHex' = BA.convert . fromJust . decodeHex
fromHex' = BA.convert . B16.decodeLenient . encodeUtf8

toHex :: BA.ByteArray a => SizedByteArray n a -> Text
toHex = encodeHex . BA.convert . AS.unSizedByteArray
toHex = decodeUtf8 . B16.encode . BA.convert . AS.unSizedByteArray

deserializePoint :: C.IsPoint p => Text -> B.Point p
deserializePoint = unsafePerformIO . C.fromAffine . deserializeAffine
Expand Down
10 changes: 0 additions & 10 deletions weeder.dhall

This file was deleted.

10 changes: 10 additions & 0 deletions weeder.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io>
# SPDX-License-Identifier: MPL-2.0

root-instances = [{ class = "\\.TestGroup$" }]
roots = [
"^Main\\.main$",
"^Crypto\\.BLST\\..*$",
"^Paths_.*",
]
unused-types = true

0 comments on commit e9fc587

Please sign in to comment.