Author

Topic: merkel root (Read 2027 times)

full member
Activity: 546
Merit: 100
March 13, 2012, 04:48:55 PM
#12
After some brute force reverse engineering I figured it out Grin First off its sha256(sha256 and then the hex string is used in reverse.

Not meant to be easy this hehe Smiley
full member
Activity: 546
Merit: 100
March 12, 2012, 05:13:02 PM
#11
Ok I'm still working on this, even after all your help Sad I've figured out that to hash the transaction you actually do a sha256(sha256(tx)), the was my first problem.
Now the problem is:

I'm looking at the merkle root in http://blockexplorer.com/rawblock/000000000000030de89e7729d5785c4730839b6e16ea9fb686a54818d3860a8d

Taking the last three hashes you should think that:
sha256(e2d23adf5c86b1266a6abb9a471eaa05bf233dc66245e36a82bb14392fb36c4713f0f97659ccb96 f0f6abd4cda25894463dec0cf3deb626acfc60d506bfd3650) = acb5aeb11e2a607e610b90f2722cf68aec719af2a2fd6a6af179764e90169af4

But no, I cant get this to work. Am i missing something again??

PS I am converting from hex to byte[]

legendary
Activity: 1428
Merit: 1093
Core Armory Developer
March 11, 2012, 04:28:42 PM
#10
Thanks, nice illustration. I think I've got it more or less working. Only struggling with the endians.

Endianness is a royal PITA in Bitcoin.  I don't know if it helps at all, but I have a working implementation of merkle-root calculation here in C++ and here in Python.   There doesn't appear to be any endianness switching in the calculations, so you just need to make sure the endianness is correct on the input and everything else show work out.   
full member
Activity: 546
Merit: 100
March 11, 2012, 04:21:46 PM
#9
Thanks, nice illustration. I think I've got it more or less working. Only struggling with the endians.
legendary
Activity: 1428
Merit: 1093
Core Armory Developer
March 11, 2012, 12:48:08 PM
#8
Here's a diagram I created a long time ago when I was starting to illustrate BTC concepts for a presentation that I ended up not giving.

The parent of two nodes (in the diagram) is created by concatenating the two child nodes (such as "0f3e32d0af34332d") and then hashing that.

If a level has an odd number of nodes, you copy the last node. to make it even:  i.e. if a level has 3 nodes:  A, B, C, you just make it A,B,C,C and then carry on.




full member
Activity: 546
Merit: 100
March 10, 2012, 03:08:16 PM
#7
Should i be able to make the merkel root I'm making now match the one i get from "getwork"??
full member
Activity: 546
Merit: 100
March 10, 2012, 12:51:51 PM
#6
 Grin
legendary
Activity: 1526
Merit: 1129
March 10, 2012, 12:41:50 PM
#5
That's right. Be careful of endianness.
full member
Activity: 546
Merit: 100
March 10, 2012, 12:27:15 PM
#4
Is this really as simple as:
* Get transactions with getmemorypool, gives:
   "blabla" = tx1
   "blabla" = tx2
   "blabla" = tx3
   "blabla" = tx4
   and so on

* Do A = sha256(tx1 | tx2), B = sha256(tx3 | tx4)
* do sha256(A | B) = merkel root

Am I on to something???
full member
Activity: 546
Merit: 100
March 10, 2012, 09:30:20 AM
#3
Perfect answer, thanks Smiley
legendary
Activity: 1526
Merit: 1129
March 10, 2012, 09:08:23 AM
#2
See here:

  http://en.wikipedia.org/wiki/Hash_tree

The leaves of the tree are transaction hashes. See also the buildMerkleTree function in BitCoinJ:

http://code.google.com/p/bitcoinj/source/browse/src/com/google/bitcoin/core/Block.java#582
full member
Activity: 546
Merit: 100
March 10, 2012, 08:35:44 AM
#1
Hi

I've been trying to understand more about how bitcoin works. But I can't find much information on how the merkel root is calculated. I understand it's a coinbase script and the transactions from this block, but not much more. Any one know of some place I can read up on this.
Jump to: