Skip to content

Commit 7d2698b

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. Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 060fdbd commit 7d2698b

File tree

5 files changed

+120
-5
lines changed

5 files changed

+120
-5
lines changed

flake.nix

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
devShells.default = util.mkShell {
8282
packages = builtins.attrValues
8383
{
84-
inherit (config.packages) linters cbmc hol_light s2n_bignum slothy toolchains_native;
84+
inherit (config.packages) linters cbmc hol_light s2n_bignum slothy toolchains_native hol_server;
8585
inherit (pkgs)
8686
direnv
8787
nix-direnv
@@ -101,17 +101,18 @@
101101
};
102102

103103
devShells.avr = util.mkShell (import ./nix/avr { inherit pkgs; });
104+
packages.hol_server = util.hol_server.hol_server_start;
104105
devShells.hol_light = (util.mkShell {
105-
packages = builtins.attrValues { inherit (config.packages) linters hol_light s2n_bignum; };
106+
packages = builtins.attrValues { inherit (config.packages) linters hol_light s2n_bignum hol_server; };
106107
}).overrideAttrs (old: { shellHook = holLightShellHook; });
107108
devShells.hol_light-cross = (util.mkShell {
108-
packages = builtins.attrValues { inherit (config.packages) linters toolchains hol_light s2n_bignum; };
109+
packages = builtins.attrValues { inherit (config.packages) linters toolchains hol_light s2n_bignum hol_server; };
109110
}).overrideAttrs (old: { shellHook = holLightShellHook; });
110111
devShells.hol_light-cross-aarch64 = (util.mkShell {
111-
packages = builtins.attrValues { inherit (config.packages) linters toolchain_aarch64 hol_light s2n_bignum; };
112+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_aarch64 hol_light s2n_bignum hol_server; };
112113
}).overrideAttrs (old: { shellHook = holLightShellHook; });
113114
devShells.hol_light-cross-x86_64 = (util.mkShell {
114-
packages = builtins.attrValues { inherit (config.packages) linters toolchain_x86_64 hol_light s2n_bignum; };
115+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_x86_64 hol_light s2n_bignum hol_server; };
115116
}).overrideAttrs (old: { shellHook = holLightShellHook; });
116117
devShells.ci = util.mkShell {
117118
packages = builtins.attrValues { inherit (config.packages) linters toolchains_native; };

nix/hol_light/hol-server.sh

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

nix/hol_light/hol_server.nix

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

nix/util.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ rec {
101101

102102
valgrind_varlat = pkgs.callPackage ./valgrind { };
103103
hol_light' = pkgs.callPackage ./hol_light { };
104+
hol_server = pkgs.callPackage ./hol_light/hol_server.nix { inherit hol_light'; };
104105
s2n_bignum = pkgs.callPackage ./s2n_bignum { };
105106
slothy = pkgs.callPackage ./slothy { };
106107
m55-an547 = pkgs.callPackage ./m55-an547-arm-none-eabi { };

proofs/hol_light/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[//]: # (SPDX-License-Identifier: CC-BY-4.0)
2+
3+
# HOL Light functional correctness proofs
4+
5+
This directory contains functional correctness proofs for x86_64 assembly routines
6+
used in mldsa-native. The proofs are written in the [HOL Light](https://hol-light.github.io/) theorem
7+
prover, utilizing the assembly verification infrastructure from [s2n-bignum](https://github.com/awslabs/s2n-bignum).
8+
9+
Each function is proved in a separate `.ml` file in [x86_64/proofs/](x86_64/proofs). Each file
10+
contains the byte code being verified, as well as the specification that is being proved.
11+
12+
## Reproducing the proofs
13+
14+
To reproduce the proofs, enter the nix shell via
15+
16+
```bash
17+
nix develop .#hol_light --experimental-features 'nix-command flakes'
18+
```
19+
20+
from mldsa-native's base directory. Then
21+
22+
```bash
23+
make -C proofs/hol_light/x86_64
24+
```
25+
26+
will build and run the proofs. Note that this may take hours even on powerful machines.
27+
28+
## Interactive proof development
29+
30+
For interactive proof development, start the HOL Light server:
31+
32+
```bash
33+
hol-server [port] # default port is 2012
34+
```
35+
36+
Then use the [HOL Light extension for VS Code](https://marketplace.visualstudio.com/items?itemName=monadius.hol-light-simple)
37+
to connect and send commands interactively.
38+
39+
Alternatively, send commands using netcat:
40+
41+
```bash
42+
echo '1+1;;' | nc -w 5 127.0.0.1 2012
43+
```
44+
45+
## What is covered?
46+
47+
- x86_64 forward NTT: [mldsa_ntt.S](x86_64/mldsa/mldsa_ntt.S)

0 commit comments

Comments
 (0)