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": [
"0x2010f7ceeb118735d309ff1ab4410d77437d6643270f341f2e5b9b9674f32317",
"0x11f580342e8543a21365e088ef337079fbd0e73c5cb1ae17d9d291ed042c33bf"
],"b": [
[
"0x1562eac9e8e36fab1c5784ba2097686c4bdfbfe232ed10cd5efc0eb9f62bee63",
"0x306098b792f0e79e945a4ff60ae7c5406b0b58850e4ed5bbe42f08b7efc85734"
],
[
"0x27f016473a580620fc2ef45c0541d35b425de6ebac1c78006a39ba286b6b9afb",
"0x1ab7506590ee8060b83324b8e71f6db79805d04fa10b949c9cada2692c15b47d"
]
],"c": [
"0x2b12f5aa5257e7356cd5aee36950e7af9914efca8eaeeed8958f9fabf9f54032",
"0x27fd7a495856d6ef3b05c9920b03b5c05f1ac90bfae28f32a8db154cc7f7978d"
]
},
"inputs": [
"0x00000000000000000000000000000000779d99147b3605d185eb5f9d017ef1ae",
"0x00000000000000000000000000000000e1c0538dd9730a859f8f2c8ca2001e04"
]
}