Skip to content

Commit ebed0f3

Browse files
committed
Add hol-server for programmatic HOL Light communication
Integrates hol_server (https://github.com/monadius/hol_server) to enable TCP-based communication with HOL Light. This allows sending commands programmatically via netcat or the VS Code extension. Usage: hol-server [port] # default port is 2012 Update documentation accordingly. - Ported from pq-code-package/mldsa-native#883 Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 78d0658 commit ebed0f3

File tree

5 files changed

+96
-5
lines changed

5 files changed

+96
-5
lines changed

flake.nix

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) The mlkem-native project authors
2+
# Copyright (c) The mldsa-native project authors
13
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
24

35
{
@@ -80,25 +82,26 @@
8082
devShells.default = util.mkShell {
8183
packages = builtins.attrValues
8284
{
83-
inherit (config.packages) linters cbmc hol_light s2n_bignum slothy toolchains_native;
85+
inherit (config.packages) linters cbmc hol_light s2n_bignum slothy toolchains_native hol_server;
8486
inherit (pkgs)
8587
direnv
8688
nix-direnv
8789
zig_0_13;
8890
} ++ pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [ config.packages.valgrind_varlat ];
8991
};
9092

93+
packages.hol_server = util.hol_server.hol_server_start;
9194
devShells.hol_light = (util.mkShell {
92-
packages = builtins.attrValues { inherit (config.packages) linters hol_light s2n_bignum; };
95+
packages = builtins.attrValues { inherit (config.packages) linters hol_light s2n_bignum hol_server; };
9396
}).overrideAttrs (old: { shellHook = holLightShellHook; });
9497
devShells.hol_light-cross = (util.mkShell {
95-
packages = builtins.attrValues { inherit (config.packages) linters toolchains hol_light s2n_bignum gcc-arm-embedded; };
98+
packages = builtins.attrValues { inherit (config.packages) linters toolchains hol_light s2n_bignum gcc-arm-embedded hol_server; };
9699
}).overrideAttrs (old: { shellHook = holLightShellHook; });
97100
devShells.hol_light-cross-aarch64 = (util.mkShell {
98-
packages = builtins.attrValues { inherit (config.packages) linters toolchain_aarch64 hol_light s2n_bignum gcc-arm-embedded; };
101+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_aarch64 hol_light s2n_bignum gcc-arm-embedded hol_server; };
99102
}).overrideAttrs (old: { shellHook = holLightShellHook; });
100103
devShells.hol_light-cross-x86_64 = (util.mkShell {
101-
packages = builtins.attrValues { inherit (config.packages) linters toolchain_x86_64 hol_light s2n_bignum gcc-arm-embedded; };
104+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_x86_64 hol_light s2n_bignum gcc-arm-embedded hol_server; };
102105
}).overrideAttrs (old: { shellHook = holLightShellHook; });
103106
devShells.ci = util.mkShell {
104107
packages = builtins.attrValues { inherit (config.packages) linters toolchains_native; };

nix/hol_light/hol-server.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) The mldsa-native project authors
3+
# Copyright (c) The mlkem-native project authors
4+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
5+
#
6+
# HOL Light server for programmatic communication
7+
# Based on https://github.com/monadius/hol_server
8+
#
9+
# Usage: hol-server [port]
10+
11+
set -e
12+
13+
PORT=${1:-2012}
14+
15+
# These are replaced by nix
16+
HOL_LIGHT_DIR="@hol_light@/lib/hol_light"
17+
HOL_SERVER_SRC="@hol_server_src@"
18+
19+
# cd to proofs directory if in mlkem-native repo
20+
PROOF_DIR="$(git rev-parse --show-toplevel 2>/dev/null)/proofs/hol_light"
21+
[ -d "$PROOF_DIR" ] && cd "$PROOF_DIR"
22+
23+
echo "Starting HOL Light server on port $PORT..."
24+
25+
{
26+
# Load required libraries for server2.ml
27+
echo '#directory "+unix";;'
28+
echo '#directory "+threads";;'
29+
echo '#load "unix.cma";;'
30+
echo '#load "threads.cma";;'
31+
32+
# Load the server using #use (not loads) for proper evaluation
33+
echo "#use \"$HOL_SERVER_SRC/server2.ml\";;"
34+
35+
# Start the server
36+
echo "start ~single_connection:false $PORT;;"
37+
38+
# Keep stdin open for the server to continue running
39+
cat
40+
} | exec "$HOL_LIGHT_DIR/hol.sh"

nix/hol_light/hol_server.nix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) The mldsa-native project authors
2+
# Copyright (c) The mlkem-native project authors
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
5+
# HOL Light server for programmatic communication
6+
# Based on https://github.com/monadius/hol_server
7+
{ fetchFromGitHub, runCommand, hol_light' }:
8+
9+
let
10+
hol_server_src = fetchFromGitHub {
11+
owner = "monadius";
12+
repo = "hol_server";
13+
rev = "vscode";
14+
hash = "sha256-o98ule5uuazm36+ppsvX2KCbtVbVwzHxGboUhbbrPCQ=";
15+
};
16+
17+
hol_server_start = runCommand "hol-server" { } ''
18+
mkdir -p $out/bin
19+
substitute ${./hol-server.sh} $out/bin/hol-server \
20+
--replace-fail "@hol_light@" "${hol_light'}" \
21+
--replace-fail "@hol_server_src@" "${hol_server_src}"
22+
chmod +x $out/bin/hol-server
23+
'';
24+
25+
in
26+
{
27+
inherit hol_server_src hol_server_start;
28+
}

nix/util.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) The mlkem-native project authors
2+
# Copyright (c) The mldsa-native project authors
13
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
24

35
{ pkgs, cbmc, bitwuzla, z3 }:
@@ -100,6 +102,7 @@ rec {
100102

101103
valgrind_varlat = pkgs.callPackage ./valgrind { };
102104
hol_light' = pkgs.callPackage ./hol_light { };
105+
hol_server = pkgs.callPackage ./hol_light/hol_server.nix { inherit hol_light'; };
103106
s2n_bignum = pkgs.callPackage ./s2n_bignum { };
104107
slothy = pkgs.callPackage ./slothy { };
105108
m55-an547 = pkgs.callPackage ./m55-an547-arm-none-eabi { };

proofs/hol_light/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ will build and run the proofs. Note that this make take hours even on powerful m
7777

7878
For convenience, you can also use `tests hol_light` which wraps the `make` invocation above; see `tests hol_light --help`.
7979

80+
## Interactive proof development
81+
82+
For interactive proof development, start the HOL Light server:
83+
84+
```bash
85+
hol-server [port] # default port is 2012
86+
```
87+
88+
Then use the [HOL Light extension for VS Code](https://marketplace.visualstudio.com/items?itemName=monadius.hol-light-simple)
89+
to connect and send commands interactively.
90+
91+
Alternatively, send commands using netcat:
92+
93+
```bash
94+
echo '1+1;;' | nc -w 5 127.0.0.1 2012
95+
```
96+
8097
## What is covered?
8198

8299
All AArch64 assembly routines used in mlkem-native are covered. Those are:

0 commit comments

Comments
 (0)