file_path
stringlengths
7
180
content
stringlengths
0
811k
repo
stringclasses
11 values
src/pfsys/evm/aggregation_kzg.rs
#[cfg(not(target_arch = "wasm32"))] use crate::graph::CircuitSize; use crate::pfsys::{Snark, SnarkWitness}; #[cfg(not(target_arch = "wasm32"))] use colored_json::ToColoredJson; use halo2_proofs::circuit::AssignedCell; use halo2_proofs::plonk::{self}; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner, Value...
https://github.com/zkonduit/ezkl
src/pfsys/evm/mod.rs
use thiserror::Error; /// Aggregate proof generation for EVM using KZG pub mod aggregation_kzg; #[derive(Error, Debug)] /// Errors related to evm verification pub enum EvmVerificationError { /// If the Solidity verifier worked but returned false #[error("Solidity verifier found the proof invalid")] Invali...
https://github.com/zkonduit/ezkl
src/pfsys/mod.rs
/// EVM related proving and verification pub mod evm; /// SRS generation, processing, verification and downloading pub mod srs; use crate::circuit::CheckMode; use crate::graph::GraphWitness; use crate::pfsys::evm::aggregation_kzg::PoseidonTranscript; use crate::{Commitments, EZKL_BUF_CAPACITY, EZKL_KEY_FORMAT}; use c...
https://github.com/zkonduit/ezkl
src/pfsys/srs.rs
use halo2_proofs::poly::commitment::CommitmentScheme; use halo2_proofs::poly::commitment::Params; use halo2_proofs::poly::commitment::ParamsProver; use log::info; use std::error::Error; use std::fs::File; use std::io::BufReader; use std::path::PathBuf; /// for now we use the urls of the powers of tau ceremony from <ht...
https://github.com/zkonduit/ezkl
src/python.rs
use crate::circuit::modules::polycommit::PolyCommitChip; use crate::circuit::modules::poseidon::{ spec::{PoseidonSpec, POSEIDON_RATE, POSEIDON_WIDTH}, PoseidonChip, }; use crate::circuit::modules::Module; use crate::circuit::{CheckMode, Tolerance}; use crate::commands::*; use crate::fieldutils::{felt_to_i128, i...
https://github.com/zkonduit/ezkl
src/srs_sha.rs
use lazy_static::lazy_static; use std::collections::HashMap; lazy_static! { /// SRS SHA256 hashes pub static ref PUBLIC_SRS_SHA256_HASHES: HashMap<u32, &'static str> = HashMap::from_iter([ ( 1, "cafb2aa72c200ddc4e28aacabb8066e829207e2484b8d17059a566232f8a297b", ), ...
https://github.com/zkonduit/ezkl
src/tensor/mod.rs
/// Implementations of common operations on tensors. pub mod ops; /// A wrapper around a tensor of circuit variables / advices. pub mod val; /// A wrapper around a tensor of Halo2 Value types. pub mod var; use halo2curves::ff::PrimeField; use maybe_rayon::{ prelude::{ IndexedParallelIterator, IntoParallelR...
https://github.com/zkonduit/ezkl
src/tensor/ops.rs
use super::TensorError; use crate::tensor::{Tensor, TensorType}; use itertools::Itertools; use maybe_rayon::{iter::ParallelIterator, prelude::IntoParallelRefIterator}; pub use std::ops::{Add, Mul, Neg, Sub}; /// Trilu operation. /// # Arguments /// * `a` - Tensor /// * `k` - i32 /// * `upper` - Boolean /// # Examples ...
https://github.com/zkonduit/ezkl
src/tensor/val.rs
use core::{iter::FilterMap, slice::Iter}; use crate::circuit::region::ConstantsMap; use super::{ ops::{intercalate_values, pad, resize}, *, }; use halo2_proofs::{arithmetic::Field, circuit::Cell, plonk::Instance}; pub(crate) fn create_constant_tensor< F: PrimeField + TensorType + std::marker::Send + std:...
https://github.com/zkonduit/ezkl
src/tensor/var.rs
use std::collections::HashSet; use log::{debug, error, warn}; use crate::circuit::{region::ConstantsMap, CheckMode}; use super::*; /// A wrapper around Halo2's `Column<Fixed>` or `Column<Advice>`. /// Typically assign [ValTensor]s to [VarTensor]s when laying out a circuit. #[derive(Clone, Default, Debug, PartialEq, ...
https://github.com/zkonduit/ezkl
src/wasm.rs
use crate::circuit::modules::polycommit::PolyCommitChip; use crate::circuit::modules::poseidon::spec::{PoseidonSpec, POSEIDON_RATE, POSEIDON_WIDTH}; use crate::circuit::modules::poseidon::PoseidonChip; use crate::circuit::modules::Module; use crate::fieldutils::felt_to_i128; use crate::fieldutils::i128_to_felt; use cra...
https://github.com/zkonduit/ezkl
tests/integration_tests.rs
#[cfg(not(target_arch = "wasm32"))] #[cfg(test)] mod native_tests { use ezkl::circuit::Tolerance; use ezkl::fieldutils::{felt_to_i128, i128_to_felt}; // use ezkl::circuit::table::RESERVED_BLINDING_ROWS_PAD; use ezkl::graph::input::{FileSource, FileSourceInner, GraphData}; use ezkl::graph::{DataSour...
https://github.com/zkonduit/ezkl
tests/output_comparison.py
import ezkl import json import onnx import onnxruntime import numpy as np import sys def get_ezkl_output(witness_file, settings_file): # convert the quantized ezkl output to float value witness_output = json.load(open(witness_file)) outputs = witness_output['outputs'] with open(settings_file) as f: ...
https://github.com/zkonduit/ezkl
tests/py_integration_tests.rs
#[cfg(not(target_arch = "wasm32"))] #[cfg(test)] mod py_tests { use lazy_static::lazy_static; use std::env::var; use std::process::{Child, Command}; use std::sync::Once; use tempdir::TempDir; static COMPILE: Once = Once::new(); static ENV_SETUP: Once = Once::new(); static DOWNLOAD_VOICE...
https://github.com/zkonduit/ezkl
tests/python/binding_tests.py
import ezkl import os import pytest import json import subprocess import time folder_path = os.path.abspath( os.path.join( os.path.dirname(__file__), '.', ) ) examples_path = os.path.abspath( os.path.join( folder_path, '..', '..', 'examples', ) ) srs_pa...
https://github.com/zkonduit/ezkl
tests/python/srs_utils.py
""" This is meant to be used locally for development. Generating the SRS is costly so we run this instead of creating a new SRS each time we run tests. """ import ezkl import os srs_path = os.path.abspath( os.path.join( os.path.dirname(__file__), '.', 'kzg_test.params', ) ) def gen_t...
https://github.com/zkonduit/ezkl
tests/wasm.rs
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] #[cfg(test)] mod wasm32 { use ezkl::circuit::modules::polycommit::PolyCommitChip; use ezkl::circuit::modules::poseidon::spec::{PoseidonSpec, POSEIDON_RATE, POSEIDON_WIDTH}; use ezkl::circuit::modules::poseidon::PoseidonChip; use ezkl::circuit::m...
https://github.com/zkonduit/ezkl
keras2circom/circom.py
# Ref: https://github.com/zk-ml/uchikoma/blob/main/python/uchikoma/circom.py from __future__ import annotations import typing import os from os import path import json from dataclasses import dataclass import re import numpy as np class SafeDict(dict): def __missing__(self, key): return '{' + key + '}' ...
https://github.com/socathie/keras2circom
keras2circom/model.py
# Read keras model into list of parameters like op, input, output, weight, bias from __future__ import annotations from dataclasses import dataclass import typing from tensorflow.keras.models import load_model from tensorflow.keras.layers import Layer as KerasLayer import numpy as np supported_ops = [ 'Activation'...
https://github.com/socathie/keras2circom
keras2circom/script.py
from .circom import Circuit, Component # template string for circuit.py python_template_string = '''""" Make an interger-only circuit of the corresponding CIRCOM circuit. Usage: circuit.py <circuit.json> <input.json> [-o <output>] circuit.py (-h | --help) Options: -h --help ...
https://github.com/socathie/keras2circom
keras2circom/transpiler.py
from .circom import * from .model import * from .script import * import os def transpile(filename: str, output_dir: str = 'output', raw: bool = False, dec: int = 18) -> Circuit: ''' Transpile a Keras model to a CIRCOM circuit.''' model = Model(filename, raw) circuit = Circuit() for layer in mode...
https://github.com/socathie/keras2circom
keras2circom/util.py
# assume all inputs are strings def AveragePooling2DInt (nRows, nCols, nChannels, poolSize, strides, input): out = [[[0 for _ in range(nChannels)] for _ in range((nCols-poolSize)//strides + 1)] for _ in range((nRows-poolSize)//strides + 1)] remainder = [[[None for _ in range(nChannels)] for _ in range((nCols-po...
https://github.com/socathie/keras2circom
main.py
""" Transpile a Keras model to a CIRCOM circuit. Usage: main.py <model.h5> [-o <output>] [--raw] [-d <decimals>] main.py (-h | --help) Options: -h --help Show this screen. -o <output> --output=<output> Output directory [default: output]. --raw ...
https://github.com/socathie/keras2circom
models/model.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# list of supported layers\n", "from tensorflow.keras.layers import (\n", " Input,\n", " Activation,\n", " AveragePooling2D,\n", " BatchNormalization,\n", " ...
https://github.com/socathie/keras2circom
test/accuracy.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!cd .. && python main.py models/model.h5" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import sys\n", "import os\n...
https://github.com/socathie/keras2circom
test/circuit.js
const chai = require('chai'); const fs = require('fs'); const wasm_tester = require('circom_tester').wasm; const F1Field = require('ffjavascript').F1Field; const Scalar = require('ffjavascript').Scalar; exports.p = Scalar.fromString('21888242871839275222246405745257275088548364400416034343698204186575808495617'); con...
https://github.com/socathie/keras2circom
test/load_input.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tensorflow.keras.datasets import mnist\n", "import json\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], ...
https://github.com/socathie/keras2circom
circuits/ArgMax.circom
// from 0xZKML/zk-mnist pragma circom 2.0.0; include "./circomlib/comparators.circom"; include "./circomlib/switcher.circom"; template ArgMax (n) { signal input in[n]; signal input out; assert (out < n); component gts[n]; // store comparators component switchers[n+1]; // switcher for com...
https://github.com/socathie/circomlib-ml
circuits/AveragePooling2D.circom
pragma circom 2.0.0; include "./SumPooling2D.circom"; // AveragePooling2D layer, poolSize is required to be equal for both dimensions, might lose precision compared to SumPooling2D template AveragePooling2D (nRows, nCols, nChannels, poolSize, strides) { signal input in[nRows][nCols][nChannels]; signal input o...
https://github.com/socathie/circomlib-ml
circuits/BatchNormalization2D.circom
pragma circom 2.0.0; // BatchNormalization layer for 2D inputs // a = gamma/(moving_var+epsilon)**.5 // b = beta-gamma*moving_mean/(moving_var+epsilon)**.5 // n = 10 to the power of the number of decimal places template BatchNormalization2D(nRows, nCols, nChannels, n) { signal input in[nRows][nCols][nChannels]; ...
https://github.com/socathie/circomlib-ml
circuits/Conv1D.circom
pragma circom 2.0.0; include "./circomlib-matrix/matElemMul.circom"; include "./circomlib-matrix/matElemSum.circom"; include "./util.circom"; // Conv1D layer with valid padding // n = 10 to the power of the number of decimal places template Conv1D (nInputs, nChannels, nFilters, kernelSize, strides, n) { signal in...
https://github.com/socathie/circomlib-ml
circuits/Conv2D.circom
pragma circom 2.0.0; include "./circomlib-matrix/matElemMul.circom"; include "./circomlib-matrix/matElemSum.circom"; include "./util.circom"; // Conv2D layer with valid padding // n = 10 to the power of the number of decimal places template Conv2D (nRows, nCols, nChannels, nFilters, kernelSize, strides, n) { sign...
https://github.com/socathie/circomlib-ml
circuits/Conv2Dsame.circom
pragma circom 2.0.0; include "./Conv2D.circom"; template Conv2Dsame (nRows, nCols, nChannels, nFilters, kernelSize, strides, n) { signal input in[nRows][nCols][nChannels]; signal input weights[kernelSize][kernelSize][nChannels][nFilters]; signal input bias[nFilters]; var rowPadding, colPadding; ...
https://github.com/socathie/circomlib-ml
circuits/Dense.circom
pragma circom 2.0.0; include "./circomlib-matrix/matMul.circom"; // Dense layer // n = 10 to the power of the number of decimal places template Dense (nInputs, nOutputs, n) { signal input in[nInputs]; signal input weights[nInputs][nOutputs]; signal input bias[nOutputs]; signal input out[nOutputs]; ...
https://github.com/socathie/circomlib-ml
circuits/DepthwiseConv2D.circom
pragma circom 2.1.1; // include "./Conv2D.circom"; include "./circomlib/sign.circom"; include "./circomlib/bitify.circom"; include "./circomlib/comparators.circom"; include "./circomlib-matrix/matElemMul.circom"; include "./circomlib-matrix/matElemSum.circom"; include "./util.circom"; // Depthwise Convolution layer w...
https://github.com/socathie/circomlib-ml
circuits/Flatten2D.circom
pragma circom 2.0.0; // Flatten layer with that accepts a 2D input template Flatten2D (nRows, nCols, nChannels) { signal input in[nRows][nCols][nChannels]; signal input out[nRows*nCols*nChannels]; var idx = 0; for (var i=0; i<nRows; i++) { for (var j=0; j<nCols; j++) { for (var k=...
https://github.com/socathie/circomlib-ml
circuits/GlobalAveragePooling2D.circom
pragma circom 2.0.0; include "./GlobalSumPooling2D.circom"; // GlobalAveragePooling2D layer, might lose precision compared to GlobalSumPooling2D template GlobalAveragePooling2D (nRows, nCols, nChannels) { signal input in[nRows][nCols][nChannels]; signal input out[nChannels]; signal input remainder[nChanne...
https://github.com/socathie/circomlib-ml
circuits/GlobalMaxPooling2D.circom
pragma circom 2.0.0; include "./util.circom"; // GlobalMaxPooling2D layer template GlobalMaxPooling2D (nRows, nCols, nChannels) { signal input in[nRows][nCols][nChannels]; signal input out[nChannels]; component max[nChannels]; for (var k=0; k<nChannels; k++) { max[k] = Max(nRows*nCols); ...
https://github.com/socathie/circomlib-ml
circuits/GlobalSumPooling2D.circom
pragma circom 2.0.0; include "./circomlib-matrix/matElemSum.circom"; include "./util.circom"; // GlobalSumPooling2D layer, basically GlobalAveragePooling2D layer with a constant scaling, more optimized for circom template GlobalSumPooling2D (nRows, nCols, nChannels) { signal input in[nRows][nCols][nChannels]; ...
https://github.com/socathie/circomlib-ml
circuits/LeakyReLU.circom
pragma circom 2.0.0; include "./util.circom"; // LeakyReLU layer template LeakyReLU (alpha) { // alpha is 10 times the actual alpha, since usual alpha is 0.2, 0.3, etc. signal input in; signal input out; signal input remainder; component isNegative = IsNegative(); isNegative.in <== in; sign...
https://github.com/socathie/circomlib-ml
circuits/MaxPooling2D.circom
pragma circom 2.0.0; include "./util.circom"; // MaxPooling2D layer template MaxPooling2D (nRows, nCols, nChannels, poolSize, strides) { signal input in[nRows][nCols][nChannels]; signal input out[(nRows-poolSize)\strides+1][(nCols-poolSize)\strides+1][nChannels]; component max[(nRows-poolSize)\strides+1]...
https://github.com/socathie/circomlib-ml
circuits/MaxPooling2Dsame.circom
pragma circom 2.0.0; include "./MaxPooling2D.circom"; template MaxPooling2Dsame (nRows, nCols, nChannels, poolSize, strides) { signal input in[nRows][nCols][nChannels]; var rowPadding, colPadding; if (nRows % strides == 0) { rowPadding = (poolSize - strides) > 0 ? (poolSize - strides) : 0; ...
https://github.com/socathie/circomlib-ml
circuits/PointwiseConv2D.circom
pragma circom 2.1.1; // include "./Conv2D.circom"; include "./circomlib/sign.circom"; include "./circomlib/bitify.circom"; include "./circomlib/comparators.circom"; include "./circomlib-matrix/matElemMul.circom"; include "./circomlib-matrix/matElemSum.circom"; include "./util.circom"; // Pointwise Convolution layer /...
https://github.com/socathie/circomlib-ml
circuits/ReLU.circom
pragma circom 2.0.0; include "./util.circom"; // ReLU layer template ReLU () { signal input in; signal input out; component isPositive = IsPositive(); isPositive.in <== in; out === in * isPositive.out; }
https://github.com/socathie/circomlib-ml
circuits/Reshape2D.circom
pragma circom 2.0.0; // Reshape layer with that accepts a 1D input template Reshape2D (nRows, nCols, nChannels) { signal input in[nRows*nCols*nChannels]; signal input out[nRows][nCols][nChannels]; for (var i=0; i<nRows; i++) { for (var j=0; j<nCols; j++) { for (var k=0; k<nChannels; k+...
https://github.com/socathie/circomlib-ml
circuits/SeparableConv2D.circom
pragma circom 2.1.1; include "./PointwiseConv2D.circom"; include "./DepthwiseConv2D.circom"; // Separable convolution layer with valid padding. // Quantization is done by the caller by multiplying float values by 10**exp. template SeparableConv2D (nRows, nCols, nChannels, nDepthFilters, nPointFilters, depthKernelSize...
https://github.com/socathie/circomlib-ml
circuits/SumPooling2D.circom
pragma circom 2.0.0; include "./circomlib-matrix/matElemSum.circom"; include "./util.circom"; // SumPooling2D layer, basically AveragePooling2D layer with a constant scaling, more optimized for circom template SumPooling2D (nRows, nCols, nChannels, poolSize, strides) { signal input in[nRows][nCols][nChannels]; ...
https://github.com/socathie/circomlib-ml
circuits/UpSampling2D.circom
pragma circom 2.0.0; template UpSampling2D(nRows, nCols, nChannels, size) { signal input in[nRows][nCols][nChannels]; signal input out[nRows * size][nCols * size][nChannels]; // nearest neighbor interpolation for (var i = 0; i < nRows; i++) { for (var j = 0; j < nCols; j++) { for (...
https://github.com/socathie/circomlib-ml
circuits/Zanh.circom
pragma circom 2.0.0; // Polynomial approximation for the tanh layer // 0.006769816 + 0.554670504 * x - 0.009411195 * x**2 - 0.014187547 * x**3 // 6769816 + 554670504 * x - 9411195 * x**2 - 14187547 * x**3 // 6769816 + x * (554670504 - 9411195 * x - 14187547 * x**2) // n = 10 to the power of the number of decimal place...
https://github.com/socathie/circomlib-ml
circuits/ZeLU.circom
pragma circom 2.0.0; // Poly activation layer: https://arxiv.org/abs/2011.05530 // n = 10 to the power of the number of decimal places // out and remainder are from division by n so out has the same number of decimal places as in template ZeLU (n) { signal input in; signal input out; signal input remainder...
https://github.com/socathie/circomlib-ml
circuits/Zigmoid.circom
pragma circom 2.0.0; // Polynomial approximation for the sigmoid layer // 0.502073021 + 0.198695283 * x - 0.001570683 * x**2 - 0.004001354 * x**3 // 502073021 + 198695283 * x - 1570683 * x**2 - 4001354 * x**3 // 502073021 + x * (198695283 - 1570683 * x - 4001354 * x**2) // n = 10 to the power of the number of decimal ...
https://github.com/socathie/circomlib-ml
circuits/circomlib-matrix/matElemMul.circom
pragma circom 2.0.0; // matrix multiplication by element template matElemMul (m,n) { signal input a[m][n]; signal input b[m][n]; signal output out[m][n]; for (var i=0; i < m; i++) { for (var j=0; j < n; j++) { out[i][j] <== a[i][j] * b[i][j]; } } }
https://github.com/socathie/circomlib-ml
circuits/circomlib-matrix/matElemSum.circom
pragma circom 2.0.0; // sum of all elements in a matrix template matElemSum (m,n) { signal input a[m][n]; signal output out; signal sum[m*n]; sum[0] <== a[0][0]; var idx = 0; for (var i=0; i < m; i++) { for (var j=0; j < n; j++) { if (idx > 0) { sum[idx...
https://github.com/socathie/circomlib-ml
circuits/circomlib-matrix/matMul.circom
pragma circom 2.0.0; include "matElemMul.circom"; include "matElemSum.circom"; // matrix multiplication template matMul (m,n,p) { signal input a[m][n]; signal input b[n][p]; signal output out[m][p]; component matElemMulComp[m][p]; component matElemSumComp[m][p]; for (var i=0; i < m; i++)...
https://github.com/socathie/circomlib-ml
circuits/circomlib/aliascheck.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/babyjub.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/binsum.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/bitify.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/comparators.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/compconstant.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/escalarmulany.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/escalarmulfix.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/mimc.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/montgomery.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/mux3.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/sign.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/circomlib/switcher.circom
/* Copyright 2018 0KIMS association. This file is part of circom (Zero Knowledge Circuit Compiler). circom is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, o...
https://github.com/socathie/circomlib-ml
circuits/crypto/ecdh.circom
// from privacy-scaling-explorations/maci pragma circom 2.0.0; include "../circomlib/bitify.circom"; include "../circomlib/escalarmulany.circom"; template Ecdh() { // Note: private key // Needs to be hashed, and then pruned before // supplying it to the circuit signal input private_key; signal input public...
https://github.com/socathie/circomlib-ml
circuits/crypto/encrypt.circom
//from zk-ml/linear-regression-demo pragma circom 2.0.0; include "../circomlib/mimc.circom"; template EncryptBits(N) { signal input plaintext[N]; signal input shared_key; signal output out[N+1]; component mimc = MultiMiMC7(N, 91); for (var i=0; i<N; i++) { mimc.in[i] <== plaintext[i]; } mimc.k <==...
https://github.com/socathie/circomlib-ml
circuits/crypto/publickey_derivation.circom
// from privacy-scaling-explorations/maci pragma circom 2.0.0; include "../circomlib/bitify.circom"; include "../circomlib/escalarmulfix.circom"; template PublicKey() { // Note: private key // Needs to be hashed, and then pruned before // supplying it to the circuit signal input private_key; signal output ...
https://github.com/socathie/circomlib-ml
circuits/util.circom
pragma circom 2.0.0; include "./circomlib/sign.circom"; include "./circomlib/bitify.circom"; include "./circomlib/comparators.circom"; include "./circomlib/switcher.circom"; template IsNegative() { signal input in; signal output out; component num2Bits = Num2Bits(254); num2Bits.in <== in; compone...
https://github.com/socathie/circomlib-ml
index.js
https://github.com/socathie/circomlib-ml
models/averagePooling2d.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/batchNormalization.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/conv1d.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/conv2d.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/conv2d_same.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tensorflow.keras.layers import Input, Conv2D\n", "from tensorflow.keras import Model\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metada...
https://github.com/socathie/circomlib-ml
models/dense.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/depthwiseConv2D.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4d60427f-21e9-41b1-a5eb-0d36d2c395ea", "metadata": {}, "outputs": [], "source": [ "import torch\n", "import torch.nn as nn\n", "import torch.nn.functional as F\n", "import numpy as np\n", "import json" ] }, ...
https://github.com/socathie/circomlib-ml
models/flatten.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tensorflow.keras.layers import Input, Flatten\n", "from tensorflow.keras import Model\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metad...
https://github.com/socathie/circomlib-ml
models/globalAveragePooling2D.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/globalMaxPooling2D.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/lr_zanh.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# example from https://towardsdatascience.com/replicate-a-logistic-regression-model-as-an-artificial-neural-network-in-keras-cd6f49cf4b2c" ] }, { "cell_type": "code", "execution_count...
https://github.com/socathie/circomlib-ml
models/lr_zigmoid.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# example from https://towardsdatascience.com/replicate-a-logistic-regression-model-as-an-artificial-neural-network-in-keras-cd6f49cf4b2c" ] }, { "cell_type": "code", "execution_count...
https://github.com/socathie/circomlib-ml
models/maxPooling2d.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/maxPooling2d_same.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tensorflow.keras.layers import Input, MaxPooling2D\n", "from tensorflow.keras import Model\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "...
https://github.com/socathie/circomlib-ml
models/mnist.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/model1.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "p = 21888242871839275222246405745257275088548364400416034343698204186575808495617" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ...
https://github.com/socathie/circomlib-ml
models/pointwiseConv2D.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "2b70084b-44da-4142-9e24-c9c8231828db", "metadata": {}, "outputs": [], "source": [ "import torch\n", "import torch.nn as nn\n", "import torch.nn.functional as F\n", "import numpy as np\n", "import json" ] }, ...
https://github.com/socathie/circomlib-ml
models/remez.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from mpmath import mp\n", "import numpy as np\n", "\n", "# from https://github.com/DKenefake/OptimalPoly\n", "\n", "def bisection_search(f, low:float, high:float):\n", " ...
https://github.com/socathie/circomlib-ml
models/reshape2d.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tensorflow.keras.layers import Input, Reshape\n", "from tensorflow.keras import Model\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metad...
https://github.com/socathie/circomlib-ml
models/separableConv2D.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "aa5be75a-ee5f-45b0-891b-da2dd340dd00", "metadata": {}, "outputs": [], "source": [ "import torch\n", "import torch.nn as nn\n", "import torch.nn.functional as F\n", "import numpy as np\n", "import json" ] }, ...
https://github.com/socathie/circomlib-ml
models/sumPooling2d.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tensorflow.keras.layers import Input, AveragePooling2D, Lambda\n", "from tensorflow.keras import Model\n", "import numpy as np" ] }, { "cell_type": "code", "execution_cou...
https://github.com/socathie/circomlib-ml
models/upSampling2d.ipynb
{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "from tensorflow.keras.layers import Input, UpSampling2D\n", "from tensorflow.keras import Model\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 13, ...
https://github.com/socathie/circomlib-ml
test/AveragePooling2D.js
const chai = require("chai"); const path = require("path"); const wasm_tester = require("circom_tester").wasm; const F1Field = require("ffjavascript").F1Field; const Scalar = require("ffjavascript").Scalar; exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");...
https://github.com/socathie/circomlib-ml
test/BatchNormalization.js
const chai = require("chai"); const path = require("path"); const wasm_tester = require("circom_tester").wasm; const F1Field = require("ffjavascript").F1Field; const Scalar = require("ffjavascript").Scalar; exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");...
https://github.com/socathie/circomlib-ml
test/Conv1D.js
const chai = require("chai"); const path = require("path"); const wasm_tester = require("circom_tester").wasm; const F1Field = require("ffjavascript").F1Field; const Scalar = require("ffjavascript").Scalar; exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");...
https://github.com/socathie/circomlib-ml
test/Conv2D.js
const chai = require("chai"); const path = require("path"); const wasm_tester = require("circom_tester").wasm; const F1Field = require("ffjavascript").F1Field; const Scalar = require("ffjavascript").Scalar; exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");...
https://github.com/socathie/circomlib-ml
test/Conv2Dsame.js
const chai = require("chai"); const path = require("path"); const wasm_tester = require("circom_tester").wasm; const F1Field = require("ffjavascript").F1Field; const Scalar = require("ffjavascript").Scalar; exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");...
https://github.com/socathie/circomlib-ml
test/Dense.js
const chai = require("chai"); const path = require("path"); const wasm_tester = require("circom_tester").wasm; const F1Field = require("ffjavascript").F1Field; const Scalar = require("ffjavascript").Scalar; exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");...
https://github.com/socathie/circomlib-ml