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
2,313 changes: 1,460 additions & 853 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ zkm-build = { git = "https://github.com/ProjectZKM/Ziren" }
zkm-core-executor = { git = "https://github.com/ProjectZKM/Ziren" }
zkm-prover = { git = "https://github.com/ProjectZKM/Ziren" }
zkm-sdk = { git = "https://github.com/ProjectZKM/Ziren" }
zkm-verifier = { git = "https://github.com/ProjectZKM/Ziren", features = ["ark"] }
zkm-verifier = { git = "https://github.com/ProjectZKM/Ziren" }
zkm-primitives = { git = "https://github.com/ProjectZKM/Ziren" }
zkm-zkvm = { git = "https://github.com/ProjectZKM/Ziren", features = ["verify"] }

#zkm-build = { path = "../Ziren/crates/build" }
#zkm-core-executor = { path = "../Ziren/crates/core/executor" }
#zkm-prover = { path = "../Ziren/crates/prover" }
#zkm-sdk = { path = "../Ziren/crates/sdk" }
#zkm-verifier = { path = "../Ziren/crates/verifier", features = ["ark"] }
#zkm-verifier = { path = "../Ziren/crates/verifier" }

bitvm2-lib = { path = "crates/bitvm2-ga" }
store = { path = "crates/store" }
Expand Down
2 changes: 1 addition & 1 deletion circuits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ For case 2,
> * If there is no Ziren upgrade during this interval, and the inputs of the proof aggregation are compressed proofs, but with different `start_pc`, `pc`, etc.
> * If there is some Ziren upgrades during this interval, once we support the multiple verification keys in Ziren, this problem can be reduced to the former one.

With multiple proof recursions, we generate a Groth16 proof, and verify with `Groth16Verifier::verify(proof, zkm_public_values, zkm_vk_hash, groth16_vk)`.
With multiple proof recursions, we generate a Groth16 proof, and verify with `Groth16Verifier::verify_by_imm_groth16_vk(proof, zkm_public_values, zkm_vk_hash, groth16_vk, part_stark_vk)`.

## Preparation

Expand Down
6 changes: 3 additions & 3 deletions circuits/commit-chain-proof/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ bincode = "1.3.3"
commit-chain = { path = "../../../crates/commit-chain" }

# Ziren
zkm-zkvm = { git = "https://github.com/ProjectZKM/Ziren", package = "zkm-zkvm", features = ["verify"] }
zkm-verifier = { git = "https://github.com/ProjectZKM/Ziren", package = "zkm-verifier" }
zkm-zkvm = { git = "https://github.com/ProjectZKM/Ziren", features = ["verify"] }
zkm-verifier = { git = "https://github.com/ProjectZKM/Ziren" }
#zkm-verifier = { path = "../../../../Ziren/crates/verifier" }
#zkm-zkvm = { path = "../../../../Ziren/crates/zkvm/entrypoint", features = ["verify"] }

Expand All @@ -36,4 +36,4 @@ alloy-primitives-v1-1-0 = { git = "https://github.com/ziren-patches/core.git", p
alloy-primitives-v1-1-2 = { git = "https://github.com/ziren-patches/core.git", package = "alloy-primitives", branch = "patch-alloy-primitives-1.1.2" }
alloy-primitives-v1-4-1 = { git = "https://github.com/ziren-patches/core.git", package = "alloy-primitives", branch = "patch-alloy-primitives-1.4.1" }
secp256k1-v0-29-1 = { git = "https://github.com/ziren-patches/rust-secp256k1", package = "secp256k1", branch = "patch-0.29.1" }
#secp256k1-v0-30-0 = { git = "https://github.com/ziren-patches/rust-secp256k1", package = "secp256k1", branch = "patch-0.30.0" }
#secp256k1-v0-30-0 = { git = "https://github.com/ziren-patches/rust-secp256k1", package = "secp256k1", branch = "patch-0.30.0" }
2 changes: 1 addition & 1 deletion circuits/commit-chain-proof/guest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_main]
zkm_zkvm::entrypoint!(main);
use commit_chain::{CommitChainCircuitInput, commit_chain_circuit};
use commit_chain::commit_chain_circuit;

