Solidity Hash of Structs (Testing hash uniqueness)
So ive been informed by one of my Advisee (Rain de Castro) that when hashing a Struct in Solidity, the hash is the same for 2 data that is different.
So i did a few tests with the following Code
True enough The returned value for a data "Aresh","555"
so based on the code the "hash2" variable returns the same hash compared to the "hash" variable
this is something to take note of for Previous Examples that ive posted
therefore hashing the data compared to the struct to create unique hashes.
So i did a few tests with the following Code
pragma solidity ^0.4.0;
contract testHashAresh{
//Declare a struct similar to C++
struct Person{
string fullName;
string number;
}
mapping (bytes32 => Person) allPersons;
function returnHash(string _name, string _time) constant returns (bytes32,bytes32)
{
Person memory p = Person(_name, _time);
bytes32 hash2 = sha256(p);
bytes32 hash = sha256(_name, _time);
return (hash2, hash);
}
}
True enough The returned value for a data "Aresh","555"
- 0: bytes32: 0xac9c046be90fd91b4a31b9d04bb937659e885264dd8e6b8a7c9e79b806ef3ead
- 1: bytes32: 0x5ffc903b2aee670ea38ec2c35a8c5b8ac04754cf77536dd89d4d9985c4fd110f
- 0: bytes32: 0xac9c046be90fd91b4a31b9d04bb937659e885264dd8e6b8a7c9e79b806ef3ead
- 1: bytes32: 0x8595e0f468c32ad618127d15c86376b4d08d9b1126d39a02f64a69961a45cbaf
so based on the code the "hash2" variable returns the same hash compared to the "hash" variable
this is something to take note of for Previous Examples that ive posted
therefore hashing the data compared to the struct to create unique hashes.
Comments
Post a Comment