Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamATD committed Nov 10, 2021
0 parents commit 604b583
Show file tree
Hide file tree
Showing 31 changed files with 3,755 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

182 changes: 182 additions & 0 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/zkCNN-quant.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions 3rd/hyrax-bls12-381
Submodule hyrax-bls12-381 added at baedf7
12 changes: 12 additions & 0 deletions CMakeLists.txt
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)
83 changes: 83 additions & 0 deletions README.md
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

![formula1](https://render.githubusercontent.com/render/math?math=ch_{in}%20%5Ccdot%20h\times%20w)

where ![formula2](https://render.githubusercontent.com/render/math?math=ch_{in}) is the number of channel, ![formula3](https://render.githubusercontent.com/render/math?math=h) is the height, ![formula4](https://render.githubusercontent.com/render/math?math=w) 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

![formula5](https://render.githubusercontent.com/render/math?math=n_{pic}%20\times%20ch_{in}%20\times%20h%20\times%20w)

where ![formula6](https://render.githubusercontent.com/render/math?math=n_{pic}) is the number of pictures, ![formula7](https://render.githubusercontent.com/render/math?math=ch_{in}) is the number of channel, ![formula8](https://render.githubusercontent.com/render/math?math=h) is the height, ![formula9](https://render.githubusercontent.com/render/math?math=w) is the width.

### Weight Part

This part is for weight in the neural network, which contains

- convolution kernel of size ![formula10](https://render.githubusercontent.com/render/math?math=ch_{out}%20\times%20ch_{in}%20\times%20m%20\times%20m)

where ![formula11](https://render.githubusercontent.com/render/math?math=ch_{out}) and ![formula12](https://render.githubusercontent.com/render/math?math=ch_{in}) are the number of output and input channels, ![formula13](https://render.githubusercontent.com/render/math?math=m) is the sideness of the kernel (here we only support square kernel).

- convolution bias of size ![formula16](https://render.githubusercontent.com/render/math?math=ch_{out})

- fully-connected kernel of size ![formula14](https://render.githubusercontent.com/render/math?math=ch_{in}\times%20ch_{out})


- fully-connected bias of size ![formula15](https://render.githubusercontent.com/render/math?math=ch_{out})


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

Binary file added data.tar.gz
Binary file not shown.
12 changes: 12 additions & 0 deletions script/build.sh
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
19 changes: 19 additions & 0 deletions script/demo.sh
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}
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
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)
Loading

0 comments on commit 604b583

Please sign in to comment.