diff --git a/contracts/javascore/cluster-connection/src/main/java/xcall/adapter/cluster/ClusterConnection.java b/contracts/javascore/cluster-connection/src/main/java/xcall/adapter/cluster/ClusterConnection.java index b5aacbc7..aff298dd 100644 --- a/contracts/javascore/cluster-connection/src/main/java/xcall/adapter/cluster/ClusterConnection.java +++ b/contracts/javascore/cluster-connection/src/main/java/xcall/adapter/cluster/ClusterConnection.java @@ -359,14 +359,8 @@ private void OnlyAdmin() { * @return the hash of the message */ private byte[] getMessageHash(String srcNetwork, BigInteger _connSn, byte[] msg, String dstNetwork) { - ByteArrayObjectWriter writer = Context.newByteArrayObjectWriter("RLPn"); - writer.beginList(4); - writer.write(srcNetwork); - writer.write(_connSn); - writer.write(msg); - writer.write(dstNetwork); - writer.end(); - return Context.hash("keccak-256", writer.toByteArray()); + String message = srcNetwork + String.valueOf(_connSn) + bytesToHex(msg) + dstNetwork; + return Context.hash("keccak-256", message.getBytes()); } } \ No newline at end of file diff --git a/contracts/javascore/cluster-connection/src/test/java/xcall/adapter/cluster/ClusterConnectionTest.java b/contracts/javascore/cluster-connection/src/test/java/xcall/adapter/cluster/ClusterConnectionTest.java index 28c691e4..6e29a92f 100644 --- a/contracts/javascore/cluster-connection/src/test/java/xcall/adapter/cluster/ClusterConnectionTest.java +++ b/contracts/javascore/cluster-connection/src/test/java/xcall/adapter/cluster/ClusterConnectionTest.java @@ -238,15 +238,21 @@ public void testRecvMessageWithSignaturesNotEnoughValidSignatures() throws Excep assertEquals("Reverted(0): Not enough valid signatures", e.getMessage()); } - public static byte[] getMessageHash(String srcNetwork, BigInteger _connSn, byte[] msg, String dstNetwork) { - ByteArrayObjectWriter writer = Context.newByteArrayObjectWriter("RLPn"); - writer.beginList(4); - writer.write(srcNetwork); - writer.write(_connSn); - writer.write(msg); - writer.write(dstNetwork); - writer.end(); - return Context.hash("keccak-256", writer.toByteArray()); + private byte[] getMessageHash(String srcNetwork, BigInteger _connSn, byte[] msg, String dstNetwork) { + String message = srcNetwork + String.valueOf(_connSn) + bytesToHex(msg) + dstNetwork; + return Context.hash("keccak-256", message.getBytes()); + } + + private String bytesToHex(byte[] bytes) { + StringBuilder hexString = new StringBuilder(); + for (byte b : bytes) { + String hex = Integer.toHexString(0xff & b); // Mask with 0xff to handle negative values correctly + if (hex.length() == 1) { + hexString.append('0'); // Add a leading zero if hex length is 1 + } + hexString.append(hex); + } + return hexString.toString(); } @Test @@ -262,4 +268,5 @@ public void testAddSigners() throws Exception { assertEquals(signers.length, 2); } + } \ No newline at end of file