I'm struggling to match two hashes. I hash a Json in String format in my Smart Contract like this.

   function verifyProof(string calldata _fullProof) public returns(bool r){
        bytes32 hashed = keccak256(abi.encodePacked(_fullProof));

I'm interacting with the Smart Contract via a external Truffle Script that I execute with the command "truffle exec truffle_script.js

In the Script I've been trying various methods to archive the same hash:

    const hashedLocal = web3.utils.soliditySha3(web3.utils.encodePacked(JSON.stringify(proof)));
    console.log("hashed local2", hashedLocal)
    console.log("hashed local3",web3.utils.keccak256(web3.utils.encodePacked(toString(proof))));
   console.log("hashed local3.5", web3.utils.keccak256(proof));
   console.log("hashed local4", web3.utils.keccak256(JSON.stringify(proof)));
   console.log("hashed local4", web3.utils.keccak256(toString(proof)));
   console.log("hashed local5" ,web3.utils.soliditySha3({t: 'string', v: proof}));
   console.log("hashed local6" ,web3.utils.soliditySha3({t: 'string', v: toString(proof)}));
   console.log("hashed local7" ,web3.utils.soliditySha3(web3.utils.toHex(proof) ));

I simply can't produce the same hash.

Does anybody have an idea what the problem might be?

The data to hash looks like this:

{"proof": {
    "a": [
    ],"b": [
    ],"c": [
"inputs": [

1 Answer 1


here is the solidity code:

    function hash(string calldata data) public pure returns(bytes32){
        return keccak256(abi.encodePacked(data));

and here is JS code:


these two codes return similar data for "hello" as input. I think you problem is inputs for these two functions, check you inputs and try simple inputs and check for uppercase and lowercase letters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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