mirror of
https://github.com/zkonduit/ezkl.git
synced 2026-01-10 06:48:01 -05:00
chore: cleanup integration tests (#600)
This commit is contained in:
31
.github/workflows/rust.yml
vendored
31
.github/workflows/rust.yml
vendored
@@ -109,8 +109,6 @@ jobs:
|
||||
with:
|
||||
crate: cargo-nextest
|
||||
locked: true
|
||||
- name: Model serialization
|
||||
run: cargo nextest run native_tests::tests::model_serialization_::t
|
||||
- name: Model serialization different binary ID
|
||||
run: cargo nextest run native_tests::tests::model_serialization_different_binaries_ --test-threads 1
|
||||
|
||||
@@ -326,7 +324,7 @@ jobs:
|
||||
run: |
|
||||
sed -i "3s|.*|imports['env'] = {memory: new WebAssembly.Memory({initial:20,maximum:65536,shared:true})}|" tests/wasm/nodejs/ezkl.js
|
||||
- name: KZG prove and verify tests double inner col
|
||||
run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_double_col
|
||||
run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_single_col
|
||||
- name: KZG prove and verify tests triple inner col
|
||||
run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_triple_col
|
||||
- name: KZG prove and verify tests quadruple inner col
|
||||
@@ -451,23 +449,6 @@ jobs:
|
||||
- name: Examples
|
||||
run: cargo nextest run --release tests_examples
|
||||
|
||||
neg-tests:
|
||||
runs-on: self-hosted
|
||||
needs: [build, library-tests, docs]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly-2023-08-24
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
- uses: baptiste0928/cargo-install@v1
|
||||
with:
|
||||
crate: cargo-nextest
|
||||
locked: true
|
||||
- name: should fail)
|
||||
run: cargo nextest run neg_tests::neg_examples_
|
||||
|
||||
python-tests:
|
||||
runs-on: self-hosted
|
||||
needs: [build, library-tests, docs]
|
||||
@@ -514,11 +495,11 @@ jobs:
|
||||
- name: Build python ezkl
|
||||
run: source .env/bin/activate; maturin develop --features python-bindings --release
|
||||
- name: Public inputs
|
||||
run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_public_inputs_ --no-capture
|
||||
run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_public_inputs_
|
||||
- name: fixed params
|
||||
run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_fixed_params_ --no-capture
|
||||
run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_fixed_params_
|
||||
- name: Public outputs
|
||||
run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_public_outputs_ --no-capture
|
||||
run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_public_outputs_
|
||||
|
||||
python-integration-tests:
|
||||
runs-on:
|
||||
@@ -591,8 +572,8 @@ jobs:
|
||||
run: source .env/bin/activate; cargo nextest run py_tests::tests::run_notebook_::tests_27_expects
|
||||
- name: KZG Vis demo
|
||||
run: source .env/bin/activate; cargo nextest run py_tests::tests::run_notebook_::tests_26_expects
|
||||
- name: Simple hub demo
|
||||
run: source .env/bin/activate; cargo nextest run py_tests::tests::run_notebook_::tests_25_expects
|
||||
# - name: Simple hub demo
|
||||
# run: source .env/bin/activate; cargo nextest run py_tests::tests::run_notebook_::tests_25_expects
|
||||
- name: Hashed DA tutorial
|
||||
run: source .env/bin/activate; cargo nextest run py_tests::tests::run_notebook_::tests_24_expects
|
||||
- name: Little transformer tutorial
|
||||
|
||||
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -1213,7 +1213,7 @@ checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30"
|
||||
[[package]]
|
||||
name = "ecc"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zkonduit/halo2wrong?branch=ac/chunked-mv-lookup#be37b4e1d21b1839e42fcca4414584e56295604f"
|
||||
source = "git+https://github.com/zkonduit/halo2wrong?branch=ac/chunked-mv-lookup#662abfc029ec236dfbcb6cd47feeccd9d5bfa51d"
|
||||
dependencies = [
|
||||
"integer",
|
||||
"num-bigint",
|
||||
@@ -2086,7 +2086,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "halo2_gadgets"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/zkonduit/halo2?branch=ac/optional-unblinded-advice#db9315e8543d6717039c151a9cbfc55b57d90fff"
|
||||
source = "git+https://github.com/zkonduit/halo2?branch=ac/more-informative-errors#ea8f3e1e002ebc840b64a7d57ca6b6c79ae6ce3f"
|
||||
dependencies = [
|
||||
"arrayvec 0.7.4",
|
||||
"bitvec 1.0.1",
|
||||
@@ -2103,7 +2103,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "halo2_proofs"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/zkonduit/halo2?branch=ac/optional-unblinded-advice#db9315e8543d6717039c151a9cbfc55b57d90fff"
|
||||
source = "git+https://github.com/zkonduit/halo2?branch=ac/more-informative-errors#ea8f3e1e002ebc840b64a7d57ca6b6c79ae6ce3f"
|
||||
dependencies = [
|
||||
"blake2b_simd",
|
||||
"env_logger",
|
||||
@@ -2123,7 +2123,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "halo2_solidity_verifier"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/alexander-camuto/halo2-solidity-verifier?branch=ac/chunked-lookup-verifier#8cf26f3164ce7e21b4323adf754833e684efdba1"
|
||||
source = "git+https://github.com/alexander-camuto/halo2-solidity-verifier?branch=ac/chunked-lookup-verifier#3b1ef2fa0443ce6caa42a4c2465b86a1e95b0ae3"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"blake2b_simd",
|
||||
@@ -2177,7 +2177,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "halo2wrong"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zkonduit/halo2wrong?branch=ac/chunked-mv-lookup#be37b4e1d21b1839e42fcca4414584e56295604f"
|
||||
source = "git+https://github.com/zkonduit/halo2wrong?branch=ac/chunked-mv-lookup#662abfc029ec236dfbcb6cd47feeccd9d5bfa51d"
|
||||
dependencies = [
|
||||
"halo2_proofs",
|
||||
"num-bigint",
|
||||
@@ -2485,7 +2485,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "integer"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zkonduit/halo2wrong?branch=ac/chunked-mv-lookup#be37b4e1d21b1839e42fcca4414584e56295604f"
|
||||
source = "git+https://github.com/zkonduit/halo2wrong?branch=ac/chunked-mv-lookup#662abfc029ec236dfbcb6cd47feeccd9d5bfa51d"
|
||||
dependencies = [
|
||||
"maingate",
|
||||
"num-bigint",
|
||||
@@ -2721,7 +2721,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
|
||||
[[package]]
|
||||
name = "maingate"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zkonduit/halo2wrong?branch=ac/chunked-mv-lookup#be37b4e1d21b1839e42fcca4414584e56295604f"
|
||||
source = "git+https://github.com/zkonduit/halo2wrong?branch=ac/chunked-mv-lookup#662abfc029ec236dfbcb6cd47feeccd9d5bfa51d"
|
||||
dependencies = [
|
||||
"halo2wrong",
|
||||
"num-bigint",
|
||||
@@ -4511,7 +4511,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snark-verifier"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zkonduit/snark-verifier?branch=ac/chunked-mv-lookup#8e2e99279469c654d7084116f2eefe5db7caea27"
|
||||
source = "git+https://github.com/zkonduit/snark-verifier?branch=ac/chunked-mv-lookup#8b866a77560a3a660eba2236153b98e1d442cd67"
|
||||
dependencies = [
|
||||
"ecc",
|
||||
"halo2_proofs",
|
||||
|
||||
@@ -13,8 +13,8 @@ crate-type = ["cdylib", "rlib"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
halo2_gadgets = { git = "https://github.com/zkonduit/halo2", branch= "ac/optional-unblinded-advice" }
|
||||
halo2_proofs = { git = "https://github.com/zkonduit/halo2", branch= "ac/optional-unblinded-advice" }
|
||||
halo2_gadgets = { git = "https://github.com/zkonduit/halo2", branch= "ac/more-informative-errors" }
|
||||
halo2_proofs = { git = "https://github.com/zkonduit/halo2", branch= "ac/more-informative-errors" }
|
||||
halo2curves = { version = "0.1.0" }
|
||||
rand = { version = "0.8", default_features = false }
|
||||
itertools = { version = "0.10.3", default_features = false }
|
||||
|
||||
@@ -1 +1,49 @@
|
||||
{"input_data":[[0.053262424,0.074970566,0.052355476,0.028825462,0.058487028,0.008225823,0.07530029,0.0821458,0.06227987,0.024306035,0.05793174,0.04044203]],"output_data":[[0.0546875,0.1328125,0.078125,0.109375,0.21875,0.109375,0.0546875,0.0859375,0.03125,0.0546875,0.0625,0.0078125,0.1328125,0.2265625,0.09375,0.078125,0.1640625,0.0859375,0.0625,0.0859375,0.0234375,0.1171875,0.1796875,0.0625,0.0546875,0.09375,0.0390625]]}
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
0.053262424,
|
||||
0.074970566,
|
||||
0.052355476,
|
||||
0.028825462,
|
||||
0.058487028,
|
||||
0.008225823,
|
||||
0.07530029,
|
||||
0.0821458,
|
||||
0.06227987,
|
||||
0.024306035,
|
||||
0.05793174,
|
||||
0.04044203
|
||||
]
|
||||
],
|
||||
"output_data": [
|
||||
[
|
||||
0.0546875,
|
||||
0.12890625,
|
||||
0.07421875,
|
||||
0.10546875,
|
||||
0.20703125,
|
||||
0.1015625,
|
||||
0.05078125,
|
||||
0.078125,
|
||||
0.02734375,
|
||||
0.05859375,
|
||||
0.06640625,
|
||||
0.0078125,
|
||||
0.1328125,
|
||||
0.22265625,
|
||||
0.08984375,
|
||||
0.07421875,
|
||||
0.15625,
|
||||
0.08203125,
|
||||
0.0625,
|
||||
0.0859375,
|
||||
0.0234375,
|
||||
0.12109375,
|
||||
0.18359375,
|
||||
0.0625,
|
||||
0.05859375,
|
||||
0.09765625,
|
||||
0.0390625
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -13,9 +13,9 @@
|
||||
],
|
||||
"output_data": [
|
||||
[
|
||||
0.4453125,
|
||||
0.1328125,
|
||||
0.734375
|
||||
0.4427490234375,
|
||||
0.128173828125,
|
||||
0.7335205078125
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -1 +1,21 @@
|
||||
{"input_data":[[0.061490554,0.040096022,0.027487868]],"input_shapes":[[3]],"output_data":[[0.0625,0.0390625,0.03125]]}
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
0.061490554,
|
||||
0.040096022,
|
||||
0.027487868
|
||||
]
|
||||
],
|
||||
"input_shapes": [
|
||||
[
|
||||
3
|
||||
]
|
||||
],
|
||||
"output_data": [
|
||||
[
|
||||
0.0625,
|
||||
0.0390625,
|
||||
0.02734375
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -25,15 +25,15 @@
|
||||
],
|
||||
"output_data": [
|
||||
[
|
||||
0.015625,
|
||||
0.01953125,
|
||||
0.015625,
|
||||
0.0859375,
|
||||
0.015625,
|
||||
0.0546875,
|
||||
0.0703125,
|
||||
0.0390625,
|
||||
0.01171875,
|
||||
0.05078125,
|
||||
0.06640625,
|
||||
0.03515625,
|
||||
0.046875,
|
||||
0.0390625,
|
||||
0.03515625,
|
||||
0.0078125,
|
||||
0.0546875,
|
||||
0.0078125
|
||||
|
||||
@@ -1 +1,22 @@
|
||||
{"input_data":[[0.06625451,0.022532081,0.025727034,0.062369008,0.093028985,0.01173302]],"output_data":[[0.0625,0.0234375,0.0234375,0.0625,0.09375,0.015625]]}
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
0.06625451,
|
||||
0.022532081,
|
||||
0.025727034,
|
||||
0.062369008,
|
||||
0.093028985,
|
||||
0.01173302
|
||||
]
|
||||
],
|
||||
"output_data": [
|
||||
[
|
||||
0.06625451,
|
||||
0.022532081,
|
||||
0.025727034,
|
||||
0.062369008,
|
||||
0.093028985,
|
||||
0.01173302
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -13,8 +13,8 @@
|
||||
],
|
||||
"output_data": [
|
||||
[
|
||||
0.1953125,
|
||||
0.0859375,
|
||||
0.20703125,
|
||||
0.08984375,
|
||||
0.3046875
|
||||
]
|
||||
]
|
||||
|
||||
@@ -1 +1,22 @@
|
||||
{"input_data":[[0.048659664,0.040321846,0.092751384,0.058180947,0.019983828,0.096692465,0.07317094,0.06064367,0.052526843]],"output_data":[[0.0,0.0,0.0]]}
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
0.048659664,
|
||||
0.040321846,
|
||||
0.092751384,
|
||||
0.058180947,
|
||||
0.019983828,
|
||||
0.096692465,
|
||||
0.07317094,
|
||||
0.06064367,
|
||||
0.052526843
|
||||
]
|
||||
],
|
||||
"output_data": [
|
||||
[
|
||||
0.0001018,
|
||||
0.00025,
|
||||
0.00036
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
],
|
||||
"output_data": [
|
||||
[
|
||||
0.015625
|
||||
0.012031913
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -9,3 +9,6 @@ pytest==7.2.2
|
||||
tomli==2.0.1
|
||||
typing-extensions==4.5.0
|
||||
zipp==3.15.0
|
||||
onnx==1.14.1
|
||||
onnxruntime==1.14.1
|
||||
numpy==1.21.6
|
||||
@@ -324,6 +324,7 @@ impl<F: PrimeField + TensorType + PartialOrd> BaseConfig<F> {
|
||||
}
|
||||
|
||||
/// Configures and creates lookup selectors
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn configure_lookup(
|
||||
&mut self,
|
||||
cs: &mut ConstraintSystem<F>,
|
||||
|
||||
@@ -2009,7 +2009,7 @@ pub fn conv<F: PrimeField + TensorType + PartialOrd + std::marker::Send + std::m
|
||||
local_kernel.flatten();
|
||||
|
||||
// this is dot product notation in einsum format
|
||||
let mut res = einsum(config, region, &mut [local_image, local_kernel], "i,i->").unwrap();
|
||||
let mut res = einsum(config, region, &[local_image, local_kernel], "i,i->").unwrap();
|
||||
|
||||
if has_bias {
|
||||
let bias = values[2].get_single_elem(start_kernel_index).unwrap();
|
||||
|
||||
@@ -260,7 +260,7 @@ impl<F: PrimeField + TensorType + PartialOrd + Serialize + for<'de> Deserialize<
|
||||
}
|
||||
PolyOp::Neg => layouts::neg(config, region, values[..].try_into()?)?,
|
||||
PolyOp::Iff => layouts::iff(config, region, values[..].try_into()?)?,
|
||||
PolyOp::Einsum { equation } => layouts::einsum(config, region, &mut values, equation)?,
|
||||
PolyOp::Einsum { equation } => layouts::einsum(config, region, &values, equation)?,
|
||||
PolyOp::Sum { axes } => {
|
||||
layouts::sum_axes(config, region, values[..].try_into()?, axes)?
|
||||
}
|
||||
|
||||
@@ -256,9 +256,11 @@ pub async fn deploy_da_verifier_via_solidity(
|
||||
Ok(contract.address())
|
||||
}
|
||||
|
||||
type ParsedCallsToAccount = (Vec<H160>, Vec<Vec<Bytes>>, Vec<Vec<U256>>);
|
||||
|
||||
fn parse_calls_to_accounts(
|
||||
calls_to_accounts: Vec<CallsToAccount>,
|
||||
) -> Result<(Vec<H160>, Vec<Vec<Bytes>>, Vec<Vec<U256>>), Box<dyn Error>> {
|
||||
) -> Result<ParsedCallsToAccount, Box<dyn Error>> {
|
||||
let mut contract_addresses = vec![];
|
||||
let mut call_data = vec![];
|
||||
let mut decimals: Vec<Vec<U256>> = vec![];
|
||||
|
||||
@@ -1410,7 +1410,9 @@ pub(crate) async fn fuzz(
|
||||
info!("fuzzing public inputs");
|
||||
|
||||
let fuzz_public_inputs = || {
|
||||
let bad_inputs = vec![Fr::random(rand::rngs::OsRng); public_inputs.len()];
|
||||
let bad_inputs: Vec<Fr> = (0..public_inputs.len())
|
||||
.map(|_| Fr::random(rand::rngs::OsRng))
|
||||
.collect();
|
||||
|
||||
let bad_proof = create_proof_circuit_kzg(
|
||||
circuit.clone(),
|
||||
@@ -1422,7 +1424,7 @@ pub(crate) async fn fuzz(
|
||||
CheckMode::UNSAFE,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
.map_err(|_| ())?;
|
||||
|
||||
verify_proof_circuit_kzg(
|
||||
params.verifier_params(),
|
||||
@@ -1499,9 +1501,14 @@ pub(crate) async fn fuzz(
|
||||
info!("fuzzing proof instances");
|
||||
|
||||
let fuzz_proof_instances = || {
|
||||
let mut bad_inputs = vec![];
|
||||
let mut bad_inputs = vec![vec![]];
|
||||
|
||||
for l in &proof.instances {
|
||||
bad_inputs.push(vec![Fr::random(rand::rngs::OsRng); l.len()]);
|
||||
bad_inputs.push(
|
||||
(0..l.len())
|
||||
.map(|_| Fr::random(rand::rngs::OsRng))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
let bad_proof = Snark::<_, _> {
|
||||
@@ -1637,6 +1644,7 @@ pub(crate) fn setup_aggregate(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn aggregate(
|
||||
proof_path: PathBuf,
|
||||
aggregation_snarks: Vec<PathBuf>,
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
missing_debug_implementations,
|
||||
unsafe_code
|
||||
)]
|
||||
// we allow this for our dynamic range based indexing scheme
|
||||
#![allow(clippy::single_range_in_vec_init)]
|
||||
#![feature(round_ties_even)]
|
||||
|
||||
//! A library for turning computational graphs, such as neural networks, into ZK-circuits.
|
||||
|
||||
@@ -72,6 +72,25 @@ pub enum AggregationError {
|
||||
ProofCreate,
|
||||
}
|
||||
|
||||
type AggregationResult<'a> = (
|
||||
// accumulator
|
||||
KzgAccumulator<G1Affine, Rc<Halo2Loader<'a>>>,
|
||||
// the set of assigned cells
|
||||
Vec<Vec<AssignedCell<Fr, Fr>>>,
|
||||
);
|
||||
|
||||
type LoadedProof<'a> = verifier::plonk::PlonkProof<
|
||||
G1Affine,
|
||||
Rc<
|
||||
loader::halo2::Halo2Loader<
|
||||
'a,
|
||||
G1Affine,
|
||||
halo2_wrong_ecc::BaseFieldEccChip<G1Affine, 4, 68>,
|
||||
>,
|
||||
>,
|
||||
KzgAs<Bn256, Bdfg21>,
|
||||
>;
|
||||
|
||||
/// Aggregate one or more application snarks of the same shape into a KzgAccumulator
|
||||
pub fn aggregate<'a>(
|
||||
svk: &Svk,
|
||||
@@ -79,13 +98,7 @@ pub fn aggregate<'a>(
|
||||
snarks: &[SnarkWitness<Fr, G1Affine>],
|
||||
as_proof: Value<&'_ [u8]>,
|
||||
split_proofs: bool,
|
||||
) -> Result<
|
||||
(
|
||||
KzgAccumulator<G1Affine, Rc<Halo2Loader<'a>>>,
|
||||
Vec<Vec<AssignedCell<Fr, Fr>>>,
|
||||
),
|
||||
plonk::Error,
|
||||
> {
|
||||
) -> Result<AggregationResult<'a>, plonk::Error> {
|
||||
let assign_instances = |instances: &[Vec<Value<Fr>>]| {
|
||||
instances
|
||||
.iter()
|
||||
@@ -100,19 +113,7 @@ pub fn aggregate<'a>(
|
||||
|
||||
let mut accumulators = vec![];
|
||||
let mut snark_instances = vec![];
|
||||
let mut proofs: Vec<
|
||||
verifier::plonk::PlonkProof<
|
||||
G1Affine,
|
||||
Rc<
|
||||
loader::halo2::Halo2Loader<
|
||||
'_,
|
||||
G1Affine,
|
||||
halo2_wrong_ecc::BaseFieldEccChip<G1Affine, 4, 68>,
|
||||
>,
|
||||
>,
|
||||
KzgAs<Bn256, Bdfg21>,
|
||||
>,
|
||||
> = vec![];
|
||||
let mut proofs: Vec<LoadedProof<'_>> = vec![];
|
||||
|
||||
for snark in snarks.iter() {
|
||||
let protocol = snark.protocol.as_ref().unwrap().loaded(loader);
|
||||
|
||||
@@ -409,6 +409,7 @@ where
|
||||
}
|
||||
|
||||
/// a wrapper around halo2's create_proof
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn create_proof_circuit<
|
||||
'params,
|
||||
Scheme: CommitmentScheme,
|
||||
@@ -505,7 +506,6 @@ where
|
||||
|
||||
/// Swaps the proof commitments to a new set in the proof
|
||||
pub fn swap_proof_commitments<
|
||||
'params,
|
||||
F: PrimeField,
|
||||
Scheme: CommitmentScheme,
|
||||
E: EncodedChallenge<Scheme::Curve>,
|
||||
@@ -693,6 +693,7 @@ pub fn save_params<Scheme: CommitmentScheme>(
|
||||
}
|
||||
|
||||
/// helper function
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn create_proof_circuit_kzg<
|
||||
'params,
|
||||
C: Circuit<Fr>,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::circuit::modules::elgamal::{ElGamalCipher, ElGamalVariables};
|
||||
use crate::circuit::modules::kzg::KZGChip;
|
||||
use crate::circuit::modules::poseidon::{
|
||||
spec::{PoseidonSpec, POSEIDON_RATE, POSEIDON_WIDTH},
|
||||
PoseidonChip,
|
||||
@@ -13,7 +14,8 @@ use crate::graph::{
|
||||
};
|
||||
use crate::pfsys::evm::aggregation::AggregationCircuit;
|
||||
use crate::pfsys::{
|
||||
load_pk, save_params, load_vk, save_vk, srs::gen_srs as ezkl_gen_srs, srs::load_srs, ProofType, Snark, TranscriptType,
|
||||
load_pk, load_vk, save_params, save_vk, srs::gen_srs as ezkl_gen_srs, srs::load_srs, ProofType,
|
||||
Snark, TranscriptType,
|
||||
};
|
||||
use crate::RunArgs;
|
||||
use ethers::types::H160;
|
||||
@@ -29,7 +31,6 @@ use snark_verifier::util::arithmetic::PrimeField;
|
||||
use std::str::FromStr;
|
||||
use std::{fs::File, path::PathBuf};
|
||||
use tokio::runtime::Runtime;
|
||||
use crate::circuit::modules::kzg::KZGChip;
|
||||
|
||||
type PyFelt = [u64; 4];
|
||||
|
||||
@@ -448,15 +449,19 @@ fn poseidon_hash(message: Vec<PyFelt>) -> PyResult<Vec<PyFelt>> {
|
||||
Ok(hash)
|
||||
}
|
||||
|
||||
|
||||
/// Generate a kzg commitment.
|
||||
#[pyfunction(signature = (
|
||||
message,
|
||||
srs_path,
|
||||
vk_path,
|
||||
srs_path,
|
||||
vk_path,
|
||||
settings_path
|
||||
))]
|
||||
fn kzg_commit(message: Vec<PyFelt>, srs_path: PathBuf, vk_path: PathBuf, settings_path: PathBuf) -> PyResult<Vec<PyG1Affine>> {
|
||||
fn kzg_commit(
|
||||
message: Vec<PyFelt>,
|
||||
srs_path: PathBuf,
|
||||
vk_path: PathBuf,
|
||||
settings_path: PathBuf,
|
||||
) -> PyResult<Vec<PyG1Affine>> {
|
||||
let message: Vec<Fr> = message
|
||||
.iter()
|
||||
.map(|x| crate::pfsys::vecu64_to_field_montgomery::<Fr>(&x))
|
||||
@@ -471,30 +476,28 @@ fn kzg_commit(message: Vec<PyFelt>, srs_path: PathBuf, vk_path: PathBuf, setting
|
||||
let vk = load_vk::<KZGCommitmentScheme<Bn256>, Fr, GraphCircuit>(vk_path, settings)
|
||||
.map_err(|_| PyIOError::new_err("Failed to load vk"))?;
|
||||
|
||||
let output = KZGChip::commit(message, vk.cs().degree() as u32, (vk.cs().blinding_factors() + 1) as u32, &srs);
|
||||
let output = KZGChip::commit(
|
||||
message,
|
||||
vk.cs().degree() as u32,
|
||||
(vk.cs().blinding_factors() + 1) as u32,
|
||||
&srs,
|
||||
);
|
||||
|
||||
|
||||
Ok(output
|
||||
.iter()
|
||||
.map(|x| (*x).into())
|
||||
.collect::<Vec<_>>())
|
||||
Ok(output.iter().map(|x| (*x).into()).collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
/// Swap the commitments in a proof
|
||||
#[pyfunction(signature = (
|
||||
proof_path,
|
||||
witness_path,
|
||||
witness_path,
|
||||
))]
|
||||
fn swap_proof_commitments(proof_path: PathBuf, witness_path: PathBuf) -> PyResult<()> {
|
||||
|
||||
crate::execute::swap_proof_commitments(proof_path, witness_path)
|
||||
.map_err(|_| PyIOError::new_err("Failed to swap commitments"))?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Encrypt using elgamal
|
||||
#[pyfunction(signature = (
|
||||
pk, message, r
|
||||
@@ -705,13 +708,21 @@ fn calibrate_settings(
|
||||
data,
|
||||
model,
|
||||
output,
|
||||
vk_path=None,
|
||||
vk_path=None,
|
||||
srs_path=None,
|
||||
))]
|
||||
fn gen_witness(data: PathBuf, model: PathBuf, output: Option<PathBuf>, vk_path: Option<PathBuf>, srs_path: Option<PathBuf>) -> PyResult<PyObject> {
|
||||
fn gen_witness(
|
||||
data: PathBuf,
|
||||
model: PathBuf,
|
||||
output: Option<PathBuf>,
|
||||
vk_path: Option<PathBuf>,
|
||||
srs_path: Option<PathBuf>,
|
||||
) -> PyResult<PyObject> {
|
||||
let output = Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(crate::execute::gen_witness(model, data, output, vk_path, srs_path))
|
||||
.block_on(crate::execute::gen_witness(
|
||||
model, data, output, vk_path, srs_path,
|
||||
))
|
||||
.map_err(|e| {
|
||||
let err_str = format!("Failed to run generate witness: {}", e);
|
||||
PyRuntimeError::new_err(err_str)
|
||||
@@ -742,7 +753,11 @@ fn mock(witness: PathBuf, model: PathBuf) -> PyResult<bool> {
|
||||
logrows,
|
||||
split_proofs = false,
|
||||
))]
|
||||
fn mock_aggregate(aggregation_snarks: Vec<PathBuf>, logrows: u32, split_proofs: bool) -> PyResult<bool> {
|
||||
fn mock_aggregate(
|
||||
aggregation_snarks: Vec<PathBuf>,
|
||||
logrows: u32,
|
||||
split_proofs: bool,
|
||||
) -> PyResult<bool> {
|
||||
crate::execute::mock_aggregate(aggregation_snarks, logrows, split_proofs).map_err(|e| {
|
||||
let err_str = format!("Failed to run mock: {}", e);
|
||||
PyRuntimeError::new_err(err_str)
|
||||
@@ -847,12 +862,18 @@ fn setup_aggregate(
|
||||
logrows: u32,
|
||||
split_proofs: bool,
|
||||
) -> Result<bool, PyErr> {
|
||||
crate::execute::setup_aggregate(sample_snarks, vk_path, pk_path, srs_path, logrows, split_proofs).map_err(
|
||||
|e| {
|
||||
let err_str = format!("Failed to setup aggregate: {}", e);
|
||||
PyRuntimeError::new_err(err_str)
|
||||
},
|
||||
)?;
|
||||
crate::execute::setup_aggregate(
|
||||
sample_snarks,
|
||||
vk_path,
|
||||
pk_path,
|
||||
srs_path,
|
||||
logrows,
|
||||
split_proofs,
|
||||
)
|
||||
.map_err(|e| {
|
||||
let err_str = format!("Failed to setup aggregate: {}", e);
|
||||
PyRuntimeError::new_err(err_str)
|
||||
})?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@@ -307,10 +307,7 @@ impl<F: PrimeField + TensorType + PartialOrd> ValTensor<F> {
|
||||
|
||||
///
|
||||
pub fn is_instance(&self) -> bool {
|
||||
match self {
|
||||
ValTensor::Instance { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, ValTensor::Instance { .. })
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
@@ -293,7 +293,6 @@ impl VarTensor {
|
||||
constant: F,
|
||||
) -> Result<AssignedCell<F, F>, halo2_proofs::plonk::Error> {
|
||||
let (x, y, z) = self.cartesian_coord(offset);
|
||||
|
||||
match &self {
|
||||
VarTensor::Advice { inner: advices, .. } => {
|
||||
region.assign_advice_from_constant(|| "constant", advices[x][y], z, constant)
|
||||
@@ -320,10 +319,7 @@ impl VarTensor {
|
||||
if omissions.contains(&coord) {
|
||||
return Ok(k);
|
||||
}
|
||||
let (x, y, z) = self.cartesian_coord(offset + assigned_coord);
|
||||
let cell =
|
||||
self.assign_value(region, offset, k.clone(), x, y, z, assigned_coord)?;
|
||||
|
||||
let cell = self.assign_value(region, offset, k.clone(), assigned_coord)?;
|
||||
assigned_coord += 1;
|
||||
|
||||
match k {
|
||||
@@ -384,9 +380,7 @@ impl VarTensor {
|
||||
},
|
||||
ValTensor::Value { inner: v, .. } => Ok(v
|
||||
.enum_map(|coord, k| {
|
||||
let (x, y, z) = self.cartesian_coord(offset + coord);
|
||||
let cell = self.assign_value(region, offset, k.clone(), x, y, z, coord)?;
|
||||
|
||||
let cell = self.assign_value(region, offset, k.clone(), coord)?;
|
||||
match k {
|
||||
ValType::Constant(f) => Ok::<ValType<F>, halo2_proofs::plonk::Error>(
|
||||
ValType::AssignedConstant(cell, f),
|
||||
@@ -498,7 +492,7 @@ impl VarTensor {
|
||||
assert_eq!(Into::<i32>::into(k.clone()), Into::<i32>::into(v[coord - 1].clone()));
|
||||
};
|
||||
|
||||
let cell = self.assign_value(region, offset, k.clone(), x, y, z, coord * step)?;
|
||||
let cell = self.assign_value(region, offset, k.clone(), coord * step)?;
|
||||
|
||||
if single_inner_col {
|
||||
if z == 0 {
|
||||
@@ -555,11 +549,9 @@ impl VarTensor {
|
||||
region: &mut Region<F>,
|
||||
offset: usize,
|
||||
k: ValType<F>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
z: usize,
|
||||
coord: usize,
|
||||
) -> Result<AssignedCell<F, F>, halo2_proofs::plonk::Error> {
|
||||
let (x, y, z) = self.cartesian_coord(offset + coord);
|
||||
match k {
|
||||
ValType::Value(v) => match &self {
|
||||
VarTensor::Advice { inner: advices, .. } => {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,9 +32,9 @@ describe('Generate witness, prove and verify', () => {
|
||||
|
||||
it('prove', async () => {
|
||||
let result
|
||||
let witness = await readEzklArtifactsFile(path, example, 'input.json');
|
||||
let witness = await readEzklArtifactsFile(path, example, 'witness.json');
|
||||
let pk = await readEzklArtifactsFile(path, example, 'key.pk');
|
||||
let circuit_ser = await readEzklArtifactsFile(path, example, 'network.onnx');
|
||||
let circuit_ser = await readEzklArtifactsFile(path, example, 'network.compiled');
|
||||
circuit_settings_ser = await readEzklArtifactsFile(path, example, 'settings.json');
|
||||
params_ser = await readEzklSrsFile(path, example);
|
||||
const startTimeProve = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user