Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ jobs:
uses: Swatinem/rust-cache@v2
with:
workspaces: |
crates/verifier-sdk
crates/aptos-verifier-api
crates/vk-gen-examples
crates/halo2
crates/halo2-verifier

- name: Cache Aptos CLI
id: cache-aptos
Expand Down Expand Up @@ -66,22 +68,27 @@ jobs:

- name: Code formatting check
run: |
cargo fmt --manifest-path ./crates/verifier-sdk/Cargo.toml -- --check
cargo fmt --manifest-path ./crates/aptos-verifier-api/Cargo.toml -- --check
cargo fmt --manifest-path ./crates/vk-gen-examples/Cargo.toml -- --check
cargo fmt --manifest-path ./crates/halo2/Cargo.toml -- --check
cargo fmt --manifest-path ./crates/halo2-verifier/Cargo.toml -- --check

- name: Clippy lint
run: |
cargo clippy --manifest-path ./crates/verifier-sdk/Cargo.toml --all-targets --all-features -- -D warnings
cargo clippy --manifest-path ./crates/aptos-verifier-api/Cargo.toml --all-targets --all-features -- -D warnings
cargo clippy --manifest-path ./crates/vk-gen-examples/Cargo.toml --all-targets --all-features -- -D warnings

cargo clippy --manifest-path ./crates/halo2/Cargo.toml --all-targets --all-features -- -D warnings
cargo clippy --manifest-path ./crates/halo2-verifier/Cargo.toml --all-targets --all-features -- -D warnings

- name: Run Move tests
run: |
aptos move test --package-dir ./packages/common --skip-fetch-latest-git-deps --dev --experiments spec-check=off
aptos move test --package-dir ./packages/verifier --skip-fetch-latest-git-deps --dev --experiments spec-check=off
aptos move test --package-dir ./packages/api --skip-fetch-latest-git-deps --dev --experiments spec-check=off
# aptos move test --package-dir ./packages/common --skip-fetch-latest-git-deps --dev --experiments spec-check=off
# aptos move test --package-dir ./packages/verifier --skip-fetch-latest-git-deps --dev --experiments spec-check=off
# aptos move test --package-dir ./packages/api --skip-fetch-latest-git-deps --dev --experiments spec-check=off

- name: Run Rust tests
run: |
cargo test --manifest-path ./crates/verifier-sdk/Cargo.toml --all-features
cargo test --manifest-path ./crates/vk-gen-examples/Cargo.toml --all-features
cargo test --manifest-path ./crates/aptos-verifier-api/Cargo.toml --all-features
cargo test --manifest-path ./crates/vk-gen-examples/Cargo.toml --all-features
cargo test --manifest-path ./crates/halo2/Cargo.toml --all-features
cargo test --manifest-path ./crates/halo2-verifier/Cargo.toml --all-features
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"rust-analyzer.linkedProjects": [
"./crates/verifier-sdk/Cargo.toml",
"./crates/vk-gen-examples/Cargo.toml",
"./crates/vk-gen-examples/Cargo.toml",
]
}
File renamed without changes.
25 changes: 16 additions & 9 deletions crates/verifier-sdk/Cargo.toml → crates/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[workspace]
members = [
"shape-generator",
# "aptos-verifier-api"
"halo2-verifier",
"aptos-verifier-api",
"halo2",
"vk-gen-examples",
]
resolver = "2"

Expand All @@ -13,6 +15,17 @@ categories = ["cryptography"]
edition = "2021"

[workspace.dependencies]
halo2-verifier={path="./halo2-verifier"}
aptos-verifier-api={path="./aptos-verifier-api"}
halo2={path="./halo2"}
vk-gen-examples={path="./vk-gen-examples"}

halo2_proofs = { git = "https://github.com/zkmove/halo2.git", branch = "zkmove", default-features = false, features = ["batch", "bits"] }
halo2_frontend = { git = "https://github.com/zkmove/halo2.git", branch = "zkmove", default-features = false, features = ["bits"] }
halo2_middleware = { git = "https://github.com/zkmove/halo2.git", branch = "zkmove" }
halo2_backend = { git = "https://github.com/zkmove/halo2.git", branch = "zkmove" }
halo2curves = { git = "https://github.com/zkmove/halo2curves", branch = "zkmove" }

