From 854f6ce3103ffd04822251b1edb44e3e34b3915a Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 28 Aug 2023 16:16:28 +0800 Subject: [PATCH] fix make lint --- common/libzkp/impl/src/batch.rs | 32 ++++++++++++++++++++------------ common/libzkp/impl/src/chunk.rs | 14 ++++++++------ common/libzkp/impl/src/lib.rs | 2 +- prover/core/prover.go | 5 ++++- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/common/libzkp/impl/src/batch.rs b/common/libzkp/impl/src/batch.rs index 8629b12d96..7429556813 100644 --- a/common/libzkp/impl/src/batch.rs +++ b/common/libzkp/impl/src/batch.rs @@ -1,5 +1,7 @@ -use crate::utils::{c_char_to_str, c_char_to_vec, string_to_c_char, vec_to_c_char, OUTPUT_DIR}; -use crate::types::{CheckChunkProofsResponse, ProofResult}; +use crate::{ + types::{CheckChunkProofsResponse, ProofResult}, + utils::{c_char_to_str, c_char_to_vec, string_to_c_char, vec_to_c_char, OUTPUT_DIR}, +}; use libc::c_char; use prover::{ aggregator::{Prover, Verifier}, @@ -64,11 +66,14 @@ pub unsafe extern "C" fn check_chunk_proofs(chunk_proofs: *const c_char) -> *con return Err("Provided chunk proofs are empty.".to_string()); } - PROVER.get() - .map_err(|_| "Failed to get reference to PROVER.".to_string())? - .check_chunk_proofs(&chunk_proofs) - .map_err(|e| format!("Error checking chunk proofs: {:?}", e)) - }).unwrap_or_else(|err| Err(format!("Unwind error: {:?}", err))); + let prover_ref = PROVER + .get() + .ok_or_else(|| "Failed to get reference to PROVER.".to_string())?; + + let valid = prover_ref.check_chunk_proofs(&chunk_proofs); + Ok(valid) + }) + .unwrap_or_else(|err| Err(format!("Unwind error: {:?}", err))); let r = match check_result { Ok(valid) => CheckChunkProofsResponse { @@ -103,17 +108,20 @@ pub unsafe extern "C" fn gen_batch_proof( return Err("Chunk hashes and chunk proofs lengths mismatch.".to_string()); } - let chunk_hashes_proofs = chunk_hashes.into_iter().zip(chunk_proofs.into_iter()).collect(); + let chunk_hashes_proofs = chunk_hashes + .into_iter() + .zip(chunk_proofs.into_iter()) + .collect(); let proof = PROVER .get_mut() - .map_err(|_| "Failed to get mutable reference to PROVER.".to_string())? + .ok_or_else(|| "Failed to get mutable reference to PROVER.".to_string())? .gen_agg_evm_proof(chunk_hashes_proofs, None, OUTPUT_DIR.as_deref()) .map_err(|e| format!("Proof generation failed: {:?}", e))?; - serde_json::to_vec(&proof) - .map_err(|e| format!("Failed to serialize the proof: {:?}", e)) - }).unwrap_or_else(|err| Err(format!("Unwind error: {:?}", err))); + serde_json::to_vec(&proof).map_err(|e| format!("Failed to serialize the proof: {:?}", e)) + }) + .unwrap_or_else(|err| Err(format!("Unwind error: {:?}", err))); let r = match proof_result { Ok(proof_bytes) => ProofResult { diff --git a/common/libzkp/impl/src/chunk.rs b/common/libzkp/impl/src/chunk.rs index 9c0ec9bfdc..ba1e49ce5e 100644 --- a/common/libzkp/impl/src/chunk.rs +++ b/common/libzkp/impl/src/chunk.rs @@ -1,5 +1,7 @@ -use crate::utils::{c_char_to_str, c_char_to_vec, string_to_c_char, vec_to_c_char, OUTPUT_DIR}; -use crate::types::ProofResult; +use crate::{ + types::ProofResult, + utils::{c_char_to_str, c_char_to_vec, string_to_c_char, vec_to_c_char, OUTPUT_DIR}, +}; use libc::c_char; use prover::{ utils::init_env_and_log, @@ -63,13 +65,13 @@ pub unsafe extern "C" fn gen_chunk_proof(block_traces: *const c_char) -> *const let proof = PROVER .get_mut() - .map_err(|_| "Failed to get mutable reference to PROVER.".to_string())? + .ok_or_else(|| "Failed to get mutable reference to PROVER.".to_string())? .gen_chunk_proof(block_traces, None, OUTPUT_DIR.as_deref()) .map_err(|e| format!("Proof generation failed: {:?}", e))?; - serde_json::to_vec(&proof) - .map_err(|e| format!("Failed to serialize the proof: {:?}", e)) - }).unwrap_or_else(|err| Err(format!("Unwind error: {:?}", err))); + serde_json::to_vec(&proof).map_err(|e| format!("Failed to serialize the proof: {:?}", e)) + }) + .unwrap_or_else(|err| Err(format!("Unwind error: {:?}", err))); let r = match proof_result { Ok(proof_bytes) => ProofResult { diff --git a/common/libzkp/impl/src/lib.rs b/common/libzkp/impl/src/lib.rs index c172cbabf5..49af267459 100644 --- a/common/libzkp/impl/src/lib.rs +++ b/common/libzkp/impl/src/lib.rs @@ -2,5 +2,5 @@ mod batch; mod chunk; -mod utils; mod types; +mod utils; diff --git a/prover/core/prover.go b/prover/core/prover.go index ef7c7a9d0a..ed54cd942a 100644 --- a/prover/core/prover.go +++ b/prover/core/prover.go @@ -125,7 +125,10 @@ func (p *ProverCore) ProveChunk(taskID string, traces []*types.BlockTrace) (*mes if err != nil { return nil, err } - proofByt := p.proveChunk(tracesByt) + proofByt, err := p.proveChunk(tracesByt) + if err != nil { + return nil, err + } err = p.mayDumpProof(taskID, proofByt) if err != nil {