script

Representations and fast conversions for Script (docs.ppad.tech/script).
git clone git://git.ppad.tech/script.git
Log | Files | Refs | README | LICENSE

commit a9dd507c44e9c4789a71c430269e2f51004ea3a4
parent 99988478ed9f5c5cb6df422049d65c74ea211ad3
Author: Jared Tobin <jared@jtobin.io>
Date:   Sun, 28 Dec 2025 16:40:57 -0330

release: v0.2.2

Diffstat:
MCHANGELOG | 3+++
MREADME.md | 38+++++++++++++++++---------------------
Mflake.lock | 28++++++++++++++--------------
Mflake.nix | 15++++++++++-----
Mppad-script.cabal | 13++++++++++---
5 files changed, 54 insertions(+), 43 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,5 +1,8 @@ # Changelog +- 0.2.2 (2025-12-28) + * Adds an 'llvm' flag and tests with GHC 9.10.3. + - 0.2.1 (2025-01-21) * Minor Haddock improvements. diff --git a/README.md b/README.md @@ -53,37 +53,33 @@ Haddocks (API documentation, etc.) are hosted at The aim is best-in-class performance for highly-auditable Haskell code. -Current benchmark figures on my mid-2020 MacBook Air look like (use +Current benchmark figures on my M4 Silicon MacBook Air look like (use `cabal bench` to run the benchmark suite): ``` benchmarking to_script - time 484.9 ns (478.3 ns .. 491.4 ns) - 0.998 R² (0.997 R² .. 0.999 R²) - mean 496.2 ns (485.8 ns .. 508.1 ns) - std dev 37.17 ns (30.08 ns .. 49.95 ns) - variance introduced by outliers: 83% (severely inflated) + time 228.1 ns (227.9 ns .. 228.6 ns) + 1.000 R² (1.000 R² .. 1.000 R²) + mean 228.9 ns (228.5 ns .. 230.0 ns) + std dev 2.167 ns (1.241 ns .. 3.840 ns) benchmarking from_script - time 380.8 ns (374.3 ns .. 387.5 ns) - 0.998 R² (0.996 R² .. 0.999 R²) - mean 383.0 ns (375.3 ns .. 395.4 ns) - std dev 31.88 ns (22.41 ns .. 43.86 ns) - variance introduced by outliers: 86% (severely inflated) + time 329.3 ns (327.4 ns .. 331.4 ns) + 1.000 R² (1.000 R² .. 1.000 R²) + mean 331.3 ns (330.1 ns .. 332.3 ns) + std dev 3.502 ns (2.723 ns .. 4.492 ns) benchmarking to_base16 - time 291.3 ns (285.6 ns .. 297.9 ns) - 0.996 R² (0.995 R² .. 0.998 R²) - mean 298.3 ns (291.8 ns .. 308.1 ns) - std dev 26.38 ns (21.25 ns .. 34.27 ns) - variance introduced by outliers: 87% (severely inflated) + time 150.3 ns (149.6 ns .. 150.9 ns) + 1.000 R² (1.000 R² .. 1.000 R²) + mean 149.6 ns (149.3 ns .. 149.9 ns) + std dev 1.101 ns (884.2 ps .. 1.334 ns) benchmarking from_base16 - time 439.1 ns (429.9 ns .. 448.2 ns) - 0.997 R² (0.996 R² .. 0.998 R²) - mean 437.9 ns (429.9 ns .. 450.0 ns) - std dev 32.67 ns (26.12 ns .. 44.04 ns) - variance introduced by outliers: 83% (severely inflated) + time 101.1 ns (100.8 ns .. 101.4 ns) + 1.000 R² (1.000 R² .. 1.000 R²) + mean 100.7 ns (100.4 ns .. 101.0 ns) + std dev 949.7 ps (766.3 ps .. 1.162 ns) ``` where the inputs to the above functions are variations of the script found diff --git a/flake.lock b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1725910328, - "narHash": "sha256-n9pCtzGZ0httmTwMuEbi5E78UQ4ZbQMr1pzi5N0LAG8=", + "lastModified": 1766840161, + "narHash": "sha256-Ss/LHpJJsng8vz1Pe33RSGIWUOcqM1fjrehjUkdrWio=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5775c2583f1801df7b790bf7f7d710a19bac66f4", + "rev": "3edc4a30ed3903fdf6f90c837f961fa6b49582d1", "type": "github" }, "original": { @@ -51,11 +51,11 @@ ] }, "locked": { - "lastModified": 1737297378, - "narHash": "sha256-8N1RG2s5+Wpt30sFSRpwq2bwt4Y/bMddz4CZmhr7rDM=", + "lastModified": 1766934151, + "narHash": "sha256-BUFpuLfrGXE2xi3Wa9TYCEhhRhFp175Ghxnr0JRbG2I=", "ref": "master", - "rev": "47ba5540652bddf6d9f80f9ca88fa4def4d8e02c", - "revCount": 11, + "rev": "58dfb7922401a60d5de76825fcd5f6ecbcd7afe0", + "revCount": 26, "type": "git", "url": "git://git.ppad.tech/base16.git" }, @@ -71,11 +71,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1737297101, - "narHash": "sha256-EnXnq+JLflbWt+DvaGGnY2gfAqsGNOm5vPgHh3hkfwQ=", + "lastModified": 1766932084, + "narHash": "sha256-GvVsbTfW+B7IQ9K/QP2xcXJAm1lhBin1jYZWNjOzT+o=", "ref": "master", - "rev": "f29823875250bc99b3891f7373535ccde9a29a44", - "revCount": 1, + "rev": "353e61763b959b960a55321a85423501e3e9ed7a", + "revCount": 2, "type": "git", "url": "git://git.ppad.tech/nixpkgs.git" }, diff --git a/flake.nix b/flake.nix @@ -26,12 +26,17 @@ pkgs = import nixpkgs { inherit system; }; hlib = pkgs.haskell.lib; + llvm = pkgs.llvmPackages_19.llvm; base16 = ppad-base16.packages.${system}.default; + base16-llvm = + hlib.addBuildTools + (hlib.enableCabalFlag base16 "llvm") + [ llvm ]; - hpkgs = pkgs.haskell.packages.ghc981.extend (new: old: { - ppad-base16 = base16; - ${lib} = old.callCabal2nixWithOptions lib ./. "--enable-profiling" { + hpkgs = pkgs.haskell.packages.ghc910.extend (new: old: { + ppad-base16 = base16-llvm; + ${lib} = new.callCabal2nixWithOptions lib ./. "--enable-profiling" { ppad-base16 = new.ppad-base16; }; }); @@ -51,10 +56,9 @@ buildInputs = [ cabal cc + llvm ]; - inputsFrom = builtins.attrValues self.packages.${system}; - doBenchmark = true; shellHook = '' @@ -63,6 +67,7 @@ echo "cc: $(${cc}/bin/cc --version)" echo "ghc: $(${ghc}/bin/ghc --version)" echo "cabal: $(${cabal}/bin/cabal --version)" + echo "llc: $(${llvm}/bin/llc --version | head -2 | tail -1)" ''; }; } diff --git a/ppad-script.cabal b/ppad-script.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: ppad-script -version: 0.2.1 +version: 0.2.2 synopsis: Primitive Script support. license: MIT license-file: LICENSE @@ -8,7 +8,7 @@ author: Jared Tobin maintainer: jared@ppad.tech category: Cryptography build-type: Simple -tested-with: GHC == { 9.8.1 } +tested-with: GHC == 9.10.3 extra-doc-files: CHANGELOG description: Representations for [Script](https://en.bitcoin.it/wiki/Script), @@ -16,6 +16,11 @@ description: 'ByteString' versions, as well as fast conversion utilities for working with them. +flag llvm + description: Use GHC's LLVM backend. + default: False + manual: True + source-repository head type: git location: git.ppad.tech/script.git @@ -25,13 +30,15 @@ library hs-source-dirs: lib ghc-options: -Wall + if flag(llvm) + ghc-options: -fllvm -O2 exposed-modules: Bitcoin.Prim.Script build-depends: base >= 4.9 && < 5 , bytestring >= 0.9 && < 0.13 , primitive >= 0.8 && < 0.10 - , ppad-base16 >= 0.1 && < 0.3 + , ppad-base16 >= 0.2.1 && < 0.3 test-suite script-tests type: exitcode-stdio-1.0