Skip to content

Conversation

@noel2004
Copy link
Member

@noel2004 noel2004 commented Jul 7, 2025

Summary by CodeRabbit

  • New Features

    • Added optional debug dumping of failed proofs and tasks to files for enhanced troubleshooting, triggered by environment variables.
    • Introduced additional logging for proof verification and task generation attempts.
    • Normalized task fork names to ensure consistency during task processing.
  • Bug Fixes

    • Improved error handling and user feedback when dumping debug information fails.

@coderabbitai
Copy link

coderabbitai bot commented Jul 7, 2025

Walkthrough

The changes remove the debug proof dumping logic from crates/libzkp/src/lib.rs and introduce enhanced, environment-variable-controlled debug dumping and logging in crates/libzkp_c/src/lib.rs. The new logic conditionally saves failed proofs and tasks to timestamped JSON files in /tmp and adds tracing statements for verification and task generation. Additionally, gen_universal_task normalizes fork_name inputs for consistency. The Cargo workspace dependencies have been updated to new Git commit revisions.

Changes

File(s) Change Summary
crates/libzkp/src/lib.rs Normalized fork_name in gen_universal_task; removed debug proof dumping logic from verify_proof.
crates/libzkp_c/src/lib.rs Added enable_dump() function; added conditional debug dumping and enhanced logging for proof verification and task generation failures.
Cargo.toml Updated Git commit revisions for scroll-zkvm-prover-euclid, scroll-zkvm-verifier-euclid, and scroll-zkvm-types dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant libzkp_c
    participant libzkp

    User->>libzkp_c: verify_proof(proof)
    libzkp_c->>libzkp: verify_proof(proof)
    libzkp-->>libzkp_c: result
    libzkp_c->>libzkp_c: Log verification attempt
    alt Verification fails and enable_dump()
        libzkp_c->>libzkp_c: Dump proof input to /tmp
        libzkp_c->>User: Print error message
    end
    libzkp_c-->>User: Return result
Loading
sequenceDiagram
    participant User
    participant libzkp_c

    User->>libzkp_c: gen_universal_task(task_json)
    libzkp_c->>libzkp_c: Log task generation attempt
    alt Generation fails and enable_dump()
        libzkp_c->>libzkp_c: Dump task JSON to /tmp
        libzkp_c->>User: Print error message
    end
    libzkp_c-->>User: Return result
Loading

Suggested reviewers

  • zimpha

Poem

In the warren, logs now leap and bound,
Debug files hop to /tmp/ when troubles are found.
Old code swept away, new checks in the air,
With tracing and dumping, we handle with care.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a18377 and 0596bc2.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • crates/libzkp/src/lib.rs (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/libzkp/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: tests
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3050ccb and 9a18377.

📒 Files selected for processing (2)
  • crates/libzkp/src/lib.rs (0 hunks)
  • crates/libzkp_c/src/lib.rs (4 hunks)
💤 Files with no reviewable changes (1)
  • crates/libzkp/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: tests
🔇 Additional comments (5)
crates/libzkp_c/src/lib.rs (5)

12-20: LGTM: Clean environment variable checking with proper caching.

The implementation correctly uses OnceLock to cache the environment variable check and handles multiple environment variables appropriately.


65-65: Store the original proof pointer for debugging purposes.

This line correctly preserves the original C string pointer for later use in the debug dumping logic.


67-67: Add tracing for verification attempts.

Good addition of logging to track verification attempts with relevant context.


183-183: Add tracing for task generation attempts.

Good addition of logging to track task generation attempts with relevant context.


83-88: Memory safety and JSON handling are correct

The C string passed into verify_proof is created from serde_json::to_string(), wrapped with CString::new(...).into_raw(), and thus is null-terminated. Calling CStr::from_ptr(...).to_bytes() reads the full JSON payload (JSON text cannot contain embedded NULs), so nothing is truncated. The same applies to c_char_to_vec. No changes required.

Comment on lines +74 to 92
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
}
}
Copy link

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:

  1. Race condition: Using only timestamp for filename could cause collisions if multiple threads/processes call this simultaneously
  2. Security: Writing to /tmp might not be secure in all environments
  3. Portability: Hard-coded /tmp path won't work on Windows

Consider this improved implementation:

-                let filename = format!("/tmp/proof_{}.json", timestamp);
+                let filename = format!("/tmp/proof_{}_{}.json", std::process::id(), timestamp);

Or better yet, use a more robust approach:

-                let filename = format!("/tmp/proof_{}.json", timestamp);
+                let temp_dir = std::env::temp_dir();
+                let filename = temp_dir.join(format!("proof_{}_{}.json", std::process::id(), timestamp));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
}
}
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 temp_dir = std::env::temp_dir();
+ let filename = temp_dir.join(format!("proof_{}_{}.json", std::process::id(), 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.display(), e);
} else {
println!("Dumped failed proof to {}", filename.display());
}
}
result as c_char
}
🤖 Prompt for AI Agents
In crates/libzkp_c/src/lib.rs around lines 74 to 92, the debug dumping uses a
timestamp-based filename in /tmp, which risks race conditions, security issues,
and lacks portability. Fix this by generating a unique filename using a UUID or
a secure random value instead of just a timestamp, use a platform-independent
temporary directory obtained via standard library functions, and ensure file
permissions are set securely when writing the dump file.

Comment on lines +202 to +216
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);
}
}

Copy link

Choose a reason for hiding this comment

The 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:

  • Race conditions by including process ID
  • Portability by using std::env::temp_dir()
  • Better organization by including fork name in filename
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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);
}
}
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 temp_dir = std::env::temp_dir();
let filename = temp_dir.join(format!(
"task_{}_{}_{}.json",
fork_name_str,
std::process::id(),
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);
}
}
🤖 Prompt for AI Agents
In crates/libzkp_c/src/lib.rs around lines 202 to 216, the task dumping logic
has race conditions and security issues similar to the proof dumping logic. Fix
this by generating the dump filename using std::env::temp_dir() for portability,
include the process ID to avoid race conditions, and ensure the fork name is
part of the filename for better organization. Update the filename construction
accordingly and handle errors as before.

@noel2004
Copy link
Member Author

Has been deprecated since we have #1694

@noel2004 noel2004 closed this Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant