Skip to content

Repository files navigation

LightShark

Our implementation is based on a forked version of shark.


Project Origin & License

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.

Our Implementation

LightShark is a lightweight framework that fully utilizes DPF for actively secure machine-learning inference.

Tested Environments

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

Building

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.

1. Install system packages

On Ubuntu 22.04:

sudo apt-get update
sudo apt-get install -y build-essential cmake git libboost-system-dev libeigen3-dev libssl-dev

2. Configure dependencies and build LightShark

Run 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 -j

After 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 -j

Benchmarking

The benchmark script can run selected protocol or inference benchmarks. Build the project first, then run the script from the project root.

Local Setup

In case you want to run all parties of LightShark on a single machine, use:

bash script/run-benchmarks-light.sh protocols rsqrt

Available protocol benchmarks:

drelu relu gap_trunc trunc sigmoid sqrt rsqrt tanh

Available inference benchmarks:

CNN alexnet vgg16 bert

Benchmark Mapping to the Paper

The protocol benchmarks correspond to the protocol components evaluated in the paper:

  • drelu evaluates the DReLU protocol in Figure 6.
  • relu evaluates the ReLU protocol in Figure 11.
  • gap_trunc evaluates the gap truncation protocol in Figure 12.
  • trunc evaluates the truncation protocol described in Section A.4.2.
  • rsqrt evaluates the reciprocal-square-root protocol in Figure 16.
  • sigmoid, sqrt, and tanh are 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 bert

Output 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.

Network Emulation

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_off

To emulate a WAN environment, use tc_wan instead:

source network.sh
tc_wan
bash script/run-benchmarks-light.sh inference CNN bert
tc_off

The 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.

Modifying Code or Adding Benchmarks

If you modify the source code, recompile the project from the project root:

cmake --build build/ --config Release --target all -j

If you want to add a new benchmark:

  1. Add the new benchmark source file to benchmark_protocols/ or benchmark_inference/.
  2. Register it in the corresponding CMakeLists.txt with add_test_case_with_run(...).
  3. 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"
  1. Recompile the project:
cmake --build build/ --config Release --target all -j

NOTE: 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.

Experimental Setup in the Paper

Ubuntu PC equipped with an Intel(R) Xeon(R) Silver 4210 and 128GB of RAM.

Getting Started with Docker (Recommended !!)

1. Build the Docker Image (only once)

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.tar

2. Run the program on docker

Enter 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"

About

LightShark is a lightweight framework that fully utilizes DPF for actively secure inference of machine learning models .

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages