diff --git a/rln-cli/src/commands.rs b/rln-cli/src/commands.rs index dbc9f16..abb3267 100644 --- a/rln-cli/src/commands.rs +++ b/rln-cli/src/commands.rs @@ -41,4 +41,25 @@ pub(crate) enum Commands { index: usize, }, GetRoot, + GetProof { + index: usize, + }, + Prove { + #[arg(short, long)] + input: PathBuf, + }, + Verify { + #[arg(short, long)] + file: PathBuf, + }, + GenerateProof { + #[arg(short, long)] + input: PathBuf, + }, + VerifyWithRoots { + #[arg(short, long)] + input: PathBuf, + #[arg(short, long)] + roots: PathBuf, + }, } diff --git a/rln-cli/src/main.rs b/rln-cli/src/main.rs index a704118..650af03 100644 --- a/rln-cli/src/main.rs +++ b/rln-cli/src/main.rs @@ -105,6 +105,49 @@ fn main() -> Result<()> { .get_root(writer)?; Ok(()) } + Some(Commands::GetProof { index }) => { + let writer = std::io::stdout(); + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .get_proof(*index, writer)?; + Ok(()) + } + Some(Commands::Prove { input }) => { + let input_data = File::open(&input)?; + let writer = std::io::stdout(); + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .prove(input_data, writer)?; + Ok(()) + } + Some(Commands::Verify { file }) => { + let input_data = File::open(&file)?; + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .verify(input_data)?; + Ok(()) + } + Some(Commands::GenerateProof { input }) => { + let input_data = File::open(&input)?; + let writer = std::io::stdout(); + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .generate_rln_proof(input_data, writer)?; + Ok(()) + } + Some(Commands::VerifyWithRoots { input, roots }) => { + let input_data = File::open(&input)?; + let roots_data = File::open(&roots)?; + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .verify_with_roots(input_data, roots_data)?; + Ok(()) + } None => Ok(()), } } diff --git a/rln/src/pm_tree_adapter.rs b/rln/src/pm_tree_adapter.rs index e9bb730..10cd433 100644 --- a/rln/src/pm_tree_adapter.rs +++ b/rln/src/pm_tree_adapter.rs @@ -61,10 +61,22 @@ impl FromStr for PmtreeConfig { let temporary = config["temporary"].as_bool(); let path = config["path"].as_str(); let path = path.map(PathBuf::from); + let cache_capacity = config["cache_capacity"].as_u64(); + let flush_every_ms = config["flush_every_ms"].as_u64(); + let mode = match config["mode"].as_str() { + Some("HighThroughput") => Mode::HighThroughput, + Some("LowSpace") => Mode::LowSpace, + _ => Mode::HighThroughput, + }; + let use_compression = config["use_compression"].as_bool(); let config = pm_tree::Config::new() .temporary(temporary.unwrap_or(get_tmp())) - .path(path.unwrap_or(get_tmp_path())); + .path(path.unwrap_or(get_tmp_path())) + .cache_capacity(cache_capacity.unwrap_or(1024 * 1024 * 1024)) + .flush_every_ms(flush_every_ms) + .mode(mode) + .use_compression(use_compression.unwrap_or(false)); Ok(PmtreeConfig(config)) } } @@ -72,7 +84,15 @@ impl FromStr for PmtreeConfig { impl Default for PmtreeConfig { fn default() -> Self { let tmp_path = get_tmp_path(); - PmtreeConfig(pm_tree::Config::new().temporary(true).path(tmp_path)) + PmtreeConfig( + pm_tree::Config::new() + .temporary(true) + .path(tmp_path) + .cache_capacity(150_000) + .mode(Mode::HighThroughput) + .use_compression(false) + .flush_every_ms(Some(12_000)), + ) } } impl Debug for PmtreeConfig {