diff --git a/contracts/evm/contracts/adapters/ClusterConnection.sol b/contracts/evm/contracts/adapters/ClusterConnection.sol index 9dc65c5e..69efae42 100644 --- a/contracts/evm/contracts/adapters/ClusterConnection.sol +++ b/contracts/evm/contracts/adapters/ClusterConnection.sol @@ -10,12 +10,18 @@ import "@xcall/contracts/xcall/interfaces/IConnection.sol"; import "@iconfoundation/xcall-solidity-library/interfaces/ICallService.sol"; import "@iconfoundation/xcall-solidity-library/utils/RLPEncode.sol"; import "@iconfoundation/xcall-solidity-library/utils/RLPEncode.sol"; +import "@iconfoundation/xcall-solidity-library/utils/Strings.sol"; +import "@iconfoundation/xcall-solidity-library/utils/Integers.sol"; +/// @custom:oz-upgrades-from contracts/adapters/ClusterConnectionV1.sol:ClusterConnectionV1 contract ClusterConnection is Initializable, IConnection { using RLPEncode for bytes; using RLPEncode for string; using RLPEncode for uint256; + using Strings for bytes; + using Integers for uint256; + mapping(string => uint256) private messageFees; mapping(string => uint256) private responseFees; mapping(string => mapping(uint256 => bool)) receipts; @@ -312,15 +318,14 @@ contract ClusterConnection is Initializable, IConnection { bytes calldata _msg, string memory dstNetwork ) internal pure returns (bytes32) { - bytes memory rlp = abi + bytes memory encoded = abi .encodePacked( - srcNetwork.encodeString(), - _connSn.encodeUint(), - _msg.encodeBytes(), - dstNetwork.encodeString() - ) - .encodeList(); - return keccak256(rlp); + srcNetwork, + _connSn.toString(), + _msg.bytesToHex(), + dstNetwork + ); + return keccak256(encoded); } function publicKeyToAddress( diff --git a/contracts/evm/library/xcall/utils/Strings.sol b/contracts/evm/library/xcall/utils/Strings.sol index 0e86716e..3ac7020b 100644 --- a/contracts/evm/library/xcall/utils/Strings.sol +++ b/contracts/evm/library/xcall/utils/Strings.sol @@ -47,7 +47,7 @@ library Strings { converted[i * 2 + 1] = _base[uint8(buffer[i]) & 0xf]; } - return string(abi.encodePacked("0x", converted)); + return string(converted); } /** diff --git a/contracts/evm/test/adapters/ClusterConnection.t.sol b/contracts/evm/test/adapters/ClusterConnection.t.sol index b459b367..e301a8b2 100644 --- a/contracts/evm/test/adapters/ClusterConnection.t.sol +++ b/contracts/evm/test/adapters/ClusterConnection.t.sol @@ -8,7 +8,8 @@ import "@xcall/contracts/xcall/CallService.sol"; import "@xcall/contracts/mocks/multi-protocol-dapp/MultiProtocolSampleDapp.sol"; import "@xcall/utils/Types.sol"; import "@iconfoundation/xcall-solidity-library/utils/RLPEncode.sol"; - +import "@iconfoundation/xcall-solidity-library/utils/Strings.sol"; +import "@iconfoundation/xcall-solidity-library/utils/Integers.sol"; contract ClusterConnectionTest is Test { using RLPEncode for bytes; using RLPEncode for string; @@ -16,6 +17,9 @@ contract ClusterConnectionTest is Test { using RLPEncodeStruct for Types.CSMessage; using RLPEncodeStruct for Types.CSMessageRequestV2; + using Strings for bytes; + using Integers for uint256; + event CallExecuted(uint256 indexed _reqId, int _code, string _msg); event RollbackExecuted(uint256 indexed _sn); @@ -393,14 +397,13 @@ contract ClusterConnectionTest is Test { bytes memory _msg, string memory dstNetwork ) internal pure returns (bytes32) { - bytes memory rlp = abi + bytes memory encoded = abi .encodePacked( - srcNetwork.encodeString(), - _connSn.encodeUint(), - _msg.encodeBytes(), - dstNetwork.encodeString() - ) - .encodeList(); - return keccak256(rlp); + srcNetwork, + _connSn.toString(), + _msg.bytesToHex(), + dstNetwork + ); + return keccak256(encoded); } -} +} \ No newline at end of file