refactor: hard fail for verify (#347)

This commit is contained in:
dante
2023-07-09 22:12:57 +01:00
committed by GitHub
parent b8913c92d9
commit da0755c5fc
14 changed files with 16967 additions and 308 deletions

View File

@@ -275,6 +275,10 @@ jobs:
locked: true
- name: KZG prove and verify tests
run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_::t --test-threads 8
- name: KZG prove and verify tests (public inputs)
run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_public_inputs --test-threads 8
- name: KZG prove and verify tests (public params)
run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_public_params --test-threads 8
- name: KZG prove and verify tests (hashed outputs)
run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_hashed --test-threads 8
- name: KZG prove and verify tests (encrypted outputs)

View File

@@ -0,0 +1,40 @@
import torch
from torch import nn
import json
class MyModel(nn.Module):
def __init__(self):
super(MyModel, self).__init__()
def forward(self, x):
return x
circuit = MyModel()
x = 0.1*torch.rand(1, *[2], requires_grad=True)
# Flips the neural net into inference mode
circuit.eval()
# Export the model
torch.onnx.export(circuit, # model being run
# model input (or a tuple for multiple inputs)
x,
# where to save the model (can be a file or file-like object)
"network.onnx",
export_params=True, # store the trained parameter weights inside the model file
opset_version=10, # the ONNX version to export the model to
do_constant_folding=True, # whether to execute constant folding for optimization
input_names=['input'], # the model's input names
output_names=['output'], # the model's output names
dynamic_axes={'input': {0: 'batch_size'}, # variable length axes
'output': {0: 'batch_size'}})
data_array = ((x).detach().numpy()).reshape([-1]).tolist()
data = dict(input_data=[data_array])
# Serialize data into file:
json.dump(data, open("input.json", 'w'))

View File

@@ -0,0 +1,14 @@
{
"input_data": [
[
0.014873981475830078,
0.06348338723182678
]
],
"output_data": [
[
0.014873981475830078,
0.06348338723182678
]
]
}

View File

@@ -0,0 +1,14 @@
pytorch2.0.1:y
%
inputoutput
Identity_0"Identity torch_jitZ!
input


batch_size
b"
output


batch_size
B

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -437,15 +437,7 @@ impl Module<Fr> for ElGamalGadget {
// 1. empty maingate instance
// 2. c1, sk_hash
// 3. c2
vec![0, 0, var_len[0]]
}
fn instance_increment_module(&self) -> Vec<usize> {
// in order
// 1. empty maingate instance
// 2. c1, sk_hash
// 3. c2
vec![0, 3, 0]
vec![0, 3, var_len[0]]
}
fn run(input: Self::RunInputs) -> Result<Vec<Vec<Fr>>, Box<dyn std::error::Error>> {
@@ -477,24 +469,40 @@ impl Module<Fr> for ElGamalGadget {
let (msg_var, sk_var) = layouter.assign_region(
|| "plaintext",
|mut region| {
let message_word = |i: usize| {
let value = &message.get_inner_tensor().unwrap()[i];
match value {
ValType::Value(v) => region.assign_advice(
|| format!("load message_{}", i),
self.config.plaintext_col,
i,
|| *v,
),
ValType::PrevAssigned(v) => Ok(v.clone()),
_ => panic!("wrong input type"),
let msg_var: Result<Vec<AssignedCell<Fr, Fr>>, Error> = match &message {
ValTensor::Value { inner: v, .. } => v
.iter()
.enumerate()
.map(|(i, value)| match value {
ValType::Value(v) => region.assign_advice(
|| format!("load message_{}", i),
self.config.plaintext_col,
i,
|| *v,
),
ValType::PrevAssigned(v) => Ok(v.clone()),
_ => panic!("wrong input type, must be previously assigned"),
})
.collect(),
ValTensor::Instance {
inner: col, dims, ..
} => {
// this should never ever fail
let num_elems = dims.iter().product::<usize>();
(0..num_elems)
.map(|i| {
region.assign_advice_from_instance(
|| "pub input anchor",
*col,
i,
self.config.plaintext_col,
i,
)
})
.collect()
}
};
let msg_var: Result<Vec<AssignedCell<Fr, Fr>>, Error> =
(0..message.len()).map(message_word).collect();
let sk = match sk.get_inner_tensor().unwrap()[0] {
ValType::Value(v) => v,
_ => panic!("wrong input type"),

View File

@@ -45,8 +45,6 @@ pub trait Module<F: PrimeField + TensorType + PartialOrd> {
input: &[ValTensor<F>],
row_offsets: Vec<usize>,
) -> Result<ValTensor<F>, Error>;
/// Number of instance values the module uses
/// Number of instance values the module uses every time it is applied
fn instance_increment_input(&self, _: Vec<usize>) -> Vec<usize>;
/// How to increment when creating a new module
fn instance_increment_module(&self) -> Vec<usize>;
}

View File

@@ -68,10 +68,6 @@ impl<S: Spec<Fp, WIDTH, RATE> + Sync, const WIDTH: usize, const RATE: usize, con
vec![1]
}
fn instance_increment_module(&self) -> Vec<usize> {
vec![0]
}
/// Constructs a new PoseidonChip
fn new(config: Self::Config) -> Self {
Self {
@@ -128,27 +124,46 @@ impl<S: Spec<Fp, WIDTH, RATE> + Sync, const WIDTH: usize, const RATE: usize, con
let res = layouter.assign_region(
|| "load message",
|mut region| {
let assigned_message: Result<Vec<AssignedCell<Fp, Fp>>, Error> = message
.get_inner_tensor()
.map_err(|_| Error::Synthesis)?
.iter()
.enumerate()
.map(|(i, value)| {
let x = i % WIDTH;
let y = i / WIDTH;
let assigned_message: Result<Vec<AssignedCell<Fp, Fp>>, Error> = match &message {
ValTensor::Value { inner: v, .. } => v
.iter()
.enumerate()
.map(|(i, value)| {
let x = i % WIDTH;
let y = i / WIDTH;
match value {
ValType::Value(v) => region.assign_advice(
|| format!("load message_{}", i),
self.config.hash_inputs[x],
y,
|| *v,
),
ValType::PrevAssigned(v) => Ok(v.clone()),
_ => panic!("wrong input type, must be previously assigned"),
}
})
.collect();
match value {
ValType::Value(v) => region.assign_advice(
|| format!("load message_{}", i),
self.config.hash_inputs[x],
y,
|| *v,
),
ValType::PrevAssigned(v) => Ok(v.clone()),
_ => panic!("wrong input type, must be previously assigned"),
}
})
.collect(),
ValTensor::Instance {
inner: col, dims, ..
} => {
// this should never ever fail
let num_elems = dims.iter().product::<usize>();
(0..num_elems)
.map(|i| {
let x = i % WIDTH;
let y = i / WIDTH;
region.assign_advice_from_instance(
|| "pub input anchor",
*col,
i,
self.config.hash_inputs[x],
y,
)
})
.collect()
}
};
let offset = message.len() / WIDTH + 1;

View File

@@ -8,7 +8,6 @@ use halo2_proofs::circuit::Value;
use halo2curves::ff::PrimeField;
use itertools::Itertools;
use log::error;
use rayon::prelude::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};
use super::{
chip::{BaseConfig, CheckMode, CircuitError},
@@ -237,7 +236,7 @@ pub fn einsum<F: PrimeField + TensorType + PartialOrd>(
})
.product::<usize>();
output.par_iter_mut().enumerate().for_each(|(i, o)| {
output.iter_mut().enumerate().for_each(|(i, o)| {
let coord = cartesian_coord[i].clone();
// Compute the slice of each input tensor given the current coordinate of the output tensor
let inputs = (0..inputs.len())
@@ -259,27 +258,12 @@ pub fn einsum<F: PrimeField + TensorType + PartialOrd>(
// in this case its just a dot product :)
if non_common_coord_size == 1 && inputs.len() == 2 {
let overflowed_len = overflowed_len(
region.offset(),
i * common_coord.len(),
config.output.col_size(),
);
let local_offset = region.offset() + overflowed_len;
let mut local_region = RegionCtx::from_wrapped_region(region.region(), local_offset);
*o = dot(config, &mut local_region, inputs[..].try_into().unwrap())
*o = dot(config, region, inputs[..].try_into().unwrap())
.unwrap()
.get_inner_tensor()
.unwrap()[0]
.clone();
} else {
// index * the number of elements that are multiplied together during the inner loop of an einsum operation
let local_offset =
// we subtract 1 because we don't need to add for the first loop
region.offset() + i * (common_coord.len() * 2 * (non_common_coord_size) - 1); // we have non_common_coord_size multiplies and adds per inner loop
let mut local_region = RegionCtx::from_wrapped_region(region.region(), local_offset);
let mut prod = None;
// Compute the cartesian product of all common indices
@@ -313,13 +297,8 @@ pub fn einsum<F: PrimeField + TensorType + PartialOrd>(
pair[1..]
.iter()
.fold(ValTensor::from(pair[0].clone()), |acc, x| {
pairwise(
config,
&mut local_region,
&[acc, x.clone().into()],
BaseOp::Mult,
)
.unwrap()
pairwise(config, region, &[acc, x.clone().into()], BaseOp::Mult)
.unwrap()
});
if prod.is_none() {
@@ -328,7 +307,7 @@ pub fn einsum<F: PrimeField + TensorType + PartialOrd>(
prod = Some(
pairwise(
config,
&mut local_region,
region,
&[prod.unwrap(), product_across_pair],
BaseOp::Add,
)
@@ -342,33 +321,6 @@ pub fn einsum<F: PrimeField + TensorType + PartialOrd>(
}
});
let non_common_indices_size = non_common_indices
.into_iter()
.filter(|c| !output_eq.contains(**c))
.map(|c| indices_to_size[c])
.product::<usize>();
if non_common_indices_size > 1 {
let increment = output_shape.iter().product::<usize>()
* (2 * common_indices_to_inputs
.into_iter()
.filter(|c| !output_eq.contains(*c))
.map(|c| indices_to_size[&c])
.product::<usize>()
* non_common_indices_size
- 1);
region.increment(increment);
} else {
let vanilla_len = output_shape.iter().product::<usize>()
* (common_indices_to_inputs
.into_iter()
.filter(|c| !output_eq.contains(*c))
.map(|c| indices_to_size[&c])
.product::<usize>());
let overflowed_len = overflowed_len(region.offset(), vanilla_len, config.output.col_size());
region.increment(overflowed_len);
}
if matches!(&config.check_mode, CheckMode::SAFE) {
// during key generation this will be 0 so we use this as a flag to check
// TODO: this isn't very safe and would be better to get the phase directly
@@ -1069,7 +1021,7 @@ pub fn conv<F: PrimeField + TensorType + PartialOrd + std::marker::Send + std::m
.multi_cartesian_product()
.collect::<Vec<_>>();
output.par_iter_mut().enumerate().for_each(|(idx, o)| {
output.iter_mut().enumerate().for_each(|(idx, o)| {
let cartesian_coord_per_group = &cartesian_coord[idx];
let (batch, group, i, j, k) = (
cartesian_coord_per_group[0],
@@ -1103,23 +1055,8 @@ pub fn conv<F: PrimeField + TensorType + PartialOrd + std::marker::Send + std::m
local_kernel.flatten();
let mut total_len = idx * local_image.len();
if has_bias {
total_len += idx;
}
let overflowed_len = overflowed_len(region.offset(), total_len, config.output.col_size());
let local_offset = region.offset() + overflowed_len;
let mut local_region = RegionCtx::from_wrapped_region(region.region(), local_offset);
// this is dot product notation in einsum format
let mut res = einsum(
config,
&mut local_region,
&mut [local_image, local_kernel],
"i,i->",
)
.unwrap();
let mut res = einsum(config, region, &mut [local_image, local_kernel], "i,i->").unwrap();
if has_bias {
let bias = values[2]
@@ -1127,7 +1064,7 @@ pub fn conv<F: PrimeField + TensorType + PartialOrd + std::marker::Send + std::m
.unwrap()
.get_slice(&[start_kernel_index..end_kernel_index])
.unwrap();
res = pairwise(config, &mut local_region, &[res, bias.into()], BaseOp::Add).unwrap()
res = pairwise(config, region, &[res, bias.into()], BaseOp::Add).unwrap()
}
*o = res.get_inner_tensor().unwrap()[0].clone();

View File

@@ -1460,7 +1460,7 @@ pub(crate) fn verify(
elapsed.subsec_millis()
);
info!("verified: {}", result.is_ok());
Ok(())
result.map_err(|e| e.into())
}
pub(crate) fn verify_aggr(
@@ -1485,6 +1485,7 @@ pub(crate) fn verify_aggr(
elapsed.subsec_millis()
);
info!("verified: {}", result.is_ok());
result?;
Ok(())
}

View File

@@ -336,15 +336,11 @@ impl GraphModules {
.iter()
.enumerate()
{
// increment the instance offset to make way for future module layouts
instance_offset[i] += inc;
}
// increment the instance offset to make way for future module layouts
});
for (i, inc) in module.instance_increment_module().iter().enumerate() {
instance_offset[i] += inc;
}
Ok(())
}

View File

@@ -150,7 +150,9 @@ where
let hex_proof = hex::encode(&self.proof);
state.serialize_field("proof", &hex_proof)?;
state.serialize_field("transcript_type", &self.transcript_type)?;
state.serialize_field("protocol", &self.protocol)?;
if self.protocol.is_some() {
state.serialize_field("protocol", &self.protocol)?;
}
state.end()
}
}
@@ -591,7 +593,7 @@ mod tests {
use super::*;
use halo2_proofs::poly::kzg::commitment::KZGCommitmentScheme;
use halo2curves::bn256::Bn256;
use halo2curves::bn256::{Bn256, Fr, G1Affine};
use tempfile::Builder;
#[tokio::test]
@@ -628,4 +630,25 @@ mod tests {
let res = srs::load_srs::<KZGCommitmentScheme<Bn256>>(fname);
assert!(res.is_ok())
}
#[test]
fn test_snark_serialization_roundtrip() {
let snark = Snark::<Fr, G1Affine> {
proof: vec![1, 2, 3, 4, 5, 6, 7, 8],
instances: vec![vec![Fr::from(1)], vec![Fr::from(2)]],
transcript_type: TranscriptType::EVM,
protocol: None,
};
snark
.save(&"test_snark_serialization_roundtrip.json".into())
.unwrap();
let snark2 = Snark::<Fr, G1Affine>::load::<KZGCommitmentScheme<Bn256>>(
&"test_snark_serialization_roundtrip.json".into(),
)
.unwrap();
assert_eq!(snark.instances, snark2.instances);
assert_eq!(snark.proof, snark2.proof);
assert_eq!(snark.transcript_type, snark2.transcript_type);
}
}

View File

@@ -4,17 +4,13 @@ mod native_tests {
use core::panic;
use ezkl::graph::input::{FileSource, GraphData};
use ezkl::graph::DataSource;
use ezkl::graph::{DataSource, GraphSettings};
use lazy_static::lazy_static;
use std::env::var;
use std::process::Command;
use std::sync::Once;
use tempdir::TempDir;
static COMPILE: Once = Once::new();
static KZG19: Once = Once::new();
static KZG17: Once = Once::new();
static KZG23: Once = Once::new();
static KZG26: Once = Once::new();
static START_ANVIL: Once = Once::new();
//Sure to run this once
@@ -45,66 +41,40 @@ mod native_tests {
});
}
fn init_params_19() {
KZG19.call_once(|| {
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"gen-srs",
&format!("--srs-path={}/kzg19.srs", TEST_DIR.path().to_str().unwrap()),
"--logrows=19",
])
.status()
.expect("failed to execute process");
assert!(status.success());
});
}
fn init_params_17() {
KZG17.call_once(|| {
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"gen-srs",
&format!("--srs-path={}/kzg17.srs", TEST_DIR.path().to_str().unwrap()),
"--logrows=17",
])
.status()
.expect("failed to execute process");
assert!(status.success());
});
}
fn init_params_23() {
KZG23.call_once(|| {
fn download_srs(logrows: u32) -> String {
let srs_path = format!("{}/kzg{}.srs", TEST_DIR.path().to_str().unwrap(), logrows);
// if does not exist, download it
if !std::path::Path::new(&srs_path).exists() {
let status = Command::new("curl")
.args([
"-o",
&format!(
"{}/kzg23.srs",
TEST_DIR.path().to_str().unwrap()
"{}/kzg{}.srs",
TEST_DIR.path().to_str().unwrap(),
logrows
),
&format!(
"https://trusted-setup-halo2kzg.s3.eu-central-1.amazonaws.com/perpetual-powers-of-tau-raw-{}",
logrows
),
"https://trusted-setup-halo2kzg.s3.eu-central-1.amazonaws.com/perpetual-powers-of-tau-raw-23",
])
.status()
.expect("failed to execute process");
assert!(status.success());
})
}
srs_path
}
fn init_params_26() {
KZG26.call_once(|| {
let status = Command::new("curl")
.args([
"-o",
&format!(
"{}/kzg24.srs",
TEST_DIR.path().to_str().unwrap()
),
"https://trusted-setup-halo2kzg.s3.eu-central-1.amazonaws.com/perpetual-powers-of-tau-raw-26",
])
.status()
.expect("failed to execute process");
assert!(status.success());
})
fn init_params(settings_path: std::path::PathBuf) -> String {
println!("using settings path: {}", settings_path.to_str().unwrap());
// read in settings json
let settings =
std::fs::read_to_string(settings_path).expect("failed to read settings file");
// read in to GraphSettings object
let settings: GraphSettings = serde_json::from_str(&settings).unwrap();
let logrows = settings.run_args.logrows;
download_srs(logrows)
}
fn mv_test_(test: &str) {
@@ -169,7 +139,7 @@ mod native_tests {
const LARGE_TESTS: [&str; 3] = ["self_attention", "nanoGPT", "mobilenet"];
const TESTS: [&str; 35] = [
const TESTS: [&str; 37] = [
"1l_mlp",
"1l_slice",
"1l_concat",
@@ -207,6 +177,8 @@ mod native_tests {
"1l_max_pool",
"1l_conv_transpose",
"1l_upsample",
"1l_identity",
"idolmodel",
];
const TESTS_AGGR: [&str; 20] = [
@@ -238,7 +210,7 @@ mod native_tests {
("2l_relu_small", "2l_relu_sigmoid_small"),
];
const TESTS_EVM: [&str; 18] = [
const TESTS_EVM: [&str; 20] = [
"1l_mlp",
"1l_flatten",
"1l_average",
@@ -258,6 +230,8 @@ mod native_tests {
"min",
"max",
"1l_max_pool",
"idolmodel",
"1l_identity",
];
const EXAMPLES: [&str; 2] = ["mlp_4d_einsum", "conv2d_mnist"];
@@ -277,7 +251,6 @@ mod native_tests {
#(#[test_case(TESTS_AGGR[N])])*
fn kzg_aggr_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_23();
crate::native_tests::mv_test_(test);
kzg_aggr_prove_and_verify(test.to_string());
}
@@ -309,7 +282,7 @@ mod native_tests {
}
seq!(N in 0..=34 {
seq!(N in 0..=36 {
#(#[test_case(TESTS[N])])*
fn render_circuit_(test: &str) {
@@ -439,25 +412,36 @@ mod native_tests {
#(#[test_case(TESTS[N])])*
fn kzg_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
kzg_prove_and_verify(test.to_string(), 17, "safe", "private", "private", "public");
kzg_prove_and_verify(test.to_string(), "safe", "private", "private", "public");
}
#(#[test_case(TESTS[N])])*
fn kzg_prove_and_verify_public_input_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::mv_test_(test);
kzg_prove_and_verify(test.to_string(), "safe", "public", "private", "public");
}
#(#[test_case(TESTS[N])])*
fn kzg_prove_and_verify_public_params_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::mv_test_(test);
kzg_prove_and_verify(test.to_string(), "safe", "private", "public", "public");
}
#(#[test_case(TESTS[N])])*
fn kzg_prove_and_verify_hashed_output(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
kzg_prove_and_verify(test.to_string(), 17, "safe", "private", "private", "hashed");
kzg_prove_and_verify(test.to_string(), "safe", "private", "private", "hashed");
}
#(#[test_case(TESTS[N])])*
fn kzg_prove_and_verify_encrypted_output(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_19();
crate::native_tests::mv_test_(test);
kzg_prove_and_verify(test.to_string(), 19, "safe", "private", "private", "encrypted");
kzg_prove_and_verify(test.to_string(), "safe", "private", "private", "encrypted");
}
#(#[test_case(TESTS[N])])*
@@ -476,9 +460,8 @@ mod native_tests {
#[ignore]
fn large_kzg_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_26();
crate::native_tests::mv_test_(test);
kzg_prove_and_verify(test.to_string(), 24, "unsafe", "private", "private", "public");
kzg_prove_and_verify(test.to_string(), "unsafe", "private", "private", "public");
}
#(#[test_case(LARGE_TESTS[N])])*
@@ -532,10 +515,10 @@ mod native_tests {
#(#[test_case(TESTS_ON_CHAIN_INPUT[N])])*
fn kzg_evm_on_chain_input_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
crate::native_tests::start_anvil();
kzg_evm_on_chain_input_prove_and_verify(test.to_string(), "on-chain", "file", 17);
kzg_evm_on_chain_input_prove_and_verify(test.to_string(), "on-chain", "file");
}
});
@@ -543,10 +526,10 @@ mod native_tests {
#(#[test_case(TESTS_ON_CHAIN_INPUT[N])])*
fn kzg_evm_on_chain_output_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
crate::native_tests::start_anvil();
kzg_evm_on_chain_input_prove_and_verify(test.to_string(), "file", "on-chain", 17);
kzg_evm_on_chain_input_prove_and_verify(test.to_string(), "file", "on-chain");
}
});
@@ -555,50 +538,50 @@ mod native_tests {
#(#[test_case(TESTS_ON_CHAIN_INPUT[N])])*
fn kzg_evm_on_chain_input_output_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
crate::native_tests::start_anvil();
kzg_evm_on_chain_input_prove_and_verify(test.to_string(), "on-chain", "on-chain", 17);
kzg_evm_on_chain_input_prove_and_verify(test.to_string(), "on-chain", "on-chain");
}
});
seq!(N in 0..= 17 {
seq!(N in 0..= 19 {
#(#[test_case(TESTS_EVM[N])])*
fn kzg_evm_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
crate::native_tests::start_anvil();
kzg_evm_prove_and_verify(test.to_string(), "private", "private", "public", 17);
kzg_evm_prove_and_verify(test.to_string(), "private", "private", "public");
}
#(#[test_case(TESTS_EVM[N])])*
fn kzg_evm_hashed_input_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
crate::native_tests::start_anvil();
kzg_evm_prove_and_verify(test.to_string(), "hashed", "private", "private", 17);
kzg_evm_prove_and_verify(test.to_string(), "hashed", "private", "private");
}
#(#[test_case(TESTS_EVM[N])])*
fn kzg_evm_hashed_params_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
crate::native_tests::start_anvil();
kzg_evm_prove_and_verify(test.to_string(), "private", "hashed", "public", 17);
kzg_evm_prove_and_verify(test.to_string(), "private", "hashed", "public");
}
#(#[test_case(TESTS_EVM[N])])*
fn kzg_evm_hashed_output_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_17();
crate::native_tests::mv_test_(test);
crate::native_tests::start_anvil();
kzg_evm_prove_and_verify(test.to_string(), "private", "private", "hashed", 17);
kzg_evm_prove_and_verify(test.to_string(), "private", "private", "hashed");
}
@@ -615,7 +598,6 @@ mod native_tests {
#[ignore]
fn kzg_evm_aggr_prove_and_verify_(test: &str) {
crate::native_tests::init_binary();
crate::native_tests::init_params_23();
crate::native_tests::mv_test_(test);
crate::native_tests::start_anvil();
kzg_evm_aggr_prove_and_verify(test.to_string());
@@ -913,6 +895,9 @@ mod native_tests {
.expect("failed to execute process");
assert!(status.success());
let srs_path = download_srs(23);
let srs_path = format!("--srs-path={}", srs_path);
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"setup",
@@ -922,7 +907,7 @@ mod native_tests {
&format!("{}/{}/key.pk", test_dir, example_name),
"--vk-path",
&format!("{}/{}/key.vk", test_dir, example_name),
&format!("--srs-path={}/kzg23.srs", TEST_DIR.path().to_str().unwrap()),
&srs_path,
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
@@ -942,7 +927,7 @@ mod native_tests {
&format!("{}/{}/proof.pf", test_dir, example_name),
"--pk-path",
&format!("{}/{}/key.pk", test_dir, example_name),
&format!("--srs-path={}/kzg23.srs", TEST_DIR.path().to_str().unwrap()),
&srs_path,
"--transcript=poseidon",
"--strategy=accum",
&format!(
@@ -963,7 +948,7 @@ mod native_tests {
&format!("{}/{}/aggr.pf", test_dir, example_name),
"--vk-path",
&format!("{}/{}/aggr.vk", test_dir, example_name),
&format!("--srs-path={}/kzg23.srs", TEST_DIR.path().to_str().unwrap()),
&srs_path,
"--transcript=blake",
])
.status()
@@ -977,7 +962,7 @@ mod native_tests {
&format!("{}/{}/aggr.pf", test_dir, example_name),
"--vk-path",
&format!("{}/{}/aggr.vk", test_dir, example_name),
&format!("--srs-path={}/kzg23.srs", TEST_DIR.path().to_str().unwrap()),
&srs_path,
])
.status()
.expect("failed to execute process");
@@ -1035,6 +1020,9 @@ mod native_tests {
.expect("failed to execute process");
assert!(status.success());
let srs_path = download_srs(23);
let srs_path = format!("--srs-path={}", srs_path);
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"setup",
@@ -1044,7 +1032,7 @@ mod native_tests {
&format!("{}/{}/evm.vk", test_dir, example_name),
"--pk-path",
&format!("{}/{}/evm.pk", test_dir, example_name),
&format!("--srs-path={}/kzg23.srs", test_dir),
&srs_path,
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
@@ -1065,7 +1053,7 @@ mod native_tests {
&format!("{}/{}/evm.pf", test_dir, example_name),
"--pk-path",
&format!("{}/{}/evm.pk", test_dir, example_name),
&format!("--srs-path={}/kzg23.srs", test_dir),
&srs_path,
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
@@ -1086,14 +1074,13 @@ mod native_tests {
&format!("{}/{}/evm_aggr.pf", test_dir, example_name),
"--vk-path",
&format!("{}/{}/evm_aggr.vk", test_dir, example_name),
&format!("--srs-path={}/kzg23.srs", test_dir),
&srs_path,
"--transcript=evm",
])
.status()
.expect("failed to execute process");
assert!(status.success());
let param_arg = format!("--srs-path={}/kzg23.srs", test_dir);
let vk_arg = format!("{}/{}/evm_aggr.vk", test_dir, example_name);
fn build_args<'a>(
@@ -1113,7 +1100,7 @@ mod native_tests {
let base_args = vec![
"create-evm-verifier-aggr",
param_arg.as_str(),
srs_path.as_str(),
"--vk-path",
vk_arg.as_str(),
];
@@ -1174,7 +1161,6 @@ mod native_tests {
// prove-serialize-verify, the usual full path
fn kzg_prove_and_verify(
example_name: String,
logrows: usize,
checkmode: &str,
input_visibility: &str,
param_visibility: &str,
@@ -1182,15 +1168,14 @@ mod native_tests {
) {
let test_dir = TEST_DIR.path().to_str().unwrap();
let settings_path = format!("{}/{}/settings.json", test_dir, example_name);
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"gen-settings",
"-M",
format!("{}/{}/network.onnx", test_dir, example_name).as_str(),
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
&format!("--input-visibility={}", input_visibility),
&format!("--param-visibility={}", param_visibility),
&format!("--output-visibility={}", output_visibility),
@@ -1206,15 +1191,15 @@ mod native_tests {
format!("{}/{}/input.json", test_dir, example_name).as_str(),
"-M",
format!("{}/{}/network.onnx", test_dir, example_name).as_str(),
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
])
.status()
.expect("failed to execute process");
assert!(status.success());
let srs_path = init_params(settings_path.clone().into());
let srs_path = format!("--srs-path={}", srs_path);
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"gen-witness",
@@ -1222,10 +1207,7 @@ mod native_tests {
format!("{}/{}/input.json", test_dir, example_name).as_str(),
"-M",
format!("{}/{}/network.onnx", test_dir, example_name).as_str(),
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
"-O",
format!("{}/{}/input.json", test_dir, example_name).as_str(),
])
@@ -1242,11 +1224,8 @@ mod native_tests {
&format!("{}/{}/key.pk", test_dir, example_name),
"--vk-path",
&format!("{}/{}/key.vk", test_dir, example_name),
&format!("--srs-path={}/kzg{}.srs", test_dir, logrows),
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
&srs_path,
format!("--settings-path={}", settings_path).as_str(),
])
.status()
.expect("failed to execute process");
@@ -1262,13 +1241,10 @@ mod native_tests {
&format!("{}/{}/proof.pf", test_dir, example_name),
"--pk-path",
&format!("{}/{}/key.pk", test_dir, example_name),
&format!("--srs-path={}/kzg{}.srs", test_dir, logrows),
&srs_path,
"--transcript=blake",
"--strategy=single",
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
&format!("--check-mode={}", checkmode),
])
.status()
@@ -1277,15 +1253,12 @@ mod native_tests {
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"verify",
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
"--proof-path",
&format!("{}/{}/proof.pf", test_dir, example_name),
"--vk-path",
&format!("{}/{}/key.vk", test_dir, example_name),
&format!("--srs-path={}/kzg{}.srs", test_dir, logrows),
&srs_path,
])
.status()
.expect("failed to execute process");
@@ -1350,20 +1323,18 @@ mod native_tests {
input_visibility: &str,
param_visibility: &str,
output_visibility: &str,
logrows: usize,
) {
let test_dir = TEST_DIR.path().to_str().unwrap();
let anvil_url = ANVIL_URL.as_str();
let settings_path = format!("{}/{}/settings.json", test_dir, example_name);
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"gen-settings",
"-M",
format!("{}/{}/network.onnx", test_dir, example_name).as_str(),
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
&format!("--input-visibility={}", input_visibility),
&format!("--param-visibility={}", param_visibility),
&format!("--output-visibility={}", output_visibility),
@@ -1379,15 +1350,15 @@ mod native_tests {
format!("{}/{}/input.json", test_dir, example_name).as_str(),
"-M",
format!("{}/{}/network.onnx", test_dir, example_name).as_str(),
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
])
.status()
.expect("failed to execute process");
assert!(status.success());
let srs_path = init_params(settings_path.clone().into());
let srs_path = format!("--srs-path={}", srs_path);
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"gen-witness",
@@ -1395,10 +1366,7 @@ mod native_tests {
format!("{}/{}/input.json", test_dir, example_name).as_str(),
"-M",
format!("{}/{}/network.onnx", test_dir, example_name).as_str(),
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
"-O",
format!("{}/{}/input.json", test_dir, example_name).as_str(),
])
@@ -1415,11 +1383,8 @@ mod native_tests {
&format!("{}/{}/key.pk", test_dir, example_name),
"--vk-path",
&format!("{}/{}/key.vk", test_dir, example_name),
&format!("--srs-path={}/kzg{}.srs", test_dir, logrows),
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
&srs_path,
format!("--settings-path={}", settings_path).as_str(),
])
.status()
.expect("failed to execute process");
@@ -1436,34 +1401,27 @@ mod native_tests {
&format!("{}/{}/proof.pf", test_dir, example_name),
"--pk-path",
&format!("{}/{}/key.pk", test_dir, example_name),
&format!("--srs-path={}/kzg{}.srs", test_dir, logrows),
&srs_path,
"--transcript=evm",
"--strategy=single",
&format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
),
format!("--settings-path={}", settings_path).as_str(),
])
.status()
.expect("failed to execute process");
assert!(status.success());
let circuit_settings = format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
);
let vk_arg = format!("{}/{}/key.vk", test_dir, example_name);
let param_arg = format!("--srs-path={}/kzg{}.srs", test_dir, logrows);
let rpc_arg = format!("--rpc-url={}", anvil_url);
let addr_path_arg = format!("--addr-path={}/{}/addr.txt", test_dir, example_name);
let settings_arg = format!("--settings-path={}", settings_path);
// create the verifier
let mut args = vec![
"create-evm-verifier",
param_arg.as_str(),
&srs_path,
"--vk-path",
vk_arg.as_str(),
circuit_settings.as_str(),
&vk_arg,
&settings_arg,
];
let sol_arg = format!("{}/{}/kzg.sol", test_dir, example_name);
@@ -1528,7 +1486,6 @@ mod native_tests {
example_name: String,
input_source: &str,
output_source: &str,
logrows: usize,
) {
let test_dir = TEST_DIR.path().to_str().unwrap();
@@ -1536,17 +1493,14 @@ mod native_tests {
let input_visbility = "public";
let output_visbility = "public";
let model_path = format!("{}/{}/network.onnx", test_dir, example_name);
let circuit_settings = format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
);
let settings_path = format!("{}/{}/settings.json", test_dir, example_name);
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"gen-settings",
"-M",
model_path.as_str(),
circuit_settings.as_str(),
&model_path,
format!("--settings-path={}", settings_path).as_str(),
&format!("--input-visibility={}", input_visbility),
&format!("--output-visibility={}", output_visbility),
"--param-visibility=private",
@@ -1557,6 +1511,9 @@ mod native_tests {
.expect("failed to execute process");
assert!(status.success());
let srs_path = download_srs(17);
let srs_path = format!("--srs-path={}", srs_path);
let data_path = format!("{}/{}/input.json", test_dir, example_name);
let witness_path = format!("{}/{}/witness.json", test_dir, example_name);
let test_on_chain_data_path = format!("{}/{}/on_chain_input.json", test_dir, example_name);
@@ -1571,8 +1528,8 @@ mod native_tests {
"-D",
data_path.as_str(),
"-M",
model_path.as_str(),
circuit_settings.as_str(),
&model_path,
format!("--settings-path={}", settings_path).as_str(),
"--test-data",
test_on_chain_data_path.as_str(),
rpc_arg.as_str(),
@@ -1589,10 +1546,10 @@ mod native_tests {
"-D",
test_on_chain_data_path.as_str(),
"-M",
model_path.as_str(),
circuit_settings.as_str(),
&model_path,
format!("--settings-path={}", settings_path).as_str(),
"-O",
witness_path.as_str(),
&witness_path,
])
.status()
.expect("failed to execute process");
@@ -1602,13 +1559,13 @@ mod native_tests {
.args([
"setup",
"-M",
model_path.as_str(),
&model_path,
"--pk-path",
&format!("{}/{}/key.pk", test_dir, example_name),
"--vk-path",
&format!("{}/{}/key.vk", test_dir, example_name),
&format!("--srs-path={}/kzg{}.srs", test_dir, logrows),
circuit_settings.as_str(),
&srs_path,
format!("--settings-path={}", settings_path).as_str(),
])
.status()
.expect("failed to execute process");
@@ -1618,28 +1575,23 @@ mod native_tests {
.args([
"prove",
"-W",
witness_path.as_str(),
&witness_path,
"-M",
model_path.as_str(),
&model_path,
"--proof-path",
&format!("{}/{}/proof.pf", test_dir, example_name),
"--pk-path",
&format!("{}/{}/key.pk", test_dir, example_name),
&format!("--srs-path={}/kzg{}.srs", test_dir, logrows),
&srs_path,
"--transcript=evm",
"--strategy=single",
circuit_settings.as_str(),
format!("--settings-path={}", settings_path).as_str(),
])
.status()
.expect("failed to execute process");
assert!(status.success());
let circuit_settings = format!(
"--settings-path={}/{}/settings.json",
test_dir, example_name
);
let vk_arg = format!("{}/{}/key.vk", test_dir, example_name);
let param_arg = format!("--srs-path={}/kzg{}.srs", test_dir, logrows);
let sol_arg = format!("{}/{}/kzg.sol", test_dir, example_name);
@@ -1647,12 +1599,12 @@ mod native_tests {
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"create-evm-da-verifier",
circuit_settings.as_str(),
format!("--settings-path={}", settings_path).as_str(),
"--sol-code-path",
sol_arg.as_str(),
param_arg.as_str(),
&srs_path,
"--vk-path",
vk_arg.as_str(),
&vk_arg,
"-D",
test_on_chain_data_path.as_str()
])
@@ -1664,7 +1616,7 @@ mod native_tests {
let status = Command::new(format!("{}/release/ezkl", *CARGO_TARGET_DIR))
.args([
"deploy-evm-da-verifier",
circuit_settings.as_str(),
format!("--settings-path={}", settings_path).as_str(),
"-D",
test_on_chain_data_path.as_str(),
"--sol-code-path",