pub fn main() {
let input = zkm_zkvm::io::read();
Expand Down
70 changes: 50 additions & 20 deletions circuits/commit-chain-proof/host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const COMMIT_CHAIN: &[u8] = include_elf!("guest");
use std::fs;

use clap::Parser;

/// The arguments for the cli.
#[derive(Debug, Clone, Parser, serde::Deserialize, serde::Serialize)]
pub struct Args {
Expand Down Expand Up @@ -114,12 +115,19 @@ pub async fn fetch_commit_chain(
.iter()
.map(|compressed_pk| PublicKey::from_str(compressed_pk).unwrap())
.collect();
let next_publisher_public_keys = ci.next_publisher_public_keys.as_ref().map(|keys| {
keys.iter()
.map(|compressed_pk| PublicKey::from_str(compressed_pk).unwrap())
.collect::<Vec<_>>()
});
tracing::info!("sequencer_hash: {:?}", sequencer_hash(&ci.sequencers));
let commit = CircuitCommit {
commit_txn,
sequencers: ci.sequencers.clone(),
publisher_public_keys,
threshold: ci.threshold,
next_publisher_public_keys,
next_threshold: ci.next_threshold,
genesis_txid: Txid::from_str(&ci.genesis_txid)?.as_raw_hash().to_byte_array(),
block_height,
};
Expand Down Expand Up @@ -181,26 +189,45 @@ impl ProofBuilder for CommitChainProofBuilder {
//let prev: CommitChainCircuitOutput = serde_json::from_slice(&public_inputs).unwrap();
Some(public_inputs)
};
let (prev_proof, zkm_proof, zkm_public_values, zkm_vk_hash) = match prev_receipt.clone() {
Some(public_inputs) => {
let proof_bytes =
fs::read(input_proof).context("Failed to read input proof file")?;
let zkm_vk_hash =
fs::read(&format!("{}.vk_hash.bin", input_proof)).context("Read vk hash")?;
let prev_output: CommitChainCircuitOutput =
zkm_sdk::ZKMPublicValues::from(&public_inputs).read();
(
CommitChainPrevProofType::PrevProof(prev_output),
proof_bytes,
public_inputs,
zkm_vk_hash.to_vec(),
)
}
None => (CommitChainPrevProofType::GenesisBlock, Vec::new(), Vec::new(), Vec::new()),
};
let (prev_proof, zkm_proof, zkm_public_values, zkm_vk_hash, zkm_version) =
match prev_receipt.clone() {
Some(public_inputs) => {
let proof_bytes =
fs::read(input_proof).context("Failed to read input proof file")?;
let zkm_vk_hash = fs::read(&format!("{}.vk_hash.bin", input_proof))
.context("Read vk hash")?;
let version_path = format!("{input_proof}.zkm_version.bin");
let zkm_version = fs::read(&version_path)
.with_context(|| {
format!("failed to read zkm_version file '{version_path}'")
})
.and_then(|raw_zkm_version| {
String::from_utf8(raw_zkm_version).with_context(|| {
format!("invalid UTF-8 in zkm_version file '{version_path}'")
})
})?;
let prev_output: CommitChainCircuitOutput =
zkm_sdk::ZKMPublicValues::from(&public_inputs).read();
(
CommitChainPrevProofType::PrevProof(prev_output),
proof_bytes,
public_inputs,
zkm_vk_hash.to_vec(),
zkm_version,
)
}
None => (
CommitChainPrevProofType::GenesisBlock,
Vec::new(),
Vec::new(),
Vec::new(),
"v1.2.5".into(),
),
};

let input: CommitChainCircuitInput = CommitChainCircuitInput {
zkm_vk_hash,
zkm_version,
zkm_proof,
prev_proof,
commits: commits.to_vec(),
Expand Down Expand Up @@ -238,9 +265,10 @@ impl ProofBuilder for CommitChainProofBuilder {

tracing::info!("Commit chain proof cycles: {}", cycles);

if let Err(e) = self.client.verify(&proof, &self.verifying_key) {
panic!("{}", e);
}
// todo: verify the proof laterr
// if let Err(e) = self.client.verify(&proof, &self.verifying_key) {
// panic!("{}", e);
// }

let input = bincode::serialize(&input)?;
Ok((input, proof, cycles, proving_time))
Expand All @@ -267,11 +295,13 @@ impl ProofBuilder for CommitChainProofBuilder {
std::fs::write(&format!("{}", output_proof), proof.bytes())?;
let public_value_hex = hex::encode(proof.public_values.to_vec());
let proof_size = proof.bytes().len();
let zkm_version = proof.zkm_version.clone();
std::fs::write(
&format!("{}.public_inputs.bin", output_proof),
proof.public_values.to_vec(),
)?;
std::fs::write(&format!("{}.vk_hash.bin", output_proof), self.verifying_key.bytes32())?;
std::fs::write(&format!("{}.zkm_version.bin", output_proof), zkm_version)?;
Ok((public_value_hex, proof_size))
}
}
Expand Down
2 changes: 1 addition & 1 deletion circuits/data/commit-chain/0-1.bin.commits
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"commit_txn":{"version":2,"lock_time":0,"input":[{"previous_output":"622eeea26cd959df530643268a94d859ebcb3ba0917691a77b830481af640501:0","script_sig":"","sequence":4294967295,"witness":["30440220411d76ca263fee5bcb6b0e18d7aad8232ca0f2e99eaaed0bc8b977169e2f1b6d022053186175329f8714d7802ad0e92365744d087dfdf858f9819142351dbb697d5281","02add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce4"]}],"output":[{"value":500,"script_pubkey":"0020e38259e612b85728633fa8b8d00457594ed650fb5c6559b881575f49226d048a"},{"value":0,"script_pubkey":"6a4035e3a5a2736974eac20a6290f79fd153ba4d45df444ec953704f03f8cb3dd5b5070292c12aec12a7b213f65b1deb03c6b59b69620b6a1d9b110bda3a00346878"}]},"genesis_txid":[62,113,183,217,27,117,122,227,144,26,0,59,106,246,51,184,53,250,56,55,165,81,188,30,132,254,190,180,247,102,127,10],"publisher_public_keys":["02add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce4","025d415767660a937ee954d08fa09dc055b4a14e5ffc22c38372499dd198cf7aa4","02cb5075f2ff841fa49728a8e7d6b22b471f756cf6b3f7c625dcc5e325ebe7e233"],"threshold":2,"sequencers":[{"address":"9104a28cdf6a00a546a1c365007ebf017b0645af","pub_key":[2,164,213,70,208,195,228,161,14,136,64,141,227,85,111,57,106,134,108,153,204,28,225,73,21,111,180,225,54,254,104,172,110],"power":2000000,"name":null},{"address":"70cce9b7fb446d4ccf793c8cbc12dbef99a10f83","pub_key":[3,196,102,123,104,171,225,100,11,219,187,51,186,113,186,15,45,4,175,100,30,205,166,95,208,95,225,161,219,63,153,87,105],"power":1750000,"name":null},{"address":"fc139929ae753d5580dc6145d9bc8c5c25f73298","pub_key":[3,212,171,157,196,79,116,160,72,222,230,127,158,112,84,118,51,1,46,182,155,255,134,203,202,133,13,89,35,37,29,185,128],"power":1000000,"name":null}],"block_height":119164}]
[{"commit_txn":{"version":2,"lock_time":0,"input":[{"previous_output":"dc3ab4f512c412f417347ee8624bec6fa9ddef4e4ab832e0749986b8fac41812:0","script_sig":"","sequence":4294967295,"witness":["30440220055614d8ae09d309d24df5ff37ccdf0bfd3343abbf92bf72065f8fb5f8526efe022044da12fc0f78d65890dd09dea787d6113f3c511c177db00207ca00bae4df8d4281","02add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce4"]}],"output":[{"value":500,"script_pubkey":"0020e38259e612b85728633fa8b8d00457594ed650fb5c6559b881575f49226d048a"},{"value":0,"script_pubkey":"6a40600316026949ac291ff23c2f2b045a92868a9be546ff440d74524ba97d25f22b2b9791b90336e820684537ded50aeb9c5fdf591d5d1992cd5e04a1d74e07a2f7"}]},"genesis_txid":[38,32,132,254,96,19,216,150,70,107,27,2,105,4,169,155,65,232,159,113,86,110,97,178,230,248,167,101,45,5,250,154],"publisher_public_keys":["02add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce4","025d415767660a937ee954d08fa09dc055b4a14e5ffc22c38372499dd198cf7aa4","02cb5075f2ff841fa49728a8e7d6b22b471f756cf6b3f7c625dcc5e325ebe7e233"],"threshold":2,"next_publisher_public_keys":null,"next_threshold":null,"sequencers":[{"address":"9104a28cdf6a00a546a1c365007ebf017b0645af","pub_key":[2,164,213,70,208,195,228,161,14,136,64,141,227,85,111,57,106,134,108,153,204,28,225,73,21,111,180,225,54,254,104,172,110],"power":2000000,"name":null},{"address":"70cce9b7fb446d4ccf793c8cbc12dbef99a10f83","pub_key":[3,196,102,123,104,171,225,100,11,219,187,51,186,113,186,15,45,4,175,100,30,205,166,95,208,95,225,161,219,63,153,87,105],"power":1750000,"name":null},{"address":"fc139929ae753d5580dc6145d9bc8c5c25f73298","pub_key":[3,212,171,157,196,79,116,160,72,222,230,127,158,112,84,118,51,1,46,182,155,255,134,203,202,133,13,89,35,37,29,185,128],"power":1100000,"name":null}],"block_height":120054}]
2 changes: 1 addition & 1 deletion circuits/data/commit-chain/1-1.bin.commits
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"commit_txn":{"version":2,"lock_time":0,"input":[{"previous_output":"0a7f66f7b4befe841ebc51a53738fa35b833f66a3b001a90e37a751bd9b7713e:0","script_sig":"","sequence":4294967295,"witness":["","3045022100b4257b7dacefc591048fc816052c899c710943dd3c4c39bfa818c53035994243022018256e7e1bea6b2dbcfdb62e58b0bc98ef7aa26c678a7298ac0dc4b9552825bc81","3044022068f8468be22db5613d0b3a6fda5fa70110b178b11c2ea5fcdc5714e04557202a022009c2e10755678389deb00eb872114a7529afc2e3e8f4bb211c1984245914e51d81","522102add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce421025d415767660a937ee954d08fa09dc055b4a14e5ffc22c38372499dd198cf7aa42102cb5075f2ff841fa49728a8e7d6b22b471f756cf6b3f7c625dcc5e325ebe7e23353ae"]},{"previous_output":"7d0f6eadd008275745a3eb1d57b85f5387aa3b6488106f5bcf4868a5edcbd5f3:0","script_sig":"","sequence":4294967295,"witness":["304402206b5a5c8c0de45e121ea382c09d63b6cf87ed889db2024c2f66504cf3b5b5c49e022077edb94b793e01d78f54d874d640880540ec79e645cbd944d9f4c30568334ebe81","02add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce4"]}],"output":[{"value":500,"script_pubkey":"0020e38259e612b85728633fa8b8d00457594ed650fb5c6559b881575f49226d048a"},{"value":0,"script_pubkey":"6a4035e3a5a2736974eac20a6290f79fd153ba4d45df444ec953704f03f8cb3dd5b5070292c12aec12a7b213f65b1deb03c6b59b69620b6a1d9b110bda3a00346878"}]},"genesis_txid":[62,113,183,217,27,117,122,227,144,26,0,59,106,246,51,184,53,250,56,55,165,81,188,30,132,254,190,180,247,102,127,10],"publisher_public_keys":["02add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce4","025d415767660a937ee954d08fa09dc055b4a14e5ffc22c38372499dd198cf7aa4","02cb5075f2ff841fa49728a8e7d6b22b471f756cf6b3f7c625dcc5e325ebe7e233"],"threshold":2,"sequencers":[{"address":"9104a28cdf6a00a546a1c365007ebf017b0645af","pub_key":[2,164,213,70,208,195,228,161,14,136,64,141,227,85,111,57,106,134,108,153,204,28,225,73,21,111,180,225,54,254,104,172,110],"power":2000000,"name":null},{"address":"70cce9b7fb446d4ccf793c8cbc12dbef99a10f83","pub_key":[3,196,102,123,104,171,225,100,11,219,187,51,186,113,186,15,45,4,175,100,30,205,166,95,208,95,225,161,219,63,153,87,105],"power":1750000,"name":null},{"address":"fc139929ae753d5580dc6145d9bc8c5c25f73298","pub_key":[3,212,171,157,196,79,116,160,72,222,230,127,158,112,84,118,51,1,46,182,155,255,134,203,202,133,13,89,35,37,29,185,128],"power":1000000,"name":null}],"block_height":119166}]
[{"commit_txn":{"version":2,"lock_time":0,"input":[{"previous_output":"9afa052d65a7f8e6b2616e56719fe8419ba90469021b6b4696d81360fe842026:0","script_sig":"","sequence":4294967295,"witness":["","3044022036aea0879bb34a78225ba291c4b812b0a4b5a699471648a048b3b54b277b600102200a723b69e171740a01d03cb19ab90f3aaa94f3e1267d64bed23df1e60546f33381","3044022044a53670d03d464c710ba0b65547b7ead2a916c0d4821273e6d37de1ee923bd802206d0639be92e8e6d76e870b3fd9086ab7644122b2b47cb7684115a6265a1a801f81","522102add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce421025d415767660a937ee954d08fa09dc055b4a14e5ffc22c38372499dd198cf7aa42102cb5075f2ff841fa49728a8e7d6b22b471f756cf6b3f7c625dcc5e325ebe7e23353ae"]},{"previous_output":"f650ed861a45a849004e75c5203d27365ff2fba8954c2af0c1d57612485954dd:0","script_sig":"","sequence":4294967295,"witness":["3045022100f43050df85a8daa024a7f49cde271bca25bef857e00b224700185b756a0095000220771508ae331a3fb17e21ec762b0839f8928c7ae03fa1c61fa96f3b0388772fcb81","02add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce4"]}],"output":[{"value":500,"script_pubkey":"0020e38259e612b85728633fa8b8d00457594ed650fb5c6559b881575f49226d048a"},{"value":0,"script_pubkey":"6a402beffe4c53efd70f42c04ac0c83002a2a062bfeabaa5fffc6eb1280d411f0bb22b9791b90336e820684537ded50aeb9c5fdf591d5d1992cd5e04a1d74e07a2f7"}]},"genesis_txid":[38,32,132,254,96,19,216,150,70,107,27,2,105,4,169,155,65,232,159,113,86,110,97,178,230,248,167,101,45,5,250,154],"publisher_public_keys":["02add57ae77706046bc4af1e9533fb2ccaa96316e656756dd0884407ae72501ce4","025d415767660a937ee954d08fa09dc055b4a14e5ffc22c38372499dd198cf7aa4","02cb5075f2ff841fa49728a8e7d6b22b471f756cf6b3f7c625dcc5e325ebe7e233"],"threshold":2,"next_publisher_public_keys":null,"next_threshold":null,"sequencers":[{"address":"70cce9b7fb446d4ccf793c8cbc12dbef99a10f83","pub_key":[3,196,102,123,104,171,225,100,11,219,187,51,186,113,186,15,45,4,175,100,30,205,166,95,208,95,225,161,219,63,153,87,105],"power":1750000,"name":null},{"address":"9104a28cdf6a00a546a1c365007ebf017b0645af","pub_key":[2,164,213,70,208,195,228,161,14,136,64,141,227,85,111,57,106,134,108,153,204,28,225,73,21,111,180,225,54,254,104,172,110],"power":1500000,"name":null},{"address":"fc139929ae753d5580dc6145d9bc8c5c25f73298","pub_key":[3,212,171,157,196,79,116,160,72,222,230,127,158,112,84,118,51,1,46,182,155,255,134,203,202,133,13,89,35,37,29,185,128],"power":1100000,"name":null}],"block_height":121470}]
Binary file not shown.
10 changes: 5 additions & 5 deletions circuits/header-chain-proof/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ publish = false
bincode = "1.3.3"
# workspace
header-chain = { path = "../../../crates/header-chain" }
borsh = {version = "1.5.3", features = ["derive"] }
borsh = { version = "1.5.3", features = ["derive"] }

