Author

Topic: Problems verifying merkle root from two child nodes (Read 620 times)

newbie
Activity: 9
Merit: 0
AHHH THANKSSSSS.

danneu, that was exactly my problem!

wings, thanks for checking the values for me!
newbie
Activity: 32
Merit: 0
Code:
(-> "0d0eb1b4c4b49fd27d100e9cce555d4110594661b1b8ac05a4b8879c84959bd4"
    hex->bytes
    reverse-bytes
    double-sha256
    bytes->hex)

;; "2b9f3fd09cf042ce9eb019b72ac356db63121c1f56ad6af6cbd401bdf0d51f16"

Here're my Java crypto:

Code:
(:import
 [java.security MessageDigest])

(defn sha256 [data]
  (-> (MessageDigest/getInstance "SHA-256" "BC")
      (.digest data)))

(defn double-sha256 [data]
  (sha256 (sha256 data)))

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?
full member
Activity: 141
Merit: 100
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  Tongue

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;

newbie
Activity: 9
Merit: 0
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"
flipHex(hash); //d49b95849c87b8a405acb8b161465910415d55ce9c0e107dd29fb4c4b4b10e0d
dsha256(flipHex(hash)); //fa17aefd43501ded4b8dba60fcd1f3f7254eeb0023894a543d0ca800998591bd

Completely different.  Now I am questioning my dsha256 method...
full member
Activity: 141
Merit: 100
For reference

"0d0eb1b4c4b49fd27d100e9cce555d4110594661b1b8ac05a4b8879c84959bd4"

Endian swapped and double sha256:
"2b9f3fd09cf042ce9eb019b72ac356db63121c1f56ad6af6cbd401bdf0d51f16"

EDIT:

Shouldn't this be 1?
String output = hex.substring(i, (i + 2));


newbie
Activity: 9
Merit: 0
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";
byteSwap(childNode); //d49b95849c87b8a405acb8b161465910415d55ce9c0e107dd29fb4c4b4b10e0d
hexToAscii(byteSwap(childNode)); //Ô¸¤¬¸±aFYA]UÎ}Ò´Ä´±

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)));
//e799dc13aaeaa1c2797596f5d4bf6c408b97a8595bf32c27c9186125454560d9

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) {
 StringBuilder sb = new StringBuilder();
 StringBuilder temp = new StringBuilder();
 //49204c6f7665204a617661 split into two characters 49, 20, 4c...
 for(int i = 0; i < hex.length() - 1; i += 2){
     //grab the hex in pairs
     String output = hex.substring(i, (i + 2));
     //convert hex to decimal
     int decimal = Integer.parseInt(output, 16);
     //convert the decimal to character
      sb.append((char)decimal);
     temp.append(decimal);
 }
 return sb.toString();
}


Some expertise would be appreciated here =/  Thanks

Jump to: