Skip to content

Commit

Permalink
Merge pull request #30 from ZKStats/del_sub
Browse files Browse the repository at this point in the history
Migrate submodule
  • Loading branch information
JernKunpittaya authored Apr 25, 2024
2 parents e9ae9ed + d52c53f commit dd6297d
Show file tree
Hide file tree
Showing 53 changed files with 18,760 additions and 33 deletions.
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

27 changes: 16 additions & 11 deletions tests/onnx2circom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,52 @@

## Test onnx2keras

Follow [the instructions](../../zkstats/onnx2circom/README.md) to sync submodules:

Go to the root of the repo and sync the submodules:
```bash
cd ../../
git submodule init
git submodule update
```

Run the test:

```bash
pytest -s tests/onnx2circom/test_onnx_to_keras.py
```

## Test onnx2circom

### circom-2-arithc

Clone circom-2-arithc. Use a fork for now. Will change to the official repo soon.

```bash
cd ..
git clone https://github.com/mhchia/circom-2-arithc.git
cd circom-2-arithc
# Initialize env file
git checkout mpcstats
# Initialize env file
cp .env.example .env
circom_2_arithc_project_root=$(pwd)
```

Build the compiler:

```bash
cargo build --release
```

### MP-SPDZ

Clone the repo

```bash
cd ..
git clone https://github.com/mhchia/MP-SPDZ
cd MP-SPDZ
git checkout arith-extcutor

git remote add kevin_mpc https://github.com/mhchia/MP-SPDZ.git
git fetch kevin_mpc
git checkout arith-executor

mp_spdz_project_root=$(pwd)
```

Build the MPC vm for `semi` protocol

```bash
make -j8 semi-party.x
# Make sure `semi-party.x` exists
Expand All @@ -55,18 +57,21 @@ ls semi-party.x
### Run the test

Modify the configs in `tests/onnx2circom/test_onnx_to_circom.py` to point to the correct paths. Just fill in the paths to the two projects you just cloned.

```bash
# NOTE: Change the path to your own path
CIRCOM_2_ARITHC_PROJECT_ROOT = Path('/path/to/circom-2-arithc-project-root')
MP_SPDZ_PROJECT_ROOT = Path('/path/to/mp-spdz-project-root')
```

Go back to the zkstats library project root

```bash
cd ../zk-stats-lib
```

Run the test:

```bash
pytest -s tests/onnx2circom/test_onnx_to_circom.py
```
24 changes: 10 additions & 14 deletions zkstats/onnx2circom/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
# onnx2circom

## Submodules
- onnx2keras
- keras2circom
- circomlib-ml

## Clone and sync submodules
```bash
git submodule init
```

```bash
git submodule update
```

## Run onnx2circom

```bash
$ python3 main.py model.onnx --circom_path model.circom
```

See circom code in `model.circom`

```bash
$ ls model.circom
model.circom
Expand All @@ -35,3 +24,10 @@ model_path = "model.onnx"
circom_path = "model.circom"
onnx_to_circom(model_path, circom_path)
```

Note that this onnx2circom originally comes from two modified forked repos as follows

- https://github.com/JernKunpittaya/onnx2keras/tree/stats_onnx2keras
- https://github.com/JernKunpittaya/keras2circom/tree/stats_keras2circom

Our implementation for zkstats can make onnx2circom diverge a lot from these fork repos, so we migrate all codes here without using submodules anymore.
1 change: 0 additions & 1 deletion zkstats/onnx2circom/keras2circom
Submodule keras2circom deleted from d92244
199 changes: 199 additions & 0 deletions zkstats/onnx2circom/keras2circom/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

tmp

.DS_Store

output/
X_test/
y_test.json
21 changes: 21 additions & 0 deletions zkstats/onnx2circom/keras2circom/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 drCathieSo.eth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit dd6297d

Please sign in to comment.