Bitcoin Forum
July 25, 2024, 01:06:06 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: merkle root  (Read 437 times)
clarity510 (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
January 14, 2016, 04:14:58 PM
 #1

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
Fuserleer
Legendary
*
Offline Offline

Activity: 1064
Merit: 1020



View Profile WWW
January 14, 2016, 05:07:23 PM
 #2

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

clarity510 (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
January 14, 2016, 05:21:07 PM
 #3

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
Fuserleer
Legendary
*
Offline Offline

Activity: 1064
Merit: 1020



View Profile WWW
January 14, 2016, 05:26:38 PM
 #4

A little confusing but yes.

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


slapper
Legendary
*
Offline Offline

Activity: 2002
Merit: 1101


Leading Crypto Sports Betting & Casino Platform


View Profile
January 14, 2016, 05:29:23 PM
 #5

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)

..Stake.com..   ▄████████████████████████████████████▄
   ██ ▄▄▄▄▄▄▄▄▄▄            ▄▄▄▄▄▄▄▄▄▄ ██  ▄████▄
   ██ ▀▀▀▀▀▀▀▀▀▀ ██████████ ▀▀▀▀▀▀▀▀▀▀ ██  ██████
   ██ ██████████ ██      ██ ██████████ ██   ▀██▀
   ██ ██      ██ ██████  ██ ██      ██ ██    ██
   ██ ██████  ██ █████  ███ ██████  ██ ████▄ ██
   ██ █████  ███ ████  ████ █████  ███ ████████
   ██ ████  ████ ██████████ ████  ████ ████▀
   ██ ██████████ ▄▄▄▄▄▄▄▄▄▄ ██████████ ██
   ██            ▀▀▀▀▀▀▀▀▀▀            ██ 
   ▀█████████▀ ▄████████████▄ ▀█████████▀
  ▄▄▄▄▄▄▄▄▄▄▄▄███  ██  ██  ███▄▄▄▄▄▄▄▄▄▄▄▄
 ██████████████████████████████████████████
▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
█  ▄▀▄             █▀▀█▀▄▄
█  █▀█             █  ▐  ▐▌
█       ▄██▄       █  ▌  █
█     ▄██████▄     █  ▌ ▐▌
█    ██████████    █ ▐  █
█   ▐██████████▌   █ ▐ ▐▌
█    ▀▀██████▀▀    █ ▌ █
█     ▄▄▄██▄▄▄     █ ▌▐▌
█                  █▐ █
█                  █▐▐▌
█                  █▐█
▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀█
▄▄█████████▄▄
▄██▀▀▀▀█████▀▀▀▀██▄
▄█▀       ▐█▌       ▀█▄
██         ▐█▌         ██
████▄     ▄█████▄     ▄████
████████▄███████████▄████████
███▀    █████████████    ▀███
██       ███████████       ██
▀█▄       █████████       ▄█▀
▀█▄    ▄██▀▀▀▀▀▀▀██▄  ▄▄▄█▀
▀███████         ███████▀
▀█████▄       ▄█████▀
▀▀▀███▄▄▄███▀▀▀
..PLAY NOW..
watashi-kokoto
Sr. Member
****
Offline Offline

Activity: 683
Merit: 269



View Profile
January 14, 2016, 06:23:00 PM
 #6

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.
watashi-kokoto
Sr. Member
****
Offline Offline

Activity: 683
Merit: 269



View Profile
January 14, 2016, 06:47:57 PM
 #7

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)



Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!