vestigia

Detect where execution depends on secrets.
git clone git://git.ppad.tech/vestigia.git
Log | Files | Refs | README | LICENSE

default.nix (2792B)


      1 # Spike 3: ppad-secp256k1 under vestigia, on x86_64-linux: the
      2 # release (fdb80d5), a constant-time control, and the elenchus
      3 # vector's mutants (S1 a secret-indexed window load, S2 a branch on
      4 # each ladder bit, S3 a zero-byte shortcut on the key in Schnorr).
      5 #
      6 #   nix build --impure -f etc/spike/secp256k1 all
      7 let
      8   system = "x86_64-linux";
      9   vestigia = builtins.getFlake (toString ../../..);
     10   secp = builtins.getFlake ("git+file:///Users/jtobin/src/ppad/secp256k1"
     11     + "?rev=fdb80d54b86c61bd1a15e2e8db351091d02c89ee");
     12   pkgs = import vestigia.inputs.nixpkgs { inherit system; };
     13   hlib = pkgs.haskell.lib;
     14   llvm = pkgs.llvmPackages_19.llvm;
     15   clang = pkgs.llvmPackages_19.clang;
     16   withLlvm = p: hlib.addBuildTools (hlib.enableCabalFlag p "llvm")
     17     [ llvm clang ];
     18   input = n: withLlvm secp.inputs.${n}.packages.${system}.default;
     19 
     20   variant = name: patches:
     21     let
     22       hpkgs = pkgs.haskell.packages.ghc910.extend (new: old: {
     23         ppad-base16 = input "ppad-base16";
     24         ppad-sha256 = input "ppad-sha256";
     25         ppad-hmac-drbg = input "ppad-hmac-drbg";
     26         ppad-fixed = input "ppad-fixed";
     27         ppad-secp256k1 = withLlvm (hlib.dontCheck (hlib.dontBenchmark
     28           (hlib.appendPatches
     29             (new.callCabal2nix "ppad-secp256k1" secp.outPath {
     30               ppad-base16 = new.ppad-base16;
     31               ppad-sha256 = new.ppad-sha256;
     32               ppad-hmac-drbg = new.ppad-hmac-drbg;
     33               ppad-fixed = new.ppad-fixed;
     34             })
     35             patches)));
     36       });
     37       ghc = hpkgs.ghcWithPackages (p: [ p.ppad-secp256k1 ]);
     38       harness = pkgs.runCommandCC "secp256k1-${name}-harness" {
     39         nativeBuildInputs = [ ghc llvm clang ];
     40       } ''
     41         mkdir -p $out/bin build
     42         cp ${./Harness.hs} build/Harness.hs
     43         cp ${vestigia.packages.${system}.include}/include/vestigia.c build/marks.c
     44         cd build
     45         ghc -O2 -rtsopts '-with-rtsopts=-xr1G -V0' Harness.hs marks.c \
     46           -I${vestigia.packages.${system}.include}/include \
     47           -I${vestigia.lib.${system}.valgrindDev}/include \
     48           -o $out/bin/harness
     49       '';
     50       bin = "${harness}/bin/harness";
     51     in pkgs.linkFarm "secp256k1-${name}" [
     52       { name = "trace";
     53         path = vestigia.lib.${system}.traceOf {
     54           name = "secp256k1-${name}";
     55           harness = bin;
     56           runs = [ [ "2" "1" ] ];
     57         }; }
     58       { name = "diff";
     59         path = vestigia.lib.${system}.diffOf {
     60           name = "secp256k1-${name}";
     61           harness = bin;
     62           runs = map (s: [ "1" s ]) [ "1" "2" "3" ];
     63           objects = [ "harness" ];
     64         }; }
     65     ];
     66 in
     67 {
     68   all = pkgs.linkFarm "secp256k1-spike" [
     69     { name = "release"; path = variant "release" [ ]; }
     70     { name = "mutants"; path = variant "mutants" [ ./mutants.patch ]; }
     71   ];
     72 }