Skip to content

Commit

Permalink
membership proof msg for packet receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Jan 31, 2025
1 parent 52a32b0 commit 5828ef2
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use core::marker::PhantomData;
use cgp::prelude::*;
use hermes_cairo_encoding_components::strategy::ViaCairo;
use hermes_cairo_encoding_components::types::as_felt::AsFelt;
use hermes_chain_components::traits::commitment_prefix::HasIbcCommitmentPrefix;
use hermes_chain_components::traits::queries::chain_status::CanQueryChainStatus;
use hermes_chain_components::traits::queries::packet_receipt::PacketReceiptQuerier;
use hermes_chain_components::traits::types::height::HasHeightType;
use hermes_chain_components::traits::types::ibc::{
Expand All @@ -15,6 +17,7 @@ use hermes_encoding_components::traits::encode::CanEncode;
use hermes_encoding_components::traits::has_encoding::HasEncoding;
use hermes_encoding_components::traits::types::encoded::HasEncodedType;
use ibc::core::host::types::identifiers::{PortId as IbcPortId, Sequence as IbcSequence};
use ibc::core::host::types::path::{Path, ReceiptPath};
use starknet::core::types::Felt;
use starknet::macros::selector;

Expand All @@ -24,15 +27,19 @@ use crate::traits::types::blob::HasBlobType;
use crate::traits::types::method::HasSelectorType;
use crate::types::channel_id::ChannelId;
use crate::types::commitment_proof::StarknetCommitmentProof;
use crate::types::membership_proof_signer::MembershipVerifierContainer;
use crate::types::messages::ibc::channel::PortId as CairoPortId;
use crate::types::messages::ibc::packet::Sequence;
use crate::types::status::StarknetChainStatus;

pub struct QueryStarknetPacketReceipt;

impl<Chain, Counterparty, Encoding> PacketReceiptQuerier<Chain, Counterparty>
for QueryStarknetPacketReceipt
where
Chain: HasHeightType<Height = u64>
+ CanQueryChainStatus<ChainStatus = StarknetChainStatus>
+ HasIbcCommitmentPrefix<CommitmentPrefix = Vec<u8>>
+ HasChannelIdType<Counterparty, ChannelId = ChannelId>
+ HasPortIdType<Counterparty, PortId = IbcPortId>
+ HasPacketReceiptType<Counterparty, PacketReceipt = Vec<u8>>
Expand All @@ -53,7 +60,7 @@ where
channel_id: &ChannelId,
port_id: &IbcPortId,
sequence: &IbcSequence,
height: &u64,
_height: &u64,
) -> Result<(Vec<u8>, StarknetCommitmentProof), Chain::Error> {
let encoding = chain.encoding();

Expand All @@ -75,12 +82,6 @@ where
.call_contract(&contract_address, &selector!("packet_receipt"), &calldata)
.await?;

// TODO(rano): how to get the proof?
let dummy_proof = StarknetCommitmentProof {
proof_height: *height,
proof_bytes: vec![0x1],
};

let receipt_status = encoding.decode(&output).map_err(Chain::raise_error)?;

// TODO(rano): are these bytes correct?
Expand All @@ -93,6 +94,25 @@ where
}
.to_vec();

let chain_status = chain.query_chain_status().await?;

// hack(rano): passing block hash to message builder
let membership_proof_message = MembershipVerifierContainer {
state_root: chain_status.block_hash.to_bytes_be().to_vec(),
prefix: chain.ibc_commitment_prefix().clone(),
path: Path::Receipt(ReceiptPath::new(port_id, channel_id, *sequence))
.to_string()
.into(),
value: Some(receipt_bytes.clone()),
}
.canonical_bytes();

// TODO(rano): how to get the proof?
let dummy_proof = StarknetCommitmentProof {
proof_height: chain_status.height,
proof_bytes: membership_proof_message,
};

Ok((receipt_bytes, dummy_proof))
}
}

0 comments on commit 5828ef2

Please sign in to comment.