Skip to content

Commit

Permalink
Countermeasure that fixes #1038
Browse files Browse the repository at this point in the history
  • Loading branch information
adizere committed Jun 8, 2021
1 parent 2b84667 commit 1098ac0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
18 changes: 15 additions & 3 deletions relayer/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,24 @@ impl Channel {
let a_channel = self
.src_chain()
.query_channel(&self.src_port_id(), src_channel_id, Height::zero())
.map_err(|_| ChannelError::Failed("Failed to query source chain".into()))?;
.map_err(|_| {
ChannelError::Failed(
format!("failed to query source chain {}", self.src_chain().id()).into(),
)
})?;

let b_channel = self
.dst_chain()
.query_channel(&self.dst_port_id(), dst_channel_id, Height::zero())
.map_err(|_| ChannelError::Failed("Failed to query destination chain".into()))?;
.map_err(|_| {
ChannelError::Failed(
format!(
"failed to query destination chain {}",
self.dst_chain().id()
)
.into(),
)
})?;

match (a_channel.state(), b_channel.state()) {
(State::Init, State::TryOpen) | (State::TryOpen, State::TryOpen) => {
Expand Down Expand Up @@ -457,7 +469,7 @@ impl Channel {
info!("done {} => {:#?}\n", self.src_chain().id(), event)
}
(State::Open, State::Open) => {
info!("Channel handshake finished for {:#?}\n", self);
info!("channel handshake finished for {:#?}\n", self);
}
_ => { /* TODO channel close */ }
}
Expand Down
37 changes: 37 additions & 0 deletions relayer/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,43 @@ impl Link {
)));
}

// Check that the counterparty details on the destination chain matches the source chain
let b_channel = b_chain
.query_channel(
&a_channel.counterparty().port_id,
&b_channel_id,
Height::default(),
)
.map_err(|e| {
LinkError::Failed(format!(
"channel/port {}/{} does not exist on destination chain {}; context={}",
b_channel_id,
a_channel.counterparty().port_id,
b_chain.id(),
e
))
})?;
match b_channel.counterparty().channel_id.clone() {
Some(actual_a_channel_id) => {
if actual_a_channel_id.ne(a_channel_id)
|| b_channel.counterparty().port_id != opts.src_port_id
{
return Err(LinkError::Failed(format!("conflicting link configuration: channel/port {}/{} on destination chain {} does not point back to the source chain {}:{}/{} (but points to {}/{})",
b_channel_id, a_channel.counterparty().port_id, b_chain.id(), a_chain.id(),
a_channel_id, opts.src_port_id, actual_a_channel_id, b_channel.counterparty().port_id)));
}
}
None => {
return Err(LinkError::Failed(format!(
"the channel/port {}/{} on destination chain {} has no counterparty channel set",
b_channel_id,
a_channel.counterparty().port_id,
b_chain.id()
)));
}
}

// Check the underlying connection
let a_connection_id = a_channel.connection_hops()[0].clone();
let a_connection = a_chain.query_connection(&a_connection_id, Height::zero())?;

Expand Down

0 comments on commit 1098ac0

Please sign in to comment.