Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
149 changes: 4 additions & 145 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ arkworks = [
]
parallel = ["dep:rayon", "ark-ec?/parallel", "ark-ff?/parallel"]
cache = ["arkworks", "dep:once_cell", "parallel"]
disk-persistence = ["dep:dirs"]
disk-persistence = []

[dependencies]
thiserror = "2.0"
rand_core = "0.6"
dory-derive = { version = "0.1.0", path = "derive" }
tracing = "0.1"
dirs = { version = "5.0", optional = true }

# Arkworks backend
ark-bn254 = { version = "0.5.0", optional = true }
Expand Down
46 changes: 33 additions & 13 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,26 +196,46 @@ impl<E: PairingCurve> ProverSetup<E> {
}
}

/// Get the storage directory for Dory setup files
/// Get the full path to the setup file for a given max_log_n
///
/// Returns the appropriate storage directory based on the OS:
/// Determines the appropriate storage directory based on the OS:
/// - Linux: `~/.cache/dory/`
/// - macOS: `~/Library/Caches/dory/`
/// - Windows: `{FOLDERID_LocalAppData}\dory\`
///
/// Note: Uses XDG cache directory for persistent storage.
#[cfg(feature = "disk-persistence")]
fn get_storage_dir() -> Option<PathBuf> {
dirs::cache_dir().map(|mut path| {
path.push("dory");
path
})
}

/// Get the full path to the setup file for a given max_log_n
/// Note: Detects OS at runtime by checking environment variables then chooses XDG cache directory for persistent storage.
#[cfg(feature = "disk-persistence")]
fn get_storage_path(max_log_n: usize) -> Option<PathBuf> {
get_storage_dir().map(|mut path| {
let cache_directory = {
// Check for Windows first (LOCALAPPDATA is Windows-specific)
if let Ok(local_app_data) = std::env::var("LOCALAPPDATA") {
Some(PathBuf::from(local_app_data))
} else if let Ok(home) = std::env::var("HOME") {
let mut path = PathBuf::from(&home);

// Check if Library/Caches exists (macOS indicator)
let macos_cache = {
let mut test_path = PathBuf::from(&home);
test_path.push("Library");
test_path.push("Caches");
test_path.exists()
};

if macos_cache {
path.push("Library");
path.push("Caches");
} else {
// Linux and other Unix-like systems
path.push(".cache");
}
Some(path)
} else {
None
}
};

cache_directory.map(|mut path| {
path.push("dory");
path.push(format!("dory_{}.urs", max_log_n));
path
})
Expand Down
39 changes: 35 additions & 4 deletions tests/arkworks/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,41 @@ fn test_arkworks_setup_new_from_urs() {
let max_log_n = 14;

// Clean up any existing cache file first
if let Some(cache_dir) = dirs::cache_dir() {
let cache_file = cache_dir
.join("dory")
.join(format!("dory_{}.urs", max_log_n));
let cache_directory = {
// Check for Windows first (LOCALAPPDATA is Windows-specific)
if let Ok(local_app_data) = std::env::var("LOCALAPPDATA") {
Some(std::path::PathBuf::from(local_app_data))
} else if let Ok(home) = std::env::var("HOME") {
let mut path = std::path::PathBuf::from(&home);

// Check if Library/Caches exists (macOS indicator)
let macos_cache = {
let mut test_path = std::path::PathBuf::from(&home);
test_path.push("Library");
test_path.push("Caches");
test_path.exists()
};

if macos_cache {
path.push("Library");
path.push("Caches");
} else {
// Linux and other Unix-like systems
path.push(".cache");
}
Some(path)
} else {
None
}
};

let cache_file = cache_directory.map(|mut path| {
path.push("dory");
path.push(format!("dory_{}.urs", max_log_n));
path
});

if let Some(cache_file) = cache_file {
let _ = std::fs::remove_file(&cache_file);
}

Expand Down