-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "3rd/hyrax-bls12-381"] | ||
path = 3rd/hyrax-bls12-381 | ||
url = [email protected]:TAMUCrypto/hyrax-bls12-381.git |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(zkCNN) | ||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
link_directories(3rd/hyrax-bls12-381) | ||
|
||
include_directories(src) | ||
include_directories(3rd) | ||
include_directories(3rd/hyrax-bls12-381/3rd/mcl/include) | ||
|
||
add_subdirectory(src) | ||
add_subdirectory(3rd/hyrax-bls12-381) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# zkCNN | ||
|
||
## Introduction | ||
|
||
This is a GKR-based zero-knowledge proof for CNN reference, containing some widely used network such as LeNet5, vgg11 and vgg16. | ||
|
||
|
||
|
||
## Requirement | ||
|
||
- C++14 | ||
- cmake >= 3.10 | ||
- GMP library | ||
|
||
|
||
|
||
## Input Format | ||
|
||
The input has two part which are data and weight in the matrix. | ||
|
||
### Data Part | ||
|
||
There are two cases supported in this repo. | ||
|
||
- **Single picture** | ||
|
||
Then the picture is a vector reshaped from its original matrix by | ||
|
||
 | ||
|
||
where  is the number of channel,  is the height,  is the width. | ||
|
||
|
||
|
||
- **Multiply picture** | ||
|
||
This solve the case when the user wants to infer multiple pictures by the same network. Then the picture is a vector reshaped from its original matrix by | ||
|
||
 | ||
|
||
where  is the number of pictures,  is the number of channel,  is the height,  is the width. | ||
|
||
### Weight Part | ||
|
||
This part is for weight in the neural network, which contains | ||
|
||
- convolution kernel of size  | ||
|
||
where  and  are the number of output and input channels,  is the sideness of the kernel (here we only support square kernel). | ||
|
||
- convolution bias of size  | ||
|
||
- fully-connected kernel of size  | ||
|
||
|
||
- fully-connected bias of size  | ||
|
||
|
||
All the input above are scanned one by one. | ||
|
||
## Experiment Script | ||
### Clone the repo | ||
To run the code, make sure you clone with | ||
``` bash | ||
git clone [email protected]:TAMUCrypto/zkCNN.git | ||
git submodule update --init --recursive | ||
``` | ||
since the polynomial commitment is included as a submodule. | ||
|
||
### Run a demo of vgg11 | ||
The script to run vgg11 model (please run the script in ``script/`` directory). | ||
``` bash | ||
./demo.sh | ||
``` | ||
|
||
- The input data is in ``data/vgg11/``. | ||
- The experiment evaluation is ``output/single/demo-result.txt``. | ||
- The inference result is ``output/single/vgg11.cifar.relu-1-infer.csv``. | ||
|
||
## Polynomial Commitment | ||
|
||
Here we implement a hyrax polynomial commitment based on BLS12-381 elliptic curve. It is a submodule and someone who is interested can refer to this repo [hyrax-bls12-381](https://github.com/TAMUCrypto/hyrax-bls12-381). | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
cd .. | ||
mkdir -p cmake-build-release | ||
cd cmake-build-release | ||
/usr/bin/cmake -DCMAKE_BUILD_TYPE=Release -G "CodeBlocks - Unix Makefiles" .. | ||
cd .. | ||
|
||
if [ ! -d "./data" ] | ||
then | ||
tar -xzvf data.tar.gz | ||
fi | ||
cd script |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
./build.sh | ||
/usr/bin/cmake --build ../cmake-build-release --target demo_run -- -j 6 | ||
|
||
run_file=../cmake-build-release/src/demo_run | ||
out_file=../output/single/demo-result.txt | ||
|
||
mkdir -p ../output/single | ||
mkdir -p ../log/single | ||
|
||
vgg11_i=../data/vgg11/vgg11.cifar.relu-1-images-weights-qint8.csv | ||
vgg11_c=../data/vgg11/vgg11.cifar.relu-1-scale-zeropoint-uint8.csv | ||
vgg11_o=../output/single/vgg11.cifar.relu-1-infer.csv | ||
vgg11_n=../data/vgg11/vgg11-config.csv | ||
|
||
${run_file} ${vgg11_i} ${vgg11_c} ${vgg11_o} ${vgg11_n} 1 > ${out_file} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
aux_source_directory(. conv_src) | ||
list(FILTER conv_src EXCLUDE REGEX "main*") | ||
|
||
add_library(cnn_lib ${conv_src}) | ||
|
||
add_executable(demo_run main_demo.cpp) | ||
target_link_libraries(demo_run cnn_lib hyrax_lib mcl mclbn384_256) |