How can I receive the same hash in solidity and web3? Multiple values where one is a multi dimensional array.
Solidity v0.5.x:
pragma solidity 0.5.6;
pragma experimental ABIEncoderV2;
contract Hash{
uint256[][] public data;
function append(uint _a, uint _b) public {
data.push([_a, _b]);
}
function hash(uint256 _idx, string memory _b) public view returns(bytes32) {
return keccak256(abi.encodePacked(data[_idx], _b));
}
}
Solidity output:
decoded input
{
"uint256 _idx": "0",
"string _b": "a"
}
decoded output
{
"0": "bytes32: 0x8385585c10cea4e82d9662964b0a952bc1ad925ded1aff4ab359eb38b6d23d11"
}
Web3:
truffle(development)> var arr = new Array(2);
truffle(development)> arr.push([1, 2]);
truffle(development)> web3.utils.soliditySha3(arr,"a")
Web3 output:
/Users/xxx/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/cli.bundled.js:345535
throw new Error('Autodetection of array types is not supported.');
I also tried
web3.utils.keccak256(
web3.eth.abi.encodeParameters(["uint256[][]", "string"], [arr, "a"])
);
which provides a different hash.
web3.utils.soliditySha3(a);
– Senju Jun 18 '19 at 6:52