Skip to content

Commit

Permalink
chore: add docs and unclog
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani committed Jul 10, 2024
1 parent 0683d8c commit ab2f16f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [ibc-core-client] Enable `verify_(non_)membership()` methods to accept custom
paths as bytes by defining a new `serializer_path()` API allowing light client
developers to introduce the path serialization behavior of their system.
([\#1255](https://github.com/cosmos/ibc-rs/issues/1255))
4 changes: 2 additions & 2 deletions ibc-clients/ics07-tendermint/src/client_state/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub fn verify_membership<H: HostFunctionsProvider>(
path: PathBytes,
value: Vec<u8>,
) -> Result<(), ClientError> {
let merkle_path = MerklePath::new(vec![prefix.clone().into_vec().into(), path]);
let merkle_path = MerklePath::new(vec![prefix.as_bytes().to_vec().into(), path]);
let merkle_proof = MerkleProof::try_from(proof).map_err(ClientError::InvalidCommitmentProof)?;

merkle_proof
Expand All @@ -251,7 +251,7 @@ pub fn verify_non_membership<H: HostFunctionsProvider>(
root: &CommitmentRoot,
path: PathBytes,
) -> Result<(), ClientError> {
let merkle_path = MerklePath::new(vec![prefix.clone().into_vec().into(), path]);
let merkle_path = MerklePath::new(vec![prefix.as_bytes().to_vec().into(), path]);
let merkle_proof = MerkleProof::try_from(proof).map_err(ClientError::InvalidCommitmentProof)?;

merkle_proof
Expand Down
8 changes: 7 additions & 1 deletion ibc-core/ics02-client/context/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ pub trait ClientStateCommon: Convertible<Any> {
root: &CommitmentRoot,
) -> Result<(), ClientError>;

/// Determines how a path should be serialized into a `PathBytes` object.
/// Serializes a given path into a `PathBytes` object.
///
/// This method provides essential information for IBC modules, enabling
/// them to understand how path serialization is performed on the
/// counterparty chain (where this light client represents it) before
/// passing the path bytes to either `verify_membership()` or
/// `verify_non_membership()`.
fn serialize_path(&self, path: impl Into<Path>) -> Result<PathBytes, ClientError>;

// Verify_membership is a generic proof verification method which verifies a
Expand Down
13 changes: 13 additions & 0 deletions ibc-core/ics23-commitment/types/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ use crate::commitment::CommitmentRoot;
use crate::error::CommitmentError;
use crate::specs::ProofSpecs;

/// A wrapper type representing a Merkle path, consisting of a sequence of path
/// bytes.
///
/// This struct by definition is compatible with Cosmos SDK chains, but it is
/// also applicable to other blockchain implementations that follow similar path
/// structures. Note that while Cosmos SDK chains and some non-Cosmos chains
/// adhere to this definition, it may not be universally applicable to all
/// non-Cosmos chains.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

Check warning on line 27 in ibc-core/ics23-commitment/types/src/merkle.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics23-commitment/types/src/merkle.rs#L27

Added line #L27 was not covered by tests
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq)]
Expand All @@ -24,6 +32,7 @@ pub struct MerklePath {
}

impl MerklePath {
/// Constructs a new `MerklePath` from a given `Vec<PathBytes>`.
pub fn new(key_path: Vec<PathBytes>) -> Self {
Self { key_path }
}
Expand All @@ -41,6 +50,10 @@ impl From<RawMerklePath> for MerklePath {
}

Check warning on line 50 in ibc-core/ics23-commitment/types/src/merkle.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics23-commitment/types/src/merkle.rs#L42-L50

Added lines #L42 - L50 were not covered by tests
}

// The conversion from `MerklePath`` to `RawMerklePath` is not provided as we
// cannot assume how the key paths of `Vec<PathBytes>` type should be serialized
// to the `Vec<String>`.

impl From<CommitmentRoot> for MerkleRoot {
fn from(root: CommitmentRoot) -> Self {
Self {
Expand Down

0 comments on commit ab2f16f

Please sign in to comment.