Title: Problems verifying merkle root from two child nodes Post by: tyrick on December 03, 2013, 07:02:15 PM I am having issues with verifying the mrkl_root with the two children nodes.
Let's use the following block for a reference: http://blockexplorer.com/rawblock/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d According to my understanding (correct if wrong), I need to perform a byteSwap on each child, perform a hexToAscii, concatenate, then perform a double sha256. I am doing this in JAVA, an suspect that my hexToAscii method is off. I was hoping I could give some results to see if someone can verify where the problem is. Code: String childNode = "0d0eb1b4c4b49fd27d100e9cce555d4110594661b1b8ac05a4b8879c84959bd4"; And just to verify that my hexToAscii result is correct, can someone check the sha256 hash of the result? I feel that there are encoding issues with my implementation Code: sha256(hexToAscii(byteSwap(childNode))); Would appreciate any advice if something seems off! Thanks! I am convinced that there is a JAVA issue with my hexToAscii implementation. Code: public String hexToBin(String hex) { Some expertise would be appreciated here =/ Thanks Title: Re: Problems verifying merkle root from two child nodes Post by: GoldenWings91 on December 03, 2013, 07:38:25 PM For reference
"0d0eb1b4c4b49fd27d100e9cce555d4110594661b1b8ac05a4b8879c84959bd4" Endian swapped and double sha256: "2b9f3fd09cf042ce9eb019b72ac356db63121c1f56ad6af6cbd401bdf0d51f16" EDIT: String output = hex.substring(i, (i + 2)); Title: Re: Problems verifying merkle root from two child nodes Post by: tyrick on December 03, 2013, 08:15:12 PM Thanks for the reply! Actually, substring(i, (i + 2)) isn't inclusive of i + 2, so the result is just the two consecutive chars.
Also, you said Quote Endian swapped and double sha256: "2b9f3fd09cf042ce9eb019b72ac356db63121c1f56ad6af6cbd401bdf0d51f16" Are you sure that is all you did? I got the following: Code: String hash = "0d0eb1b4c4b49fd27d100e9cce555d4110594661b1b8ac05a4b8879c84959bd4" Completely different. Now I am questioning my dsha256 method... Title: Re: Problems verifying merkle root from two child nodes Post by: GoldenWings91 on December 03, 2013, 08:23:23 PM Quote Thanks for the reply! Actually, substring(i, (i + 2)) isn't inclusive of i + 2, so the result is just the two consecutive chars. I'm no Java developer so that was just an incorrect guess :P Quote Are you sure that is all you did? I got the following: I'm 100% sure "2b9f3fd09cf042ce9eb019b72ac356db63121c1f56ad6af6cbd401bdf0d51f16" (little endian) is the correct double sha256 hash of "d49b95849c87b8a405acb8b161465910415d55ce9c0e107dd29fb4c4b4b10e0d" (little endian) EDIT: Code: std::cout << functions::double_sha256( functions::hexTostring( functions::endian_swap( "0d0eb1b4c4b49fd27d100e9cce555d4110594661b1b8ac05a4b8879c84959bd4" ) ) ) << std::endl; Title: Re: Problems verifying merkle root from two child nodes Post by: danneu on December 03, 2013, 08:44:50 PM Code: (-> "0d0eb1b4c4b49fd27d100e9cce555d4110594661b1b8ac05a4b8879c84959bd4" Here're my Java crypto: Code: (:import Are you sure you're working with the actual bytes that the hex represents and not, for example, the bytes of the chars that make up the hex string? Title: Re: Problems verifying merkle root from two child nodes Post by: tyrick on December 03, 2013, 09:23:52 PM AHHH THANKSSSSS.
danneu, that was exactly my problem! wings, thanks for checking the values for me! |