feat: upgrade zkvm-prover to feynman fork (#1686)

Co-authored-by: colinlyguo <colinlyguo@scroll.io>
This commit is contained in:
Ho
2025-07-03 19:48:33 +09:00
committed by GitHub
parent 80807dbb75
commit b7a172a519
26 changed files with 1978 additions and 1191 deletions

View File

@@ -5,10 +5,9 @@ mod zk_circuits_handler;
use clap::{ArgAction, Parser, Subcommand};
use prover::{LocalProver, LocalProverConfig};
use scroll_proving_sdk::{
prover::{types::ProofType, ProverBuilder},
prover::ProverBuilder,
utils::{get_version, init_tracing},
};
use std::{fs::File, path::Path};
#[derive(Parser, Debug)]
#[command(disable_version_flag = true)]
@@ -36,33 +35,11 @@ struct Args {
enum Commands {
/// Dump vk of this prover
Dump {
/// File to save the vks
file_name: String,
/// path to save the verifier's asset
asset_path: String,
},
}
fn dump_vk(file: &Path, prover: &LocalProver, fork_name: &str) -> eyre::Result<()> {
let f = File::create(file)?;
#[derive(Debug, serde::Serialize)]
struct VKDump {
pub chunk_vk: String,
pub batch_vk: String,
pub bundle_vk: String,
}
let handler = prover.new_handler(fork_name);
let dump = VKDump {
chunk_vk: handler.get_vk(ProofType::Chunk),
batch_vk: handler.get_vk(ProofType::Batch),
bundle_vk: handler.get_vk(ProofType::Bundle),
};
serde_json::to_writer(f, &dump)?;
Ok(())
}
#[tokio::main]
async fn main() -> eyre::Result<()> {
init_tracing();
@@ -80,10 +57,10 @@ async fn main() -> eyre::Result<()> {
let local_prover = LocalProver::new(cfg.clone());
match args.command {
Some(Commands::Dump { file_name }) => {
Some(Commands::Dump { asset_path }) => {
let fork_name = args.fork_name.unwrap_or(default_fork_name);
println!("dump vk for {fork_name}");
dump_vk(Path::new(&file_name), &local_prover, &fork_name)?;
println!("dump assets for {fork_name} into {asset_path}");
local_prover.dump_verifier_assets(&fork_name, asset_path.as_ref())?;
}
None => {
let prover = ProverBuilder::new(sdk_config, local_prover)

View File

@@ -16,6 +16,7 @@ use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
fs::File,
path::Path,
sync::{Arc, OnceLock},
time::{SystemTime, UNIX_EPOCH},
};
@@ -71,7 +72,7 @@ impl ProvingService for LocalProver {
vks.push(vk.clone())
} else {
let handler = self.get_or_init_handler(hard_fork_name);
vks.push(handler.get_vk(*proof_type));
vks.push(handler.get_vk(*proof_type).await);
}
}
}
@@ -194,4 +195,51 @@ impl LocalProver {
as Arc<dyn CircuitsHandler>,
}
}
pub fn dump_verifier_assets(&self, hard_fork_name: &str, out_path: &Path) -> Result<()> {
let config = self
.config
.circuits
.get(hard_fork_name)
.ok_or_else(|| eyre::eyre!("no corresponding config for fork {hard_fork_name}"))?;
let workspace_path = &config.workspace_path;
let universal_prover = EuclidV2Handler::new(config);
let _ = universal_prover
.get_prover()
.dump_universal_verifier(Some(out_path))?;
#[derive(Debug, serde::Serialize)]
struct VKDump {
pub chunk_vk: String,
pub batch_vk: String,
pub bundle_vk: String,
}
let dump = VKDump {
chunk_vk: universal_prover.get_vk_and_cache(ProofType::Chunk),
batch_vk: universal_prover.get_vk_and_cache(ProofType::Batch),
bundle_vk: universal_prover.get_vk_and_cache(ProofType::Bundle),
};
let f = File::create(out_path.join("openVmVk.json"))?;
serde_json::to_writer(f, &dump)?;
// Copy verifier.bin from workspace bundle directory to output path
let bundle_verifier_path = Path::new(workspace_path)
.join("bundle")
.join("verifier.bin");
if bundle_verifier_path.exists() {
let dest_path = out_path.join("verifier.bin");
std::fs::copy(&bundle_verifier_path, &dest_path)
.map_err(|e| eyre::eyre!("Failed to copy verifier.bin: {}", e))?;
} else {
eprintln!(
"Warning: verifier.bin not found at {:?}",
bundle_verifier_path
);
}
Ok(())
}
}

View File

@@ -11,7 +11,7 @@ use std::path::Path;
#[async_trait]
pub trait CircuitsHandler: Sync + Send {
fn get_vk(&self, task_type: ProofType) -> String;
async fn get_vk(&self, task_type: ProofType) -> String;
async fn get_proof_data(&self, prove_request: ProveRequest) -> Result<String>;
}

View File

@@ -57,6 +57,12 @@ impl EuclidV2Handler {
}
}
/// get_prover get the inner prover, later we would replace chunk/batch/bundle_prover with
/// universal prover, before that, use bundle_prover as the represent one
pub fn get_prover(&self) -> &BundleProverEuclidV2 {
&self.bundle_prover
}
pub fn get_vk_and_cache(&self, task_type: ProofType) -> String {
match task_type {
ProofType::Chunk => self.cached_vks[&ProofType::Chunk]
@@ -64,7 +70,7 @@ impl EuclidV2Handler {
ProofType::Batch => self.cached_vks[&ProofType::Batch]
.get_or_init(|| BASE64_STANDARD.encode(self.batch_prover.get_app_vk())),
ProofType::Bundle => self.cached_vks[&ProofType::Bundle]
.get_or_init(|| BASE64_STANDARD.encode(self.bundle_prover.get_evm_vk())),
.get_or_init(|| BASE64_STANDARD.encode(self.bundle_prover.get_app_vk())),
_ => unreachable!("Unsupported proof type {:?}", task_type),
}
.clone()
@@ -73,10 +79,8 @@ impl EuclidV2Handler {
#[async_trait]
impl CircuitsHandler for Arc<Mutex<EuclidV2Handler>> {
fn get_vk(&self, task_type: ProofType) -> String {
self.try_lock()
.expect("get vk is on called before other entry is used")
.get_vk_and_cache(task_type)
async fn get_vk(&self, task_type: ProofType) -> String {
self.lock().await.get_vk_and_cache(task_type)
}
async fn get_proof_data(&self, prove_request: ProveRequest) -> Result<String> {