Skip to content

Commit

Permalink
feat: check sender is ibc handler in ICS20Transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
blckngm authored and jjyr committed Oct 26, 2023
1 parent 8213b64 commit e0d1f4b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions contracts/apps/20-transfer/ICS20Transfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ abstract contract ICS20Transfer is Context, IICS20Transfer {

IBCHandler ibcHandler;

/**
* @dev Throws if called by any account other than the IBC contract.
*/
modifier onlyIBC() {
require(address(ibcHandler) == _msgSender(), "IBCAppBase: caller is not the IBC contract");
_;
}

mapping(string => address) channelEscrowAddresses;

constructor(IBCHandler ibcHandler_) {
Expand Down Expand Up @@ -56,6 +64,7 @@ abstract contract ICS20Transfer is Context, IICS20Transfer {
external
virtual
override
onlyIBC
returns (bytes memory acknowledgement)
{
FungibleTokenPacketData.Data memory data = FungibleTokenPacketData.decode(packet.data);
Expand Down Expand Up @@ -83,6 +92,7 @@ abstract contract ICS20Transfer is Context, IICS20Transfer {
external
virtual
override
onlyIBC
{
if (!_isSuccessAcknowledgement(acknowledgement)) {
_refundTokens(FungibleTokenPacketData.decode(packet.data), packet.sourcePort, packet.sourceChannel);
Expand All @@ -96,8 +106,8 @@ abstract contract ICS20Transfer is Context, IICS20Transfer {
string calldata channelId,
ChannelCounterparty.Data calldata,
string calldata
) external virtual override {
// TODO authenticate a capability
) external virtual override onlyIBC
{
channelEscrowAddresses[channelId] = address(this);
}

Expand All @@ -109,22 +119,22 @@ abstract contract ICS20Transfer is Context, IICS20Transfer {
ChannelCounterparty.Data calldata,
string calldata,
string calldata
) external virtual override {
// TODO authenticate a capability
) external virtual override onlyIBC {
channelEscrowAddresses[channelId] = address(this);
}

function onChanOpenAck(string calldata portId, string calldata channelId, string calldata counterpartyVersion)
external
virtual
override
onlyIBC
{}

function onChanOpenConfirm(string calldata portId, string calldata channelId) external virtual override {}
function onChanOpenConfirm(string calldata portId, string calldata channelId) external virtual override onlyIBC {}

function onChanCloseInit(string calldata portId, string calldata channelId) external virtual override {}
function onChanCloseInit(string calldata portId, string calldata channelId) external virtual override onlyIBC {}

function onChanCloseConfirm(string calldata portId, string calldata channelId) external virtual override {}
function onChanCloseConfirm(string calldata portId, string calldata channelId) external virtual override onlyIBC {}

/// Internal functions ///

Expand Down

0 comments on commit e0d1f4b

Please sign in to comment.