Skip to content

Commit

Permalink
fix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
CeciliaZ030 committed Jun 27, 2024
1 parent c727781 commit 7377ded
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 62 deletions.
4 changes: 2 additions & 2 deletions core/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions lib/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Vec<u8>>,
pub blob_proof: Option<BlobProof>,
}

Expand Down
56 changes: 0 additions & 56 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(value: &Option<[u8; 48]>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match value {
Some(arr) => arr.serialize(serializer),
None => serializer.serialize_none(),
}
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<[u8; 48]>, 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<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(None)
}

fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: Deserializer<'de>,
{
let vec = Vec::<u8>::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)
}
}
}
3 changes: 2 additions & 1 deletion lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7377ded

Please sign in to comment.