From 7377dedc8bf4b4efed351517b69751b7b3adfebe Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Thu, 27 Jun 2024 08:33:46 +0000 Subject: [PATCH] fix serialization --- core/src/preflight.rs | 4 +-- lib/src/input.rs | 4 +-- lib/src/lib.rs | 56 ------------------------------------ lib/src/protocol_instance.rs | 3 +- 4 files changed, 5 insertions(+), 62 deletions(-) diff --git a/core/src/preflight.rs b/core/src/preflight.rs index 1987053a..e6e4fd55 100644 --- a/core/src/preflight.rs +++ b/core/src/preflight.rs @@ -296,8 +296,8 @@ async fn prepare_taiko_chain_input( .map_err(|e| anyhow!(e))?; // Save to sumit onchain for point evaluation verification save_cur_blob_proof(&proof, &commitment).map_err(|e| anyhow!(e))?; - - (blob, Some(commitment)) + + (blob, Some(commitment.to_vec())) } else { // Get the tx list data directly from the propose transaction data let proposal_call = proposeBlockCall::abi_decode(&proposal_tx.input, false) diff --git a/lib/src/input.rs b/lib/src/input.rs index 618b80a3..51c010a4 100644 --- a/lib/src/input.rs +++ b/lib/src/input.rs @@ -13,7 +13,6 @@ use reth_primitives::{Block as RethBlock, Header}; #[cfg(not(feature = "std"))] use crate::no_std::*; -use crate::serde_helper::option_array_48; use crate::{consts::ChainSpec, primitives::mpt::MptNode}; /// Represents the state of an account's storage. @@ -73,8 +72,7 @@ pub struct TaikoGuestInput { pub anchor_tx: String, pub block_proposed: BlockProposed, pub prover_data: TaikoProverData, - #[serde(with = "option_array_48")] - pub blob_commitment: Option<[u8; 48]>, + pub blob_commitment: Option>, pub blob_proof: Option, } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 60c81bb0..c85d477a 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -185,59 +185,3 @@ pub fn commitment_to_version_hash(commitment: &[u8; 48]) -> B256 { hash[0] = VERSIONED_HASH_VERSION_KZG; B256::new(hash.into()) } - -pub mod serde_helper { - - pub mod option_array_48 { - - use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; - - pub fn serialize(value: &Option<[u8; 48]>, serializer: S) -> Result - where - S: Serializer, - { - match value { - Some(arr) => arr.serialize(serializer), - None => serializer.serialize_none(), - } - } - - pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where - D: Deserializer<'de>, - { - struct OptionArrayVisitor; - - impl<'de> de::Visitor<'de> for OptionArrayVisitor { - type Value = Option<[u8; 48]>; - - fn expecting(&self, formatter: &mut core::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("an option of a 48-byte array") - } - - fn visit_none(self) -> Result - where - E: de::Error, - { - Ok(None) - } - - fn visit_some(self, deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let vec = Vec::::deserialize(deserializer)?; - if vec.len() == 48 { - let mut array = [0u8; 48]; - array.copy_from_slice(&vec); - Ok(Some(array)) - } else { - Err(de::Error::custom("expected a 48-byte array")) - } - } - } - - deserializer.deserialize_option(OptionArrayVisitor) - } - } -} diff --git a/lib/src/protocol_instance.rs b/lib/src/protocol_instance.rs index 613d9b10..dd8fab53 100644 --- a/lib/src/protocol_instance.rs +++ b/lib/src/protocol_instance.rs @@ -56,7 +56,8 @@ impl ProtocolInstance { return Err(anyhow::anyhow!("kzg feature is not enabled")); } ); - commitment_to_version_hash(commitment) + let commitment: [u8; 48] = commitment.clone().try_into().unwrap(); + commitment_to_version_hash(&commitment) } else { return Err(anyhow::anyhow!( "blob_proof and blob_commitment must be provided"