ff = { version = "0.13.0" }
num-traits = { version = "0.2.17" }
derivative = { version = "2.2.0" }
Expand All @@ -21,13 +34,7 @@ rand_core = { version = "0.6" }
serde = { version = "1" }
serde_json = { version = "1" }
hex = { version = "0.4.3" }
halo2_proofs = { git = "https://github.com/zkmove/halo2.git", branch = "zkmove", default-features = false, features = ["batch", "bits"] }
halo2_frontend = { git = "https://github.com/zkmove/halo2.git", branch = "zkmove", default-features = false, features = ["bits"] }
halo2_middleware = { git = "https://github.com/zkmove/halo2.git", branch = "zkmove" }
halo2_backend = { git = "https://github.com/zkmove/halo2.git", branch = "zkmove" }
halo2curves = { git = "https://github.com/zkmove/halo2curves", branch = "zkmove" }
hex-literal = { version = "0.4.1" }
bcs = { version = "0.1.6" }
blake2b_simd = { version = "1" }
anyhow = { version = "1.0.38" }

shape-generator={path="./shape-generator"}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ edition.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
shape-generator.workspace=true
halo2-verifier.workspace=true
serde.workspace=true
serde_json.workspace=true
halo2_proofs.workspace=true
halo2_backend.workspace=true
hex.workspace=true
rand.workspace = true
rand_core.workspace=true
anyhow.workspace=true
190 changes: 190 additions & 0 deletions crates/aptos-verifier-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
use crate::types::{ArgWithTypeJSON, EntryFunctionArgumentsJSON, HexEncodedBytes};
use anyhow::{Error, Result};
use halo2_backend::arithmetic::CurveAffine;
use halo2_backend::helpers::SerdeFormat;
use halo2_backend::plonk::VerifyingKey;
use halo2_backend::poly::commitment::Params;
use halo2_proofs::halo2curves::bn256::{Bn256, Fr, G1Affine};
use halo2_proofs::halo2curves::ff::{FromUniformBytes, PrimeField};
use halo2_proofs::plonk::Circuit;
use halo2_proofs::poly::kzg::commitment::ParamsKZG;
use halo2_verifier::circuit::{generate_serialized_circuit, generate_serialized_protocol};
use halo2_verifier::params::serialize_kzg_params;
use serde_json::json;

pub mod types;

/// module names shared by move verifier and native verifier
const VERIFIER_MODULE: &str = "verifier_api";
const PARAMS_MODULE: &str = "param_store";
const VK_MODULE: &str = "vk_store";

/// function names for move verifier
const PUBLISH_PROTOCOL_FUNC: &str = "publish_protocol";
const VERIFY_PROOF_FUNC: &str = "verify_proof";

/// function names for native verifier
const PUBLISH_PARAMS_FUNC: &str = "publish_serialized_params";
const PUBLISH_VK_FUNC: &str = "publish_serialized_vk";
const PUBLISH_CIRCUIT_FUNC: &str = "publish_serialized_circuit";

/// Move verifier related APIs
/// build publish protocol transaction payload for aptos.
/// Returns a structure which can be serialized to json string,
/// and when output the json to file, it can be run by `aptos move run`.
pub fn build_publish_protocol_transaction_payload<ConcreteCircuit>(
params: &ParamsKZG<Bn256>,
circuit: &ConcreteCircuit,
verifier_address: String,
) -> Result<EntryFunctionArgumentsJSON, Error>
where
ConcreteCircuit: Circuit<Fr>,
{
let protocol = generate_serialized_protocol(params, circuit)
.expect("generate circuit info should not fail");

let args: Vec<_> = protocol
.into_iter()
.map(|arg| ArgWithTypeJSON {
arg_type: "hex".to_string(),
value: json!(arg
.into_iter()
.map(|i| HexEncodedBytes(i).to_string())
.collect::<Vec<_>>()),
})
.collect();
let json = EntryFunctionArgumentsJSON {
function_id: format!(
"{}::{}::{}",
verifier_address, VERIFIER_MODULE, PUBLISH_PROTOCOL_FUNC
),
type_args: vec![],
args,
};
Ok(json)
}

