Our implementation is based on a forked version of
shark.
This repository inherits the MIT license from the upstream project.
- Upstream repo:
shark - Upstream license: see
LICENSE - All new files (
src/protocols/light_*,include/shark/protocols/light_*,benchmarks_inference/light_*,benchmarks_protocols/light_*,include/shark/crypto/lightdcf.hpp,src/crypto/lightdcf.cpp) remain under MIT unless a different license header is explicitly stated.
LightShark is a lightweight framework that fully utilizes DPF for actively secure machine-learning inference.
LightShark has been tested on the following environments:
- Ubuntu 22.04 on x86/x86_64
- Ubuntu 22.04 on ARM/aarch64
- macOS 15.3.1 with Docker v27.4.0
Note: All commands should be executed from the project root directory.
LightShark requires CMake (>= 3.16), a C++ compiler with C++20 support, OpenSSL, Boost.System, Eigen3, and emp-tool.
On Ubuntu 22.04:
sudo apt-get update
sudo apt-get install -y build-essential cmake git libboost-system-dev libeigen3-dev libssl-devRun the following commands from the project root. Eigen is provided by libeigen3-dev; emp-tool is built from the bundled source and installed to $HOME/.local.
# Install emp-tool.
cmake -S ext/emp-tool -B build-emp-tool -DCMAKE_BUILD_TYPE=Release
cmake --build build-emp-tool -j
cmake --install build-emp-tool --prefix "$HOME/.local"
# Configure LightShark.
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="$HOME/.local" \
-S . -B build/
# Compile LightShark.
cmake --build build/ --config Release --target all -jAfter installation, the emp-tool path used by CMake is:
CMAKE_PREFIX_PATH=$HOME/.local
If CMake reports that Eigen or emp-tool cannot be found, clean the build directory and rerun the configure/build commands:
cmake -E rm -rf build/
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="$HOME/.local" \
-S . -B build/
cmake --build build/ --config Release --target all -jThe benchmark script can run selected protocol or inference benchmarks. Build the project first, then run the script from the project root.
In case you want to run all parties of LightShark on a single machine, use:
bash script/run-benchmarks-light.sh protocols rsqrtAvailable protocol benchmarks:
drelu relu gap_trunc trunc sigmoid sqrt rsqrt tanh
Available inference benchmarks:
CNN alexnet vgg16 bert
The protocol benchmarks correspond to the protocol components evaluated in the paper:
dreluevaluates the DReLU protocol in Figure 6.reluevaluates the ReLU protocol in Figure 11.gap_truncevaluates the gap truncation protocol in Figure 12.truncevaluates the truncation protocol described in Section A.4.2.rsqrtevaluates the reciprocal-square-root protocol in Figure 16.sigmoid,sqrt, andtanhare instantiations of the spline protocol in Figure 8. Their concrete parameters are described in Section 5.2.
The inference benchmarks (CNN, alexnet, vgg16, and bert) correspond to the neural network inference experiments in Section 5.3.
Examples:
# List all available benchmarks.
bash script/run-benchmarks-light.sh --list
# Run all protocol benchmarks.
bash script/run-benchmarks-light.sh protocols all
# Run selected protocol benchmarks.
bash script/run-benchmarks-light.sh protocols rsqrt trunc
# Run selected inference benchmarks.
bash script/run-benchmarks-light.sh inference CNN bertOutput Examples:
root@68e26b12e6ea:~/home/LightShark# bash script/run-benchmarks-light.sh protocol drelu
Starting benchmark 'drelu' from benchmark_protocols
Starting Party 2 Dealer...
Starting Party 0 and Party 1...
Benchmarking drelu
=======================
Party 0
=======================
waiting for connection from client...connected
key_read: 5 ms, 0 KB
key_read-input: 1 ms, 0 KB
light_drelu: 80 ms, 1172.22 KB
reconstruct: 9 ms, 390.625 KB
Party 1
=======================
trying to connect with server...connected
key_read: 6 ms, 0 KB
light_drelu: 88 ms, 1172.22 KB
reconstruct: 4 ms, 390.625 KB
LightShark uses a trusted dealer architecture: Party 2 acts as the trusted dealer and runs the preprocessing phase, while Party 0 and Party 1 run the online phase. Therefore, the reported entries under Party 0 and Party 1 correspond to online execution measurements. In the example above, light_drelu reports the online execution time and communication cost of the DReLU protocol (Figure 6 in our paper), and reconstruct reports the time and communication cost required for secret reconstruction in the online phase.
For experiments under different network conditions, you can use Linux tc to emulate LAN and WAN environments on the loopback interface. LightShark provides helper functions in network.sh:
# Load tc helper functions.
source network.sh
# Emulate a LAN environment: 1 Gbit bandwidth with low latency.
tc_lan
# Run the desired benchmarks.
bash script/run-benchmarks-light.sh protocols rsqrt
# Clear the tc configuration after finishing the experiment.
tc_offTo emulate a WAN environment, use tc_wan instead:
source network.sh
tc_wan
bash script/run-benchmarks-light.sh inference CNN bert
tc_offThe current helper settings are:
LAN: 1 Gbit bandwidth, 0.25 ms average delay
WAN: 100 Mbit bandwidth, 20 ms average delay
These commands require sudo because tc modifies the system network configuration. Always run tc_off after each experiment to restore the default loopback settings.
If you modify the source code, recompile the project from the project root:
cmake --build build/ --config Release --target all -jIf you want to add a new benchmark:
- Add the new benchmark source file to
benchmark_protocols/orbenchmark_inference/. - Register it in the corresponding
CMakeLists.txtwithadd_test_case_with_run(...). - Add the benchmark name to the corresponding list near the top of
script/run-benchmarks-light.sh:
protocol_benchmarks="drelu relu gap_trunc trunc sigmoid sqrt rsqrt tanh"
inference_benchmarks="CNN alexnet vgg16 bert"- Recompile the project:
cmake --build build/ --config Release --target all -jNOTE: The script runs each party with 16 OpenMP threads by default. Depending on the performance of different devices, the time required for the Dealer to generate preprocessing material may vary significantly and can be quite long.
Ubuntu PC equipped with an Intel(R) Xeon(R) Silver 4210 and 128GB of RAM.
Make sure the following are installed:
- Docker (v20.10+ recommended)
Build the image:(Optional)
docker build -f Dockerfile -t lightshark-image .Load the image:
docker load -i lightshark-image.tarEnter the image:
docker run --cap-add=NET_ADMIN --rm -it lightshark-image You can also mount your code directory if you want to persist changes:
docker run --cap-add=NET_ADMIN --rm -it -v ./:/root/home/LightShark lightshark-image /bin/bash -c "cd /root/home/LightShark && bash"