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

Make capability storage type address instead of address[] #240

Merged
merged 2 commits into from
Dec 4, 2023
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
49 changes: 25 additions & 24 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
IBCTest:testBenchmarkCreateMockClient() (gas: 211733)
IBCTest:testBenchmarkRecvPacket() (gas: 139993)
IBCTest:testBenchmarkSendPacket() (gas: 86019)
IBCTest:testBenchmarkRecvPacket() (gas: 137422)
IBCTest:testBenchmarkSendPacket() (gas: 85195)
IBCTest:testBenchmarkUpdateMockClient() (gas: 126635)
IBCTest:testToUint128((uint64,uint64)) (runs: 256, μ: 917, ~: 917)
TestICS02:testCreateClient() (gas: 23295732)
TestICS02:testInvalidCreateClient() (gas: 23143327)
TestICS02:testInvalidUpdateClient() (gas: 23147156)
TestICS02:testRegisterClient() (gas: 22767378)
TestICS02:testRegisterClientDuplicatedClientType() (gas: 22749428)
TestICS02:testRegisterClientInvalidClientType() (gas: 22734298)
TestICS02:testUpdateClient() (gas: 23290442)
TestICS03Handshake:testConnOpenAck() (gas: 1589222)
TestICS03Handshake:testConnOpenConfirm() (gas: 1722517)
TestICS03Handshake:testConnOpenInit() (gas: 1285075)
TestICS02:testCreateClient() (gas: 23194177)
TestICS02:testInvalidCreateClient() (gas: 23041922)
TestICS02:testInvalidUpdateClient() (gas: 23045689)
TestICS02:testRegisterClient() (gas: 22665889)
TestICS02:testRegisterClientDuplicatedClientType() (gas: 22647939)
TestICS02:testRegisterClientInvalidClientType() (gas: 22632765)
TestICS02:testUpdateClient() (gas: 23188909)
TestICS03Handshake:testConnOpenAck() (gas: 1589200)
TestICS03Handshake:testConnOpenConfirm() (gas: 1722518)
TestICS03Handshake:testConnOpenInit() (gas: 1285031)
TestICS03Handshake:testConnOpenTry() (gas: 2082502)
TestICS03Handshake:testInvalidConnOpenAck() (gas: 1945699)
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 1965710)
TestICS03Handshake:testInvalidConnOpenAck() (gas: 1945633)
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 1965802)
TestICS03Handshake:testInvalidConnOpenInit() (gas: 671931)
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2087487)
TestICS03Version:testCopyVersions() (gas: 558658)
Expand All @@ -24,16 +24,17 @@ TestICS03Version:testIsSupportedVersion() (gas: 7864)
TestICS03Version:testPickVersion() (gas: 25399)
TestICS03Version:testVerifyProposedVersion() (gas: 11777)
TestICS03Version:testVerifySupportedFeature() (gas: 4153)
TestICS04Handshake:testChanOpenAck() (gas: 2985837)
TestICS04Handshake:testChanOpenConfirm() (gas: 3168093)
TestICS04Handshake:testChanOpenInit() (gas: 2274367)
TestICS04Handshake:testChanOpenTry() (gas: 2757417)
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2115048)
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2174082)
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1279457)
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1353660)
TestICS04Packet:testInvalidSendPacket() (gas: 2315761)
TestICS04Packet:testSendPacket() (gas: 2373812)
TestICS04Handshake:testBindPort() (gas: 40421)
TestICS04Handshake:testChanOpenAck() (gas: 2887537)
TestICS04Handshake:testChanOpenConfirm() (gas: 3067861)
TestICS04Handshake:testChanOpenInit() (gas: 2203120)
TestICS04Handshake:testChanOpenTry() (gas: 2661049)
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2064863)
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2122953)
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1279180)
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1353271)
TestICS04Packet:testInvalidSendPacket() (gas: 2210343)
TestICS04Packet:testSendPacket() (gas: 2269694)
TestICS20:testAddressToHex(address) (runs: 256, μ: 22675, ~: 22824)
TestICS20:testHexToAddress(string) (runs: 256, μ: 4776, ~: 4734)
TestICS20:testIsEscapedString() (gas: 48979)
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/24-host/IBCStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract contract IBCStore {
mapping(string => mapping(string => uint64)) internal nextSequenceSends;
mapping(string => mapping(string => uint64)) internal nextSequenceRecvs;
mapping(string => mapping(string => uint64)) internal nextSequenceAcks;
mapping(bytes => address[]) internal capabilities;
mapping(string => address) internal capabilities;

// Host parameters
uint64 internal expectedTimePerBlock;
Expand Down
44 changes: 18 additions & 26 deletions contracts/core/26-router/IBCModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ contract IBCModuleManager is IBCHost, Context {
* @dev lookupModuleByPort will return the IBCModule along with the capability associated with a given portID
*/
function lookupModuleByPort(string memory portId) internal view virtual returns (IIBCModule) {
(address[] storage modules, bool found) = lookupModules(portCapabilityPath(portId));
require(found);
return IIBCModule(modules[0]);
address module = lookupModule(portCapabilityPath(portId));
require(module != address(0), "module not found");
return IIBCModule(module);
}

/**
Expand All @@ -27,47 +27,39 @@ contract IBCModuleManager is IBCHost, Context {
virtual
returns (IIBCModule)
{
(address[] storage modules, bool found) = lookupModules(channelCapabilityPath(portId, channelId));
require(found);
return IIBCModule(modules[0]);
address module = lookupModule(channelCapabilityPath(portId, channelId));
require(module != address(0), "module not found");
return IIBCModule(module);
}

/**
* @dev claimCapability allows the IBC app module to claim a capability that core IBC passes to it
*/
function claimCapability(bytes memory name, address addr) internal {
for (uint32 i = 0; i < capabilities[name].length; i++) {
require(capabilities[name][i] != addr);
}
capabilities[name].push(addr);
function claimCapability(string memory name, address addr) internal {
require(capabilities[name] == address(0), "capability already claimed");
capabilities[name] = addr;
}

/**
* @dev authenticateCapability attempts to authenticate a given name from a caller.
* It allows for a caller to check that a capability does in fact correspond to a particular name.
*/
function authenticateCapability(bytes memory name) internal view returns (bool) {
address caller = _msgSender();
for (uint32 i = 0; i < capabilities[name].length; i++) {
if (capabilities[name][i] == caller) {
return true;
}
}
return false;
function authenticateCapability(string memory name) internal view returns (bool) {
return _msgSender() == capabilities[name];
}

/**
* @dev lookupModules will return the IBCModule addresses bound to a given name.
* @dev lookupModule will return the IBCModule addresses bound to a given name.
*/
function lookupModules(bytes memory name) internal view returns (address[] storage, bool) {
return (capabilities[name], capabilities[name].length > 0);
function lookupModule(string memory name) internal view returns (address) {
return capabilities[name];
}

/**
* @dev portCapabilityPath returns the path under which owner module address associated with a port should be stored.
*/
function portCapabilityPath(string memory portId) internal pure returns (bytes memory) {
return abi.encodePacked(portId);
function portCapabilityPath(string memory portId) internal pure returns (string memory) {
return portId;
}

/**
Expand All @@ -76,9 +68,9 @@ contract IBCModuleManager is IBCHost, Context {
function channelCapabilityPath(string memory portId, string memory channelId)
internal
pure
returns (bytes memory)
returns (string memory)
{
return abi.encodePacked(portId, "/", channelId);
return string.concat(portId, "/", channelId);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion pkg/contract/erc20/erc20.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading