From 62a65019aab62a997c3ed87e630fd055115cdbf4 Mon Sep 17 00:00:00 2001 From: Hussein Ait Lahcen Date: Mon, 16 Oct 2023 23:01:59 +0200 Subject: [PATCH] fix(evm): ensure we provide counterparty channel at `OpenAck` --- evm/contracts/apps/Base.sol | 1 + evm/contracts/apps/ucs/00-pingpong/PingPong.sol | 11 ++++++----- evm/contracts/apps/ucs/01-relay/Relay.sol | 11 ++++++++--- evm/contracts/core/05-port/IIBCModule.sol | 1 + evm/contracts/core/25-handler/IBCChannelHandler.sol | 1 + evm/contracts/core/DevnetIBCHandlerInit.sol | 7 ++++++- evm/tests/src/MockApp.t.sol | 1 + evm/tests/src/utils/MockApp.sol | 1 + 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/evm/contracts/apps/Base.sol b/evm/contracts/apps/Base.sol index b8617b1ec5..9d3e5d2f23 100644 --- a/evm/contracts/apps/Base.sol +++ b/evm/contracts/apps/Base.sol @@ -67,6 +67,7 @@ abstract contract IBCAppBase is Context, IIBCModule { function onChanOpenAck( string calldata portId, string calldata channelId, + string calldata counterpartyChannelId, string calldata counterpartyVersion ) external virtual override onlyIBC {} diff --git a/evm/contracts/apps/ucs/00-pingpong/PingPong.sol b/evm/contracts/apps/ucs/00-pingpong/PingPong.sol index e5c6bd85f1..c54d313110 100644 --- a/evm/contracts/apps/ucs/00-pingpong/PingPong.sol +++ b/evm/contracts/apps/ucs/00-pingpong/PingPong.sol @@ -153,7 +153,8 @@ contract PingPong is IBCAppBase { function onChanOpenAck( string calldata _portId, string calldata _channelId, - string calldata + string calldata _counterpartyChannelId, + string calldata _counterpartyVersion ) external virtual override onlyIBC { portId = _portId; channelId = _channelId; @@ -168,15 +169,15 @@ contract PingPong is IBCAppBase { } function onChanCloseInit( - string calldata, - string calldata + string calldata _portId, + string calldata _channelId ) external virtual override onlyIBC { revert("This game is infinite"); } function onChanCloseConfirm( - string calldata, - string calldata + string calldata _portId, + string calldata _channelId ) external virtual override onlyIBC { revert("This game is infinite"); } diff --git a/evm/contracts/apps/ucs/01-relay/Relay.sol b/evm/contracts/apps/ucs/01-relay/Relay.sol index 3547e2b581..861e1f7b5d 100644 --- a/evm/contracts/apps/ucs/01-relay/Relay.sol +++ b/evm/contracts/apps/ucs/01-relay/Relay.sol @@ -432,10 +432,15 @@ contract UCS01Relay is IBCAppBase { } function onChanOpenAck( - string calldata _portId, - string calldata _channelId, + string calldata portId, + string calldata channelId, + string calldata counterpartyChannelId, string calldata _counterpartyVersion - ) external virtual override onlyIBC {} + ) external virtual override onlyIBC { + // Counterparty channel was empty. + counterpartyEndpoints[portId][channelId] + .channel_id = counterpartyChannelId; + } function onChanOpenConfirm( string calldata _portId, diff --git a/evm/contracts/core/05-port/IIBCModule.sol b/evm/contracts/core/05-port/IIBCModule.sol index c51f555b1d..e5aa2679db 100644 --- a/evm/contracts/core/05-port/IIBCModule.sol +++ b/evm/contracts/core/05-port/IIBCModule.sol @@ -47,6 +47,7 @@ interface IIBCModule { function onChanOpenAck( string calldata portId, string calldata channelId, + string calldata counterpartyChannelId, string calldata counterpartyVersion ) external; diff --git a/evm/contracts/core/25-handler/IBCChannelHandler.sol b/evm/contracts/core/25-handler/IBCChannelHandler.sol index ad8717a3bd..180edbcf63 100644 --- a/evm/contracts/core/25-handler/IBCChannelHandler.sol +++ b/evm/contracts/core/25-handler/IBCChannelHandler.sol @@ -134,6 +134,7 @@ abstract contract IBCChannelHandler is ModuleManager { lookupModuleByPort(msg_.portId).onChanOpenAck( msg_.portId, msg_.channelId, + msg_.counterpartyChannelId, msg_.counterpartyVersion ); diff --git a/evm/contracts/core/DevnetIBCHandlerInit.sol b/evm/contracts/core/DevnetIBCHandlerInit.sol index 080077efaa..fa179c96c4 100644 --- a/evm/contracts/core/DevnetIBCHandlerInit.sol +++ b/evm/contracts/core/DevnetIBCHandlerInit.sol @@ -45,7 +45,12 @@ contract DevnetIBCHandlerInit is IBCHost { channel.counterparty, channel.version ); - module.onChanOpenAck(portId, channelId, channel.version); + module.onChanOpenAck( + portId, + channelId, + channel.counterparty.channel_id, + channel.version + ); claimCapability( channelCapabilityPath(portId, channelId), address(module) diff --git a/evm/tests/src/MockApp.t.sol b/evm/tests/src/MockApp.t.sol index 2fcfdeb4f6..5866b4e34a 100644 --- a/evm/tests/src/MockApp.t.sol +++ b/evm/tests/src/MockApp.t.sol @@ -52,6 +52,7 @@ contract MockApp is IIBCModule { function onChanOpenAck( string calldata portId, string calldata channelId, + string calldata counterpartyChannelId, string calldata counterpartyVersion ) external virtual override {} diff --git a/evm/tests/src/utils/MockApp.sol b/evm/tests/src/utils/MockApp.sol index 649ecb79a7..b8c5ae6408 100644 --- a/evm/tests/src/utils/MockApp.sol +++ b/evm/tests/src/utils/MockApp.sol @@ -66,6 +66,7 @@ contract MockApp is IIBCModule { function onChanOpenAck( string calldata portId, string calldata channelId, + string calldata counterpartyChannelId, string calldata counterpartyVersion ) external virtual override { emit MockChannelOpenAck();