Skip to content

Commit

Permalink
BLS12-381 bindings (#266)
Browse files Browse the repository at this point in the history
Bindings in Haskell for curve BLS12-381 operations. End goal is to add BLS12-381 bindings to Plutus, following [CIP-0381](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0381). Bindings based in the [blst](https://github.com/supranational/blst) library. 

Co-authored-by: iquerejeta <querejeta.azurmendi@iohk.io>
Co-authored-by: Moritz Angermann <moritz.angermann@gmail.com>
Co-authored-by: Alexey Kuleshevich <alexey.kuleshevich@iohk.io>
  • Loading branch information
4 people authored Mar 30, 2023
1 parent f954aec commit 56a71b1
Show file tree
Hide file tree
Showing 14 changed files with 1,778 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build-blst.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
# I don't understand why this just vanishes.
export PATH=/usr/bin:$PATH

mkdir blst-sources && cd blst-sources
git clone https://github.com/supranational/blst
cd blst
git reset --hard $BLST_REF
./build.sh
cd ../..
41 changes: 32 additions & 9 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:

# current ref from: 27.02.2022
SECP256K1_REF: ac83be33d0956faf6b7f61a60ab524ef7d6a473a
# current ref from: 25.11.2022
BLST_REF: 03b5124029979755c752eec45f3c29674b558446

# Modify this value to "invalidate" the secp cache.
SECP_CACHE_VERSION: "2023-03-22"
Expand Down Expand Up @@ -96,6 +98,17 @@ jobs:
if: runner.os == 'macOS'
run: brew install autoconf automake libtool

- name: "WINDOWS: Install blst"
if: runner.os == 'Windows'
env:
MSYS2_PATH_TYPE: inherit
MSYSTEM: MINGW64
run: C:\\msys64\\usr\\bin\\bash.exe .github/workflows/build-blst.bash

- name: "NON-WINDOWS: Install blst"
if: runner.os != 'Windows'
run: .github/workflows/build-blst.bash

- name: Install secp256k1
uses: input-output-hk/setup-secp256k1@v1
with:
Expand Down Expand Up @@ -140,21 +153,30 @@ jobs:
# The tests call out to msys2 commands. We generally do not want to mix toolchains, so
# we are very deliberate about only adding msys64 to the path where absolutely necessary.
${{ (runner.os == 'Windows' && '$env:PATH=("C:\msys64\mingw64\bin;{0}" -f $env:PATH)') || '' }}
cabal build all --enable-tests --only-dependencies
cabal build all --enable-tests --only-dependencies -j --ghc-option=-j4
- name: Build
run: |
# The tests call out to msys2 commands. We generally do not want to mix toolchains, so
# we are very deliberate about only adding msys64 to the path where absolutely necessary.
${{ (runner.os == 'Windows' && '$env:PATH=("C:\msys64\mingw64\bin;{0}" -f $env:PATH)') || '' }}
cabal build all --enable-tests
- name: Build [WIN - testing]
if: runner.os == 'Windows'
run: cabal build all --enable-tests --extra-lib-dirs ${env:GITHUB_WORKSPACE}/blst-sources/blst -j --ghc-option=-j4

- name: Build [non-WIN - testing]
if: runner.os != 'Windows'
run: cabal build all --enable-tests --extra-lib-dirs ${GITHUB_WORKSPACE}/blst-sources/blst -j

- name: Run tests
- name: Run tests [WIN]
if: runner.os == 'Windows'
env:
MSYS2_PATH_TYPE: inherit
MSYSTEM: MINGW64
run: |
# The tests call out to msys2 commands. We generally do not want to mix toolchains, so
# we are very deliberate about only adding msys64 to the path where absolutely necessary.
${{ (runner.os == 'Windows' && '$env:PATH=("C:\msys64\mingw64\bin;{0}" -f $env:PATH)') || '' }}
cabal test all --enable-tests --test-show-details=direct -j1 -v3
cabal test all --enable-tests --test-show-details=direct -j1 --extra-lib-dirs ${env:GITHUB_WORKSPACE}/blst-sources/blst
- name: Run tests [non-WIN]
if: runner.os != 'Windows'
run: cabal test all --enable-tests --test-show-details=direct -j1 --extra-lib-dirs ${GITHUB_WORKSPACE}/blst-sources/blst

- uses: actions/upload-artifact@v3
with:
Expand All @@ -177,6 +199,7 @@ jobs:
# and will silently fail if msys2 is not in path. See the "Run tests" step.
#
# - name: Setup tmate session
# if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
# with:
# limit-access-to-actor: true
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ test-show-details: direct

program-options
ghc-options: -Werror

3 changes: 3 additions & 0 deletions cardano-crypto-class/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.1.1.0
* Included bindings to `blst` library to enable operations over curve BLS12-381

## 2.1.0.1

* Remove `development` flag: #372
Expand Down
11 changes: 9 additions & 2 deletions cardano-crypto-class/cardano-crypto-class.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: cardano-crypto-class
version: 2.1.0.1
version: 2.1.1.0
synopsis:
Type classes abstracting over cryptography primitives for Cardano

Expand All @@ -19,6 +19,8 @@ category: Currency
build-type: Simple
extra-source-files: README.md
CHANGELOG.md
extra-source-files: cbits/blst.h
, cbits/blst_aux.h

flag secp256k1-support
description: Enable support for functions from libsecp256k1. Requires
Expand All @@ -45,6 +47,8 @@ library
Cardano.Crypto.DSIGN.Ed448
Cardano.Crypto.DSIGN.Mock
Cardano.Crypto.DSIGN.NeverUsed
Cardano.Crypto.EllipticCurve.BLS12_381
Cardano.Crypto.EllipticCurve.BLS12_381.Internal
Cardano.Crypto.Hash
Cardano.Crypto.Hash.Blake2b
Cardano.Crypto.Hash.Class
Expand Down Expand Up @@ -90,7 +94,7 @@ library
, aeson
, base
, base16-bytestring >=1
, bytestring
, bytestring >= 0.11
, cardano-binary >= 1.6
, cardano-strict-containers
, cryptonite
Expand Down Expand Up @@ -121,6 +125,9 @@ library
pkgconfig-depends: libsecp256k1 -any
cpp-options: -DSECP256K1_ENABLED

extra-libraries: blst
c-sources: cbits/blst_util.c

test-suite test-memory-example
import: base, project-config
-- Temporarily removing this as it is breaking the CI, and
Expand Down
Loading

0 comments on commit 56a71b1

Please sign in to comment.