# Ziren
zkm-zkvm = { git = "https://github.com/ProjectZKM/Ziren", package = "zkm-zkvm", features = ["verify"] }
zkm-verifier = { git = "https://github.com/ProjectZKM/Ziren", package = "zkm-verifier" }
zkm-zkvm = { git = "https://github.com/ProjectZKM/Ziren", features = ["verify"] }
zkm-verifier = { git = "https://github.com/ProjectZKM/Ziren" }
#zkm-verifier = { path = "../../../Ziren/crates/verifier" }
#zkm-zkvm = { path = "../../../Ziren/crates/zkvm/entrypoint", features = ["verify"] }

Expand All @@ -36,5 +36,5 @@ p256 = { git = "https://github.com/ziren-patches/elliptic-curves", branch = "pat
alloy-primitives-v1-0-0 = { git = "https://github.com/ziren-patches/core.git", package = "alloy-primitives", branch = "patch-alloy-primitives-1.0.0" }
alloy-primitives-v1-1-0 = { git = "https://github.com/ziren-patches/core.git", package = "alloy-primitives", branch = "patch-alloy-primitives-1.1.0" }
alloy-primitives-v1-1-2 = { git = "https://github.com/ziren-patches/core.git", package = "alloy-primitives", branch = "patch-alloy-primitives-1.1.2" }
#secp256k1-v0-29-1 = { git = "https://github.com/ziren-patches/rust-secp256k1", package = "secp256k1", branch = "patch-0.29.1" }
#secp256k1-v0-30-0 = { git = "https://github.com/ziren-patches/rust-secp256k1", package = "secp256k1", branch = "patch-0.30.0" }
secp256k1-v0-29-1 = { git = "https://github.com/ziren-patches/rust-secp256k1", package = "secp256k1", branch = "patch-0.29.1" }
#secp256k1-v0-30-0 = { git = "https://github.com/ziren-patches/rust-secp256k1", package = "secp256k1", branch = "patch-0.30.0" }
7 changes: 1 addition & 6 deletions circuits/header-chain-proof/guest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#![no_main]
zkm_zkvm::entrypoint!(main);

use header_chain::{
verify_merkle_proof, BlockHeaderCircuitOutput, BlockInclusionProof, ChainState,
CircuitTransaction, HeaderChainCircuitInput, HeaderChainPrevProofType,
header_chain_circuit,
};
use header_chain::{header_chain_circuit, HeaderChainCircuitInput};

use borsh::{BorshDeserialize, BorshSerialize};


pub fn main() {
let input: HeaderChainCircuitInput = zkm_zkvm::io::read();
let output = header_chain_circuit(input);
Expand Down
Loading
Loading