Skip to content

Commit

Permalink
q
Browse files Browse the repository at this point in the history
  • Loading branch information
iajoiner committed Oct 28, 2024
1 parent 1d962c1 commit 2d41427
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
4 changes: 2 additions & 2 deletions crates/proof-of-sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ std = ["snafu/std"]
workspace = true

[[bin]]
name = "commit-utility"
path = "utils/commit-utility/main.rs"
name = "commitment-utility"
path = "utils/commitment-utility/main.rs"

[[example]]
name = "hello_world"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Utility to deserialize and print a commitment from a file or stdin.
use clap::Parser;
use clap::{Parser, ValueEnum};
use curve25519_dalek::ristretto::RistrettoPoint;
use proof_of_sql::{
base::commitment::TableCommitment,
Expand All @@ -9,49 +9,58 @@ use snafu::Snafu;
use std::{
fs::File,
io::{self, Read, Write},
path::PathBuf,
};

#[derive(ValueEnum, Clone, Debug)]
/// Supported commitment schemes.
enum CommitmentScheme {
/// Inner Product Argument (IPA) commitment scheme.
Ipa,
/// Dory commitment scheme.
Dory,
/// Dynamic Dory commitment scheme.
DynamicDory,
}

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// Input file (defaults to stdin)
/// Input file (defaults to None which is stdin)
#[arg(short, long)]
input: Option<String>,
input: Option<PathBuf>,

/// Output file (defaults to stdout)
/// Output file (defaults to None which is stdout)
#[arg(short, long)]
output: Option<String>,
output: Option<PathBuf>,

/// Commitment scheme (e.g. `ipa`, `dynamic_dory`, `dory`)
#[arg(long)]
scheme: String,
#[arg(long, value_enum, default_value = "CommitmentScheme::DynamicDory")]
scheme: CommitmentScheme,
}

#[derive(Debug, Snafu)]
enum CommitUtilityError {
#[snafu(display("Failed to open input file '{}'", filename))]
OpenInputFile { filename: String },
#[snafu(display("Failed to open input file '{:?}'", filename))]
OpenInputFile { filename: PathBuf },

#[snafu(display("Failed to read from input file '{}'", filename))]
ReadInputFile { filename: String },
#[snafu(display("Failed to read from input file '{:?}'", filename))]
ReadInputFile { filename: PathBuf },

#[snafu(display("Failed to read from stdin"))]
ReadStdin,

#[snafu(display("Failed to create output file '{}'", filename))]
CreateOutputFile { filename: String },
#[snafu(display("Failed to create output file '{:?}'", filename))]
CreateOutputFile { filename: PathBuf },

#[snafu(display("Failed to write to output file '{}'", filename))]
WriteOutputFile { filename: String },
#[snafu(display("Failed to write to output file '{:?}'", filename))]
WriteOutputFile { filename: PathBuf },

#[snafu(display("Failed to write to stdout"))]
WriteStdout,

#[snafu(display("Failed to deserialize commitment"))]
DeserializationError,

#[snafu(display("Unknown scheme: '{}'", scheme))]
UnknownScheme { scheme: String },
}

type CommitUtilityResult<T, E = CommitUtilityError> = std::result::Result<T, E>;
Expand Down Expand Up @@ -83,28 +92,23 @@ fn main() -> CommitUtilityResult<()> {
};

// Deserialize commitment based on the scheme
let human_readable = match cli.scheme.to_lowercase().as_str() {
"dynamic_dory" | "dynamic-dory" => {
let human_readable = match cli.scheme {
CommitmentScheme::DynamicDory => {
let commitment: TableCommitment<DynamicDoryCommitment> =
postcard::from_bytes(&input_data)
.map_err(|_| CommitUtilityError::DeserializationError)?;
format!("{commitment:#?}")
}
"dory" => {
CommitmentScheme::Dory => {
let commitment: TableCommitment<DoryCommitment> = postcard::from_bytes(&input_data)
.map_err(|_| CommitUtilityError::DeserializationError)?;
format!("{commitment:#?}")
}
"ipa" | "innerproductargument" => {
CommitmentScheme::Ipa => {
let commitment: TableCommitment<RistrettoPoint> = postcard::from_bytes(&input_data)
.map_err(|_| CommitUtilityError::DeserializationError)?;
format!("{commitment:#?}")
}
_ => {
return Err(CommitUtilityError::UnknownScheme {
scheme: cli.scheme.clone(),
});
}
};

// Write output data
Expand Down

0 comments on commit 2d41427

Please sign in to comment.