Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICS24 Path variants as types #1760

Merged
merged 7 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Extract all `ics24_host::Path` variants into their separate types
([#1760](https://github.com/informalsystems/ibc-rs/issues/1760))
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ safe-regex = { version = "0.2.4", default-features = false }
subtle-encoding = { version = "0.5", default-features = false }
sha2 = { version = "0.10.1", default-features = false }
flex-error = { version = "0.4.4", default-features = false }
derive_more = { version = "0.99.0", default-features = false, features = ["from", "display"] }

[dependencies.tendermint]
version = "=0.23.4"
Expand Down
41 changes: 23 additions & 18 deletions modules/src/clients/ics07_tendermint/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ use crate::core::ics24_host::Path;
use crate::prelude::*;
use crate::Height;

use crate::core::ics24_host::path::{
AcksPath, ChannelEndsPath, ClientConsensusStatePath, ClientStatePath, CommitmentsPath,
ConnectionsPath, ReceiptsPath, SeqRecvsPath,
};
use crate::downcast;

#[derive(Clone, Debug, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -201,12 +205,11 @@ impl ClientDef for TendermintClient {
) -> Result<(), Ics02Error> {
client_state.verify_height(height)?;

let path = Path::ClientConsensusState {
let path = ClientConsensusStatePath {
client_id: client_id.clone(),
epoch: consensus_height.revision_number,
height: consensus_height.revision_height,
}
.to_string();
};
let value = expected_consensus_state.encode_vec().unwrap();
verify_membership(client_state, prefix, proof, root, path, value)
}
Expand All @@ -223,7 +226,7 @@ impl ClientDef for TendermintClient {
) -> Result<(), Ics02Error> {
client_state.verify_height(height)?;

let path = Path::Connections(connection_id.clone()).to_string();
let path = ConnectionsPath(connection_id.clone());
let value = expected_connection_end.encode_vec().unwrap();
verify_membership(client_state, prefix, proof, root, path, value)
}
Expand All @@ -241,7 +244,7 @@ impl ClientDef for TendermintClient {
) -> Result<(), Ics02Error> {
client_state.verify_height(height)?;

let path = Path::ChannelEnds(port_id.clone(), channel_id.clone()).to_string();
let path = ChannelEndsPath(port_id.clone(), channel_id.clone());
let value = expected_channel_end.encode_vec().unwrap();
verify_membership(client_state, prefix, proof, root, path, value)
}
Expand All @@ -258,7 +261,7 @@ impl ClientDef for TendermintClient {
) -> Result<(), Ics02Error> {
client_state.verify_height(height)?;

let path = Path::ClientState(client_id.clone()).to_string();
let path = ClientStatePath(client_id.clone());
let value = expected_client_state.encode_vec().unwrap();
verify_membership(client_state, prefix, proof, root, path, value)
}
Expand All @@ -279,7 +282,7 @@ impl ClientDef for TendermintClient {
client_state.verify_height(height)?;
verify_delay_passed(ctx, height, connection_end)?;

let commitment_path = Path::Commitments {
let commitment_path = CommitmentsPath {
port_id: port_id.clone(),
channel_id: channel_id.clone(),
sequence,
Expand All @@ -289,7 +292,7 @@ impl ClientDef for TendermintClient {
connection_end.counterparty().prefix(),
proof,
root,
commitment_path.to_string(),
commitment_path,
commitment.encode_to_vec(),
)
}
Expand All @@ -310,7 +313,7 @@ impl ClientDef for TendermintClient {
client_state.verify_height(height)?;
verify_delay_passed(ctx, height, connection_end)?;

let ack_path = Path::Acks {
let ack_path = AcksPath {
port_id: port_id.clone(),
channel_id: channel_id.clone(),
sequence,
Expand All @@ -320,7 +323,7 @@ impl ClientDef for TendermintClient {
connection_end.counterparty().prefix(),
proof,
root,
ack_path.to_string(),
ack_path,
ack,
)
}
Expand All @@ -340,13 +343,13 @@ impl ClientDef for TendermintClient {
client_state.verify_height(height)?;
verify_delay_passed(ctx, height, connection_end)?;

let seq_path = Path::SeqRecvs(port_id.clone(), channel_id.clone());
let seq_path = SeqRecvsPath(port_id.clone(), channel_id.clone());
verify_membership(
client_state,
connection_end.counterparty().prefix(),
proof,
root,
seq_path.to_string(),
seq_path,
u64::from(sequence).encode_to_vec(),
)
}
Expand All @@ -366,7 +369,7 @@ impl ClientDef for TendermintClient {
client_state.verify_height(height)?;
verify_delay_passed(ctx, height, connection_end)?;

let receipt_path = Path::Receipts {
let receipt_path = ReceiptsPath {
port_id: port_id.clone(),
channel_id: channel_id.clone(),
sequence,
Expand All @@ -376,7 +379,7 @@ impl ClientDef for TendermintClient {
connection_end.counterparty().prefix(),
proof,
root,
receipt_path.to_string(),
receipt_path,
)
}

Expand All @@ -396,10 +399,11 @@ fn verify_membership(
prefix: &CommitmentPrefix,
proof: &CommitmentProofBytes,
root: &CommitmentRoot,
path: String,
path: impl Into<Path>,
value: Vec<u8>,
) -> Result<(), Ics02Error> {
let merkle_path = apply_prefix(prefix, vec![path]).map_err(Error::ics23_error)?;
let merkle_path =
apply_prefix(prefix, vec![path.into().to_string()]).map_err(Error::ics23_error)?;
let merkle_proof: MerkleProof = RawMerkleProof::try_from(proof.clone())
.map_err(Ics02Error::invalid_commitment_proof)?
.into();
Expand All @@ -420,9 +424,10 @@ fn verify_non_membership(
prefix: &CommitmentPrefix,
proof: &CommitmentProofBytes,
root: &CommitmentRoot,
path: String,
path: impl Into<Path>,
) -> Result<(), Ics02Error> {
let merkle_path = apply_prefix(prefix, vec![path]).map_err(Error::ics23_error)?;
let merkle_path =
apply_prefix(prefix, vec![path.into().to_string()]).map_err(Error::ics23_error)?;
let merkle_proof: MerkleProof = RawMerkleProof::try_from(proof.clone())
.map_err(Ics02Error::invalid_commitment_proof)?
.into();
Expand Down
Loading