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 onChanOpenInit and onChanOpenTry to returns a module address #300

Merged
merged 2 commits into from
Sep 30, 2024
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
125 changes: 64 additions & 61 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,77 @@ IBCBenchmarks:testRecvPacket() (gas: 154889)
IBCBenchmarks:testSendPacket() (gas: 94843)
IBCBenchmarks:testUpdateMockClientDirectly() (gas: 64879)
IBCBenchmarks:testUpdateMockClientViaHandler() (gas: 148239)
IBCMockAppTest:testHandshake() (gas: 4162455)
IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3104765)
IBCMockAppTest:testPacketRelay() (gas: 11461419)
IBCMockAppTest:testPacketTimeout() (gas: 4059968)
IBCMockAppFactoryTest:testHandshake() (gas: 8710771)
IBCMockAppFactoryTest:testPacketRelay() (gas: 15995791)
IBCMockAppTest:testHandshake() (gas: 4183963)
IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3130978)
IBCMockAppTest:testPacketRelay() (gas: 11493798)
IBCMockAppTest:testPacketTimeout() (gas: 4089477)
ICS24HostTest:testValidatePortIdentifier() (gas: 44476)
TestICS02:testCreateClient() (gas: 30594453)
TestICS02:testCreateClient() (gas: 30936959)
TestICS02:testHeightToUint128((uint64,uint64)) (runs: 256, μ: 907, ~: 907)
TestICS02:testInvalidCreateClient() (gas: 30479715)
TestICS02:testInvalidUpdateClient() (gas: 30483432)
TestICS02:testRegisterClient() (gas: 30143677)
TestICS02:testRegisterClientDuplicatedClientType() (gas: 30129897)
TestICS02:testRegisterClientInvalidClientType() (gas: 30158859)
TestICS02:testUpdateClient() (gas: 30650006)
TestICS03Handshake:testConnOpenAck() (gas: 1811232)
TestICS03Handshake:testConnOpenConfirm() (gas: 1989361)
TestICS03Handshake:testConnOpenInit() (gas: 1423016)
TestICS03Handshake:testConnOpenTry() (gas: 2348031)
TestICS03Handshake:testInvalidConnOpenAck() (gas: 2323525)
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2422540)
TestICS02:testInvalidCreateClient() (gas: 30822171)
TestICS02:testInvalidUpdateClient() (gas: 30825962)
TestICS02:testRegisterClient() (gas: 30486209)
TestICS02:testRegisterClientDuplicatedClientType() (gas: 30472391)
TestICS02:testRegisterClientInvalidClientType() (gas: 30501395)
TestICS02:testUpdateClient() (gas: 30992560)
TestICS03Handshake:testConnOpenAck() (gas: 1810871)
TestICS03Handshake:testConnOpenConfirm() (gas: 1988723)
TestICS03Handshake:testConnOpenInit() (gas: 1422940)
TestICS03Handshake:testConnOpenTry() (gas: 2347689)
TestICS03Handshake:testInvalidConnOpenAck() (gas: 2322689)
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2421514)
TestICS03Handshake:testInvalidConnOpenInit() (gas: 776893)
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2283536)
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2283346)
TestICS03Version:testCopyVersions() (gas: 570207)
TestICS03Version:testFindSupportedVersion() (gas: 34452)
TestICS03Version:testIsSupportedVersion() (gas: 13568)
TestICS03Version:testPickVersion() (gas: 37836)
TestICS03Version:testVerifyProposedVersion() (gas: 21308)
TestICS03Version:testVerifySupportedFeature() (gas: 10229)
TestICS04Handshake:testBindPort() (gas: 456448)
TestICS04Handshake:testChanClose() (gas: 12159177)
TestICS04Handshake:testChanOpenAck() (gas: 3242652)
TestICS04Handshake:testChanOpenConfirm() (gas: 3538460)
TestICS04Handshake:testChanOpenInit() (gas: 2395251)
TestICS04Handshake:testChanOpenTry() (gas: 2897730)
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2317075)
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2391732)
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1677410)
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1692299)
TestICS04Packet:testAcknowledgementPacket() (gas: 3111209)
TestICS04Packet:testInvalidSendPacket() (gas: 3294829)
TestICS04Packet:testRecvPacket() (gas: 9485892)
TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3053603)
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3077652)
TestICS04Packet:testSendPacket() (gas: 4393801)
TestICS04Packet:testTimeoutOnClose() (gas: 3304846)
TestICS04Upgrade:testCrossingHelloInconsistentVersions() (gas: 9732925)
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 44979235)
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3297188)
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5125194)
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5088264)
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4844529)
TestICS04Upgrade:testUpgradeFull() (gas: 55706062)
TestICS04Upgrade:testUpgradeInit() (gas: 2925623)
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2342894)
TestICS04Upgrade:testUpgradeNotUpgradableModule() (gas: 3443205)
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3728418)
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5097801)
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5469958)
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 3907976)
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17324220)
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 20921139)
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 68900740)
TestICS04Upgrade:testUpgradeToOrdered() (gas: 52811190)
TestICS04Upgrade:testUpgradeToUnordered() (gas: 42156184)
TestICS04Handshake:testBindPort() (gas: 461372)
TestICS04Handshake:testChanClose() (gas: 12244889)
TestICS04Handshake:testChanOpenAck() (gas: 3264520)
TestICS04Handshake:testChanOpenConfirm() (gas: 3561004)
TestICS04Handshake:testChanOpenInit() (gas: 2411027)
TestICS04Handshake:testChanOpenTry() (gas: 2918880)
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2327618)
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2402634)
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1677184)
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1692266)
TestICS04Packet:testAcknowledgementPacket() (gas: 3133839)
TestICS04Packet:testInvalidSendPacket() (gas: 3317459)
TestICS04Packet:testRecvPacket() (gas: 9561916)
TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3083947)
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3107997)
TestICS04Packet:testSendPacket() (gas: 4425319)
TestICS04Packet:testTimeoutOnClose() (gas: 3335905)
TestICS04Upgrade:testCrossingHelloInconsistentVersions() (gas: 9761065)
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 45179742)
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3309916)
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5142516)
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5101888)
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4859793)
TestICS04Upgrade:testUpgradeFull() (gas: 55736320)
TestICS04Upgrade:testUpgradeInit() (gas: 2937759)
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2354426)
TestICS04Upgrade:testUpgradeNotUpgradableModule() (gas: 3470809)
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3741133)
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5115114)
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5487347)
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 3920258)
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17345060)
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 20945649)
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 69105350)
TestICS04Upgrade:testUpgradeToOrdered() (gas: 53030759)
TestICS04Upgrade:testUpgradeToUnordered() (gas: 42323192)
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 62062)
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2365672)
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2346118)
TestICS20:testAddressToHex(address) (runs: 256, μ: 26869, ~: 27044)
TestICS20:testHexToAddress(string) (runs: 256, μ: 4636, ~: 4595)
TestICS20:testIsEscapedString() (gas: 62745)
TestICS20:testMarshaling() (gas: 180081)
TestICS20:testParseAmount(uint256) (runs: 256, μ: 31973, ~: 28039)
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2376902)
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2357348)
TestICS20:testAddressToHex(address) (runs: 256, μ: 26910, ~: 27088)
TestICS20:testHexToAddress(string) (runs: 256, μ: 4658, ~: 4617)
TestICS20:testIsEscapedString() (gas: 64753)
TestICS20:testMarshaling() (gas: 180017)
TestICS20:testParseAmount(uint256) (runs: 256, μ: 31599, ~: 27438)
TestICS20:testParseUint256String() (gas: 26745)
8 changes: 4 additions & 4 deletions contracts/apps/20-transfer/ICS20Transfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ abstract contract ICS20Transfer is IBCAppBase, IICS20Errors {
virtual
override
onlyIBC
returns (string memory)
returns (address, string memory)
{
if (msg_.order != Channel.Order.ORDER_UNORDERED) {
revert IBCModuleChannelOrderNotAllowed(msg_.portId, msg_.channelId, msg_.order);
Expand All @@ -86,15 +86,15 @@ abstract contract ICS20Transfer is IBCAppBase, IICS20Errors {
revert ICS20UnexpectedVersion(msg_.version);
}
channelEscrowAddresses[msg_.channelId] = address(this);
return ICS20_VERSION;
return (address(this), ICS20_VERSION);
}

function onChanOpenTry(IIBCModule.MsgOnChanOpenTry calldata msg_)
external
virtual
override
onlyIBC
returns (string memory)
returns (address, string memory)
{
if (msg_.order != Channel.Order.ORDER_UNORDERED) {
revert IBCModuleChannelOrderNotAllowed(msg_.portId, msg_.channelId, msg_.order);
Expand All @@ -103,7 +103,7 @@ abstract contract ICS20Transfer is IBCAppBase, IICS20Errors {
revert ICS20UnexpectedVersion(msg_.counterpartyVersion);
}
channelEscrowAddresses[msg_.channelId] = address(this);
return ICS20_VERSION;
return (address(this), ICS20_VERSION);
}

function onChanOpenAck(IIBCModule.MsgOnChanOpenAck calldata msg_) external virtual override onlyIBC {
Expand Down
25 changes: 20 additions & 5 deletions contracts/apps/commons/IBCAppBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Context} from "@openzeppelin/contracts/utils/Context.sol";
import {Packet} from "../../core/04-channel/IIBCChannel.sol";
import {IIBCModule} from "../../core/26-router/IIBCModule.sol";
import {IIBCModule, IIBCModuleInitializer} from "../../core/26-router/IIBCModule.sol";
import {IIBCModuleErrors} from "../../core/26-router/IIBCModuleErrors.sol";

abstract contract AppBase is Context, IERC165, IIBCModuleErrors {
Expand Down Expand Up @@ -41,6 +41,17 @@ abstract contract AppBase is Context, IERC165, IIBCModuleErrors {
}
}

abstract contract IBCAppInitializerBase is AppBase, IIBCModuleInitializer {
/**
* @dev See {IERC165-supportsInterface}
*
* NOTE: This must return true if the `interfaceId` is equal to the `IIBCModule` interface.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, AppBase) returns (bool) {
return interfaceId == type(IIBCModuleInitializer).interfaceId || super.supportsInterface(interfaceId);
}
}

/**
* @dev Base contract of the IBC App protocol
*/
Expand All @@ -55,8 +66,10 @@ abstract contract IBCAppBase is AppBase, IIBCModule {
virtual
override
onlyIBC
returns (string memory)
{}
returns (address, string memory)
{
return (address(this), "");
}

/**
* @dev See {IIBCModule-onChanOpenTry}
Expand All @@ -68,8 +81,10 @@ abstract contract IBCAppBase is AppBase, IIBCModule {
virtual
override
onlyIBC
returns (string memory)
{}
returns (address, string memory)
{
return (address(this), "");
}

/**
* @dev See {IIBCModule-onChanOpenAck}
Expand Down
8 changes: 4 additions & 4 deletions contracts/apps/mock/IBCMockApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,25 @@ contract IBCMockApp is IBCAppBase, IIBCMockErrors, Ownable {
virtual
override
onlyIBC
returns (string memory)
returns (address, string memory)
{
if (bytes(msg_.version).length != 0 && keccak256(bytes(msg_.version)) != keccak256(bytes(MOCKAPP_VERSION))) {
revert IBCMockUnexpectedVersion(msg_.version, MOCKAPP_VERSION);
}
return MOCKAPP_VERSION;
return (address(this), MOCKAPP_VERSION);
}

function onChanOpenTry(IIBCModule.MsgOnChanOpenTry calldata msg_)
external
virtual
override
onlyIBC
returns (string memory)
returns (address, string memory)
{
if (keccak256(bytes(msg_.counterpartyVersion)) != keccak256(bytes(MOCKAPP_VERSION))) {
revert IBCMockUnexpectedVersion(msg_.counterpartyVersion, MOCKAPP_VERSION);
}
return MOCKAPP_VERSION;
return (address(this), MOCKAPP_VERSION);
}

function onChanCloseInit(IIBCModule.MsgOnChanCloseInit calldata msg_) external virtual override onlyIBC {
Expand Down
Loading