Skip to content

Commit

Permalink
fix make lint
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Aug 28, 2023
1 parent 9631ad3 commit d309ebb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
32 changes: 20 additions & 12 deletions common/libzkp/impl/src/batch.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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).unwrap();
Ok(valid)
})
.unwrap_or_else(|err| Err(format!("Unwind error: {:?}", err)));

let r = match check_result {
Ok(valid) => CheckChunkProofsResponse {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions common/libzkp/impl/src/chunk.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion common/libzkp/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

mod batch;
mod chunk;
mod utils;
mod types;
mod utils;
5 changes: 4 additions & 1 deletion prover/core/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d309ebb

Please sign in to comment.