-
Couldn't load subscription status.
- Fork 628
More debug information from libzkp #1692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,16 @@ use std::sync::OnceLock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static LOG_SETTINGS: OnceLock<Result<(), String>> = OnceLock::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn enable_dump() -> bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static ZKVM_DEBUG_DUMP: OnceLock<bool> = OnceLock::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *ZKVM_DEBUG_DUMP.get_or_init(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::env::var("ZKVM_DEBUG") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .or_else(|_| std::env::var("ZKVM_DEBUG_PROOF")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(|s| s.to_lowercase() == "true") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap_or(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// # Safety | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub unsafe extern "C" fn init_tracing() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -52,14 +62,33 @@ pub unsafe extern "C" fn init_l2geth(config: *const c_char) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn verify_proof(proof: *const c_char, fork_name: *const c_char, task_type: TaskType) -> c_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let fork_name_str = c_char_to_str(fork_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let proof_str = proof; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let proof = c_char_to_vec(proof); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tracing::info!("verify proof for fork {fork_name_str}, type {task_type}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| match libzkp::verify_proof(proof, fork_name_str, task_type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Err(e) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tracing::error!("{:?} verify failed, error: {:#}", task_type, e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| false as c_char | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ok(result) => result as c_char, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ok(result) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if !result && enable_dump() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Dump req.input to a temporary file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let timestamp = SystemTime::now() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .duration_since(UNIX_EPOCH) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap_or_default() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .as_secs(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let filename = format!("/tmp/proof_{}.json", timestamp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let cstr = unsafe { std::ffi::CStr::from_ptr(proof_str) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let Err(e) = std::fs::write(&filename, cstr.to_bytes()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eprintln!("Failed to write proof to file {}: {}", filename, e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("Dumped failed proof to {}", filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result as c_char | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -150,10 +179,13 @@ pub unsafe extern "C" fn gen_universal_task( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| &[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let fork_name_str = c_char_to_str(fork_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tracing::info!("generate universtal task for fork {fork_name_str}, type {task_type}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let ret = libzkp::gen_universal_task( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| &task_json, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c_char_to_str(fork_name), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fork_name_str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expected_vk, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interpreter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -167,6 +199,21 @@ pub unsafe extern "C" fn gen_universal_task( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expected_pi_hash, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if enable_dump() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Dump req.input to a temporary file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let timestamp = SystemTime::now() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .duration_since(UNIX_EPOCH) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap_or_default() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .as_secs(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let filename = format!("/tmp/task_{}_{}.json", fork_name_str, timestamp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let Err(e) = std::fs::write(&filename, task_json.as_bytes()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eprintln!("Failed to write task to file {}: {}", filename, e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("Dumped failed task to {}", filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+202
to
+216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Apply same improvements as verification dump logic. The task dumping logic has the same race condition and security concerns as the proof dumping logic. Apply similar improvements: - let filename = format!("/tmp/task_{}_{}.json", fork_name_str, timestamp);
+ let temp_dir = std::env::temp_dir();
+ let filename = temp_dir.join(format!("task_{}_{}_{}.json", fork_name_str, std::process::id(), timestamp));This addresses:
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tracing::error!("gen_universal_task failed, error: {:#}", ret.unwrap_err()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| failed_handling_result() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Address potential race conditions and security concerns in debug dumping.
The debug dumping logic has several potential issues:
/tmpmight not be secure in all environments/tmppath won't work on WindowsConsider this improved implementation:
Or better yet, use a more robust approach:
📝 Committable suggestion
🤖 Prompt for AI Agents