From a099ce87dfab8367718ab7a14d0485851c436cca Mon Sep 17 00:00:00 2001 From: Thomas Dekeyser Date: Thu, 15 Feb 2024 18:24:09 +0100 Subject: [PATCH] update contracts with new vIBC core API --- .gitignore | 6 +++- contracts/CustomChanIbcContract.sol | 39 +++++++++++++------------- contracts/UniversalChanIbcContract.sol | 6 ++-- lib/vibc-core-smart-contracts | 2 +- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 24dc6e7..63d21d9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,8 @@ node_modules # solidity-coverage files /coverage -/coverage.json \ No newline at end of file +/coverage.json + +# Foundry files +/out +/cache_forge \ No newline at end of file diff --git a/contracts/CustomChanIbcContract.sol b/contracts/CustomChanIbcContract.sol index 29882c9..de79c18 100644 --- a/contracts/CustomChanIbcContract.sol +++ b/contracts/CustomChanIbcContract.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.9; import '@open-ibc/vibc-core-smart-contracts/contracts/Ibc.sol'; import '@open-ibc/vibc-core-smart-contracts/contracts/IbcReceiver.sol'; import '@open-ibc/vibc-core-smart-contracts/contracts/IbcDispatcher.sol'; +import '@open-ibc/vibc-core-smart-contracts/contracts/ProofVerifier.sol'; contract CustomChanIbcContract is IbcReceiverBase, IbcReceiver { // received packet as chain B @@ -31,6 +32,10 @@ contract CustomChanIbcContract is IbcReceiverBase, IbcReceiver { dispatcher = _dispatcher; } + function getConnectedChannels() external view returns (ChannelMapping[] memory) { + return connectedChannels; + } + /** * @dev Sends a packet with a greeting message over a specified channel. * @param message The greeting message to be sent. @@ -66,35 +71,33 @@ contract CustomChanIbcContract is IbcReceiverBase, IbcReceiver { * @param proof not implemented for now */ function createChannel( - string calldata version, + CounterParty calldata local, uint8 ordering, bool feeEnabled, string[] calldata connectionHops, CounterParty calldata counterparty, - Proof calldata proof + Ics23Proof calldata proof ) external { dispatcher.openIbcChannel( IbcChannelReceiver(address(this)), - version, + local, ChannelOrder(ordering), feeEnabled, connectionHops, counterparty, proof ); - } + } function onOpenIbcChannel( string calldata version, - ChannelOrder ordering, - bool feeEnabled, - string[] calldata connectionHops, - string calldata counterpartyPortId, - bytes32 counterpartyChannelId, - string calldata counterpartyVersion - ) external onlyIbcDispatcher returns (string memory selectedVersion) { - if (bytes(counterpartyPortId).length <= 8) { + ChannelOrder, + bool, + string[] calldata, + CounterParty calldata counterparty + ) external view onlyIbcDispatcher returns (string memory selectedVersion) { + if (bytes(counterparty.portId).length <= 8) { revert invalidCounterPartyPortId(); } /** @@ -105,7 +108,7 @@ contract CustomChanIbcContract is IbcReceiverBase, IbcReceiver { */ bool foundVersion = false; selectedVersion = keccak256(abi.encodePacked(version)) == keccak256(abi.encodePacked('')) - ? counterpartyVersion + ? counterparty.version : version; for (uint256 i = 0; i < supportedVersions.length; i++) { if (keccak256(abi.encodePacked(selectedVersion)) == keccak256(abi.encodePacked(supportedVersions[i]))) { @@ -115,9 +118,9 @@ contract CustomChanIbcContract is IbcReceiverBase, IbcReceiver { } require(foundVersion, 'Unsupported version'); // if counterpartyVersion is not empty, then it must be the same foundVersion - if (keccak256(abi.encodePacked(counterpartyVersion)) != keccak256(abi.encodePacked(''))) { + if (keccak256(abi.encodePacked(counterparty.version)) != keccak256(abi.encodePacked(''))) { require( - keccak256(abi.encodePacked(counterpartyVersion)) == keccak256(abi.encodePacked(selectedVersion)), + keccak256(abi.encodePacked(counterparty.version)) == keccak256(abi.encodePacked(selectedVersion)), 'Version mismatch' ); } @@ -151,11 +154,7 @@ contract CustomChanIbcContract is IbcReceiverBase, IbcReceiver { connectedChannels.push(channelMapping); } - function onCloseIbcChannel( - bytes32 channelId, - string calldata counterpartyPortId, - bytes32 counterpartyChannelId - ) external onlyIbcDispatcher { + function onCloseIbcChannel(bytes32 channelId, string calldata, bytes32) external onlyIbcDispatcher { // logic to determin if the channel should be closed bool channelFound = false; for (uint256 i = 0; i < connectedChannels.length; i++) { diff --git a/contracts/UniversalChanIbcContract.sol b/contracts/UniversalChanIbcContract.sol index 81c5ae4..2ede699 100644 --- a/contracts/UniversalChanIbcContract.sol +++ b/contracts/UniversalChanIbcContract.sol @@ -35,7 +35,7 @@ contract UniversalChanIbcContract is IbcMwUser, IbcUniversalPacketReceiver { function sendGreet(address destPortAddr, bytes32 channelId, bytes calldata message, uint64 timeoutTimestamp) external { IbcUniversalPacketSender(mw).sendUniversalPacket( channelId, - Ibc.toBytes32(destPortAddr), + IbcUtils.toBytes32(destPortAddr), message, timeoutTimestamp ); @@ -48,7 +48,7 @@ contract UniversalChanIbcContract is IbcMwUser, IbcUniversalPacketReceiver { recvedPackets.push(UcPacketWithChannel(channelId, packet)); // do logic // below is an example, the actual ackpacket data should be implemented by the contract developer - return AckPacket(true, abi.encodePacked(address(this), Ibc.toAddress(packet.srcPortAddr), 'ack-', packet.appData)); + return AckPacket(true, abi.encodePacked(address(this), IbcUtils.toAddress(packet.srcPortAddr), 'ack-', packet.appData)); } function onUniversalAcknowledgement( @@ -60,7 +60,7 @@ contract UniversalChanIbcContract is IbcMwUser, IbcUniversalPacketReceiver { // check onRecvUniversalPacket for the encoded ackpacket data require(ack.data.length >= 20, 'ack data too short'); address ackSender = address(bytes20(ack.data[0:20])); - require(Ibc.toAddress(packet.destPortAddr) == ackSender, 'ack address mismatch'); + require(IbcUtils.toAddress(packet.destPortAddr) == ackSender, 'ack address mismatch'); ackPackets.push(UcAckWithChannel(channelId, packet, ack)); // do logic } diff --git a/lib/vibc-core-smart-contracts b/lib/vibc-core-smart-contracts index 6e381f5..b8c69fd 160000 --- a/lib/vibc-core-smart-contracts +++ b/lib/vibc-core-smart-contracts @@ -1 +1 @@ -Subproject commit 6e381f58d271b5cc4082c1cc2253cae1ab3e20c7 +Subproject commit b8c69fda353f1469c9934c8058823ab772c4288e