Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: info logs #5

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ edition = "2021"
[dependencies]
cairo-vm = { git = "https://github.com/Moonsong-Labs/cairo-vm", rev = "b2f69d230416129a84ad8237ccc13d088992f74b", features = ["extensive_hints"] }
clap = { version = "4.5.0", features = ["derive"] }
env_logger = { version = "0.11.2", features = ["color"] }
log = "0.4.20"
serde = { version = "1.0.196", features = ["derive"] }
serde_json = { version = "1.0.113" }
stone-prover-sdk = { git = "https://github.com/Moonsong-Labs/stone-prover-sdk", tag="v0.3.0" }
stone-prover-sdk = { git = "https://github.com/Moonsong-Labs/stone-prover-sdk", tag = "v0.3.0" }
thiserror = { version = "1.0.57" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion scripts/install-stone-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eo pipefail

VERSION="v0.1.0"
VERSION="v0.1.1"
INSTALL_DIR="${HOME}/.stone/${VERSION}"
TARBALL="stone-cli-linux-x86-64.tar.gz"

Expand Down
6 changes: 6 additions & 0 deletions src/commands/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cairo_vm::types::errors::cairo_pie_error::CairoPieError;
use cairo_vm::types::errors::program_errors::ProgramError;
use cairo_vm::types::program::Program;
use cairo_vm::vm::runners::cairo_pie::CairoPie;
use log::{debug, info};
use serde::Serialize;
use stone_prover_sdk::cairo_vm::{
extract_execution_artifacts, run_bootloader_in_proof_mode, run_in_proof_mode,
Expand Down Expand Up @@ -106,6 +107,8 @@ pub fn run_with_bootloader(args: ProveWithBootloaderArgs) -> Result<ExecutionArt
}

pub fn prove(command: ProveCommand) -> Result<(), RunError> {
debug!("preparing config files...");

// Cloning here is the easiest solution to avoid borrow checks.
let config_args = command.config().clone();

Expand All @@ -122,6 +125,7 @@ pub fn prove(command: ProveCommand) -> Result<(), RunError> {
.map(|path| read_json_from_file(path).map_err(|e| RunError::Deserialize(path.clone(), e)))
.transpose()?;

info!("execution in progress...");
let execution_artifacts = match command {
ProveCommand::Bare(args) => run_program(args)?,
ProveCommand::WithBootloader(args) => run_with_bootloader(args)?,
Expand All @@ -133,6 +137,7 @@ pub fn prove(command: ProveCommand) -> Result<(), RunError> {
last_layer_degree_bound,
));

info!("proving in progress...");
let proof = run_prover(
&execution_artifacts.public_input,
&execution_artifacts.private_input,
Expand All @@ -141,6 +146,7 @@ pub fn prove(command: ProveCommand) -> Result<(), RunError> {
&prover_config,
&prover_parameters,
)?;
info!("proving completed!");

let output_file = config_args.output_file();
write_json_to_file(proof, output_file.as_ref())
Expand Down
7 changes: 6 additions & 1 deletion src/commands/verify.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use log::info;
use stone_prover_sdk::error::VerifierError;
use stone_prover_sdk::verifier::run_verifier;

use crate::cli::VerifyArgs;

pub fn verify(args: VerifyArgs) -> Result<(), VerifierError> {
run_verifier(args.proof_file.as_path())
info!("verification in progress...");
run_verifier(args.proof_file.as_path())?;
info!("verification completed!");

Ok(())
}
30 changes: 26 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::cli::Cli;
use crate::commands::prove::RunError;
use cairo_vm::vm::errors::cairo_run_errors::CairoRunError;
use clap::Parser;
use env_logger::fmt::Formatter;
use log::{error, LevelFilter, Record};
use std::io;
use std::io::Write;
use stone_prover_sdk::cairo_vm::ExecutionError;
use stone_prover_sdk::error::VerifierError;

use crate::cli::Cli;
use crate::commands::prove::RunError;

mod cli;
mod commands;
mod toolkit;
Expand All @@ -18,6 +21,23 @@ enum CliError {
Verify(#[from] VerifierError),
}

fn format_log(buf: &mut Formatter, record: &Record) -> io::Result<()> {
let level_style = buf.default_level_style(record.level());
writeln!(
buf,
"{level_style}{:<5}{level_style:#} {}",
record.level().to_string().to_lowercase(),
record.args()
)
}

fn setup_logging() {
env_logger::Builder::new()
.filter_level(LevelFilter::Info)
.format(format_log)
.init();
}

fn display_error(error: CliError) {
let error_message = match error {
CliError::Prove(run_error) => match run_error {
Expand Down Expand Up @@ -70,7 +90,7 @@ fn display_error(error: CliError) {
}
},
};
println!("Error: {}", error_message);
error!("{}", error_message);
}

fn process_cli_command(command: Cli) -> Result<(), CliError> {
Expand All @@ -83,6 +103,8 @@ fn process_cli_command(command: Cli) -> Result<(), CliError> {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
setup_logging();

let command = Cli::parse();
if let Err(e) = process_cli_command(command) {
display_error(e);
Expand Down
Loading