/// Move verifier related APIs
/// Build verify proof transaction payload for aptos.
/// Returns a structure which can be serialized to json string,
/// and when output the json to file, it can be run by `aptos move run`.
#[allow(clippy::let_and_return)]
pub fn build_verify_proof_transaction_payload(
proof: Vec<u8>,
proof_kzg_variant: u8,
instances: Vec<Vec<Fr>>,
verifier_address: String,
param_address: String,
protocol_address: String,
) -> EntryFunctionArgumentsJSON {
let instances = instances
.iter()
.map(|fr| {
fr.iter()
.map(|f| HexEncodedBytes(f.to_repr().as_ref().to_vec()).to_string())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();
let json = EntryFunctionArgumentsJSON {
function_id: format!(
"{}::{}::{}",
verifier_address, VERIFIER_MODULE, VERIFY_PROOF_FUNC
),
type_args: vec![],
args: vec![
ArgWithTypeJSON {
arg_type: "address".to_string(),
value: json!(param_address),
},
ArgWithTypeJSON {
arg_type: "address".to_string(),
value: json!(protocol_address),
},
ArgWithTypeJSON {
arg_type: "hex".to_string(),
value: json!(instances),
},
ArgWithTypeJSON {
arg_type: "hex".to_string(),
value: json!(HexEncodedBytes(proof.clone()).to_string()),
},
ArgWithTypeJSON {
arg_type: "u8".to_string(),
value: json!(proof_kzg_variant),
},
],
};

json
}

/// Native verifier related APIs
/// Build publish serialized kzg params transaction payload for aptos.
pub fn build_publish_params_transaction_payload(
params: &ParamsKZG<Bn256>,
params_store_address: String,
) -> Result<EntryFunctionArgumentsJSON, Error> {
let params_bytes = serialize_kzg_params(&params.verifier_params())
.map_err(|e| Error::msg(format!("serialize kzg params failed: {}", e)))?;
let json = EntryFunctionArgumentsJSON {
function_id: format!(
"{}::{}::{}",
params_store_address, PARAMS_MODULE, PUBLISH_PARAMS_FUNC
),
type_args: vec![],
args: vec![ArgWithTypeJSON {
arg_type: "hex".to_string(),
value: json!(HexEncodedBytes(params_bytes).to_string()),
}],
};
Ok(json)
}

/// Native verifier related APIs
/// Build publish serialized vk transaction payload for aptos.
pub fn build_publish_vk_transaction_payload(
vk: &VerifyingKey<G1Affine>,
vk_store_address: String,
) -> EntryFunctionArgumentsJSON {
let vk_bytes = vk.to_bytes(SerdeFormat::RawBytes);
let json = EntryFunctionArgumentsJSON {
function_id: format!("{}::{}::{}", vk_store_address, VK_MODULE, PUBLISH_VK_FUNC),
type_args: vec![],
args: vec![ArgWithTypeJSON {
arg_type: "hex".to_string(),
value: json!(HexEncodedBytes(vk_bytes).to_string()),
}],
};
json
}

/// Native verifier related APIs
/// Build publish serialized circuit transaction payload for aptos.
pub fn build_publish_circuit_transaction_payload<C, P, ConcreteCircuit>(
params: &P,
circuit: &ConcreteCircuit,
vk_store_address: String,
) -> Result<EntryFunctionArgumentsJSON, Error>
where
C: CurveAffine,
P: Params<C>,
ConcreteCircuit: Circuit<C::Scalar>,
C::Scalar: FromUniformBytes<64>,
C::ScalarExt: FromUniformBytes<64>,
{
let circuit_bytes = generate_serialized_circuit(params, circuit)
.map_err(|e| Error::msg(format!("generate serialized circuit failed: {}", e)))?;

let json = EntryFunctionArgumentsJSON {
function_id: format!(
"{}::{}::{}",
vk_store_address, VK_MODULE, PUBLISH_CIRCUIT_FUNC
),
type_args: vec![],
args: vec![ArgWithTypeJSON {
arg_type: "hex".to_string(),
value: json!(HexEncodedBytes(circuit_bytes).to_string()),
}],
};
Ok(json)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "shape-generator"
name = "halo2-verifier"
version.workspace = true
edition.workspace = true

Expand All @@ -13,11 +13,16 @@ halo2_middleware.workspace=true
bcs.workspace=true
blake2b_simd.workspace=true
halo2curves.workspace=true
hex.workspace=true
hex-literal.workspace=true
rand.workspace = true
halo2.workspace = true
vk-gen-examples.workspace = true

ark-bn254 = "0.4.0"
ark-ec = "0.4.0"
ark-ff = "0.4.0"
ark-serialize = "0.4.0"
hex = "0.4.3"
group = "0.13"
byteorder = "1.5.0"
byteorder = "1.5.0"
anyhow = "1.0.95"
Loading