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

Fix for chain impersonation problem. Fix for incomplete channel create #1066

Merged
merged 16 commits into from
Jun 15, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Better error, added doc comment, less clones.
  • Loading branch information
adizere committed Jun 10, 2021
commit ed49a0327df11d5a4fdae638e477b604f9f6dc36
38 changes: 20 additions & 18 deletions relayer/src/channel.rs
Original file line number Diff line number Diff line change
@@ -1258,32 +1258,34 @@ fn check_destination_channel_state(
}
}

// Query the channel end on destination chain,
// and verify that the counterparty channel/port on destination
// matches channel/port id on source.
/// Queries a channel end on a [`ChainHandle`], and verifies
/// that the counterparty of that channel matches an
/// expected counterparty.
/// Returns `Ok` if the counterparty matches, and `Err` otherwise
pub fn check_channel_counterparty(
chain: Box<dyn ChainHandle>,
local_socket: &PortChannelId,
target_chain: Box<dyn ChainHandle>,
target_socket: &PortChannelId,
expected: &PortChannelId,
) -> Result<(), ChannelError> {
let channel_end_dst = chain
let channel_end_dst = target_chain
.query_channel(
&local_socket.port_id,
&local_socket.channel_id,
&target_socket.port_id,
&target_socket.channel_id,
Height::zero(),
)
.map_err(|e| ChannelError::QueryError(chain.id(), e))?;
.map_err(|e| ChannelError::QueryError(target_chain.id(), e))?;

match channel_end_dst.counterparty().channel_id.clone() {
Some(actual_remote_channel_id) => {
let counterparty = channel_end_dst.remote;
match counterparty.channel_id {
Some(actual_channel_id) => {
let actual = PortChannelId {
channel_id: actual_remote_channel_id,
port_id: channel_end_dst.counterparty().port_id.clone(),
channel_id: actual_channel_id,
port_id: counterparty.port_id,
};
if actual.ne(expected) {
if &actual != expected {
return Err(ChannelError::MismatchingChannelEnds(
local_socket.clone(),
chain.id(),
target_socket.clone(),
target_chain.id(),
expected.clone(),
actual,
));
@@ -1292,8 +1294,8 @@ pub fn check_channel_counterparty(
None => {
error!(
"socket {} on chain {} has no counterparty channel id ",
local_socket,
chain.id()
target_socket,
target_chain.id()
);
// TODO: The error `MissingCounterpartyChannelId` should capture its
// context fully (the chain and the socket).
5 changes: 4 additions & 1 deletion relayer/src/link.rs
Original file line number Diff line number Diff line change
@@ -54,6 +54,9 @@ pub enum LinkError {
#[error("failed with underlying error: {0}")]
Generic(#[from] Error),

#[error("link initialization failed during channel counterparty verification: {0}")]
Initialization(ChannelError),

#[error("failed to construct packet proofs for chain {0} with error: {1}")]
PacketProofsConstructor(ChainId, Error),

@@ -1647,7 +1650,7 @@ impl Link {
port_id: opts.src_port_id.clone(),
},
)
.map_err(|e| LinkError::Failed(format!("counterparty verification failed: {}", e)))?;
.map_err(LinkError::Initialization)?;

// Check the underlying connection
let a_connection_id = a_channel.connection_hops()[0].clone();