0

We are trying to build a merkle tree in web3j and put the root for verification into the smart contract. Due to this problem we can't generate the same route between web3j and solidity/js...

In javascript:

Buffer.from(keccak256('4cdecb9e5f6a88b1696ca7e28b3a7e3d7474058d')).toString('hex');
Buffer.from(keccak256('0x4cdecb9e5f6a88b1696ca7e28b3a7e3d7474058d')).toString('hex');

Gives:

07c50cf7885d2f22d0ebc2b0e03eaf1f51d453169eddd2205970b9c139ec9475 47413ead80d195beca855e500674fd1a0a70c2f51bb3e82043c82959cd43d1c8

In web3j:

Numeric.toHexString(Hash.sha3("4cdecb9e5f6a88b1696ca7e28b3a7e3d7474058d".getBytes()), 0, 40, false);
Numeric.toHexString(Hash.sha3("0x4cdecb9e5f6a88b1696ca7e28b3a7e3d7474058d".getBytes()), 0, 42, false);

Gives:

07c50cf7885d2f22d0ebc2b0e03eaf1f51d453169eddd2205970b9c139ec9475 0652712e0f4e9f734d7a1e1a47413791135ed765dd25779c0eb5a282e0739c6e

The first result is the same, the 2nd different. This seems to be so with anything having '0x' at the front - regardless of string length, etc.

1 Answer 1

0

You are forgetting the concept of how a hash generates. You will obviously get entirly different wallet address by just changing one alphabet in your private key.

Sha3 is exactly doing what it has to do, it generates a hash to a given address.

Don't get distracted by 0x it just represents that this hash belongs to the Ethereum network. 0x is not generated by sha3, you have to add it your self and while validating you will yourself have to remove it from the start.

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.