I try to implement my own little modifited commit&reveal voting. I have problem with revael phase. Reveal metod signature look like:

function reveal(bytes32[] memory _reveals, bytes32[] memory _commits)

So I need to compare hashed reveal phrase and commit phrase. I discover that these hashes do not match each other.

To demonstrate my problem I created this contract:

pragma solidity >=0.5.10;

contract Utils{
   event HashedData(bytes32);

   function getHash(bytes32 data) public pure returns(bytes32){
       return keccak256(abi.encodePacked(data));

   function checkHash(bytes32 hash, bytes32 data) public returns(bool){
        bytes32 hashedData = getHash(data);
        emit HashedData(hashedData);
        return hash==hashedData;

Example input data: phrase: "1_john" to bytes32

data: 0x315f6b6f74000000000000000000000000000000000000000000000000000000

hash from data (without 0x)

hash: 0x90a0076f07f9884805bdc4d668c55756ff42238a0ad7b824b8a267783e822544

As result I receive: enter image description here

Where I made mistake?


It seems like you treated "315f6b6f74000000000000000000000000000000000000000000000000000000" like a string instead of the hexadecimal byte sequence it actually is.

Via web3 0.2.x:

> "0x90a0076f07f9884805bdc4d668c55756ff42238a0ad7b824b8a267783e822544"
web3.sha3('315f6b6f74000000000000000000000000000000000000000000000000000000', { encoding: 'hex' })
> "0x1a32a86fd2fa1e85655c2d86eadd160787458aff3d70eefae6150b79b648693f"

Note that the second value is correct, once you interpret it as hexadecimal. If the tool you're using doesn't support hexadecimal inputs, you'll need to find a different tool.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.