-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhax-driver.py
executable file
·160 lines (145 loc) · 4.18 KB
/
hax-driver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#! /usr/bin/env python3
import os
import argparse
import subprocess
import sys
def shell(command, expect=0, cwd=None, env={}):
subprocess_stdout = subprocess.DEVNULL
print("Env:", env)
print("Command: ", end="")
for i, word in enumerate(command):
if i == 4:
print("'{}' ".format(word), end="")
else:
print("{} ".format(word), end="")
print("\nDirectory: {}".format(cwd))
os_env = os.environ
os_env.update(env)
ret = subprocess.run(command, cwd=cwd, env=os_env)
if ret.returncode != expect:
raise Exception("Error {}. Expected {}.".format(ret, expect))
parser = argparse.ArgumentParser(description="Perform proofs using Hax.")
sub_parser = parser.add_subparsers(
description="Extract or typecheck",
dest="sub",
help="Extract and typecheck F* etc. from the Bertie Rust code.",
)
extract_parser = sub_parser.add_parser("extract-fstar")
extract_proverif_parser = sub_parser.add_parser("extract-proverif")
typecheck_parser = sub_parser.add_parser("typecheck")
patch_proverif_parser = sub_parser.add_parser("patch-proverif")
typecheck_proverif_parser = sub_parser.add_parser("typecheck-proverif")
typecheck_parser.add_argument(
"--lax",
action="store_true",
dest="lax",
help="Lax typecheck the code only",
)
typecheck_parser.add_argument(
"--admit",
action="store_true",
dest="admit",
help="Set admit_smt_queries to true for typechecking",
)
typecheck_parser.add_argument(
"--clean",
action="store_true",
dest="clean",
help="Clean before calling make",
)
options = parser.parse_args()
cargo_hax_into = [
"cargo",
"hax",
"-C",
"-p",
"bertie",
"-p",
"rand_core",
"--no-default-features",
";",
"into",
]
cargo_hax_into_pv = [
"cargo",
"hax",
"-C",
"-p",
"bertie",
"--no-default-features",
"--features",
"hax-pv",
";",
"into",
]
hax_env = {}
if options.sub == "extract-fstar":
# The extract sub command.
shell(
cargo_hax_into
+ [
"-i",
"-**::non_hax::** -bertie::stream::**",
"fstar",
"--interfaces",
"+** +!bertie::tls13crypto::** +!bertie::tls13utils::**"
],
cwd=".",
env=hax_env,
)
elif options.sub == "extract-handshake":
# The extract sub command.
shell(
cargo_hax_into
+ [
"-i",
"-** +~bertie::tls13handshake::**",
"fstar",
"--interfaces",
"+!** +bertie::tls13handshake::**"
],
cwd=".",
env=hax_env,
)
elif options.sub == "extract-proverif":
# The extract sub command.
shell(
cargo_hax_into_pv
+ [
"-i",
" ".join([
"-**",
"+~**::tls13handshake::**",
"+~**::server::lookup_db", # to include transitive dependency on tls13utils
"+~**::tls13utils::parse_failed", # transitive dependencies required
"+~**::tls13crypto::zero_key", # transitive dependencies required
]),
"pro-verif",
],
cwd=".",
env=hax_env,
)
elif options.sub == "typecheck":
# Typecheck subcommand.
custom_env = {}
if options.lax:
custom_env.update({"OTHERFLAGS": "--lax"})
if options.admit:
custom_env.update({"OTHERFLAGS": "--admit_smt_queries true"})
if options.clean:
shell(["make", "-C", "proofs/fstar/extraction/", "clean"])
shell(["make", "-C", "proofs/fstar/extraction/"], env=custom_env)
exit(0)
elif options.sub == "patch-proverif":
custom_env = {}
shell(["patch", "proofs/proverif/extraction/lib.pvl", "proofs/proverif/patches/lib.patch"], env=custom_env)
shell(["patch", "proofs/proverif/extraction/analysis.pv", "proofs/proverif/patches/analysis.patch"], env=custom_env)
exit(0)
elif options.sub == "typecheck-proverif":
# Typecheck subcommand.
custom_env = {}
shell(["proverif", "-lib", "proofs/proverif/handwritten_lib", "-lib", "proofs/proverif/extraction/lib", "proofs/proverif/extraction/analysis.pv"], env=custom_env)
exit(0)
else:
parser.print_help()
exit(2)