Skip to content

Commit

Permalink
fix: evm rlp to string concat
Browse files Browse the repository at this point in the history
  • Loading branch information
gcranju committed Dec 10, 2024
1 parent 25da19b commit 53b618a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
21 changes: 13 additions & 8 deletions contracts/evm/contracts/adapters/ClusterConnection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion contracts/evm/library/xcall/utils/Strings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ library Strings {
converted[i * 2 + 1] = _base[uint8(buffer[i]) & 0xf];
}

return string(abi.encodePacked("0x", converted));
return string(converted);
}

/**
Expand Down
23 changes: 13 additions & 10 deletions contracts/evm/test/adapters/ClusterConnection.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ 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;
using RLPEncode for uint256;
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);
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 53b618a

Please sign in to comment.