Skip to content

Commit

Permalink
rlp decoding fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 committed Oct 12, 2023
1 parent 84a5c2d commit 791bb96
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
10 changes: 6 additions & 4 deletions parachain/modules/ismp/sync-committee/src/arbitrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,13 @@ pub fn verify_arbitrum_payload<H: IsmpHost + Send + Sync>(
_ => Err(Error::MembershipProofVerificationFailed("Value not found in proof".to_string()))?,
};

let proof_value = <B256 as Decodable>::decode(&mut &*proof_value).map_err(|_| {
Error::ImplementationSpecific(format!("Error decoding state hash {:?}", &proof_value))
})?;
let proof_value = <alloy_primitives::U256 as Decodable>::decode(&mut &*proof_value)
.map_err(|_| {
Error::ImplementationSpecific(format!("Error decoding state hash {:?}", &proof_value))
})?
.to_be_bytes::<32>();

if proof_value.0 != state_hash.0 {
if proof_value != state_hash.0 {
Err(Error::MembershipProofVerificationFailed(
"State hash from proof does not match calculated state hash".to_string(),
))?
Expand Down
34 changes: 18 additions & 16 deletions parachain/modules/ismp/sync-committee/src/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ pub fn verify_optimism_payload<H: IsmpHost + Send + Sync>(
_ => Err(Error::MembershipProofVerificationFailed("Value not found in proof".to_string()))?,
};

let proof_value = <B256 as Decodable>::decode(&mut &*proof_value).map_err(|_| {
Error::ImplementationSpecific(format!(
"Error decoding contract account from key {:?}",
&proof_value
))
})?;
let proof_value = <alloy_primitives::U256 as Decodable>::decode(&mut &*proof_value)
.map_err(|_| {
Error::ImplementationSpecific(format!(
"Error decoding output root from {:?}",
&proof_value
))
})?
.to_be_bytes::<32>();

if proof_value.0 != output_root.0 {
if proof_value != output_root.0 {
return Err(Error::MembershipProofVerificationFailed(
"Invalid optimism output root proof".to_string(),
))
Expand All @@ -109,15 +111,15 @@ pub fn verify_optimism_payload<H: IsmpHost + Send + Sync>(
_ => Err(Error::MembershipProofVerificationFailed("Value not found in proof".to_string()))?,
};

let block_and_timestamp = <Bytes as Decodable>::decode(&mut &*block_and_timestamp)
.map_err(|_| {
Error::ImplementationSpecific(format!(
"Error decoding block and timestamp from{:?}",
&block_and_timestamp
))
})?
.0
.to_vec();
let block_and_timestamp =
<alloy_primitives::U256 as Decodable>::decode(&mut &*block_and_timestamp)
.map_err(|_| {
Error::ImplementationSpecific(format!(
"Error decoding block and timestamp from{:?}",
&block_and_timestamp
))
})?
.to_be_bytes::<32>();

let block_and_timestamp = U256::from_big_endian(&block_and_timestamp);
// Timestamp is contained in the first two u64 values
Expand Down
4 changes: 2 additions & 2 deletions parachain/modules/ismp/sync-committee/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn get_contract_storage_root<H: IsmpHost + Send + Sync>(

let contract_account = <Account as Decodable>::decode(&mut &*result).map_err(|_| {
Error::ImplementationSpecific(format!(
"Error decoding contract account from key {:?}",
"Error decoding contract account from value {:?}",
&result
))
})?;
Expand Down Expand Up @@ -172,7 +172,7 @@ pub(super) fn get_values_from_proof<H: IsmpHost + Send + Sync>(
Ok(values)
}

pub(super) fn get_value_from_proof<H: IsmpHost + Send + Sync>(
pub fn get_value_from_proof<H: IsmpHost + Send + Sync>(
key: Vec<u8>,
root: H256,
proof: Vec<Vec<u8>>,
Expand Down

0 comments on commit 791bb96

Please sign in to comment.