Skip to content

Conversation

@0xwonj
Copy link

@0xwonj 0xwonj commented Jul 15, 2024

PR Description

This PR introduces several CLI commands to the Frida Prover project, enabling users to initialize the system, generate data, create commitments, generate proofs, and verify proofs. The key additions are:

  1. Generate Data: Command to generate random data and save it to a file.
  2. Init: Command to initialize the system with default or specified parameters.
  3. Commit: Command to create a commitment from the data.
  4. Open: Command to generate a proof for specified positions.
  5. Verify: Command to verify the generated proof.

Running the Project

Run the project using Cargo with the following command:

cargo run --bin frida-poc

Commands

Generate Data

Usage:

generate-data <size>

Generates a random data file of the specified size (in bytes).

  • size: Size of the data in bytes.
    • e.g. generate-data 200 (size ≥ 200 bytes)

Options:

  • --data_path: Path to the data file. (default: data/data.bin)

Note: Use double dash (--) when specifying options.

  • e.g. generate-data 200 --data_path custom/data.bin

Init

Usage:

init

Initializes the system with default or specified values. Should be called at the start.

Options:

  • --data_path: Path to the data file. (default: data/data.bin)
  • --blowup_factor: Blowup factor of the evaluation domain (power of two). (default: 8)
  • --folding_factor: Factor by which the degree of a polynomial is reduced with each FRI layer (one of 2, 4, 8, 16). (default: 2)
  • --max_remainder_degree: Maximum allowed remainder polynomial degree. (default: 7)

Note: Ensure the data file is present at the specified path. If not, use the generate-data command to create the data first.

Commit

Usage:

commit <num_queries>

Generates a commitment from the data.

  • num_queries: Number of queries to generate.
    • e.g. commit 31

Open

Usage:

open <positions>

Generates a proof for the specified positions.

  • positions: List of positions to open.
    • e.g. open 1 2 4, open 5

Verify

Usage:

verify

Verifies the generated proof.


This PR aims to enhance the functionality and usability of the Frida Prover project by providing a set of essential CLI commands. These commands allow users to perform critical operations such as data generation, system initialization, commitment creation, proof generation, and proof verification with ease.

Please review the changes and provide feedback.

@0xwonj 0xwonj self-assigned this Jul 15, 2024
@0xwonj 0xwonj requested review from ali-rezai and frozenspider July 16, 2024 01:44
Copy link
Contributor

@frozenspider frozenspider left a comment

Choose a reason for hiding this comment

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

Reviewed, left comments

src/main.rs Outdated
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.map_err(|_| "Failed to read input.".to_string())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: In this method I think it makes sense to use unwrap/expect on IO stuff as those errors probably mean something is deeply wrong and we won't be able to recover anyway.

Copy link
Author

Choose a reason for hiding this comment

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

Changed as suggested.

let mut input = String::new();
io::stdin()
    .read_line(&mut input)
    .expect("Failed to read input.");

src/main.rs Outdated
}
}

fn match_prover(prover: &mut Option<FridaProverType>) -> &mut FridaProverType {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is better to be done on an outer level, for several reasons, specifically:

  • This should be caller's responsibility to provide a ready-to-use arguments
  • This error is not actually fatal, and caller can recover from it

I suggest this:

fn main() {
    let mut prover: Option<FridaProverType> = None;

    fn try_unwrap_mut<T>(prover: &mut Option<T>) -> Result<&mut T, String> {
        prover.as_mut().ok_or("Please call the init command first.".to_owned())
    }

    let mut iteration = || -> Result<(), String> {
        let cli = read_and_parse_command()?;

        match cli.command {
            // ...
            Commands::Commit { .. } => {
                handle_commit(cli.command, try_unwrap_mut(&mut prover)?);
            }
            // ...
        }
        Ok(())
    };

    loop {
        if let Err(err) = iteration() {
            eprintln!("Error: {}", err);
        }
    }
}

Copy link
Author

Choose a reason for hiding this comment

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

Changed as suggested.
And thanks for the detailed feedback. I really appreciate it!

Copy link
Contributor

@frozenspider frozenspider left a comment

Choose a reason for hiding this comment

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

LGTM!

@frozenspider
Copy link
Contributor

BTW @0xwonj this PR has a really nice usage description, would you mind also making a README out of it?

@ali-rezai ali-rezai merged commit d631f50 into main Sep 2, 2024
@frozenspider frozenspider deleted the feature/cli branch September 2, 2024 16:33
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.

4 participants