Skip to content

Commit

Permalink
fix: icon 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 53b618a commit 3baf010
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -262,4 +268,5 @@ public void testAddSigners() throws Exception {
assertEquals(signers.length, 2);
}


}

0 comments on commit 3baf010

Please sign in to comment.