From 790777530f771f230daf028653a59d06243f72c8 Mon Sep 17 00:00:00 2001 From: "keroroxx520@gmail.com" Date: Mon, 25 Nov 2024 16:30:31 +0800 Subject: [PATCH] chore: pass clippy Running `cargo clippy --features ${TASKDB},sp1,risc0,sgx -- -D warnings` generates some clippy errors. --- harness/macro/src/lib.rs | 62 +++++++++++++++--------------- provers/risc0/driver/src/bonsai.rs | 2 +- provers/risc0/driver/src/lib.rs | 4 +- provers/risc0/driver/src/snarks.rs | 2 +- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/harness/macro/src/lib.rs b/harness/macro/src/lib.rs index 43c4092d8..161421147 100644 --- a/harness/macro/src/lib.rs +++ b/harness/macro/src/lib.rs @@ -59,45 +59,47 @@ pub fn entrypoint(input: TokenStream) -> TokenStream { }; } - #[cfg(feature = "sp1")] - let output = quote! { - // Set up a global allocator - use sp1_zkvm::heap::SimpleAlloc; - #[global_allocator] - static HEAP: SimpleAlloc = SimpleAlloc; + let output = if cfg!(feature = "sp1") { + quote! { + // Set up a global allocator + use sp1_zkvm::heap::SimpleAlloc; + #[global_allocator] + static HEAP: SimpleAlloc = SimpleAlloc; - #[cfg(test)] - #tests_entry + #[cfg(test)] + #tests_entry - #[cfg(not(test))] - const ZKVM_ENTRY: fn() = #main_entry; - #[cfg(test)] - const ZKVM_ENTRY: fn() = run_tests; + #[cfg(not(test))] + const ZKVM_ENTRY: fn() = #main_entry; + #[cfg(test)] + const ZKVM_ENTRY: fn() = run_tests; - mod zkvm_generated_main { - #[no_mangle] - fn main() { - super::ZKVM_ENTRY() + mod zkvm_generated_main { + #[no_mangle] + fn main() { + super::ZKVM_ENTRY() + } } } - }; - - #[cfg(feature = "risc0")] - let output = quote! { - #[cfg(test)] - #tests_entry + } else if cfg!(feature = "risc0") { + quote! { + #[cfg(test)] + #tests_entry - #[cfg(not(test))] - const ZKVM_ENTRY: fn() = #main_entry; - #[cfg(test)] - const ZKVM_ENTRY: fn() = run_tests; + #[cfg(not(test))] + const ZKVM_ENTRY: fn() = #main_entry; + #[cfg(test)] + const ZKVM_ENTRY: fn() = run_tests; - mod zkvm_generated_main { - #[no_mangle] - fn main() { - super::ZKVM_ENTRY() + mod zkvm_generated_main { + #[no_mangle] + fn main() { + super::ZKVM_ENTRY() + } } } + } else { + quote! {} }; output.into() diff --git a/provers/risc0/driver/src/bonsai.rs b/provers/risc0/driver/src/bonsai.rs index 7648566f3..11c85119b 100644 --- a/provers/risc0/driver/src/bonsai.rs +++ b/provers/risc0/driver/src/bonsai.rs @@ -374,7 +374,7 @@ pub fn prove_locally( let segment_dir = PathBuf::from("/tmp/risc0-cache"); if !segment_dir.exists() { - fs::create_dir(segment_dir.clone()).map_err(|e| ProverError::FileIo(e))?; + fs::create_dir(segment_dir.clone()).map_err(ProverError::FileIo)?; } let env = env_builder .segment_path(segment_dir) diff --git a/provers/risc0/driver/src/lib.rs b/provers/risc0/driver/src/lib.rs index 2493c9dc7..536e8ebe5 100644 --- a/provers/risc0/driver/src/lib.rs +++ b/provers/risc0/driver/src/lib.rs @@ -74,7 +74,7 @@ impl Prover for Risc0Prover { let proof_key = ( input.chain_spec.chain_id, input.block.header.number, - output.hash.clone(), + output.hash, RISC0_PROVER_CODE, ); @@ -188,7 +188,7 @@ impl Prover for Risc0Prover { proof: snark_proof, receipt: serde_json::to_string(&receipt).unwrap(), uuid: "".to_owned(), - input: B256::from_slice(&receipt.journal.digest().as_bytes()), + input: B256::from_slice(receipt.journal.digest().as_bytes()), } .into()); diff --git a/provers/risc0/driver/src/snarks.rs b/provers/risc0/driver/src/snarks.rs index 58a601012..4417b014d 100644 --- a/provers/risc0/driver/src/snarks.rs +++ b/provers/risc0/driver/src/snarks.rs @@ -250,7 +250,7 @@ pub async fn verify_groth16_snark_impl( tracing_info!("Verifying SNARK:"); tracing_info!("Seal: {}", hex::encode(&enc_seal)); tracing_info!("Image ID: {}", hex::encode(image_id.as_bytes())); - tracing_info!("Post State Digest: {}", hex::encode(&post_state_digest)); + tracing_info!("Post State Digest: {}", hex::encode(post_state_digest)); tracing_info!("Journal Digest: {}", hex::encode(journal_digest)); let verify_call_res = IRiscZeroVerifier::new(groth16_verifier_addr, http_client) .verify(