File tree Expand file tree Collapse file tree 5 files changed +43
-152
lines changed Expand file tree Collapse file tree 5 files changed +43
-152
lines changed Original file line number Diff line number Diff line change @@ -47,14 +47,13 @@ arkworks = [
4747]
4848parallel = [" dep:rayon" , " ark-ec?/parallel" , " ark-ff?/parallel" ]
4949cache = [" arkworks" , " dep:once_cell" , " parallel" ]
50- disk-persistence = [" dep:dirs " ]
50+ disk-persistence = []
5151
5252[dependencies ]
5353thiserror = " 2.0"
5454rand_core = " 0.6"
5555dory-derive = { version = " 0.1.0" , path = " derive" }
5656tracing = " 0.1"
57- dirs = { version = " 5.0" , optional = true }
5857
5958# Arkworks backend
6059ark-bn254 = { version = " 0.5.0" , optional = true }
Original file line number Diff line number Diff line change @@ -110,6 +110,9 @@ pub use proof::DoryProof;
110110pub use reduce_and_fold:: { DoryProverState , DoryVerifierState } ;
111111pub use setup:: { ProverSetup , VerifierSetup } ;
112112
113+ #[ cfg( feature = "disk-persistence" ) ]
114+ pub use setup:: get_storage_dir;
115+
113116/// Generate or load prover and verifier setups from disk
114117///
115118/// Creates or loads the transparent setup parameters for Dory PCS.
Original file line number Diff line number Diff line change @@ -204,12 +204,41 @@ impl<E: PairingCurve> ProverSetup<E> {
204204/// - Windows: `{FOLDERID_LocalAppData}\dory\`
205205///
206206/// Note: Uses XDG cache directory for persistent storage.
207+ /// Detects OS at runtime by checking environment variables, then determines the cache directory.
207208#[ cfg( feature = "disk-persistence" ) ]
208- fn get_storage_dir ( ) -> Option < PathBuf > {
209- dirs:: cache_dir ( ) . map ( |mut path| {
209+ pub fn get_storage_dir ( ) -> Option < PathBuf > {
210+ // Check for Windows first (LOCALAPPDATA is Windows-specific)
211+ if let Ok ( local_app_data) = std:: env:: var ( "LOCALAPPDATA" ) {
212+ let mut path = PathBuf :: from ( local_app_data) ;
210213 path. push ( "dory" ) ;
211- path
212- } )
214+ return Some ( path) ;
215+ }
216+
217+ // For Unix-like systems, check for HOME
218+ if let Ok ( home) = std:: env:: var ( "HOME" ) {
219+ let mut path = PathBuf :: from ( & home) ;
220+
221+ // Check if Library/Caches exists (macOS indicator)
222+ let macos_cache = {
223+ let mut test_path = PathBuf :: from ( & home) ;
224+ test_path. push ( "Library" ) ;
225+ test_path. push ( "Caches" ) ;
226+ test_path. exists ( )
227+ } ;
228+
229+ if macos_cache {
230+ path. push ( "Library" ) ;
231+ path. push ( "Caches" ) ;
232+ } else {
233+ // Linux and other Unix-like systems
234+ path. push ( ".cache" ) ;
235+ }
236+
237+ path. push ( "dory" ) ;
238+ return Some ( path) ;
239+ }
240+
241+ None
213242}
214243
215244/// Get the full path to the setup file for a given max_log_n
Original file line number Diff line number Diff line change @@ -151,12 +151,13 @@ fn test_arkworks_setup_new_from_urs() {
151151 use dory_pcs:: backends:: arkworks:: ArkworksProverSetup ;
152152 use dory_pcs:: { backends:: arkworks:: BN254 , generate_urs} ;
153153 use rand:: thread_rng;
154+ use dory_pcs:: setup:: get_storage_dir;
154155
155156 let mut rng = thread_rng ( ) ;
156157 let max_log_n = 14 ;
157158
158159 // Clean up any existing cache file first
159- if let Some ( cache_dir) = dirs :: cache_dir ( ) {
160+ if let Some ( cache_dir) = get_storage_dir ( ) {
160161 let cache_file = cache_dir
161162 . join ( "dory" )
162163 . join ( format ! ( "dory_{}.urs" , max_log_n) ) ;
You can’t perform that action at this time.
0 commit comments