-
Notifications
You must be signed in to change notification settings - Fork 3
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
Change counterpartyInfo to channel #100
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ pragma solidity ^0.8.28; | |
import { IIBCApp } from "./interfaces/IIBCApp.sol"; | ||
import { IICS26Router } from "./interfaces/IICS26Router.sol"; | ||
import { IICS02Client } from "./interfaces/IICS02Client.sol"; | ||
import { ICS02Client } from "./ICS02Client.sol"; | ||
import { IICS04Channel } from "./interfaces/IICS04Channel.sol"; | ||
import { ICSCore } from "./ICSCore.sol"; | ||
import { IIBCStore } from "./interfaces/IIBCStore.sol"; | ||
import { IICS24HostErrors } from "./errors/IICS24HostErrors.sol"; | ||
import { IBCStore } from "./utils/IBCStore.sol"; | ||
|
@@ -16,6 +17,8 @@ import { IIBCAppCallbacks } from "./msgs/IIBCAppCallbacks.sol"; | |
import { ICS24Host } from "./utils/ICS24Host.sol"; | ||
import { ILightClientMsgs } from "./msgs/ILightClientMsgs.sol"; | ||
import { IICS02ClientMsgs } from "./msgs/IICS02ClientMsgs.sol"; | ||
import { IICS04ChannelMsgs } from "./msgs/IICS04ChannelMsgs.sol"; | ||
import { ReentrancyGuard } from "@openzeppelin/utils/ReentrancyGuard.sol"; | ||
import { ReentrancyGuardTransient } from "@openzeppelin/utils/ReentrancyGuardTransient.sol"; | ||
import { Multicall } from "@openzeppelin/utils/Multicall.sol"; | ||
|
||
|
@@ -24,13 +27,17 @@ import { Multicall } from "@openzeppelin/utils/Multicall.sol"; | |
contract ICS26Router is IICS26Router, IICS26RouterErrors, Ownable, ReentrancyGuardTransient, Multicall { | ||
/// @dev portId => IBC Application contract | ||
mapping(string portId => IIBCApp app) private apps; | ||
|
||
/// @inheritdoc IICS26Router | ||
IICS02Client public immutable ICS02_CLIENT; | ||
/// @dev ICS04Channel contract | ||
IICS04Channel public immutable ICS04_CHANNEL; | ||
Comment on lines
31
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two should be combined to a single variable imo. Idk if we can combine the interfaces but we can call it an address instead and use it with |
||
/// @inheritdoc IICS26Router | ||
IIBCStore public immutable IBC_STORE; | ||
|
||
constructor(address owner) Ownable(owner) { | ||
ICS02_CLIENT = new ICS02Client(owner); // using the same owner | ||
ICS02_CLIENT = new ICSCore(owner); // using the same owner | ||
ICS04_CHANNEL = IICS04Channel(address(ICS02_CLIENT)); // using the same contract | ||
IBC_STORE = new IBCStore(address(this)); // using this contract as the owner | ||
} | ||
|
||
|
@@ -75,7 +82,7 @@ contract ICS26Router is IICS26Router, IICS26RouterErrors, Ownable, ReentrancyGua | |
require(msg_.payloads.length == 1, IBCMultiPayloadPacketNotSupported()); | ||
Payload calldata payload = msg_.payloads[0]; | ||
|
||
string memory counterpartyId = ICS02_CLIENT.getCounterparty(msg_.sourceChannel).clientId; | ||
string memory counterpartyId = ICS04_CHANNEL.getChannel(msg_.sourceChannel).counterpartyId; | ||
|
||
// TODO: validate all identifiers | ||
require( | ||
|
@@ -112,15 +119,17 @@ contract ICS26Router is IICS26Router, IICS26RouterErrors, Ownable, ReentrancyGua | |
/// @param msg_ The message for receiving packets | ||
/// @inheritdoc IICS26Router | ||
function recvPacket(MsgRecvPacket calldata msg_) external nonReentrant { | ||
|
||
// TODO: Support multi-payload packets #93 | ||
require(msg_.packet.payloads.length == 1, IBCMultiPayloadPacketNotSupported()); | ||
Payload calldata payload = msg_.packet.payloads[0]; | ||
|
||
IICS02ClientMsgs.CounterpartyInfo memory cInfo = ICS02_CLIENT.getCounterparty(msg_.packet.destChannel); | ||
IICS04ChannelMsgs.Channel memory channel = ICS04_CHANNEL.getChannel(msg_.packet.destChannel); | ||
require( | ||
keccak256(bytes(cInfo.clientId)) == keccak256(bytes(msg_.packet.sourceChannel)), | ||
IBCInvalidCounterparty(cInfo.clientId, msg_.packet.sourceChannel) | ||
keccak256(bytes(channel.counterpartyId)) == keccak256(bytes(msg_.packet.sourceChannel)), | ||
IBCInvalidCounterparty(channel.counterpartyId, msg_.packet.sourceChannel) | ||
); | ||
|
||
require( | ||
msg_.packet.timeoutTimestamp > block.timestamp, | ||
IBCInvalidTimeoutTimestamp(msg_.packet.timeoutTimestamp, block.timestamp) | ||
|
@@ -133,7 +142,7 @@ contract ICS26Router is IICS26Router, IICS26RouterErrors, Ownable, ReentrancyGua | |
ILightClientMsgs.MsgMembership memory membershipMsg = ILightClientMsgs.MsgMembership({ | ||
proof: msg_.proofCommitment, | ||
proofHeight: msg_.proofHeight, | ||
path: ICS24Host.prefixedPath(cInfo.merklePrefix, commitmentPath), | ||
path: ICS24Host.prefixedPath(channel.merklePrefix, commitmentPath), | ||
value: abi.encodePacked(commitmentBz) | ||
}); | ||
|
||
|
@@ -171,10 +180,10 @@ contract ICS26Router is IICS26Router, IICS26RouterErrors, Ownable, ReentrancyGua | |
require(msg_.packet.payloads.length == 1, IBCMultiPayloadPacketNotSupported()); | ||
Payload calldata payload = msg_.packet.payloads[0]; | ||
|
||
IICS02ClientMsgs.CounterpartyInfo memory cInfo = ICS02_CLIENT.getCounterparty(msg_.packet.sourceChannel); | ||
IICS04ChannelMsgs.Channel memory channel = ICS04_CHANNEL.getChannel(msg_.packet.sourceChannel); | ||
require( | ||
keccak256(bytes(cInfo.clientId)) == keccak256(bytes(msg_.packet.destChannel)), | ||
IBCInvalidCounterparty(cInfo.clientId, msg_.packet.destChannel) | ||
keccak256(bytes(channel.counterpartyId)) == keccak256(bytes(msg_.packet.destChannel)), | ||
IBCInvalidCounterparty(channel.counterpartyId, msg_.packet.destChannel) | ||
); | ||
|
||
bytes memory commitmentPath = | ||
|
@@ -187,7 +196,7 @@ contract ICS26Router is IICS26Router, IICS26RouterErrors, Ownable, ReentrancyGua | |
ILightClientMsgs.MsgMembership memory membershipMsg = ILightClientMsgs.MsgMembership({ | ||
proof: msg_.proofAcked, | ||
proofHeight: msg_.proofHeight, | ||
path: ICS24Host.prefixedPath(cInfo.merklePrefix, commitmentPath), | ||
path: ICS24Host.prefixedPath(channel.merklePrefix, commitmentPath), | ||
value: abi.encodePacked(commitmentBz) | ||
}); | ||
|
||
|
@@ -221,22 +230,23 @@ contract ICS26Router is IICS26Router, IICS26RouterErrors, Ownable, ReentrancyGua | |
/// @param msg_ The message for timing out packets | ||
/// @inheritdoc IICS26Router | ||
function timeoutPacket(MsgTimeoutPacket calldata msg_) external nonReentrant { | ||
|
||
// TODO: Support multi-payload packets #93 | ||
require(msg_.packet.payloads.length == 1, IBCMultiPayloadPacketNotSupported()); | ||
Payload calldata payload = msg_.packet.payloads[0]; | ||
|
||
IICS02ClientMsgs.CounterpartyInfo memory cInfo = ICS02_CLIENT.getCounterparty(msg_.packet.sourceChannel); | ||
IICS04ChannelMsgs.Channel memory channel = ICS04_CHANNEL.getChannel(msg_.packet.sourceChannel); | ||
require( | ||
keccak256(bytes(cInfo.clientId)) == keccak256(bytes(msg_.packet.destChannel)), | ||
IBCInvalidCounterparty(cInfo.clientId, msg_.packet.destChannel) | ||
keccak256(bytes(channel.counterpartyId)) == keccak256(bytes(msg_.packet.destChannel)), | ||
IBCInvalidCounterparty(channel.counterpartyId, msg_.packet.destChannel) | ||
); | ||
|
||
bytes memory receiptPath = | ||
ICS24Host.packetReceiptCommitmentPathCalldata(msg_.packet.destChannel, msg_.packet.sequence); | ||
ILightClientMsgs.MsgMembership memory nonMembershipMsg = ILightClientMsgs.MsgMembership({ | ||
proof: msg_.proofTimeout, | ||
proofHeight: msg_.proofHeight, | ||
path: ICS24Host.prefixedPath(cInfo.merklePrefix, receiptPath), | ||
path: ICS24Host.prefixedPath(channel.merklePrefix, receiptPath), | ||
value: bytes("") | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,15 +2,16 @@ | |||||
pragma solidity ^0.8.28; | ||||||
|
||||||
import { IICS02Client } from "./interfaces/IICS02Client.sol"; | ||||||
import { IICS04Channel } from "./interfaces/IICS04Channel.sol"; | ||||||
import { Strings } from "@openzeppelin/utils/Strings.sol"; | ||||||
import { IBCIdentifiers } from "./utils/IBCIdentifiers.sol"; | ||||||
import { ILightClient } from "./interfaces/ILightClient.sol"; | ||||||
import { IICS02ClientErrors } from "./errors/IICS02ClientErrors.sol"; | ||||||
import { Ownable } from "@openzeppelin/access/Ownable.sol"; | ||||||
|
||||||
contract ICS02Client is IICS02Client, IICS02ClientErrors, Ownable { | ||||||
/// @dev clientId => counterpartyInfo | ||||||
mapping(string clientId => CounterpartyInfo info) private counterpartyInfos; | ||||||
contract ICSCore is IICS02Client, IICS04Channel, IICS02ClientErrors, Ownable { | ||||||
/// @dev channelId => counterpartyInfo | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
mapping(string channelId => Channel channel) private channels; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CounterpartyInfo feels more descriptive ngl 😅. Because the same light client cannot have multiple channels on top in our implementation I think |
||||||
/// @dev clientId => light client contract | ||||||
mapping(string clientId => ILightClient client) private clients; | ||||||
/// @dev clientType => nextClientSeq | ||||||
|
@@ -30,12 +31,12 @@ contract ICS02Client is IICS02Client, IICS02ClientErrors, Ownable { | |||||
return string.concat(clientType, "-", Strings.toString(seq)); | ||||||
} | ||||||
|
||||||
/// @inheritdoc IICS02Client | ||||||
function getCounterparty(string calldata clientId) public view returns (CounterpartyInfo memory) { | ||||||
CounterpartyInfo memory counterpartyInfo = counterpartyInfos[clientId]; | ||||||
require(bytes(counterpartyInfo.clientId).length != 0, IBCCounterpartyClientNotFound(clientId)); | ||||||
/// @inheritdoc IICS04Channel | ||||||
function getChannel(string calldata channelId) public view returns (Channel memory) { | ||||||
Channel memory channel = channels[channelId]; | ||||||
require(bytes(channel.counterpartyId).length != 0, IBCCounterpartyClientNotFound(channelId)); | ||||||
|
||||||
return counterpartyInfo; | ||||||
return channel; | ||||||
} | ||||||
|
||||||
/// @inheritdoc IICS02Client | ||||||
|
@@ -46,20 +47,22 @@ contract ICS02Client is IICS02Client, IICS02ClientErrors, Ownable { | |||||
return client; | ||||||
} | ||||||
|
||||||
/// @inheritdoc IICS02Client | ||||||
function addClient( | ||||||
/// @inheritdoc IICS04Channel | ||||||
function addChannel( | ||||||
string calldata clientType, | ||||||
CounterpartyInfo calldata counterpartyInfo, | ||||||
Channel calldata channel, | ||||||
address client | ||||||
) | ||||||
external | ||||||
returns (string memory) | ||||||
{ | ||||||
string memory clientId = getNextClientId(clientType); | ||||||
clients[clientId] = ILightClient(client); | ||||||
counterpartyInfos[clientId] = counterpartyInfo; | ||||||
// use the same identifier for channelId and clientId | ||||||
// for Solidity implementation | ||||||
channels[clientId] = channel; | ||||||
|
||||||
emit ICS02ClientAdded(clientId, counterpartyInfo); | ||||||
emit ICS04ChannelAdded(clientId, channel); | ||||||
|
||||||
return clientId; | ||||||
} | ||||||
|
@@ -69,10 +72,10 @@ contract ICS02Client is IICS02Client, IICS02ClientErrors, Ownable { | |||||
getClient(subjectClientId); // Ensure subject client exists | ||||||
ILightClient substituteClient = getClient(substituteClientId); | ||||||
|
||||||
getCounterparty(subjectClientId); // Ensure subject client's counterparty exists | ||||||
CounterpartyInfo memory substituteCounterpartyInfo = getCounterparty(substituteClientId); | ||||||
getChannel(subjectClientId); // Ensure channel exists for this clientId | ||||||
Channel memory substituteChannel = getChannel(substituteClientId); | ||||||
|
||||||
counterpartyInfos[subjectClientId] = substituteCounterpartyInfo; | ||||||
channels[subjectClientId] = substituteChannel; | ||||||
clients[subjectClientId] = substituteClient; | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.28; | ||
|
||
import { IICS04ChannelMsgs } from "../msgs/IICS04ChannelMsgs.sol"; | ||
|
||
/// @title ICS04 Channel Interface | ||
/// @notice IICS04CHANNEL is an interface for the IBC Eureka channel router | ||
interface IICS04Channel is IICS04ChannelMsgs { | ||
/// @notice Emitted when a new channel is added to the channel router. | ||
/// @param channelId The newly created channel identifier. NOTE: In this implementation, the channelId is the client identifier. | ||
/// @param channel The counterparty client information, if provided | ||
event ICS04ChannelAdded(string channelId, Channel channel); | ||
|
||
/// @notice Returns the channel given the channel identifier. | ||
/// @param channelId The channel identifier | ||
/// @return channel | ||
function getChannel(string calldata channelId) external view returns (Channel memory); | ||
|
||
/// @notice Adds a channel to the channel router. | ||
/// @param clientType The client type, e.g., "07-tendermint". | ||
/// @param channel The channel information | ||
/// @param client The address of the client contract | ||
/// @return The channel identifier NOTE: This is the same as the client identifier | ||
function addChannel( | ||
string calldata clientType, | ||
Channel calldata channel, | ||
address client | ||
) | ||
external | ||
returns (string memory); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.28; | ||
|
||
interface IICS04ChannelMsgs { | ||
/// @notice Channel information. | ||
/// @custom:spec | ||
/// https://github.com/cosmos/ibc/blob/67fe813f7e4ec603a7c5dec35bc654f3b012afda/spec/micro/README.md?plain=1#L91 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The link should be updated? |
||
/// @param counterpartyId The counterparty channel identifier from the counterparty chain. | ||
/// @param merklePrefix The counterparty chain's merkle prefix. | ||
struct Channel { | ||
string counterpartyId; | ||
bytes[] merklePrefix; | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had to do this to get it to install on my machine. Can remove if desired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, makes sense. The most recent operator commit doesn't need this since we removed the union dependencies