2

The problem is that sha3 in solidity returns bytes32 and I have a string returned from IPFS by oraclize, and if hash calculated in solidity and returned to web3js (bytes32 got interpreted as a string) it equals web3.utils.soliditySha3, but I can't make that comparison inside solidity because of different types. I tried converting bytes32 to string and vice versa in a few ways each, sometimes it doesn't work, sometimes they are not equal.

    bytes32 checkHash = keccak256(strConcat("0xf17f52151ebef6c7334fad080c5704d77216b732","570000000000000000"));        
    var first = checkHash.toSliceB32();
    var second = form.toSlice();   // Returned from IPFS, it's a string that looks 
        // like "0xd89a3fa2ddbed0a17fa2954b1060f41591c216155b688a7b5af5a2d7c003bb11"
        // checkHash returns the same string when pulling it out by web3js

So, I'm using this (https://github.com/Arachnid/solidity-stringutils) library to convert them both to slices and check by first.equals(second), and they are not equal. I can't convert first slice to string, it says

Error: Invalid UTF-8 detected

I tried function from here (How to convert a bytes32 to string), it says the same, tried

function stringToBytes32(string memory source) public constant returns (bytes32 result) {        
        assembly {
            result := mload(add(source, 32))
        }
}

from here(https://gist.github.com/ageyev/779797061490f5be64fb02e978feb6ac), it converts it to something else. I guess I have no clue now on how it works.

0 Answers0