Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: clarity510 on January 14, 2016, 04:14:58 PM



Title: merkle root
Post by: clarity510 on January 14, 2016, 04:14:58 PM
I'm working on an altcoin. I'm trying to figure out the merkle tree/root.

Everything that I've read has 2^n or 2^n - 1 (if odd number of nodes) nodes on the bottom of the tree. Does this have to be the case? What am I supposed to do if I have 5 transactions in the block?

Thanks,
Ryan


Title: Re: merkle root
Post by: Fuserleer on January 14, 2016, 05:07:23 PM
You hash the 5th transaction with itself to get the parent.

So, TX1 hashes with TX2, TX3 hashes with TX4, TX5 hashes with TX5.

See here:  https://en.bitcoin.it/wiki/Protocol_documentation#Merkle_Trees


Title: Re: merkle root
Post by: clarity510 on January 14, 2016, 05:21:07 PM
so we have:

TX1 + TX2, TX3 + TX4, TX5 + TX5

Then the next round:
TX1TX2 + TX3TX4, TX5TX5 + TX5TX5

Then,
TX1TX2TX3TX4 + TX5TX5TX5TX5

and finally the root is,
TX1TX2TX3TX4TX5TX5TX5TX5

Is this how to do it?

Thanks,
Ryan


Title: Re: merkle root
Post by: Fuserleer on January 14, 2016, 05:26:38 PM
A little confusing but yes.

You self hash with odd amount of leaves until you get an even amount, from there you are good :)



Title: Re: merkle root
Post by: slapper on January 14, 2016, 05:29:23 PM
Contact Spoetnik https://bitcointalk.org/index.php?action=profile;u=138471

He has reversed a lot of PC games in the past and can help you with launching altcoins but the more important factor is how many Bitcoins you have to pump your coin before launching another altcoin. We DO NOT have enough altcoins and smart developers like you are what we need to embrace cryptocurrency as a means of battling endless printing of fiat.

What's the name of the coin? I recommend PowerballCoin. (You are welcome)


Title: Re: merkle root
Post by: watashi-kokoto on January 14, 2016, 06:23:00 PM
so we have:

TX1 + TX2, TX3 + TX4, TX5 + TX5

Then the next round:
TX1TX2 + TX3TX4, TX5TX5 + TX5TX5

Then,
TX1TX2TX3TX4 + TX5TX5TX5TX5

and finally the root is,
TX1TX2TX3TX4TX5TX5TX5TX5

Is this how to do it?

Thanks,
Ryan


Small correction: when there are an odd number of elements in a level, the last one is hashed after appending it to itself. So usually hash6 of one level is H(hash12+hash13) of the level below, but it can be H(hash12+hash12) if hash12 is the last one.


Title: Re: merkle root
Post by: watashi-kokoto on January 14, 2016, 06:47:57 PM
for example when you have one transaction in a block, the transaction id is used as a merkle root.

when two just hash them
// block 170

   var a = "b1fea52486ce0c62bb442b530a3f0132b826c74e473d1f2c220bfa78111c5082"
   var b = "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16"
   var c = merkle(a,b)