text
stringlengths
1
2.05k
use std::{fs::File, io::BufReader}; use serde_derive::{Deserialize, Serialize}; pub
struct TensorMsgpack { pub idx: i64, pub shape: Vec<i64>, pub data: Vec<i64>, } pub
struct LayerMsgpack { pub layer_type: String, pub params: Vec<i64>, pub inp_idxes: Vec<i64>, pub inp_shapes: Vec<Vec<i64>>, pub out_idxes: Vec<i64>, pub out_shapes: Vec<Vec<i64>>, pub mask: Vec<i64>, } pub
struct ModelMsgpack { pub global_sf: i64, pub k: i64, pub num_cols: i64, pub inp_idxes: Vec<i64>, pub out_idxes: Vec<i64>, pub tensors: Vec<TensorMsgpack>, pub layers: Vec<LayerMsgpack>, pub use_selectors: Option<bool>, pub commit_before: Option<Vec<Vec<i64>>>, pub commit_after: Option<Vec<Vec<i64>>>, pub bits_per_elem: Option<i64>, pub num_random: Option<i64>, } pub fn load_config_msgpack(config_path: &str) -> ModelMsgpack { let model: ModelMsgpack = { let file = File::open(config_path).unwrap(); let mut reader = BufReader::new(file); rmp_serde::from_read(&mut reader).unwrap() }; model } pub fn load_model_msgpack(config_path: &str, inp_path: &str) -> ModelMsgpack { let mut model = load_config_msgpack(config_path); let inp: Vec<TensorMsgpack> = { let file = File::open(inp_path).unwrap(); let mut reader = BufReader::new(file); rmp_serde::from_read(&mut reader).unwrap() }; for tensor in inp { model.tensors.push(tensor); } if model.use_selectors.is_none() { model.use_selectors = Some(true) }; if model.commit_before.is_none() { model.commit_before = Some(vec![]) }; if model.commit_after.is_none() { model.commit_after = Some(vec![]) }; if model.bits_per_elem.is_none() { model.bits_per_elem = Some(model.k) }; if model.num_random.is_none() { model.num_random = Some(20001) }; model }
use std::{ fs::File, io::{BufReader, Write}, path::Path, time::Instant, }; use halo2_proofs::{ dev::MockProver, halo2curves::pasta::{EqAffine, Fp}, plonk::{create_proof, keygen_pk, keygen_vk, verify_proof}, poly::{ commitment::{Params, ParamsProver}, ipa::{ commitment::{IPACommitmentScheme, ParamsIPA}, multiopen::ProverIPA, strategy::SingleStrategy, }, VerificationStrategy, }, transcript::{ Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer, }, }; use crate::{model::ModelCircuit, utils::helpers::get_public_values}; pub fn get_ipa_params(params_dir: &str, degree: u32) -> ParamsIPA<EqAffine> { let path = format!("{}/{}.params", params_dir, degree); let params_path = Path::new(&path); if File::open(&params_path).is_err() { let params: ParamsIPA<EqAffine> = ParamsIPA::new(degree); let mut buf = Vec::new(); params.write(&mut buf).expect("Failed to write params"); let mut file = File::create(&params_path).expect("Failed to create params file"); file .write_all(&buf[..]) .expect("Failed to write params to file"); } let params_fs = File::open(&params_path).expect("couldn't load params"); let params: ParamsIPA<EqAffine> = Params::read::<_>(&mut BufReader::new(params_fs)).expect("Failed to read params"); params } pub
fn time_circuit_ipa(circuit: ModelCircuit<Fp>) { let rng = rand::thread_rng(); let start = Instant::now(); let degree = circuit.k as u32; let empty_circuit = circuit.clone(); let proof_circuit = circuit; let params = get_ipa_params("./params_ipa", degree); let circuit_duration = start.elapsed(); println!( "Time elapsed in params construction: {:?}", circuit_duration ); let vk = keygen_vk(&params, &empty_circuit).unwrap(); let vk_duration = start.elapsed(); println!( "Time elapsed in generating vkey: {:?}", vk_duration - circuit_duration ); let pk = keygen_pk(&params, vk, &empty_circuit).unwrap(); let pk_duration = start.elapsed(); println!( "Time elapsed in generating pkey: {:?}", pk_duration - vk_duration ); drop(empty_circuit); let fill_duration = start.elapsed(); let _prover = MockProver::run(degree, &proof_circuit, vec![vec![]]).unwrap(); let public_vals = get_public_values(); println!( "Time elapsed in filling circuit: {:?}", fill_duration - pk_duration ); let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]); create_proof::<IPACommitmentScheme<EqAffine>, ProverIPA<EqAffine>, _, _, _, _>( &params, &pk, &[proof_circuit], &[&[&public_vals]], rng, &mut transcript, ) .unwrap(); let proof = transcript.finalize(); let proof_duration = start.elapsed(); println!("Proving time: {:?}", proof_duration - fill_duration); let proof_size = { let mut folder = std::path::PathBuf::new(); folder.push("proof"); let mut fd = std::fs::File::create(folder.as_path()).unwrap(); folder.pop(); fd.write_all(&proof).unwrap(); fd.metadata().unwrap().len() }; println!("Proof size: {} bytes", proof_size); let strategy = SingleStrategy::new(&params); let mut transcript = Blake2bRead::<_, _, Challenge255<_>>::init(&proof[..]); assert!( verify_proof( &params, pk.get_vk(), strategy, &[&[&public_vals]], &mut transcript ) .is_o
k(), "proof did not verify" ); let verify_duration = start.elapsed(); println!("Verifying time: {:?}", verify_duration - proof_duration); }
use std::{ fs::File, io::{BufReader, Write}, path::Path, time::Instant, }; use halo2_proofs::{ dev::MockProver, halo2curves::bn256::{Bn256, Fr, G1Affine}, plonk::{create_proof, keygen_pk, keygen_vk, verify_proof, VerifyingKey}, poly::{ commitment::Params, kzg::{ commitment::{KZGCommitmentScheme, ParamsKZG}, multiopen::{ProverSHPLONK, VerifierSHPLONK}, strategy::SingleStrategy, }, }, transcript::{ Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer, }, SerdeFormat, }; use crate::{model::ModelCircuit, utils::helpers::get_public_values}; pub fn get_kzg_params(params_dir: &str, degree: u32) -> ParamsKZG<Bn256> { let rng = rand::thread_rng(); let path = format!("{}/{}.params", params_dir, degree); let params_path = Path::new(&path); if File::open(&params_path).is_err() { let params = ParamsKZG::<Bn256>::setup(degree, rng); let mut buf = Vec::new(); params.write(&mut buf).expect("Failed to write params"); let mut file = File::create(&params_path).expect("Failed to create params file"); file .write_all(&buf[..]) .expect("Failed to write params to file"); } let mut params_fs = File::open(&params_path).expect("couldn't load params"); let params = ParamsKZG::<Bn256>::read(&mut params_fs).expect("Failed to read params"); params } pub fn serialize(data: &Vec<u8>, path: &str) -> u64 { let mut file = File::create(path).unwrap(); file.write_all(data).unwrap(); file.metadata().unwrap().len() } pub
fn verify_kzg( params: &ParamsKZG<Bn256>, vk: &VerifyingKey<G1Affine>, strategy: SingleStrategy<Bn256>, public_vals: &Vec<Fr>, mut transcript: Blake2bRead<&[u8], G1Affine, Challenge255<G1Affine>>, ) { assert!( verify_proof::< KZGCommitmentScheme<Bn256>, VerifierSHPLONK<'_, Bn256>, Challenge255<G1Affine>, Blake2bRead<&[u8], G1Affine, Challenge255<G1Affine>>, halo2_proofs::poly::kzg::strategy::SingleStrategy<'_, Bn256>, >(&params, &vk, strategy, &[&[&public_vals]], &mut transcript) .is_ok(), "proof did not verify" ); } pub
fn time_circuit_kzg(circuit: ModelCircuit<Fr>) { let rng = rand::thread_rng(); let start = Instant::now(); let degree = circuit.k as u32; let params = get_kzg_params("./params_kzg", degree); let circuit_duration = start.elapsed(); println!( "Time elapsed in params construction: {:?}", circuit_duration ); let vk_circuit = circuit.clone(); let vk = keygen_vk(&params, &vk_circuit).unwrap(); drop(vk_circuit); let vk_duration = start.elapsed(); println!( "Time elapsed in generating vkey: {:?}", vk_duration - circuit_duration ); let vkey_size = serialize(&vk.to_bytes(SerdeFormat::RawBytes), "vkey"); println!("vkey size: {} bytes", vkey_size); let pk_circuit = circuit.clone(); let pk = keygen_pk(&params, vk, &pk_circuit).unwrap(); let pk_duration = start.elapsed(); println!( "Time elapsed in generating pkey: {:?}", pk_duration - vk_duration ); drop(pk_circuit); let pkey_size = serialize(&pk.to_bytes(SerdeFormat::RawBytes), "pkey"); println!("pkey size: {} bytes", pkey_size); let fill_duration = start.elapsed(); let proof_circuit = circuit.clone(); let _prover = MockProver::run(degree, &proof_circuit, vec![vec![]]).unwrap(); let public_vals = get_public_values(); println!( "Time elapsed in filling circuit: {:?}", fill_duration - pk_duration ); let public_vals_u8: Vec<u8> = public_vals .iter() .map(|v: &Fr| v.to_bytes().to_vec()) .flatten() .collect(); let public_vals_u8_size = serialize(&public_vals_u8, "public_vals"); println!("Public vals size: {} bytes", public_vals_u8_size); let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); create_proof::< KZGCommitmentScheme<Bn256>, ProverSHPLONK<'_, Bn256>, Challenge255<G1Affine>, _, Blake2bWrite<Vec<u8>, G1Affine, Challenge255<G1Affine>>, ModelCircuit<Fr>, >( &params, &pk, &[proof_circuit], &[&[&public_vals]], rng, &mut transcript, ) .unwrap(); let proof = transcript.fi
nalize(); let proof_duration = start.elapsed(); println!("Proving time: {:?}", proof_duration - fill_duration); let proof_size = serialize(&proof, "proof"); let proof = std::fs::read("proof").unwrap(); println!("Proof size: {} bytes", proof_size); let strategy = SingleStrategy::new(&params); let transcript_read = Blake2bRead::<_, _, Challenge255<_>>::init(&proof[..]); println!("public vals: {:?}", public_vals); verify_kzg( &params, &pk.get_vk(), strategy, &public_vals, transcript_read, ); let verify_duration = start.elapsed(); println!("Verifying time: {:?}", verify_duration - proof_duration); } pub
fn verify_circuit_kzg( circuit: ModelCircuit<Fr>, vkey_fname: &str, proof_fname: &str, public_vals_fname: &str, ) { let degree = circuit.k as u32; let params = get_kzg_params("./params_kzg", degree); println!("Loaded the parameters"); let vk = VerifyingKey::read::<BufReader<File>, ModelCircuit<Fr>>( &mut BufReader::new(File::open(vkey_fname).unwrap()), SerdeFormat::RawBytes, (), ) .unwrap(); println!("Loaded vkey"); let proof = std::fs::read(proof_fname).unwrap(); let public_vals_u8 = std::fs::read(&public_vals_fname).unwrap(); let public_vals: Vec<Fr> = public_vals_u8 .chunks(32) .map(|chunk| Fr::from_bytes(chunk.try_into().expect("conversion failed")).unwrap()) .collect(); let strategy = SingleStrategy::new(&params); let transcript = Blake2bRead::<_, _, Challenge255<_>>::init(&proof[..]); let start = Instant::now(); let verify_start = start.elapsed(); verify_kzg(&params, &vk, strategy, &public_vals, transcript); let verify_duration = start.elapsed(); println!("Verifying time: {:?}", verify_duration - verify_start); println!("Proof verified!") }
import tensorflow as tf
import os
import numpy as np interpreter = tf.lite.Interpreter( model_path=f'./testing/circuits/v2_1.0_224.tflite' ) interpreter.allocate_tensors() NAME_TO_TENSOR = {} for tensor_details in interpreter.get_tensor_details(): NAME_TO_TENSOR[tensor_details['name']] = tensor_details Wc = interpreter.get_tensor(NAME_TO_TENSOR['Const_71']['index']) Bc = interpreter.get_tensor(NAME_TO_TENSOR['MobilenetV2/Conv_1/Conv2D_bias']['index'])
class LastTwoLayers(tf.keras.Model): def __init__(self, name=None): super().__init__(name = name) self.a_variable = tf.Variable(5.0, name="train_me") self.conv1 = tf.keras.layers.Conv2D( 1280, (1, 1), activation='relu6', padding='same', input_shape=(1, 7, 7, 320) ) self.avg_pool = tf.keras.layers.AveragePooling2D( pool_size=(7, 7), padding='valid', strides=(1, 1) ) self.conv2 = tf.keras.layers.Conv2D( 102, (1, 1), padding='valid', input_shape=(1, 1, 1, 1280) ) self.softmax = tf.keras.layers.Softmax() def call(self, x): x = self.conv1(x) x = self.avg_pool(x) x = self.conv2(x) x = tf.reshape(x, [1, 102]) x = self.softmax(x) return x my_sequential_model = LastTwoLayers(name="the_model") my_sequential_model.compile(optimizer='sgd', loss='categorical_crossentropy') x = np.random.random((1, 7, 7, 320)) my_sequential_model.predict(x) my_sequential_model.conv1.set_weights([np.transpose(Wc, [1,2,3,0]), Bc]) W = np.zeros([1, 1, 1280, 102]) my_sequential_model.conv2.set_weights([ W, np.zeros([102]) ]) converter = tf.lite.TFLiteConverter.from_keras_model(my_sequential_model) tflite_model = converter.convert() with open('./examples/v2_1.0_224_truncated/v2_1.0_224_truncated.tflite', 'wb') as f: f.write(tflite_model)
import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], })
pragma circom 2.0.0;
include "./model.circom";
include "./utils/cid.circom";
include "./utils/encrypt.circom"; template Main(n) { signal input in[n][797*8]; signal input conv2d_weights[3][3][1][4]; signal input conv2d_bias[4]; signal input batch_normalization_a[4]; signal input batch_normalization_b[4]; signal input conv2d_1_weights[3][3][4][16]; signal input conv2d_1_bias[16]; signal input batch_normalization_1_a[16]; signal input batch_normalization_1_b[16]; signal input dense_weights[16][10]; signal input dense_bias[10]; signal output out[n]; signal output cids[n*2]; signal output hash; component pixel[n]; component model[n]; component cid[n]; for (var i = 0; i < n; i++) { model[i] = Model(); pixel[i] = getPixels(); cid[i] = getCid(); for (var i0 = 0; i0 < 797*8; i0++) { pixel[i].in[i0] <== in[i][i0]; cid[i].in[i0] <== in[i][i0]; } for (var i0 = 0; i0 < 2; i0++) { cids[i*2+i0] <== cid[i].out[i0]; } for (var i0 = 0; i0 < 28; i0++) { for (var i1 = 0; i1 < 28; i1++) { for (var i2 = 0; i2 < 1; i2++) { model[i].in[i0][i1][i2] <== pixel[i].out[i0][i1][i2]; }}} for (var i0 = 0; i0 < 3; i0++) { for (var i1 = 0; i1 < 3; i1++) { for (var i2 = 0; i2 < 1; i2++) { for (var i3 = 0; i3 < 4; i3++) { model[i].conv2d_weights[i0][i1][i2][i3] <== conv2d_weights[i0][i1][i2][i3]; }}}} for (var i0 = 0; i0 < 4; i0++) { model[i].conv2d_bias[i0] <== conv2d_bias[i0]; } for (var i0 = 0; i0 < 4; i0++) { model[i].batch_normalization_a[i0] <== batch_normalization_a[i0]; } for (var i0 = 0; i0 < 4; i0++) { model[i].batch_normalization_b[i0] <== batch_normalization_b[i0]; } for (var i0 = 0; i0 < 3; i0++) { for (var i1 = 0; i1 < 3; i1++) { for (var i2 = 0; i2
< 4; i2++) { for (var i3 = 0; i3 < 16; i3++) { model[i].conv2d_1_weights[i0][i1][i2][i3] <== conv2d_1_weights[i0][i1][i2][i3]; }}}} for (var i0 = 0; i0 < 16; i0++) { model[i].conv2d_1_bias[i0] <== conv2d_1_bias[i0]; } for (var i0 = 0; i0 < 16; i0++) { model[i].batch_normalization_1_a[i0] <== batch_normalization_1_a[i0]; } for (var i0 = 0; i0 < 16; i0++) { model[i].batch_normalization_1_b[i0] <== batch_normalization_1_b[i0]; } for (var i0 = 0; i0 < 16; i0++) { for (var i1 = 0; i1 < 10; i1++) { model[i].dense_weights[i0][i1] <== dense_weights[i0][i1]; }} for (var i0 = 0; i0 < 10; i0++) { model[i].dense_bias[i0] <== dense_bias[i0]; } out[i] <== model[i].out[0]; } component mimc = hash1000(); var idx = 0; for (var i0 = 0; i0 < 3; i0++) { for (var i1 = 0; i1 < 3; i1++) { for (var i2 = 0; i2 < 1; i2++) { for (var i3 = 0; i3 < 4; i3++) { mimc.in[idx] <== conv2d_weights[i0][i1][i2][i3]; idx++; }}}} for (var i0 = 0; i0 < 4; i0++) { mimc.in[idx] <== conv2d_bias[i0]; idx++; } for (var i0 = 0; i0 < 4; i0++) { mimc.in[idx] <== batch_normalization_a[i0]; idx++; } for (var i0 = 0; i0 < 4; i0++) { mimc.in[idx] <== batch_normalization_b[i0]; idx++; } for (var i0 = 0; i0 < 3; i0++) { for (var i1 = 0; i1 < 3; i1++) { for (var i2 = 0; i2 < 4; i2++) { for (var i3 = 0; i3 < 16; i3++) { mimc.in[idx] <== conv2d_1_weights[i0][i1][i2][i3]; idx++; }}}} for (var i0 = 0; i0 < 16; i0++) { mimc.in[idx] <== conv2d_1_bias[i0]; idx++; } for (var i0 = 0; i0 < 16; i0++) { mimc.in[idx] <== batch_normalization_1_a[i0]; idx++
; } for (var i0 = 0; i0 < 16; i0++) { mimc.in[idx] <== batch_normalization_1_b[i0]; idx++; } for (var i0 = 0; i0 < 16; i0++) { for (var i1 = 0; i1 < 10; i1++) { mimc.in[idx] <== dense_weights[i0][i1]; idx++; }} for (var i0 = 0; i0 < 10; i0++) { mimc.in[idx] <== dense_bias[i0]; idx++; } for (var i = idx; i < 1000; i++) { mimc.in[i] <== 0; } hash <== mimc.out; } component main = Main(10);
pragma circom 2.0.0; include "./utils/encrypt.circom"; template Main() { // public inputs signal input public_key[2]; // private inputs signal input in[1000]; // zero-padded at the end signal input private_key; // outputs signal output hash; signal output shared_key; signal output out[1001]; component hasher = hash1000(); component enc = encrypt1000(); enc.public_key[0] <== public_key[0]; enc.public_key[1] <== public_key[1]; enc.private_key <== private_key; for (var i = 0; i < 1000; i++) { hasher.in[i] <== in[i]; enc.in[i] <== in[i]; } hash <== hasher.out; shared_key <== enc.shared_key; for (var i = 0; i < 1001; i++) { out[i] <== enc.out[i]; } } component main { public [ public_key ] } = Main();
pragma circom 2.0.0;
include "../node_modules/circomlib-ml/circuits/BatchNormalization2D.circom";
include "../node_modules/circomlib-ml/circuits/Dense.circom";
include "../node_modules/circomlib-ml/circuits/Conv2D.circom";
include "../node_modules/circomlib-ml/circuits/AveragePooling2D.circom";
include "../node_modules/circomlib-ml/circuits/ArgMax.circom";
include "../node_modules/circomlib-ml/circuits/Poly.circom";
include "../node_modules/circomlib-ml/circuits/GlobalAveragePooling2D.circom"; template Model() { signal input in[28][28][1]; signal input conv2d_weights[3][3][1][4]; signal input conv2d_bias[4]; signal input batch_normalization_a[4]; signal input batch_normalization_b[4]; signal input conv2d_1_weights[3][3][4][16]; signal input conv2d_1_bias[16]; signal input batch_normalization_1_a[16]; signal input batch_normalization_1_b[16]; signal input dense_weights[16][10]; signal input dense_bias[10]; signal output out[1]; component conv2d = Conv2D(28, 28, 1, 4, 3, 1); component batch_normalization = BatchNormalization2D(26, 26, 4); component lambda[26][26][4]; for (var i0 = 0; i0 < 26; i0++) { for (var i1 = 0; i1 < 26; i1++) { for (var i2 = 0; i2 < 4; i2++) { lambda[i0][i1][i2] = Poly(1000000); }}} component average_pooling2d = AveragePooling2D(26, 26, 4, 2, 2, 250); component conv2d_1 = Conv2D(13, 13, 4, 16, 3, 1); component batch_normalization_1 = BatchNormalization2D(11, 11, 16); component lambda_1[11][11][16]; for (var i0 = 0; i0 < 11; i0++) { for (var i1 = 0; i1 < 11; i1++) { for (var i2 = 0; i2 < 16; i2++) { lambda_1[i0][i1][i2] = Poly(1000000000000000000000); }}} component average_pooling2d_1 = AveragePooling2D(11, 11, 16, 2, 2, 250); component global_average_pooling2d = GlobalAveragePooling2D(5, 5, 16, 40); component dense = Dense(16, 10); component softmax = ArgMax(10); for (var i0 = 0; i0 < 28; i0++) { for (var i1 = 0; i1 < 28; i1++) { for (var i2 = 0; i2 < 1; i2++) { conv2d.in[i0][i1][i2] <== in[i0][i1][i2]; }}} for (var i0 = 0; i0 < 3; i0++) { for (var i1 = 0; i1 < 3; i1++) { for (var i2 = 0; i2 < 1; i2++) { for (var i3 = 0; i3 < 4; i3++) { conv2d.weights[i0][i1][i2][i3] <== conv2d_weights[i0][i1][i2][i3]; }}}} for (var i0 = 0; i0 < 4; i0++) { conv2d.bias[i0] <== conv2d_bias[i0]; } for (var i0 = 0; i0 < 26; i0++) { for (var i1 = 0; i1 < 26; i1++) { for (var i2 = 0; i2 < 4; i2++)
{ batch_normalization.in[i0][i1][i2] <== conv2d.out[i0][i1][i2]; }}} for (var i0 = 0; i0 < 4; i0++) { batch_normalization.a[i0] <== batch_normalization_a[i0]; } for (var i0 = 0; i0 < 4; i0++) { batch_normalization.b[i0] <== batch_normalization_b[i0]; } for (var i0 = 0; i0 < 26; i0++) { for (var i1 = 0; i1 < 26; i1++) { for (var i2 = 0; i2 < 4; i2++) { lambda[i0][i1][i2].in <== batch_normalization.out[i0][i1][i2]; }}} for (var i0 = 0; i0 < 26; i0++) { for (var i1 = 0; i1 < 26; i1++) { for (var i2 = 0; i2 < 4; i2++) { average_pooling2d.in[i0][i1][i2] <== lambda[i0][i1][i2].out; }}} for (var i0 = 0; i0 < 13; i0++) { for (var i1 = 0; i1 < 13; i1++) { for (var i2 = 0; i2 < 4; i2++) { conv2d_1.in[i0][i1][i2] <== average_pooling2d.out[i0][i1][i2]; }}} for (var i0 = 0; i0 < 3; i0++) { for (var i1 = 0; i1 < 3; i1++) { for (var i2 = 0; i2 < 4; i2++) { for (var i3 = 0; i3 < 16; i3++) { conv2d_1.weights[i0][i1][i2][i3] <== conv2d_1_weights[i0][i1][i2][i3]; }}}} for (var i0 = 0; i0 < 16; i0++) { conv2d_1.bias[i0] <== conv2d_1_bias[i0]; } for (var i0 = 0; i0 < 11; i0++) { for (var i1 = 0; i1 < 11; i1++) { for (var i2 = 0; i2 < 16; i2++) { batch_normalization_1.in[i0][i1][i2] <== conv2d_1.out[i0][i1][i2]; }}} for (var i0 = 0; i0 < 16; i0++) { batch_normalization_1.a[i0] <== batch_normalization_1_a[i0]; } for (var i0 = 0; i0 < 16; i0++) { batch_normalization_1.b[i0] <== batch_normalization_1_b[i0]; } for (var i0 = 0; i0 < 11; i0++) { for (var i1 = 0; i1 < 11; i1++) { for (var i2 = 0; i2 < 16; i2++) { lambda_1[i0][i1][i2].in <== batch_normalization_1.out[i0][i1][i2]; }}} for (var i0 = 0; i0 < 11; i0++) { for (var i1 = 0; i1 < 11; i1++) { for (var i2 = 0; i2 < 16; i2++) { average_pooling2d_1.in[i0][i1][i2] <== lambda_1[i0][i1][i2].out; }}} for (var i0 = 0; i0 < 5; i0++) { for (var i1 = 0; i1 < 5; i1++) { fo
r (var i2 = 0; i2 < 16; i2++) { global_average_pooling2d.in[i0][i1][i2] <== average_pooling2d_1.out[i0][i1][i2]; }}} for (var i0 = 0; i0 < 16; i0++) { dense.in[i0] <== global_average_pooling2d.out[i0]; } for (var i0 = 0; i0 < 16; i0++) { for (var i1 = 0; i1 < 10; i1++) { dense.weights[i0][i1] <== dense_weights[i0][i1]; }} for (var i0 = 0; i0 < 10; i0++) { dense.bias[i0] <== dense_bias[i0]; } for (var i0 = 0; i0 < 10; i0++) { softmax.in[i0] <== dense.out[i0]; } out[0] <== softmax.out; }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ /* Ch 000 0 001 1 010 0 011 1 100 0 101 0 110 1 111 1 out = a&b ^ (!a)&c => out = a*(b-c) + c */ pragma circom 2.0.0; template Ch_t(n) { signal input a[n]; signal input b[n]; signal input c[n]; signal output out[n]; for (var k=0; k<n; k++) { out[k] <== a[k] * (b[k]-c[k]) + c[k]; } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https: */ pragma circom 2.0.0; template H(x) { signal output out[32]; var c[8] = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]; for (var i=0; i<32; i++) { out[i] <== (c[x] >> i) & 1; } } template K(x) { signal output out[32]; var c[64] = [ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 ]; for (var i=0; i<32; i++) { out[i] <== (c[x] >> i) & 1; } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ pragma circom 2.0.0; include "sha256_2.circom"; template Main() { signal input a; signal input b; signal output out; component sha256_2 = Sha256_2(); sha256_2.a <== a; sha256_2.b <== a; out <== sha256_2.out; } component main = Main();
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ /* Maj function for sha256 out = a&b ^ a&c ^ b&c => out = a*b + a*c + b*c - 2*a*b*c => out = a*( b + c - 2*b*c ) + b*c => mid = b*c out = a*( b + c - 2*mid ) + mid */ pragma circom 2.0.0; template Maj_t(n) { signal input a[n]; signal input b[n]; signal input c[n]; signal output out[n]; signal mid[n]; for (var k=0; k<n; k++) { mid[k] <== b[k]*c[k]; out[k] <== a[k] * (b[k]+c[k]-2*mid[k]) + mid[k]; } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ pragma circom 2.0.0; template RotR(n, r) { signal input in[n]; signal output out[n]; for (var i=0; i<n; i++) { out[i] <== in[ (i+r)%n ]; } }
pragma circom 2.0.0;
include "constants.circom";
include "sha256compression.circom"; template Sha256(nBits) { signal input in[nBits]; signal output out[256]; var i; var k; var nBlocks; var bitsLastBlock; nBlocks = ((nBits + 64)\512)+1; signal paddedIn[nBlocks*512]; for (k=0; k<nBits; k++) { paddedIn[k] <== in[k]; } paddedIn[nBits] <== 1; for (k=nBits+1; k<nBlocks*512-64; k++) { paddedIn[k] <== 0; } for (k = 0; k< 64; k++) { paddedIn[nBlocks*512 - k -1] <== (nBits >> k)&1; } component ha0 = H(0); component hb0 = H(1); component hc0 = H(2); component hd0 = H(3); component he0 = H(4); component hf0 = H(5); component hg0 = H(6); component hh0 = H(7); component sha256compression[nBlocks]; for (i=0; i<nBlocks; i++) { sha256compression[i] = Sha256compression() ; if (i==0) { for (k=0; k<32; k++ ) { sha256compression[i].hin[0*32+k] <== ha0.out[k]; sha256compression[i].hin[1*32+k] <== hb0.out[k]; sha256compression[i].hin[2*32+k] <== hc0.out[k]; sha256compression[i].hin[3*32+k] <== hd0.out[k]; sha256compression[i].hin[4*32+k] <== he0.out[k]; sha256compression[i].hin[5*32+k] <== hf0.out[k]; sha256compression[i].hin[6*32+k] <== hg0.out[k]; sha256compression[i].hin[7*32+k] <== hh0.out[k]; } } else { for (k=0; k<32; k++ ) { sha256compression[i].hin[32*0+k] <== sha256compression[i-1].out[32*0+31-k]; sha256compression[i].hin[32*1+k] <== sha256compression[i-1].out[32*1+31-k]; sha256compression[i].hin[32*2+k] <== sha256compression[i-1].out[32*2+31-k]; sha256compression[i].hin[32*3+k] <== sha256compression[i-1].out[32*3+31-k]; sha256compression[i].hin[32*4+k] <== sha256compression[i-1].out[32*4+31-k]; sha256compression[i].hin[32*5+k] <== sha256compression[i-1].out[32*
5+31-k]; sha256compression[i].hin[32*6+k] <== sha256compression[i-1].out[32*6+31-k]; sha256compression[i].hin[32*7+k] <== sha256compression[i-1].out[32*7+31-k]; } } for (k=0; k<512; k++) { sha256compression[i].inp[k] <== paddedIn[i*512+k]; } } for (k=0; k<256; k++) { out[k] <== sha256compression[nBlocks-1].out[k]; } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https: */ pragma circom 2.0.0;
include "constants.circom";
include "sha256compression.circom";
include "../../node_modules/circomlib-ml/circuits/circomlib/bitify.circom"; template Sha256_2() { signal input a; signal input b; signal output out; var i; var k; component bits2num = Bits2Num(216); component num2bits[2]; num2bits[0] = Num2Bits(216); num2bits[1] = Num2Bits(216); num2bits[0].in <== a; num2bits[1].in <== b; component sha256compression = Sha256compression() ; component ha0 = H(0); component hb0 = H(1); component hc0 = H(2); component hd0 = H(3); component he0 = H(4); component hf0 = H(5); component hg0 = H(6); component hh0 = H(7); for (k=0; k<32; k++ ) { sha256compression.hin[0*32+k] <== ha0.out[k]; sha256compression.hin[1*32+k] <== hb0.out[k]; sha256compression.hin[2*32+k] <== hc0.out[k]; sha256compression.hin[3*32+k] <== hd0.out[k]; sha256compression.hin[4*32+k] <== he0.out[k]; sha256compression.hin[5*32+k] <== hf0.out[k]; sha256compression.hin[6*32+k] <== hg0.out[k]; sha256compression.hin[7*32+k] <== hh0.out[k]; } for (i=0; i<216; i++) { sha256compression.inp[i] <== num2bits[0].out[215-i]; sha256compression.inp[i+216] <== num2bits[1].out[215-i]; } sha256compression.inp[432] <== 1; for (i=433; i<503; i++) { sha256compression.inp[i] <== 0; } sha256compression.inp[503] <== 1; sha256compression.inp[504] <== 1; sha256compression.inp[505] <== 0; sha256compression.inp[506] <== 1; sha256compression.inp[507] <== 1; sha256compression.inp[508] <== 0; sha256compression.inp[509] <== 0; sha256compression.inp[510] <== 0; sha256compression.inp[511] <== 0; for (i=0; i<216; i++) { bits2num.in[i] <== sha256compression.out[255-i]; } out <== bits2num.out; }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https: */ pragma circom 2.0.0;
include "constants.circom";
include "t1.circom";
include "t2.circom";
include "../../node_modules/circomlib-ml/circuits/circomlib/binsum.circom";
include "sigmaplus.circom";
include "sha256compression_function.circom"; template Sha256compression() { signal input hin[256]; signal input inp[512]; signal output out[256]; signal a[65][32]; signal b[65][32]; signal c[65][32]; signal d[65][32]; signal e[65][32]; signal f[65][32]; signal g[65][32]; signal h[65][32]; signal w[64][32]; var outCalc[256] = sha256compression(hin, inp); var i; for (i=0; i<256; i++) out[i] <-- outCalc[i]; component sigmaPlus[48]; for (i=0; i<48; i++) sigmaPlus[i] = SigmaPlus(); component ct_k[64]; for (i=0; i<64; i++) ct_k[i] = K(i); component t1[64]; for (i=0; i<64; i++) t1[i] = T1(); component t2[64]; for (i=0; i<64; i++) t2[i] = T2(); component suma[64]; for (i=0; i<64; i++) suma[i] = BinSum(32, 2); component sume[64]; for (i=0; i<64; i++) sume[i] = BinSum(32, 2); component fsum[8]; for (i=0; i<8; i++) fsum[i] = BinSum(32, 2); var k; var t; for (t=0; t<64; t++) { if (t<16) { for (k=0; k<32; k++) { w[t][k] <== inp[t*32+31-k]; } } else { for (k=0; k<32; k++) { sigmaPlus[t-16].in2[k] <== w[t-2][k]; sigmaPlus[t-16].in7[k] <== w[t-7][k]; sigmaPlus[t-16].in15[k] <== w[t-15][k]; sigmaPlus[t-16].in16[k] <== w[t-16][k]; } for (k=0; k<32; k++) { w[t][k] <== sigmaPlus[t-16].out[k]; } } } for (k=0; k<32; k++ ) { a[0][k] <== hin[k]; b[0][k] <== hin[32*1 + k]; c[0][k] <== hin[32*2 + k]; d[0][k] <== hin[32*3 + k]; e[0][k] <== hin[32*4 + k]; f[0][k] <== hin[32*5 + k]; g[0][k] <== hin[32*6 + k]; h[0][k] <== hin[32*7 + k]; } for (t = 0; t<64; t++) { for (k=0; k<32; k++) { t1[t].h[k] <== h[t][k]; t1[t].e[k] <== e[t][k]; t1[t].f[k] <== f[t][k]; t1[t].g[k] <== g[t][k]
; t1[t].k[k] <== ct_k[t].out[k]; t1[t].w[k] <== w[t][k]; t2[t].a[k] <== a[t][k]; t2[t].b[k] <== b[t][k]; t2[t].c[k] <== c[t][k]; } for (k=0; k<32; k++) { sume[t].in[0][k] <== d[t][k]; sume[t].in[1][k] <== t1[t].out[k]; suma[t].in[0][k] <== t1[t].out[k]; suma[t].in[1][k] <== t2[t].out[k]; } for (k=0; k<32; k++) { h[t+1][k] <== g[t][k]; g[t+1][k] <== f[t][k]; f[t+1][k] <== e[t][k]; e[t+1][k] <== sume[t].out[k]; d[t+1][k] <== c[t][k]; c[t+1][k] <== b[t][k]; b[t+1][k] <== a[t][k]; a[t+1][k] <== suma[t].out[k]; } } for (k=0; k<32; k++) { fsum[0].in[0][k] <== hin[32*0+k]; fsum[0].in[1][k] <== a[64][k]; fsum[1].in[0][k] <== hin[32*1+k]; fsum[1].in[1][k] <== b[64][k]; fsum[2].in[0][k] <== hin[32*2+k]; fsum[2].in[1][k] <== c[64][k]; fsum[3].in[0][k] <== hin[32*3+k]; fsum[3].in[1][k] <== d[64][k]; fsum[4].in[0][k] <== hin[32*4+k]; fsum[4].in[1][k] <== e[64][k]; fsum[5].in[0][k] <== hin[32*5+k]; fsum[5].in[1][k] <== f[64][k]; fsum[6].in[0][k] <== hin[32*6+k]; fsum[6].in[1][k] <== g[64][k]; fsum[7].in[0][k] <== hin[32*7+k]; fsum[7].in[1][k] <== h[64][k]; } for (k=0; k<32; k++) { out[31-k] === fsum[0].out[k]; out[32+31-k] === fsum[1].out[k]; out[64+31-k] === fsum[2].out[k]; out[96+31-k] === fsum[3].out[k]; out[128+31-k] === fsum[4].out[k]; out[160+31-k] === fsum[5].out[k]; out[192+31-k] === fsum[6].out[k]; out[224+31-k] === fsum[7].out[k]; } }
pragma circom 2.0.0;
function rrot(x, n) { return ((x >> n) | (x << (32-n))) & 0xFFFFFFFF; }
function bsigma0(x) { return rrot(x,2) ^ rrot(x,13) ^ rrot(x,22); }
function bsigma1(x) { return rrot(x,6) ^ rrot(x,11) ^ rrot(x,25); }
function ssigma0(x) { return rrot(x,7) ^ rrot(x,18) ^ (x >> 3); }
function ssigma1(x) { return rrot(x,17) ^ rrot(x,19) ^ (x >> 10); }
function Maj(x, y, z) { return (x&y) ^ (x&z) ^ (y&z); }
function Ch(x, y, z) { return (x & y) ^ ((0xFFFFFFFF ^x) & z); }
function sha256K(i) { var k[64] = [ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 ]; return k[i]; }
function sha256compression(hin, inp) { var H[8]; var a; var b; var c; var d; var e; var f; var g; var h; var out[256]; for (var i=0; i<8; i++) { H[i] = 0; for (var j=0; j<32; j++) { H[i] += hin[i*32+j] << j; } } a=H[0]; b=H[1]; c=H[2]; d=H[3]; e=H[4]; f=H[5]; g=H[6]; h=H[7]; var w[64]; var T1; var T2; for (var i=0; i<64; i++) { if (i<16) { w[i]=0; for (var j=0; j<32; j++) { w[i] += inp[i*32+31-j]<<j; } } else { w[i] = (ssigma1(w[i-2]) + w[i-7] + ssigma0(w[i-15]) + w[i-16]) & 0xFFFFFFFF; } T1 = (h + bsigma1(e) + Ch(e,f,g) + sha256K(i) + w[i]) & 0xFFFFFFFF; T2 = (bsigma0(a) + Maj(a,b,c)) & 0xFFFFFFFF; h=g; g=f; f=e; e=(d+T1) & 0xFFFFFFFF; d=c; c=b; b=a; a=(T1+T2) & 0xFFFFFFFF; } H[0] = H[0] + a; H[1] = H[1] + b; H[2] = H[2] + c; H[3] = H[3] + d; H[4] = H[4] + e; H[5] = H[5] + f; H[6] = H[6] + g; H[7] = H[7] + h; for (var i=0; i<8; i++) { for (var j=0; j<32; j++) { out[i*32+31-j] = (H[i] >> j) & 1; } } return out; }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ pragma circom 2.0.0; template ShR(n, r) { signal input in[n]; signal output out[n]; for (var i=0; i<n; i++) { if (i+r >= n) { out[i] <== 0; } else { out[i] <== in[ i+r ]; } } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ pragma circom 2.0.0; include "xor3.circom"; include "rotate.circom"; include "shift.circom"; template SmallSigma(ra, rb, rc) { signal input in[32]; signal output out[32]; var k; component rota = RotR(32, ra); component rotb = RotR(32, rb); component shrc = ShR(32, rc); for (k=0; k<32; k++) { rota.in[k] <== in[k]; rotb.in[k] <== in[k]; shrc.in[k] <== in[k]; } component xor3 = Xor3(32); for (k=0; k<32; k++) { xor3.a[k] <== rota.out[k]; xor3.b[k] <== rotb.out[k]; xor3.c[k] <== shrc.out[k]; } for (k=0; k<32; k++) { out[k] <== xor3.out[k]; } } template BigSigma(ra, rb, rc) { signal input in[32]; signal output out[32]; var k; component rota = RotR(32, ra); component rotb = RotR(32, rb); component rotc = RotR(32, rc); for (k=0; k<32; k++) { rota.in[k] <== in[k]; rotb.in[k] <== in[k]; rotc.in[k] <== in[k]; } component xor3 = Xor3(32); for (k=0; k<32; k++) { xor3.a[k] <== rota.out[k]; xor3.b[k] <== rotb.out[k]; xor3.c[k] <== rotc.out[k]; } for (k=0; k<32; k++) { out[k] <== xor3.out[k]; } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ pragma circom 2.0.0; include "../../node_modules/circomlib-ml/circuits/circomlib/binsum.circom"; include "sigma.circom"; template SigmaPlus() { signal input in2[32]; signal input in7[32]; signal input in15[32]; signal input in16[32]; signal output out[32]; var k; component sigma1 = SmallSigma(17,19,10); component sigma0 = SmallSigma(7, 18, 3); for (k=0; k<32; k++) { sigma1.in[k] <== in2[k]; sigma0.in[k] <== in15[k]; } component sum = BinSum(32, 4); for (k=0; k<32; k++) { sum.in[0][k] <== sigma1.out[k]; sum.in[1][k] <== in7[k]; sum.in[2][k] <== sigma0.out[k]; sum.in[3][k] <== in16[k]; } for (k=0; k<32; k++) { out[k] <== sum.out[k]; } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ pragma circom 2.0.0; include "../../node_modules/circomlib-ml/circuits/circomlib/binsum.circom"; include "sigma.circom"; include "ch.circom"; template T1() { signal input h[32]; signal input e[32]; signal input f[32]; signal input g[32]; signal input k[32]; signal input w[32]; signal output out[32]; var ki; component ch = Ch_t(32); component bigsigma1 = BigSigma(6, 11, 25); for (ki=0; ki<32; ki++) { bigsigma1.in[ki] <== e[ki]; ch.a[ki] <== e[ki]; ch.b[ki] <== f[ki]; ch.c[ki] <== g[ki]; } component sum = BinSum(32, 5); for (ki=0; ki<32; ki++) { sum.in[0][ki] <== h[ki]; sum.in[1][ki] <== bigsigma1.out[ki]; sum.in[2][ki] <== ch.out[ki]; sum.in[3][ki] <== k[ki]; sum.in[4][ki] <== w[ki]; } for (ki=0; ki<32; ki++) { out[ki] <== sum.out[ki]; } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ pragma circom 2.0.0; include "../../node_modules/circomlib-ml/circuits/circomlib/binsum.circom"; include "sigma.circom"; include "maj.circom"; template T2() { signal input a[32]; signal input b[32]; signal input c[32]; signal output out[32]; var k; component bigsigma0 = BigSigma(2, 13, 22); component maj = Maj_t(32); for (k=0; k<32; k++) { bigsigma0.in[k] <== a[k]; maj.a[k] <== a[k]; maj.b[k] <== b[k]; maj.c[k] <== c[k]; } component sum = BinSum(32, 2); for (k=0; k<32; k++) { sum.in[0][k] <== bigsigma0.out[k]; sum.in[1][k] <== maj.out[k]; } for (k=0; k<32; k++) { out[k] <== sum.out[k]; } }
/* 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, or (at your option) any later version. circom is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with circom. If not, see <https://www.gnu.org/licenses/>. */ /* Xor3 function for sha256 out = a ^ b ^ c => out = a+b+c - 2*a*b - 2*a*c - 2*b*c + 4*a*b*c => out = a*( 1 - 2*b - 2*c + 4*b*c ) + b + c - 2*b*c => mid = b*c out = a*( 1 - 2*b -2*c + 4*mid ) + b + c - 2 * mid */ pragma circom 2.0.0; template Xor3(n) { signal input a[n]; signal input b[n]; signal input c[n]; signal output out[n]; signal mid[n]; for (var k=0; k<n; k++) { mid[k] <== b[k]*c[k]; out[k] <== a[k] * (1 -2*b[k] -2*c[k] +4*mid[k]) + b[k] + c[k] -2*mid[k]; } }
pragma circom 2.0.0; include "../sha256/sha256.circom"; include "../../node_modules/circomlib-ml/circuits/circomlib/bitify.circom"; // convert a 797x8 bit array (pgm) to 28x28x1 array (pixels) template getPixels() { signal input in[797*8]; signal output out[28][28][1]; component pixels[28][28][1]; for (var i=0; i<28; i++) { for (var j=0; j<28; j++) { pixels[i][j][0] = Bits2Num(8); for (var k=0; k<8; k++) { pixels[i][j][0].in[k] <== in[13*8+i*28*8+j*8+k]; // the pgm header is 13 bytes } out[i][j][0] <== pixels[i][j][0].out; } } } // convert a 797x8 bit array (pgm) to the corresponding CID (in two parts) template getCid() { signal input in[797*8]; signal output out[2]; component sha = Sha256(797*8); for (var i=0; i<797*8; i++) { sha.in[i] <== in[i]; } component b2n[2]; for (var i=1; i>=0; i--) { b2n[i] = Bits2Num(128); for (var j=127; j>=0; j--) { b2n[i].in[127-j] <== sha.out[i*128+j]; } out[i] <== b2n[i].out; } }
pragma circom 2.0.0; include "../../node_modules/circomlib-ml/circuits/crypto/encrypt.circom"; include "../../node_modules/circomlib-ml/circuits/crypto/ecdh.circom"; // encrypt 1000 inputs template encrypt1000() { // public inputs signal input public_key[2]; // private inputs signal input in[1000]; signal input private_key; // outputs signal output shared_key; signal output out[1001]; component ecdh = Ecdh(); ecdh.private_key <== private_key; ecdh.public_key[0] <== public_key[0]; ecdh.public_key[1] <== public_key[1]; component enc = EncryptBits(1000); enc.shared_key <== ecdh.shared_key; for (var i = 0; i < 1000; i++) { enc.plaintext[i] <== in[i]; } for (var i = 0; i < 1001; i++) { out[i] <== enc.out[i]; } shared_key <== ecdh.shared_key; } // fixed MultiMiMC7 with 1000 inputs template hash1000() { signal input in[1000]; signal output out; component mimc = MultiMiMC7(1000, 91); mimc.k <== 0; for (var i = 0; i < 1000; i++) { mimc.in[i] <== in[i]; } out <== mimc.out; }
pragma solidity ^0.8.17;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./ICircuitVerifier.sol";
import "./IEncryptionVerifier.sol"; contract Bounty is Initializable, OwnableUpgradeable { uint public completedStep; IEncryptionVerifier public encryptionVerifier; string public name; string public description; bytes[] public dataCIDs; uint[] public labels; uint public accuracyThreshold; address public bountyHunter; bytes public zkeyCID; bytes public circomCID; bytes public verifierCID; ICircuitVerifier public verifier; uint[2] public a; uint[2][2] public b; uint[2] public c; uint public modelHash; bool public isComplete; uint[2] public publicKeys; uint[1005] public input; uint8 public constant CID_VERSION = 1; uint8 public constant CID_CODEC = 0x55; uint8 public constant CID_HASH = 0x12; uint8 public constant CID_LENGTH = 32; event BountyUpdated(uint step); /* Tx 1 * take owner address from factory * set bounty details * receive native tokens as bounty reward */ function initialize( address _owner, string memory _name, string memory _description, bytes[] memory _dataCIDs, uint[] memory _labels, uint _accuracyThreshold, address _encryptionVerifier ) public payable initializer { require(msg.value > 0, "Bounty reward must be greater than 0"); require( _dataCIDs.length == _labels.length, "Invalid dataCIDs or labels length" ); __Ownable_init(); transferOwnership(_owner); name = _name; description = _description; dataCIDs = _dataCIDs; labels = _labels; accuracyThreshold = _accuracyThreshold; encryptionVerifier = IEncryptionVerifier(_encryptionVerifier); completedStep = 1; } /* Tx 2: submit bounty * submit CID of zkey, circom * submit verifier address * submit proof */ function submitBounty(
bytes memory _zkeyCID, bytes memory _circomCID, bytes memory _verifierCID, address _verifier, uint[2] memory _a, uint[2][2] memory _b, uint[2] memory _c, uint[] memory _input ) public /* * n = dataCIDs.length * first n elements of input should be the model output * the next 2n elements of input should be the splitted dataCIDs * the last element is the model hash */ { require(bountyHunter == address(0), "Bounty already submitted"); require(_verifier != address(0), "Invalid verifier address"); uint n = dataCIDs.length; require(_input.length == 3 * n + 1, "Invalid input length"); uint numCorrect = 0; for (uint i = 0; i < n; i++) { if (_input[i] == labels[i]) { numCorrect++; } } require( (numCorrect * 100) / n >= accuracyThreshold, "Accuracy threshold not met" ); for (uint i = 0; i < dataCIDs.length; i++) { require( keccak256(dataCIDs[i]) == keccak256( abi.encodePacked( CID_VERSION, CID_CODEC, CID_HASH, CID_LENGTH, concatDigest( _input[n + i * 2], _input[n + i * 2 + 1] ) ) ), "Data CID mismatch" ); } verifier = ICircuitVerifier(_verifier); require(verifier.verifyProof(_a, _b, _c, _input), "Invalid proof"); a = _a; b = _b; c = _c; modelHash = _input[3 * n]; zkeyCID = _zkeyCID; circomCID = _circomCID; verifierCID = _verifierCID; bountyHunter = msg.sender; emit BountyUpdated(2); completedStep =
2; } /* Tx 3: release bounty * only callable by bounty provider * only callable if bounty is not complete * only callable if bounty hunter has submitted proof */ function releaseBounty(uint[2] memory _publicKeys) public onlyOwner { require(!isComplete, "Bounty is already complete"); require(a[0] != 0, "Bounty hunter has not submitted proof"); publicKeys = _publicKeys; isComplete = true; emit BountyUpdated(3); completedStep = 3; } /* Tx 4: claim bounty * function to submit preimage of hashed input * only callable if SHA256 of preimage matched hashed input * only callable if bounty is complete * _input */ function claimBounty( uint[2] memory _a, uint[2][2] memory _b, uint[2] memory _c, uint[1005] memory _input /* * first element is the model hash * the next element is the shared key * the next 1001 elements are the encrypted input * the last 2 elements are the public keys */ ) public { require( msg.sender == bountyHunter, "Only bounty hunter can claim bounty" ); require(isComplete, "Bounty is not complete"); require(address(this).balance > 0, "Bounty already claimed"); require( modelHash == _input[0], "Model hash does not match submitted proof" ); require( publicKeys[0] == _input[1003] && publicKeys[1] == _input[1004], "Public keys do not match" ); require( encryptionVerifier.verifyProof(_a, _b, _c, _input), "Invalid encryption" ); input = _input; payable(msg.sender).transfer(address(this).balance); emit BountyUpdated(4); completedStep = 4; } function concatDigest( uint input1, uint input2 ) publ
ic pure returns (bytes32) { return bytes32((input1 << 128) + input2); } function verifyProof( uint[2] memory _a, uint[2][2] memory _b, uint[2] memory _c, uint[] memory _input ) public view returns (bool) { return verifier.verifyProof(_a, _b, _c, _input); } function verifyEncryption( uint[2] memory _a, uint[2][2] memory _b, uint[2] memory _c, uint[1005] memory _input ) public view returns (bool) { return encryptionVerifier.verifyProof(_a, _b, _c, _input); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.17; import "./Bounty.sol"; import "@openzeppelin/contracts/proxy/Clones.sol"; contract BountyFactory { address public immutable encryptionVerifier; address public immutable bountyTemplate; address[] public bounties; uint public bountyCount; event BountyCreated(address indexed bounty); constructor(address _encryptionVerifier) { encryptionVerifier = _encryptionVerifier; bountyTemplate = address(new Bounty()); } function createBounty( string memory _name, string memory _description, bytes[] memory _dataCIDs, uint[] memory _labels, uint _accuracyThreshold ) public payable returns (address) { require(msg.value > 0, "BountyFactory: must send more than 0 wei to create bounty"); address clone = Clones.clone(bountyTemplate); Bounty(clone).initialize{value: msg.value}( msg.sender, _name, _description, _dataCIDs, _labels, _accuracyThreshold, encryptionVerifier ); bounties.push(clone); emit BountyCreated(clone); bountyCount++; return clone; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.17; interface ICircuitVerifier { function verifyProof( uint[2] memory a, uint[2][2] memory b, uint[2] memory c, uint[] memory input ) external view returns (bool); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.17; interface IEncryptionVerifier { function verifyProof( uint[2] memory a, uint[2][2] memory b, uint[2] memory c, uint[1005] memory input ) external view returns (bool); }
pragma solidity ^0.8.17; contract Pairing100 {
struct G1Point { uint X; uint Y; } G1Point[101] public vk; constructor() { vk[0] = G1Point(0,0); vk[1] = G1Point( 3066949056198555590635621162084363174762527476622332118327842035011606793952, 2162571409210902214336812509672057078658587427403012932644293527850387519156 ); vk[2] = G1Point( 8488790424014158852808006439223343295226971170088490706045068147193001550599, 15533262107732603341702625683247434142241321708314454154455671678191112358883 ); vk[3] = G1Point( 15498356887658237969202350156895359735754782519547024837768823850341320383276, 18043358128034609114248819170759582834297009296355155153256975697104654277482 ); vk[4] = G1Point( 6567029474530677569488194734194250250570285395463850727851121497011576634627, 1952169722727701625695211431819915372584015014098667009341874426445277275409 ); vk[5] = G1Point( 7983094460044061917184665751343846528917223973727668540609481601054516669380, 13073411943223982722608981931194140929654969432838450821822380279373205694540 ); vk[6] = G1Point( 6235254487603623311509594370074069771036715566675668423360562477653321213694, 16348146029413394893095677470763579440263315501392573505110251361786086111748 ); vk[7] = G1Point( 12126230703813379196905492399911032289157141882681249791742262746221956435664, 21824357088719214382926551780637722669585190256191017503396653466603977666160 ); vk[8] = G1Point( 10613712952540031218381119319419543617541815295229336208011689530011199688535, 4592079294597931003139600470582401940650194077066693677222963213001984771652 ); vk[9] = G1Point( 3911255295243246572381650626618017989180793092410038772879346029962164371222, 207071531977391524329123011395505529205205795906
41272006246634774964843219027 ); vk[10] = G1Point( 11892500116628810223727210540182406632392016834847116628237108078905657482121, 14711114067180791500399151644962712269552453743799493074158273490185336020392 ); vk[11] = G1Point( 9183014413227020895002734499598490676394098841236386025615160839774137140858, 9582865320358157815924266045220199184707642207541576610273447728638869402848 ); vk[12] = G1Point( 13892435818247230557011116927971479775033781875296602336601976433383564563228, 14733448935712935443414454397165120382231825236729361587040978447025752552981 ); vk[13] = G1Point( 17401712645354510672876078146418383500681865058306486281552878566762375427257, 20486073793183479284747068769667013438227637945205924637833865634902153972807 ); vk[14] = G1Point( 12542945177566110147515483264178913219335969620393213829679296068703471654263, 14507302716493402635132650456910109213791510706246873554623739152933578354782 ); vk[15] = G1Point( 17262671835229452055040768758779568490937342065764654420598847161477754030825, 8902971187566518627682001128928050354700036485645478563285262811824680312795 ); vk[16] = G1Point( 2517092168115592419226866474026532297002849402135262172105829244870031873767, 5441677800156144741677796942852428248886812324716256833812586939545360386553 ); vk[17] = G1Point( 16352603512600688738155061629075068863201450829351196946082637536789820772324, 18927273847130979134794259223289142814361248364229652488443571874192685947616 ); vk[18] = G1Point( 2180973227235578788710927545110613481031038894649648025035535210348330223155, 3507425497681887054666522686927478472275561239370715484736685279835745443493 ); vk[19] = G1Point( 2106
0865790233599822231133344591416589146418696172581714008599651157654485577, 11445704792629508009509530745672449871152458786577656651399880869793578183538 ); vk[20] = G1Point( 14962922779924834333807088380732268106533627899319967840459394518301601944902, 12641115320963479719774006201733593283460207791235448771211717531831128631986 ); vk[21] = G1Point( 4186981001816470806980748781585918132583910335167314696545999009872429264973, 17565855649932537025068269231075491026770085614015983747359821562568883706223 ); vk[22] = G1Point( 16312170887333793475640777226722750017815511399203573224417188753987361268062, 14942299556601867394310962262283413205020816495555982640061951999926073906170 ); vk[23] = G1Point( 11116982558963830693347282315846967801531679296436746818272732121331724415720, 5873619496054897441797349224362529314197498237479985364281745701741828890223 ); vk[24] = G1Point( 7022610961304395808415740511844195116328680518742785550228915385939858023878, 3136892863857862871481332688425068826979796665029750363309374645841360217432 ); vk[25] = G1Point( 8157557205265774407360029054875726935492541606165132860923411819480266205728, 81012924889287601351558230557166415960328857029602316655253741163216562264 ); vk[26] = G1Point( 21387183076392014337790811106800278834050500139493358334136872383128902568974, 7314778968936160478301679546290108816508132795495073939210992055620514882950 ); vk[27] = G1Point( 17445370062398000783311321822998675262681592534816043788545673331055581981338, 4675382597784294729649795567482785231305950693131859255309513051178177175147 ); vk[28] = G1Point( 2098486770907856191452018054264372066670081881036141132191766235747034517957, 1
815216053155211776578165772337605223514474799477706574780357340295527292101 ); vk[29] = G1Point( 7247597047636474744927667131995247170347121112158565895891458041517309296389, 192163179728062470503970372632568808101844243963511753219985601280107313588 ); vk[30] = G1Point( 9501203604906811513710929504005271216818701558451549918406058132625156622140, 13415551798489062914081927666384545099868303281595275344663896205914217872078 ); vk[31] = G1Point( 8034595547439438515257075919781050926864947386461328816426271763205695561810, 3642829052524533022920002316425451318885679003862750085869559319724420881642 ); vk[32] = G1Point( 7389684095037929207631024101452345138987391705473424971516979116156341370031, 20579346475224820747653673571292546222054464762132703448050660242437987760856 ); vk[33] = G1Point( 1099064042522969917142691337028490131971642761995798870015264529977810129874, 4136739376632161133724827833970087000788767831702190026854456646968400813758 ); vk[34] = G1Point( 15902640373161477583518974310718417505509060791924961343157477459642931778416, 1762478943943949736546872517381831620025398511173518621074233342446251355911 ); vk[35] = G1Point( 9487596420461016268451980893550096361069347323138723495572679418046046688516, 21544892836467812510793690303334485681390117717928076905731274778121908775623 ); vk[36] = G1Point( 5820742566388270780628696340911428355864552004252479310278041095949430795376, 7641545445878583943991373750714475758318324289158901278777701540735262273286 ); vk[37] = G1Point( 12251320072812281522145414395832737970348394787433255591714150097089431407791, 1532779231870484091585282548681946168911463262567902797320995702737440600730 );
vk[38] = G1Point( 10101613659948566217818739071435123184975710593253921139345225712243031098260, 2640636367314325922533248149727739621985364283675597424474610904727340867587 ); vk[39] = G1Point( 5274085047519363354811875262114176759943519780130758450894988285688729358933, 16937296383981904953674801963392439007888700172373626045529133960039399617263 ); vk[40] = G1Point( 3188599184332565193899369748973079401161586075804055427027494260172731823565, 12968148658083523222968587586141447230993399408675687327780669641109440554181 ); vk[41] = G1Point( 6458679214833537132762167352491386830890325825067568504280547744045616578060, 18468430467927738997242809956404712244666634410317213833141099954108019752365 ); vk[42] = G1Point( 20623060804426468927294862308817315019265876115430041233840695215686630451173, 17087264238689414062897963203925434079076282890481053770322544570572170791084 ); vk[43] = G1Point( 13325627203350085472814451732459661888038862533482320269567426702823739329985, 15776877746534956413446522278166863682458481282527146558228748205100102572752 ); vk[44] = G1Point( 21668441582737826762284872544546266101011979954395973562059583274610785704512, 8277583852037002978546735597203532757285123793571816105035644796689659489126 ); vk[45] = G1Point( 8536734248796214979017755496101738844563999731454217385048880639936148506055, 20050543179037705575872012681412619075809416420502779193387785187983159802429 ); vk[46] = G1Point( 11953986823633174213575339280604577641359038793605491295923798560589727371956, 13147634485185373963488944552653926289625401157498385879547759582230194995039 ); vk[47] = G1Point( 155071200419777464107503325683560462835215835271
3007226217725635275012226118, 11203299551088982147798422942849790450362141843828509216540844403325585105151 ); vk[48] = G1Point( 18196271432499014695041842961836011055301353978784919923839413819261319730858, 17098246883967118308242007705459913729702320623322185243317557342538873073008 ); vk[49] = G1Point( 11531116823867493145527748839530207312938155107914319337102872641313100242222, 2697631011753785502387459101482062165916413038880404121649035963091673433064 ); vk[50] = G1Point( 19631156064522474229619641610560117574796667466539324323824988031144145984381, 8937425392860060539170803423572257992722753021855554898593023194915230583803 ); vk[51] = G1Point( 18051666508329012801246216448195697328672943604860514259327889529692653255003, 9776962899569029336118636701542682706337611353719012721741705378235920461022 ); vk[52] = G1Point( 11475939723265162413789647159385731316378041455196431353866586443244485875960, 19711286708431892260060507102028877127791309206835055077147368871237918812844 ); vk[53] = G1Point( 11026344553624187160806030841924275695941597805136178910833830083155671710696, 17162259106859976824562173306587249703506336000572176722780992931150003382282 ); vk[54] = G1Point( 18072014661614829050905335947561719081371194373328681685188989976710752519958, 1048774928195049223435951979787210247304656815367952815402170340291203327793 ); vk[55] = G1Point( 3221143767918066976906625234268647838438505710085915094550693082136124954378, 10609209382910755371095430847148428568017844178029295267934890570954490604373 ); vk[56] = G1Point( 18603265763099527508808162560935573442394246009812715067853557618675227114718, 1158792240541167853659669595216681687390
5254266295729425002776504155871866385 ); vk[57] = G1Point( 10114761011080890155283117352096466322084587359113823233655131129809908439285, 5508807755576750114007448677480215198205054512071101691922034235838061098992 ); vk[58] = G1Point( 9473224577697192182393997942482349654852015982345608217160238854137662694850, 5232619463453481364828566196626075235351370331947090314816487540777930815749 ); vk[59] = G1Point( 5828405670751893034234121115192004049259338974472201883856438484025352454589, 3633323324079227154005083110521782808490892738558883105373813514476535351512 ); vk[60] = G1Point( 9481001625234164910092417433822014284864981517603152850384837599413333732088, 18386678173060928637493215959625252441776561544797402448843069753038309706398 ); vk[61] = G1Point( 364501025358600818780755326403010729029463316682362019677778479288396511819, 10921245151415767613656441640218247912049165999046837003614440575555392502991 ); vk[62] = G1Point( 7412432117223787136546267187474701163839580784868897752482245004405373487816, 14421834339860903299006524733412603591618190844451037914060151606872119869654 ); vk[63] = G1Point( 6758356448748273679612068112965369625648505132685375942552567389525551794313, 18898694627951555492949080550455672542650697400113643917079813065361088117351 ); vk[64] = G1Point( 2232426915296748097728380112764112830256664229981443467879391402850835961005, 17886990959858849028776727028779317010658807731479716471554709099443198391877 ); vk[65] = G1Point( 19386684389754528007206697728725486021492582825389320018808101756896486223763, 5387944841171208361896631485654248835440117619070885391004123093753703767533 ); vk[66] = G1Point( 1
2647065993168520043526182937209775921405750220974685444664551951358272974493, 13366972599313287188896739755647120252951756955470758833728145978865191885332 ); vk[67] = G1Point( 18787943133831207667822354828276073727409268368355483818755165180933524613843, 14157388513572656930506703772013995574294570155316280419904839453909945513212 ); vk[68] = G1Point( 21524068563373174125502750466662633697416975469194703149213549758771064143806, 19330633973479566265383470717707159202647232323953472749583165647656210689772 ); vk[69] = G1Point( 18382902852942323899973219125400009598490102054273518026407333530852107135564, 5587556133767484044476916396039091505022130703765554879534031897599284695340 ); vk[70] = G1Point( 9606930799644572048804158116652707177514237680732063560098981656270261037968, 5136249659645845922930624684319684098674157523379969261653636459876902241146 ); vk[71] = G1Point( 13552542113314993893290710085750912895320123663026256826131125947307038096408, 709273112699884026311409013166059830376072517342412739277236776866334978888 ); vk[72] = G1Point( 4877695026492837904576447514487946170274766503110664007065051006317417028911, 9446076080426295446536293256688999725548133948518312450170562478729416816073 ); vk[73] = G1Point( 7745407439919264073462666166103574869059650004645099967253653215503500518730, 8958000654601464310040236040720076000298815451674171928370656192395821571291 ); vk[74] = G1Point( 18666320048773366090983312937110187453777592458193442257099376708416358364469, 5539513286001813732779693880109891933912857627313433936315887072372257898800 ); vk[75] = G1Point( 17762000693904052174149226238971528607238820505142737089093305569141218095604,
21813189192876658164580671884381389056637414147229002438166607672106061685075 ); vk[76] = G1Point( 10620403668573083681678811832492214395842703160132031753632193443445132940858, 9287214924394327270674892448424295944430582227602780738386553108169870248604 ); vk[77] = G1Point( 3225723314799122490693549255900886936628936604463053909144327405767083517367, 13296795156783832061321769403471090730204694557283869635175430523261252422880 ); vk[78] = G1Point( 19394283269851765166190520453710260933464736369229146491483414402572036649235, 8886347394143457971098959915862183096606640244332501467928584161268657741540 ); vk[79] = G1Point( 11211101631546988901713127520653099409246632641328196192389635621453268719604, 7533450628229590941864952327666728681554006380658922550113985739199255638676 ); vk[80] = G1Point( 20281375053270705107000390143308705274685813353750898370539071869251555616918, 4191504470134081448832429650265903916036318956937686405591767766612018536246 ); vk[81] = G1Point( 21730429297217903457297617624317163698633779108372279268294203214963841239599, 3455168649241599958364434680402533707717293629319160914142901270957667623322 ); vk[82] = G1Point( 3733487430670068762717150810067800653321114341709315796018436370189955345854, 16993516290835476757984075812093517551647545212347461054793061694546089118405 ); vk[83] = G1Point( 4069347453305835841899489561884027971507987034637139177752057964697523071884, 1956678427081338497880770997396896779466225278969197692269889397339747587977 ); vk[84] = G1Point( 12688563169962246380429505363810909719278960011517597178276847596058759674530, 2927641600345355068914853681494591852216028218422911788003225244122043842764
); vk[85] = G1Point( 4455557144275882809490589083576310491054371424484637119621439376441819761829, 9731487948258565288497893143140566785594886936141150696674322531881129525085 ); vk[86] = G1Point( 2619477629022801354541827825039395847140273659251589045546247153678969401001, 17836540777608540858002712754656630392833096079100756487601556239085848528635 ); vk[87] = G1Point( 17062191534864932254047439130752387946329235277076184342923625213771678836935, 12069527596907551270256200398919523423277992112424100276678513119084727281716 ); vk[88] = G1Point( 16805402258218753489165124144746360879274608960953677668700957483879628729815, 10410789682524022432691807145340097146023648177608444718821101447661767567785 ); vk[89] = G1Point( 8008007635828919944721498889155253916141351807179483997112773450223661089031, 3056216602318722957626231548277738119817129937156384969718806681210818813385 ); vk[90] = G1Point( 17667744232917991611151306720567572212556922769873510455013405323308378680476, 2890516289406621384766044747643579791042650014890801167964314867977213603626 ); vk[91] = G1Point( 3143780756554946361446807874127330304332880216504691698401282667783892825765, 5028022739746074390415051300734944677415023517308139648614267686230087830490 ); vk[92] = G1Point( 4441632139452511774754687310993428522463840333562308532916275348517874568273, 3805657638938374125360055067937180653723886063939263403849322700999001648464 ); vk[93] = G1Point( 3013746618735534923159878225091501634239528953276121826823488677950608530535, 13303028874453780721063879979526033805375485792805017809758536559366914354384 ); vk[94] = G1Point( 14789748181560854817833042182581216273309010
9575127779417863797051852392003, 8640707092187677945028587417279452926189344446161983387648630388517595059973 ); vk[95] = G1Point( 2577256613690079498068095765293720593058588557523481248270938666627067239265, 557967286957109878996836148405729465277762109969903801336199294077387543421 ); vk[96] = G1Point( 8686488647634619838672230770846132946046686268388456771190560796889050807187, 9655938106080828371789874989347293139151622023273311610492266716485237742652 ); vk[97] = G1Point( 16599968643048917866313339039047045832907766174850659964114094763810732985169, 12352676869643809540552538084233558931904841866746829566346313116816615110547 ); vk[98] = G1Point( 9267573706827759556576977525684723234253097476251745496874796559184732114237, 19587468868070611863092114139198146359967042685205673652032650844827081496187 ); vk[99] = G1Point( 11705191676975146315944183303161754911767575431964910047638549236413625571714, 8095106176974497014713170771085910822558210350216200986553411154835804708953 ); vk[100] = G1Point( 5280447958522165271753443781707956962932493679043298614057258828764744713115, 2950965016195187402652016874997101060634411125365212216271760448064603541692 ); } }
pragma solidity ^0.8.17; contract Pairing1000 {
struct G1Point { uint X; uint Y; } G1Point[106] public vk; constructor() { vk[0] = G1Point( 19391891390609481429849774145579503985374912055370046060106347963180567737648, 7728129834219170358551601609946089408272789276196019291377633982082964264714 ); vk[1] = G1Point( 228181717483219631881657075204725935385048273455808643893243197164559350421, 15508572652012038327422985835367154161109393774231544670603904898987703339046 ); vk[2] = G1Point( 16754121749542176817018561144730772493675261004204649097804584067550029429764, 17198634116191727394680940996772782519853632044920636906274502553914565398533 ); vk[3] = G1Point( 17957826624334676365790727934855184468288134758298197553821849563875784518295, 11406944883794382503312535656888338714736169159186960939240866611040057953907 ); vk[4] = G1Point( 4430494423928001497300523686255609706462362613573142892959836577073966586667, 13162682470663696321459107672743862398804392623617041025907097398229531565530 ); vk[5] = G1Point( 14257009587274680131434329887478603228568836644077894222628586460501309457074, 11646274224080018681410242920703798265921447377022922965379193380569262526301 ); vk[6] = G1Point( 9705958142725732334171292951895582262453103495226515030924122300318445171445, 13694782303955607160992526693851231852459773108619276337185038380591985756496 ); vk[7] = G1Point( 17144012643506768456362242707497029877693906598559317669357981307632003015152, 11530719059110160059659430237719853818953715174794303473948058261774712009985 ); vk[8] = G1Point( 14483890631953705848041353681278392175692989931587713018682235387322135726786, 174270215863488124044990812526395765995205870946665360226232207012853505304
68 ); vk[9] = G1Point( 17889382316777192599293408639688887991696476616460947563545460888753944231405, 20352775334017958538073502200757565414898846974625645781257112656447740307043 ); vk[10] = G1Point( 5951262494284676135349496221747578090299959473645061787220637810949004073376, 14922032753898924330673643869866676805069688661209194494635965419171158760589 ); vk[11] = G1Point( 14157110821921252447764389098290770100004176856427647780277344609571231620687, 20709704698226862108207042948311273224238835582484024370305399265471877818695 ); vk[12] = G1Point( 7728759661843518063486549138063376271515204045617668507188211998990686355923, 10711743748251684178249009586963144563210034088884838210857401639959975316833 ); vk[13] = G1Point( 2651390927031831475551158402902979685807224853052037975527524295438342728413, 11004334363823378697748692777964374325632053561615011779936484804038418721791 ); vk[14] = G1Point( 8246811305647017907134069673379285161957161889986106809441259650967328678244, 20494711448810555007005264172937271620975611130788125438879019136802800991047 ); vk[15] = G1Point( 9227237815575743955536388616372607676700984624496162638091113803457981055424, 7490146127910565474405078546634898959685582216342077796995152448422625084147 ); vk[16] = G1Point( 14988255449888576466983686333725846498816266130898987208151466403609279975637, 171153654716536684403810039714768984905610497645997537317020641135452111030 ); vk[17] = G1Point( 4313051815878873447335298243871896526283302009812695687199895781635541219892, 18022206114946361755183429638924181803457754841419074711392713576527324416177 ); vk[18] = G1Point( 1259650105362839398464416377418785
3284269767174172592557301269012245428487146, 21204447263079063745466366206201043101439752606465213007704313903164357344632 ); vk[19] = G1Point( 4130034343055488361685767779382955857974023520998228920193364089842314664441, 8542303792250873618267744068827215642358232542234575387855251882269356769896 ); vk[20] = G1Point( 6874451393411262130192832783491921955806954538787269105471079063336949779335, 6461933848170403547021264180029668962878963209941514169961510428223244909955 ); vk[21] = G1Point( 14446083874196363503105045557966370866184469389586599702851903416345637521014, 3794939657763066492124405264096579882646447937001202207430292939220594903055 ); vk[22] = G1Point( 12619429072171004657585865286806128551255324771581379374115006053003312336296, 19034585709515568979275882623176869138315316932867345905842355860246882800271 ); vk[23] = G1Point( 9587228225561280563242073506877752354490385404177352841706335890979927900938, 13956343537392811329003855132730055606205214193873442646494391935942884829436 ); vk[24] = G1Point( 20101337934907004002377597083705994838193569275135806876517069383194438778874, 11932388712951261352094258210650491031751658096692447547561800199948408982592 ); vk[25] = G1Point( 4864969763814313389538966758485110878780529318576302874540654995999903361786, 21172133458608732300887989383427281965171394293400317363673505108237404173045 ); vk[26] = G1Point( 5598686200209475726801826209869416677931202133322427961462147150076924987454, 12622619536843741987254461244719750638031901625031570099275218121269742818251 ); vk[27] = G1Point( 14751187683369284974807198981066190747232275415561207627517237286483560910232, 7370796989413051296003280586