diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 45d44fd..0a77697 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -63,6 +63,9 @@ jobs: - name: Build run: cargo build --verbose + - name: Cargo fmt + run: cargo fmt --check + - name: Lint with Clippy run: cargo clippy -- -D warnings diff --git a/integration-tests/evm-test/src/lib.rs b/integration-tests/evm-test/src/lib.rs index e9b2c33..7948bef 100644 --- a/integration-tests/evm-test/src/lib.rs +++ b/integration-tests/evm-test/src/lib.rs @@ -11,14 +11,15 @@ use stark_evm_adapter::{ annotation_parser::{split_fri_merkle_statements, SplitProofs}, ContractFunctionCall, }; -use std::{ - convert::TryFrom, fs, path::PathBuf, str::FromStr, sync::Arc -}; +use std::{convert::TryFrom, fs, path::PathBuf, str::FromStr, sync::Arc}; /// Verify a proof file against Ethereum SHARP contracts. -/// +/// /// See lib.rs for more details -pub async fn verify_annotated_proof_with_l1(annotated_proof_file: &PathBuf, mainnet_rpc: String) -> Result<(), Box> { +pub async fn verify_annotated_proof_with_l1( + annotated_proof_file: &PathBuf, + mainnet_rpc: String, +) -> Result<(), Box> { let proof_str = fs::read_to_string(annotated_proof_file)?; let annotated_proof: AnnotatedProof = serde_json::from_str(proof_str.as_str())?; @@ -28,7 +29,10 @@ pub async fn verify_annotated_proof_with_l1(annotated_proof_file: &PathBuf, main verify_split_proofs_with_l1(&split_proofs, mainnet_rpc).await } -pub async fn verify_split_proofs_with_l1(split_proofs: &SplitProofs, mainnet_rpc: String) -> Result<(), Box> { +pub async fn verify_split_proofs_with_l1( + split_proofs: &SplitProofs, + mainnet_rpc: String, +) -> Result<(), Box> { let anvil = Some(Anvil::new().fork(mainnet_rpc).spawn()); let endpoint = anvil.as_ref().unwrap().endpoint(); let provider = Provider::::try_from(endpoint.as_str())?; diff --git a/integration-tests/evm-test/src/main.rs b/integration-tests/evm-test/src/main.rs index 4f4fe66..f3c3421 100644 --- a/integration-tests/evm-test/src/main.rs +++ b/integration-tests/evm-test/src/main.rs @@ -3,16 +3,16 @@ use std::path::PathBuf; /// Binary borrowed from `stark-evm-adapter` used to test a split proof against in-production /// SHARP provers on Ethereum. -/// +/// /// Source: https://github.com/notlesh/stark-evm-adapter/blob/main/examples/verify_stone_proof.rs -/// +/// /// Input file ("split proof") should be a proof JSON file generated from `cpu_air_prover` along /// with an `annotations` field (array) and `extra_annotations` field (array) which come from, /// respectively, `--annotations_file` and `--extra_output_file` from `cpu_air_verifier`. -/// +/// /// This also requires `anvil` from `forge` /// [to be installed](https://book.getfoundry.sh/getting-started/installation). -/// +/// /// A suitable input file can be borrowed from /// https://github.com/notlesh/stark-evm-adapter/blob/main/tests/fixtures/annotated_proof.json diff --git a/madara-prover-rpc-server/src/evm_adapter.rs b/madara-prover-rpc-server/src/evm_adapter.rs index b9e272a..41fb7dc 100644 --- a/madara-prover-rpc-server/src/evm_adapter.rs +++ b/madara-prover-rpc-server/src/evm_adapter.rs @@ -2,8 +2,8 @@ use std::path::Path; use madara_prover_common::toolkit::read_json_from_file; use stark_evm_adapter::{ - annotation_parser::{split_fri_merkle_statements, SplitProofs}, annotated_proof::AnnotatedProof, + annotation_parser::{split_fri_merkle_statements, SplitProofs}, }; use std::io::BufRead; use thiserror::Error; @@ -13,19 +13,19 @@ pub enum SplitProverError { #[error("I/O Error")] Io(#[from] std::io::Error), #[error("Error involving split proof")] - ProofParseError(#[from] stark_evm_adapter::errors::ParseError) + ProofParseError(#[from] stark_evm_adapter::errors::ParseError), } -/// Uses stark-evm-adapter to split the proof. +/// Uses stark-evm-adapter to split the proof. pub fn split_proof( proof_file: &Path, annotations_file: &Path, - extra_annotations_file: &Path + extra_annotations_file: &Path, ) -> Result { // 'proof_file' is not expected to have an annotations or an extra_annotations field. // but this will cause an error if we try to parse it as an AnnotatedProof without these // fields. - // + // // since these values are given as separate files, we will with the proof as a JSON object // and add the 'annotations' and 'extra_annotations' fields manually, as the `stark-evm-adapter` // binary does. @@ -33,11 +33,10 @@ pub fn split_proof( proof_json["annotations"] = load_annotations_file(annotations_file)?.into(); proof_json["extra_annotations"] = load_annotations_file(extra_annotations_file)?.into(); - let annotated_proof: AnnotatedProof = serde_json::from_value(proof_json) - .unwrap(); // TODO + let annotated_proof: AnnotatedProof = serde_json::from_value(proof_json).unwrap(); // TODO let split_proofs: SplitProofs = split_fri_merkle_statements(annotated_proof)?; - + Ok(split_proofs) } @@ -56,17 +55,24 @@ pub fn load_annotations_file(file: &Path) -> std::io::Result> { mod tests { #[test] fn split_proof_works_with_empty_bootloader_proof() { - let annotated_proof_file = test_cases::get_test_case_file_path("bootloader/empty_bootloader_proof/annotated_proof.json"); - let annotations_file = test_cases::get_test_case_file_path("bootloader/empty_bootloader_proof/annotations.txt"); - let extra_annotations_file = test_cases::get_test_case_file_path("bootloader/empty_bootloader_proof/extra_annotations.txt"); + let annotated_proof_file = test_cases::get_test_case_file_path( + "bootloader/empty_bootloader_proof/annotated_proof.json", + ); + let annotations_file = test_cases::get_test_case_file_path( + "bootloader/empty_bootloader_proof/annotations.txt", + ); + let extra_annotations_file = test_cases::get_test_case_file_path( + "bootloader/empty_bootloader_proof/extra_annotations.txt", + ); let split_proofs = crate::evm_adapter::split_proof( &annotated_proof_file, &annotations_file, - &extra_annotations_file - ).unwrap(); + &extra_annotations_file, + ) + .unwrap(); assert!(split_proofs.merkle_statements.len() > 0); assert!(split_proofs.fri_merkle_statements.len() > 0); assert!(split_proofs.main_proof.proof.len() > 0); } -} \ No newline at end of file +} diff --git a/madara-prover-rpc-server/src/services/common.rs b/madara-prover-rpc-server/src/services/common.rs index 0db6f20..8730dff 100644 --- a/madara-prover-rpc-server/src/services/common.rs +++ b/madara-prover-rpc-server/src/services/common.rs @@ -1,6 +1,8 @@ use crate::cairo::ExecutionArtifacts; use crate::evm_adapter; -use madara_prover_common::models::{Proof, ProofAnnotations, ProverConfig, ProverParameters, ProverWorkingDirectory}; +use madara_prover_common::models::{ + Proof, ProofAnnotations, ProverConfig, ProverParameters, ProverWorkingDirectory, +}; use stone_prover::error::{ProverError, VerifierError}; use stone_prover::fri::generate_prover_parameters; use stone_prover::prover::{run_prover_async, run_verifier_async}; @@ -65,7 +67,7 @@ pub fn format_verifier_error(e: VerifierError) -> Status { )), VerifierError::IoError(io_error) => { Status::internal(format!("Could not run the verifier: {}", io_error)) - }, + } } } @@ -88,16 +90,23 @@ pub fn get_prover_parameters( /// Calls `cpu_air_verifier` to verify the proof and produce annotations, then uses /// `stark-evm-adapter` to split the proof. The given Proof will then be modified to contain /// this additional split-proof. -pub async fn verify_and_annotate_proof(proof: &mut Proof, working_dir: &mut ProverWorkingDirectory) -> Result<(), Status> { +pub async fn verify_and_annotate_proof( + proof: &mut Proof, + working_dir: &mut ProverWorkingDirectory, +) -> Result<(), Status> { let _ = // TODO: return type seems worthless here call_verifier(working_dir) .await .map_err(format_verifier_error)?; let proof_file_path = working_dir.proof_file.as_path(); - let annotations_file_path = working_dir.annotations_file.clone() + let annotations_file_path = working_dir + .annotations_file + .clone() .ok_or(Status::internal("Expected annotations_file_path"))?; - let extra_annotations_file_path = working_dir.extra_annotations_file.clone() + let extra_annotations_file_path = working_dir + .extra_annotations_file + .clone() .ok_or(Status::internal("Expected extra_annotations_file_path"))?; let split_proof = evm_adapter::split_proof( @@ -106,8 +115,8 @@ pub async fn verify_and_annotate_proof(proof: &mut Proof, working_dir: &mut Prov extra_annotations_file_path.as_path(), ) .map_err(|_| Status::internal("Unable to generate split proof"))?; - + proof.split_proofs = Some(split_proof); Ok(()) -} \ No newline at end of file +} diff --git a/madara-prover-rpc-server/src/services/starknet_prover.rs b/madara-prover-rpc-server/src/services/starknet_prover.rs index 63047d3..c09bbb5 100644 --- a/madara-prover-rpc-server/src/services/starknet_prover.rs +++ b/madara-prover-rpc-server/src/services/starknet_prover.rs @@ -23,7 +23,9 @@ use madara_prover_common::models::{Proof, ProverConfig, ProverWorkingDirectory}; use stone_prover::error::ProverError; use crate::cairo::{extract_execution_artifacts, ExecutionArtifacts, ExecutionError}; -use crate::services::common::{call_prover, format_prover_error, get_prover_parameters, verify_and_annotate_proof}; +use crate::services::common::{ + call_prover, format_prover_error, get_prover_parameters, verify_and_annotate_proof, +}; use crate::services::starknet_prover::starknet_prover_proto::starknet_prover_server::StarknetProver; use crate::services::starknet_prover::starknet_prover_proto::{ StarknetExecutionRequest, StarknetProverResponse, @@ -212,8 +214,8 @@ impl StarknetProver for StarknetProverService { let (mut proof, mut working_dir) = call_prover(&execution_artifacts, &prover_config, &prover_parameters) - .await - .map_err(format_prover_error)?; + .await + .map_err(format_prover_error)?; // If split proof was requested, build it if split_proof { diff --git a/stone-prover/build.rs b/stone-prover/build.rs index 7f952e9..cb2337b 100644 --- a/stone-prover/build.rs +++ b/stone-prover/build.rs @@ -71,7 +71,6 @@ fn make_docker_build_command(repo_dir: &Path, image_name: &str) -> String { docker_build_command.push_str(" --build-arg CMAKE_ARGS=-DNO_AVX=1"); } - // Check if a cache image exists. Used by the CI/CD pipeline. if let Ok(cache_image) = std::env::var("STONE_PROVER_DOCKER_CACHE") { docker_build_command.push_str(&format!(" --cache-from {cache_image}")); diff --git a/stone-prover/src/error.rs b/stone-prover/src/error.rs index 20db125..8f74a1e 100644 --- a/stone-prover/src/error.rs +++ b/stone-prover/src/error.rs @@ -16,4 +16,4 @@ pub enum VerifierError { IoError(#[from] std::io::Error), #[error("verifier run failed")] CommandError(std::process::Output), -} \ No newline at end of file +} diff --git a/stone-prover/src/lib.rs b/stone-prover/src/lib.rs index fbb21c5..1d251a8 100644 --- a/stone-prover/src/lib.rs +++ b/stone-prover/src/lib.rs @@ -1,3 +1,3 @@ pub mod error; -pub mod prover; pub mod fri; +pub mod prover; diff --git a/stone-prover/src/prover.rs b/stone-prover/src/prover.rs index b76cdb3..a2dd6b9 100644 --- a/stone-prover/src/prover.rs +++ b/stone-prover/src/prover.rs @@ -3,7 +3,9 @@ use std::path::Path; use tempfile::tempdir; -use madara_prover_common::models::{Proof, ProofAnnotations, ProverConfig, ProverParameters, ProverWorkingDirectory, PublicInput}; +use madara_prover_common::models::{ + Proof, ProofAnnotations, ProverConfig, ProverParameters, ProverWorkingDirectory, PublicInput, +}; use madara_prover_common::toolkit::{read_json_from_file, write_json_to_file}; use crate::error::{ProverError, VerifierError}; @@ -272,14 +274,8 @@ pub async fn run_verifier_async( annotation_file: &Path, extra_output_file: &Path, ) -> Result { - // Call the verifier - run_verifier_from_command_line_async( - in_file, - annotation_file, - extra_output_file, - ) - .await?; + run_verifier_from_command_line_async(in_file, annotation_file, extra_output_file).await?; let annotations = ProofAnnotations { annotation_file: annotation_file.into(),