-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmechanism.sh
More file actions
executable file
·130 lines (119 loc) · 3.47 KB
/
Copy pathmechanism.sh
File metadata and controls
executable file
·130 lines (119 loc) · 3.47 KB
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
#!/usr/bin/env bash
set -Eeuo pipefail
repo_dir="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
base_image="comppoly-rabin-replay-repro:mechanism-base"
mechanism_image="comppoly-rabin-replay-repro:mechanism"
runner_args=()
build_jobs=4
clean_only=false
build_only=false
usage() {
cat <<'EOF'
Usage: ./mechanism.sh [--verbose] [--jobs N]
./mechanism.sh --build-only [--jobs N]
./mechanism.sh --clean
Build and run the opt-in diagnostic kernel experiment. The first build fetches
and compiles exact pinned sources; allow 30 to 40 GiB of free disk space.
The experiment itself runs offline with 8 GiB memory, no swap, four CPUs, an
8 MiB OS main-thread stack limit, and process/time bounds enforced inside the
container. Lean normally dispatches its program main to its own worker stack.
Options:
--verbose Print the complete instrumented kernel trace.
--jobs N Lean source-build parallelism, from 1 through 4 (default: 4).
--build-only Build the two pinned images without running the diagnostic.
--clean Remove only this experiment's two Docker images, then exit.
EOF
}
while (($#)); do
case "$1" in
--verbose)
runner_args+=(--verbose)
shift
;;
--jobs)
if (($# < 2)); then
echo "missing value for --jobs" >&2
usage >&2
exit 2
fi
build_jobs="$2"
shift 2
;;
--jobs=*)
build_jobs="${1#*=}"
shift
;;
--clean)
clean_only=true
shift
;;
--build-only)
build_only=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown argument: $1" >&2
usage >&2
exit 2
;;
esac
done
if ! [[ "$build_jobs" =~ ^[1-4]$ ]]; then
echo "--jobs must be an integer from 1 through 4" >&2
exit 2
fi
if [[ "$clean_only" == true ]]; then
for image in "$mechanism_image" "$base_image"; do
if docker image inspect "$image" >/dev/null 2>&1; then
docker image rm "$image"
fi
done
exit 0
fi
# Build the same exact original-suite image used by the unmodified Comparator
# reproduction. Network access exists only during these image-build steps.
docker build \
--tag "$base_image" \
--build-arg "LEAN_VERSION=4.32.2" \
--build-arg "COMPPOLY_REPOSITORY=https://github.com/zksecurity/CompPoly.git" \
--build-arg "BASE_COMPPOLY_REV=6133f9f796707c438d0a614f97dc218ae976ab8f" \
--build-arg "TARGET_COMPPOLY_REV=641694629e4557520a1539b272ec338c9f3044c7" \
--build-arg "BASE_EXPECTATION=pathological" \
--build-arg "SUITE_NAME=original" \
--build-arg "COMPPOLY_MANIFEST_SHA256=5f52302efd2c429a7d6cd2f72b26573a6fc09af56f7f956a6037c85e3d10f172" \
--build-arg "COMPARE_EXPORTS=false" \
"$repo_dir"
# Build the diagnostic Lean kernel from the pinned Lean source and the exact
# committed instrumentation patch. Docker layer caching makes later runs much
# faster than the first source build.
docker build \
--file "$repo_dir/deep-dive/Dockerfile.mechanism" \
--tag "$mechanism_image" \
--build-arg "BASE_IMAGE=$base_image" \
--build-arg "LEAN_BUILD_JOBS=$build_jobs" \
"$repo_dir"
if [[ "$build_only" == true ]]; then
exit 0
fi
docker_run_args=(
run
--rm
--init
--network none
--memory 8g
--memory-swap 8g
--cpus 4
--pids-limit 2048
--ulimit stack=8388608:8388608
--security-opt no-new-privileges
--env ELAN_TOOLCHAIN=leanprover/lean4:v4.32.2
"$mechanism_image"
)
if ((${#runner_args[@]})); then
docker_run_args+=("${runner_args[@]}")
fi
docker "${docker_run_args[@]}"