Skip to content

Commit

Permalink
chore: fix clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Dec 30, 2024
1 parent dff02c0 commit bbeb2fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
25 changes: 14 additions & 11 deletions host/src/server/api/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use raiko_core::interfaces::{AggregationRequest, ProofRequestOpt};
use raiko_lib::proof_type::ProofType;
use raiko_core::interfaces::{
get_aggregation_image, get_proving_image, AggregationRequest, ProofRequestOpt,
};
use raiko_lib::{proof_type::ProofType, prover::encode_image_id};

use crate::{
interfaces::{HostError, HostResult},
Expand Down Expand Up @@ -41,8 +43,8 @@ pub fn ensure_proof_request_image_id(proof_request_opt: &mut ProofRequestOpt) ->
Some(image_id) => {
// Temporarily workaround for RISC0/SP1 proof type: assert that the image_id is the same with `get_aggregation_image_id()`,
// that means we don't support custom image_id for RISC0/SP1 proof type.
let supported_image_id =
raiko_lib::prover_util::get_proving_image_id(&proof_type);
let (_, supported_image_id) = get_proving_image(proof_type)?;
let supported_image_id = encode_image_id(supported_image_id);
if *image_id != supported_image_id {
return Err(HostError::InvalidRequestConfig(
format!(
Expand All @@ -54,8 +56,9 @@ pub fn ensure_proof_request_image_id(proof_request_opt: &mut ProofRequestOpt) ->
}
None => {
// If image_id is None, fill it with the default value
proof_request_opt.image_id =
Some(raiko_lib::prover_util::get_proving_image_id(&proof_type));
let (_, supported_image_id) = get_proving_image(proof_type)?;
let supported_image_id = encode_image_id(supported_image_id);
proof_request_opt.image_id = Some(supported_image_id);
}
}
}
Expand Down Expand Up @@ -93,8 +96,8 @@ pub fn ensure_aggregation_request_image_id(
Some(image_id) => {
// Temporarily workaround for RISC0/SP1 proof type: assert that the image_id is the same with `get_aggregation_image_id()`,
// that means we don't support custom image_id for RISC0/SP1 proof type.
let supported_image_id =
raiko_lib::prover_util::get_aggregation_image_id(&proof_type);
let (_, supported_image_id) = get_aggregation_image(proof_type)?;
let supported_image_id = encode_image_id(supported_image_id);
if *image_id != supported_image_id {
return Err(HostError::InvalidRequestConfig(
format!(
Expand All @@ -106,9 +109,9 @@ pub fn ensure_aggregation_request_image_id(
}
None => {
// If image_id is None, fill it with the default value
aggregation_request.image_id = Some(
raiko_lib::prover_util::get_aggregation_image_id(&proof_type),
);
let (_, supported_image_id) = get_aggregation_image(proof_type)?;
let supported_image_id = encode_image_id(supported_image_id);
aggregation_request.image_id = Some(supported_image_id);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub mod primitives;
pub mod proof_type;
pub mod protocol_instance;
pub mod prover;
pub mod prover_util;
pub mod utils;

#[cfg(not(target_os = "zkvm"))]
Expand Down
9 changes: 8 additions & 1 deletion lib/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ pub fn encode_image_id(image_id: &[u32; 8]) -> String {

/// A helper function to decode image id from hex string.
pub fn decode_image_id(hex_image_id: &str) -> Result<[u32; 8], hex::FromHexError> {
let bytes: Vec<u8> = hex::decode(hex_image_id)?;
let bytes: Vec<u8> = if let Some(stripped) = hex_image_id.strip_prefix("0x") {
hex::decode(stripped)?
} else {
hex::decode(hex_image_id)?
};
let array: &[u32] = bytemuck::cast_slice::<u8, u32>(&bytes);
let result: [u32; 8] = array.try_into().expect("invalid hex image id");
Ok(result)
Expand All @@ -113,5 +117,8 @@ mod test {
);
let decoded = decode_image_id(&encoded).unwrap();
assert_eq!(decoded, image_id);

let decoded = decode_image_id(&format!("0x{encoded}")).unwrap();
assert_eq!(decoded, image_id);
}
}

0 comments on commit bbeb2fe

Please sign in to comment.