<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=MidnightLightning</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=MidnightLightning"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/MidnightLightning"/>
	<updated>2026-05-17T07:27:21Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=List_of_address_prefixes&amp;diff=44015</id>
		<title>List of address prefixes</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=List_of_address_prefixes&amp;diff=44015"/>
		<updated>2014-01-24T21:25:35Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Blockchain-based currencies use addresses, which are a [[Base58Check encoding]] of some hash, typically that of a public key. The encoding includes a version byte, which affects the first character in the address. The following is a list of some prefixes which are in use.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Decimal version&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Use&lt;br /&gt;
!Example&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|Bitcoin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|3&lt;br /&gt;
|Bitcoin script hash&lt;br /&gt;
| &amp;lt;tt&amp;gt;3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|L&lt;br /&gt;
|Litecoin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;LhK2kQwiaAvhjWY799cZvMyYwnQAcxkarr&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|Namecoin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;NATX6zEUNfxfvgVwz8qVnnw3hLhhYXhgQn&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|Bitcoin testnet pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|128&lt;br /&gt;
|5&lt;br /&gt;
|Bitcoin Private key&lt;br /&gt;
|&amp;lt;tt&amp;gt;5Hwgr3u458GLafKBgxtssHSPqJnYoGrSzgQsPwLFhLNYskDPyyA&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|196&lt;br /&gt;
|2&lt;br /&gt;
|Testnet script hash&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|239&lt;br /&gt;
|9&lt;br /&gt;
|Testnet Private key&lt;br /&gt;
|&amp;lt;tt&amp;gt;92Pg46rUhgTT7romnV7iGW6W1gbGdeezqdbJCzShkCsYNzyyNcc&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following table shows the leading symbol(s) and address length(s) for 160 bit hashes for each of the possible decimal version values:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Decimal version&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Address length&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|up to 34&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Q-Z, a-k, m-o&lt;br /&gt;
|33&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|o-z, 2&lt;br /&gt;
|33 or 34&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|2&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|2 or 3&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|5-6&lt;br /&gt;
|3&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|3 or 4&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|4&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
|4 or 5&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|10-11&lt;br /&gt;
|5&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|5 or 6&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|13&lt;br /&gt;
|6&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|14&lt;br /&gt;
|6 or 7&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|15-16&lt;br /&gt;
|7&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|17&lt;br /&gt;
|7 or 8&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|18&lt;br /&gt;
|8&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|19&lt;br /&gt;
|8 or 9&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|20-21&lt;br /&gt;
|9&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|22&lt;br /&gt;
|9 or A&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|23&lt;br /&gt;
|A&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|24&lt;br /&gt;
|A or B&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|25-26&lt;br /&gt;
|B&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|27&lt;br /&gt;
|B or C&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|28&lt;br /&gt;
|C&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|29&lt;br /&gt;
|C or D&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|30-31&lt;br /&gt;
|D&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|32&lt;br /&gt;
|D or E&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|33&lt;br /&gt;
|E&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|34&lt;br /&gt;
|E or F&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|35-36&lt;br /&gt;
|F&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|37&lt;br /&gt;
|F or G&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|38&lt;br /&gt;
|G&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|39&lt;br /&gt;
|G or H&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|40-41&lt;br /&gt;
|H&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|42&lt;br /&gt;
|H or J&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|43&lt;br /&gt;
|J&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|44&lt;br /&gt;
|J or K&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|45-46&lt;br /&gt;
|K&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|47&lt;br /&gt;
|K or L&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|L&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|49&lt;br /&gt;
|L or M&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|50-51&lt;br /&gt;
|M&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|53&lt;br /&gt;
|N&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|54&lt;br /&gt;
|N or P&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|55-56&lt;br /&gt;
|P&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|57&lt;br /&gt;
|P or Q&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|58&lt;br /&gt;
|Q&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|59&lt;br /&gt;
|Q or R&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|60-61&lt;br /&gt;
|R&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|62&lt;br /&gt;
|R or S&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|63&lt;br /&gt;
|S&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|64&lt;br /&gt;
|S or T&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|65-66&lt;br /&gt;
|T&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|67&lt;br /&gt;
|T or U&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|68&lt;br /&gt;
|U&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|69&lt;br /&gt;
|U or V&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|70-71&lt;br /&gt;
|V&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|72&lt;br /&gt;
|V or W&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|73&lt;br /&gt;
|W&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|74&lt;br /&gt;
|W or X&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|75-76&lt;br /&gt;
|X&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|77&lt;br /&gt;
|X or Y&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|78&lt;br /&gt;
|Y&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|79&lt;br /&gt;
|Y or Z&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|80-81&lt;br /&gt;
|Z&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|82&lt;br /&gt;
|Z or a&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|83&lt;br /&gt;
|a&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|84&lt;br /&gt;
|a or b&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|85&lt;br /&gt;
|b&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|86&lt;br /&gt;
|b or c&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|87-88&lt;br /&gt;
|c&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|89&lt;br /&gt;
|c or d&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|90&lt;br /&gt;
|d&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|91&lt;br /&gt;
|d or e&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|92-93&lt;br /&gt;
|e&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|94&lt;br /&gt;
|e or f&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|95&lt;br /&gt;
|f&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|96&lt;br /&gt;
|f or g&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|97-98&lt;br /&gt;
|g&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|99&lt;br /&gt;
|g or h&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|100&lt;br /&gt;
|h&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|101&lt;br /&gt;
|h or i&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|102-103&lt;br /&gt;
|i&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|104&lt;br /&gt;
|i or j&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|105&lt;br /&gt;
|j&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|106&lt;br /&gt;
|j or k&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|107-108&lt;br /&gt;
|k&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|109&lt;br /&gt;
|k or m&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|110&lt;br /&gt;
|m&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|112-113&lt;br /&gt;
|n&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|114&lt;br /&gt;
|n or o&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|115&lt;br /&gt;
|o&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|116&lt;br /&gt;
|o or p&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|117-118&lt;br /&gt;
|p&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|119&lt;br /&gt;
|p or q&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|120&lt;br /&gt;
|q&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|121&lt;br /&gt;
|q or r&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|122-123&lt;br /&gt;
|r&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|124&lt;br /&gt;
|r or s&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|125&lt;br /&gt;
|s&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|126&lt;br /&gt;
|s or t&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|127-128&lt;br /&gt;
|t&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|129&lt;br /&gt;
|t or u&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|130&lt;br /&gt;
|u&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|131&lt;br /&gt;
|u or v&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|132-133&lt;br /&gt;
|v&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|134&lt;br /&gt;
|v or w&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|135&lt;br /&gt;
|w&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|136&lt;br /&gt;
|w or x&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|137-138&lt;br /&gt;
|x&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|139&lt;br /&gt;
|x or y&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|140&lt;br /&gt;
|y&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|141&lt;br /&gt;
|y or z&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|142-143&lt;br /&gt;
|z&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|144&lt;br /&gt;
|z or 2&lt;br /&gt;
|34 or 35&lt;br /&gt;
|-&lt;br /&gt;
|145-255&lt;br /&gt;
|2&lt;br /&gt;
|35&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=43759</id>
		<title>Protocol documentation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=43759"/>
		<updated>2014-01-16T16:57:34Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Network address */ change presentation of IPv6 address to standard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sources:&lt;br /&gt;
* [[Original Bitcoin client]] source&lt;br /&gt;
&lt;br /&gt;
Type names used in this documentation are from the C99 standard.&lt;br /&gt;
&lt;br /&gt;
For protocol used in mining, see [[Getwork]].&lt;br /&gt;
&lt;br /&gt;
==Common standards==&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Usually, when a hash is computed within bitcoin, it is computed twice. Most of the time [http://en.wikipedia.org/wiki/SHA-2 SHA-256] hashes are used, however [http://en.wikipedia.org/wiki/RIPEMD RIPEMD-160] is also used when a shorter hash is desirable (for example when creating a bitcoin address).&lt;br /&gt;
&lt;br /&gt;
Example of double-SHA-256 encoding of string &amp;quot;hello&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round of sha-256)&lt;br /&gt;
 9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50 (second round of sha-256)&lt;br /&gt;
&lt;br /&gt;
For bitcoin addresses (RIPEMD-160) this would give:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round is sha-256)&lt;br /&gt;
 b6a9c8c230722b7c748331a8b450f05566dc7d0f (with ripemd-160)&lt;br /&gt;
&lt;br /&gt;
=== Merkle Trees ===&lt;br /&gt;
&lt;br /&gt;
Merkle trees are binary trees of hashes. Merkle trees in bitcoin use a &#039;&#039;&#039;double&#039;&#039;&#039; SHA-256, the SHA-256 hash of the SHA-256 hash of something.&lt;br /&gt;
&lt;br /&gt;
If, when forming a row in the tree (other than the root of the tree), it would have an odd number of elements, the final double-hash is duplicated to ensure that the row has an even number of hashes.&lt;br /&gt;
&lt;br /&gt;
First form the bottom row of the tree with the ordered double-SHA-256 hashes of the byte streams of the transactions in the block.&lt;br /&gt;
&lt;br /&gt;
Then the row above it consists of half that number of hashes.  Each entry is the double-SHA-256 of the 64-byte concatenation of the corresponding two hashes below it in the tree.&lt;br /&gt;
&lt;br /&gt;
This procedure repeats recursively until we reach a row consisting of just a single double-hash.  This is the &#039;&#039;&#039;merkle root&#039;&#039;&#039; of the tree.&lt;br /&gt;
&lt;br /&gt;
For example, imagine a block with three transactions &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039;.   The merkle tree is: &lt;br /&gt;
&lt;br /&gt;
 d1 = dhash(a)&lt;br /&gt;
 d2 = dhash(b)&lt;br /&gt;
 d3 = dhash(c)&lt;br /&gt;
 d4 = dhash(c)            # a, b, c are 3. that&#039;s an odd number, so we take the c twice&lt;br /&gt;
 &lt;br /&gt;
 d5 = dhash(d1 concat d2)&lt;br /&gt;
 d6 = dhash(d3 concat d4)&lt;br /&gt;
 &lt;br /&gt;
 d7 = dhash(d5 concat d6)&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
 &lt;br /&gt;
 dhash(a) = sha256(sha256(a))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;d7&#039;&#039; is the merkle root of the 3 transactions in this block.&lt;br /&gt;
&lt;br /&gt;
Note: Hashes in Merkle Tree displayed in the [[Block Explorer]] are of little-endian notation. For some implementations and [http://www.fileformat.info/tool/hash.htm calculations], the bits need to be reversed before they are hashed, and again after the hashing operation.&lt;br /&gt;
&lt;br /&gt;
=== Signatures ===&lt;br /&gt;
&lt;br /&gt;
Bitcoin uses [http://en.wikipedia.org/wiki/Elliptic_curve_cryptography Elliptic Curve] [http://en.wikipedia.org/wiki/Digital_Signature_Algorithm Digital Signature Algorithm] ([http://en.wikipedia.org/wiki/Elliptic_Curve_DSA ECDSA]) to sign transactions. &lt;br /&gt;
&lt;br /&gt;
For ECDSA the secp256k1 curve from http://www.secg.org/collateral/sec2_final.pdf is used.&lt;br /&gt;
&lt;br /&gt;
Public keys (in scripts) are given as 04 &amp;lt;x&amp;gt; &amp;lt;y&amp;gt; where &#039;&#039;x&#039;&#039; and &#039;&#039;y&#039;&#039; are 32 byte big-endian integers representing the coordinates of a point on the curve or in compressed form given as &amp;lt;sign&amp;gt; &amp;lt;x&amp;gt; where &amp;lt;sign&amp;gt; is 0x02 if &#039;&#039;y&#039;&#039; is even and 0x03 if &#039;&#039;y&#039;&#039; is odd.&lt;br /&gt;
&lt;br /&gt;
Signatures use [http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules DER encoding] to pack the &#039;&#039;r&#039;&#039; and &#039;&#039;s&#039;&#039; components into a single byte stream (this is also what OpenSSL produces by default).&lt;br /&gt;
&lt;br /&gt;
=== Transaction Verification ===&lt;br /&gt;
Transactions are cryptographically signed records that reassign ownership of Bitcoins to new addresses.  Transactions have &#039;&#039;inputs&#039;&#039; - records which reference the funds from other previous transactions - and &#039;&#039;outputs&#039;&#039; - records which determine the new owner of the transferred Bitcoins, and which will be referenced as inputs in future transactions as those funds are respent.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;input&#039;&#039; must have a cryptographic digital signature that unlocks the funds from the prior transaction.  Only the person possessing the appropriate [[private key]] is able to create a satisfactory signature; this in effect ensures that funds can only be spent by their owners.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;output&#039;&#039; determines which Bitcoin address (or other criteria, see [[Scripting]]) is the recipient of the funds.&lt;br /&gt;
&lt;br /&gt;
In a transaction, the sum of all inputs must be equal to or greater than the sum of all outputs.  If the inputs exceed the outputs, the difference is considered a [[transaction fee]], and is redeemable by whoever first includes the transaction into the block chain.&lt;br /&gt;
&lt;br /&gt;
A special kind of transaction, called a [[coinbase transaction]], has no inputs.  It is created by [[miners]], and there is one coinbase transaction per block.  Because each block comes with a reward of newly created Bitcoins (e.g. 50 BTC for the first 210,000 blocks), the first transaction of a block is, with few exceptions, the transaction that grants those coins to their recipient (the miner).  In addition to the newly created Bitcoins, the coinbase transaction is also used for assigning the recipient of any transaction fees that were paid within the other transactions being included in the same block.  The coinbase transaction can assign the entire reward to a single Bitcoin address, or split it in portions among multiple addresses, just like any other transaction.  Coinbase transactions always contain outputs totaling the sum of the block reward plus all transaction fees collected from the other transactions in the same block.&lt;br /&gt;
&lt;br /&gt;
The [[coinbase transaction]] in block zero cannot be spent. This is due to a quirk of the reference client implementation that would open the potential for a block chain fork if some nodes accepted the spend and others did not&amp;lt;ref&amp;gt;[http://bitcointalk.org/index.php?topic=119645.msg1288552#msg1288552 Block 0 Network Fork]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Most Bitcoin outputs encumber the newly transferred coins with a single ECDSA private key.  The actual record saved with inputs and outputs isn&#039;t necessarily a key, but a &#039;&#039;script&#039;&#039;.  Bitcoin uses an interpreted scripting system to determine whether an output&#039;s criteria have been satisfied, with which more complex operations are possible, such as outputs that require two ECDSA signatures, or two-of-three-signature schemes.  An output that references a single Bitcoin address is a &#039;&#039;typical&#039;&#039; output; an output actually contains this information in the form of a script that requires a single ECDSA signature (see [[OP_CHECKSIG]]).  The output script specifies what must be provided to unlock the funds later, and when the time comes in the future to spend the transaction in another input, that input must provide all of the thing(s) that satisfy the requirements defined by the original output script.&lt;br /&gt;
&lt;br /&gt;
=== Addresses ===&lt;br /&gt;
&lt;br /&gt;
A bitcoin address is in fact the hash of a ECDSA public key, computed this way:&lt;br /&gt;
&lt;br /&gt;
 Version = 1 byte of 0 (zero); on the test network, this is 1 byte of 111&lt;br /&gt;
 Key hash = Version concatenated with RIPEMD-160(SHA-256(public key))&lt;br /&gt;
 Checksum = 1st 4 bytes of SHA-256(SHA-256(Key hash))&lt;br /&gt;
 Bitcoin Address = Base58Encode(Key hash concatenated with Checksum)&lt;br /&gt;
&lt;br /&gt;
The Base58 encoding used is home made, and has some differences. Especially, leading zeroes are kept as single zeroes when conversion happens.&lt;br /&gt;
&lt;br /&gt;
== Common structures ==&lt;br /&gt;
&lt;br /&gt;
Almost all integers are encoded in little endian. Only IP or port number are encoded big endian.&lt;br /&gt;
&lt;br /&gt;
=== Message structure ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || uint32_t || Magic value indicating message origin network, and used to seek to next message when stream state is unknown&lt;br /&gt;
|-&lt;br /&gt;
| 12 || command || char[12] || ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || length || uint32_t || Length of payload in number of bytes&lt;br /&gt;
|-&lt;br /&gt;
| 4 || checksum || uint32_t || First 4 bytes of sha256(sha256(payload))&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || uchar[] || The actual data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Known magic values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Network !! Magic value !! Sent over wire as&lt;br /&gt;
|-&lt;br /&gt;
| main || 0xD9B4BEF9 || F9 BE B4 D9&lt;br /&gt;
|-&lt;br /&gt;
| testnet || 0xDAB5BFFA || FA BF B5 DA&lt;br /&gt;
|-&lt;br /&gt;
| testnet3 || 0x0709110B || 0B 11 09 07&lt;br /&gt;
|-&lt;br /&gt;
| namecoin || 0xFEB4BEF9 || F9 BE B4 FE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Variable length integer ===&lt;br /&gt;
&lt;br /&gt;
Integer can be encoded depending on the represented value to save space.&lt;br /&gt;
Variable length integers always precede an array/vector of a type of data that may vary in length.&lt;br /&gt;
Longer numbers are encoded in little endian.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Storage length !! Format&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 0xfd || 1 || uint8_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffff || 3 || 0xfd followed by the length as uint16_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffffffff || 5 || 0xfe followed by the length as uint32_t&lt;br /&gt;
|-&lt;br /&gt;
| - || 9 || 0xff followed by the length as uint64_t&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re reading the Satoshi client code (BitcoinQT) it refers to this as a &amp;quot;CompactSize&amp;quot;. Modern BitcoinQT has also CVarInt class which implements even more compact integer for the purpose of local storage (which is incompatible with &amp;quot;CompactSize&amp;quot; described here). CVarInt is not a part of the protocol.&lt;br /&gt;
&lt;br /&gt;
=== Variable length string ===&lt;br /&gt;
&lt;br /&gt;
Variable length string can be stored using a variable length integer followed by the string itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the string&lt;br /&gt;
|-&lt;br /&gt;
| ? || string || char[] || The string itself (can be empty)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Network address ===&lt;br /&gt;
&lt;br /&gt;
When a network address is needed somewhere, this structure is used.  This protocol and structure supports IPv6, &#039;&#039;&#039;but note that the original client currently only supports IPv4 networking&#039;&#039;&#039;. Network addresses are not prefixed with a timestamp in the version message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || time || uint32 || the Time (version &amp;gt;= 31402)&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || same service(s) listed in [[#version|version]]&lt;br /&gt;
|-&lt;br /&gt;
| 16 || IPv6/4 || char[16] || IPv6 address. Network byte order. The original client only supports IPv4 and only reads the last 4 bytes to get the IPv4 address. However, the IPv4 address is written into the message as a 16 byte [http://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses IPv4-mapped IPv6 address]&lt;br /&gt;
(12 bytes &#039;&#039;00 00 00 00  00 00 00 00  00 00 FF FF&#039;&#039;, followed by the 4 bytes of the IPv4 address).&lt;br /&gt;
|-&lt;br /&gt;
| 2 || port || uint16_t || port number, network byte order&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of Network address structure&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0010   00 00 FF FF 0A 00 00 01  20 8D                    ........ .&lt;br /&gt;
&lt;br /&gt;
Network address:&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK: see services listed under version command)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv6: ::ffff:a00:1 or IPv4: 10.0.0.1&lt;br /&gt;
 20 8D                                           - Port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inventory Vectors ===&lt;br /&gt;
&lt;br /&gt;
Inventory vectors are used for notifying other nodes about objects they have or data which is being requested.&lt;br /&gt;
&lt;br /&gt;
Inventory vectors consist of the following data format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || type || uint32_t || Identifies the object type linked to this inventory&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object type is currently defined as one of the following possibilities:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || ERROR || Any data of with this number may be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 1 || MSG_TX || Hash is related to a transaction&lt;br /&gt;
|-&lt;br /&gt;
| 2 || MSG_BLOCK || Hash is related to a data block&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Other Data Type values are considered reserved for future implementations.&lt;br /&gt;
&lt;br /&gt;
=== Block Headers ===&lt;br /&gt;
&lt;br /&gt;
Block headers are sent in a headers packet in response to a getheaders message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A timestamp recording when this block was created (Will overflow in 2106&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unix_time#Notable.C2.A0events.C2.A0in.C2.A0Unix.C2.A0time&amp;lt;/ref&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated difficulty target being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| 1 || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries, this value is always 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Message types ==&lt;br /&gt;
&lt;br /&gt;
=== version ===&lt;br /&gt;
&lt;br /&gt;
When a node creates an outgoing connection, it will immediately [[Version Handshake|advertise]] its version. The remote node will respond with its version. No futher communication is possible until both peers have exchanged their version.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Identifies protocol version being used by the node&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || bitfield of features to be enabled for this connection&lt;br /&gt;
|-&lt;br /&gt;
| 8 || timestamp || int64_t || standard UNIX timestamp in seconds&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_recv || net_addr || The network address of the node receiving this message&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| version &amp;gt;= 106&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_from || net_addr || The network address of the node emitting this message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self.&lt;br /&gt;
|-&lt;br /&gt;
| ? || user_agent || [[#Variable length string|var_str]] || [[BIP_0014|User Agent]] (0x00 if string is 0 bytes long)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || start_height || int32_t || The last block received by the emitting node&lt;br /&gt;
|-&lt;br /&gt;
| 1 || relay || bool || Whether the remote peer should announce relayed transactions or not, see [[BIP 0037]], since version &amp;gt;= 70001&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;verack&amp;quot; packet shall be sent if the version packet was accepted.&lt;br /&gt;
&lt;br /&gt;
The following services are currently assigned:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NODE_NETWORK || This node can be asked for full blocks instead of just headers.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of version message (OBSOLETE EXAMPLE. This example lacks a checksum and user-agent):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 73  69 6F 6E 00 00 00 00 00   ....version.....&lt;br /&gt;
0010   55 00 00 00 9C 7C 00 00  01 00 00 00 00 00 00 00   U....|..........&lt;br /&gt;
0020   E6 15 10 4D 00 00 00 00  01 00 00 00 00 00 00 00   ...M............&lt;br /&gt;
0030   00 00 00 00 00 00 00 00  00 00 FF FF 0A 00 00 01   ................&lt;br /&gt;
0040   20 8D 01 00 00 00 00 00  00 00 00 00 00 00 00 00   ................&lt;br /&gt;
0050   00 00 00 00 FF FF 0A 00  00 02 20 8D DD 9D 20 2C   .......... ... ,&lt;br /&gt;
0060   3A B4 57 13 00 55 81 01  00                        :.W..U...&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 55 00 00 00                                                                   - Payload is 85 bytes long&lt;br /&gt;
                                                                               - No checksum in version message until 20 February 2012. See https://bitcointalk.org/index.php?topic=55852.0&lt;br /&gt;
Version message:&lt;br /&gt;
 9C 7C 00 00                                                                   - 31900 (version 0.3.19)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 E6 15 10 4D 00 00 00 00                                                       - Mon Dec 20 21:50:14 EST 2010&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 20 8D - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 02 20 8D - Sender address info - see Network Address&lt;br /&gt;
 DD 9D 20 2C 3A B4 57 13                                                       - Node random unique ID&lt;br /&gt;
 00                                                                            - &amp;quot;&amp;quot; sub-version string (string is 0 bytes long)&lt;br /&gt;
 55 81 01 00                                                                   - Last block sending node has is block #98645&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here&#039;s a modern (60002) protocol version client advertising itself to a local peer...&lt;br /&gt;
&lt;br /&gt;
Newer protocol includes the checksum now, this is from a mainline (satoshi) client during &lt;br /&gt;
an outgoing connection to another local client, notice that it does not fill out the &lt;br /&gt;
address information at all when the source or destination is &amp;quot;unroutable&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
0000   f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00  ....version.....&lt;br /&gt;
0010   64 00 00 00 35 8d 49 32 62 ea 00 00 01 00 00 00  d...5.I2b.......&lt;br /&gt;
0020   00 00 00 00 11 b2 d0 50 00 00 00 00 01 00 00 00  .......P........&lt;br /&gt;
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff  ................&lt;br /&gt;
0040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0050   00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00  ................&lt;br /&gt;
0060   3b 2e b3 5d 8c e6 17 65 0f 2f 53 61 74 6f 73 68  ;..]...e./Satosh&lt;br /&gt;
0070   69 3a 30 2e 37 2e 32 2f c0 3e 03 00              i:0.7.2/.&amp;gt;..&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 64 00 00 00                                                                   - Payload is 100 bytes long&lt;br /&gt;
 3B 64 8D 5A                                                                   - payload checksum&lt;br /&gt;
&lt;br /&gt;
Version message:&lt;br /&gt;
 62 EA 00 00                                                                   - 60002 (protocol version 60002)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 11 B2 D0 50 00 00 00 00                                                       - Tue Dec 18 10:12:33 PST 2012&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Sender address info - see Network Address&lt;br /&gt;
 3B 2E B3 5D 8C E6 17 65                                                       - Node ID&lt;br /&gt;
 0F 2F 53 61 74 6F 73 68 69 3A 30 2E 37 2E 32 2F                               - &amp;quot;/Satoshi:0.7.2/&amp;quot; sub-version string (string is 15 bytes long)&lt;br /&gt;
 C0 3E 03 00                                                                   - Last block sending node has is block #212672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== verack ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;verack&#039;&#039; message is sent in reply to &#039;&#039;version&#039;&#039;.  This message consists of only a [[#Message structure|message header]] with the command string &amp;quot;verack&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Hexdump of the verack message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 61  63 6B 00 00 00 00 00 00   ....verack......&lt;br /&gt;
0010   00 00 00 00 5D F6 E0 E2                            ........&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                          - Main network magic bytes&lt;br /&gt;
 76 65 72 61  63 6B 00 00 00 00 00 00 - &amp;quot;verack&amp;quot; command&lt;br /&gt;
 00 00 00 00                          - Payload is 0 bytes long&lt;br /&gt;
 5D F6 E0 E2                          - Checksum&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== addr ===&lt;br /&gt;
&lt;br /&gt;
Provide information on known nodes of the network. Non-advertised nodes should be forgotten after typically 3 hours&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of address entries (max: 1000)&lt;br /&gt;
|-&lt;br /&gt;
| 30x? || addr_list || (uint32_t + net_addr)[] || Address of other nodes on the network. version &amp;lt; 209 will only read the first one. The uint32_t is a timestamp (see note below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Starting version 31402, addresses are prefixed with a timestamp. If no timestamp is present, the addresses should not be relayed to other peers, unless it is indeed confirmed they are up.&lt;br /&gt;
&lt;br /&gt;
Hexdump example of &#039;&#039;addr&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 61 64 64 72  00 00 00 00 00 00 00 00   ....addr........&lt;br /&gt;
0010   1F 00 00 00 ED 52 39 9B  01 E2 15 10 4D 01 00 00   .....R9.....M...&lt;br /&gt;
0020   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 FF   ................&lt;br /&gt;
0030   FF 0A 00 00 01 20 8D                               ..... .&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                     - Main network magic bytes&lt;br /&gt;
 61 64 64 72  00 00 00 00 00 00 00 00            - &amp;quot;addr&amp;quot;&lt;br /&gt;
 1F 00 00 00                                     - payload is 31 bytes long&lt;br /&gt;
 ED 52 39 9B                                     - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
 01                                              - 1 address in this message&lt;br /&gt;
&lt;br /&gt;
Address:&lt;br /&gt;
 E2 15 10 4D                                     - Mon Dec 20 21:50:10 EST 2010 (only when version is &amp;gt;= 31402)&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK service - see version message)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv4: 10.0.0.1, IPv6: ::ffff:10.0.0.1 (IPv4-mapped IPv6 address)&lt;br /&gt;
 20 8D                                           - port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== inv ===&lt;br /&gt;
&lt;br /&gt;
Allows a node to advertise its knowledge of one or more objects. It can be received unsolicited, or in reply to &#039;&#039;getblocks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getdata ===&lt;br /&gt;
&lt;br /&gt;
getdata is used in response to inv, to retrieve the content of a specific object, and is usually sent after receiving an &#039;&#039;inv&#039;&#039; packet, after filtering known elements. It can be used to retrieve transactions, but only if they are in the memory pool or relay set - arbitrary access to transactions in the chain is not allowed to avoid having clients start to depend on nodes having full transaction indexes (which modern nodes do not).&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== notfound ===&lt;br /&gt;
&lt;br /&gt;
notfound is a response to a getdata, sent if any requested data items could not be relayed, for example, because the requested transaction was not in the memory pool or relay set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getblocks ===&lt;br /&gt;
&lt;br /&gt;
Return an &#039;&#039;inv&#039;&#039; packet containing the list of blocks starting right after the last known hash in the block locator object, up to hash_stop or 500 blocks, whichever comes first. &lt;br /&gt;
&lt;br /&gt;
The locator hashes are processed by a node in the order as they appear in the message. If a block hash if found in the node&#039;s main chain, the list of it&#039;s children is returned back via the &#039;&#039;inv&#039;&#039; message and the remaining locators are ignored, no matter if the requested limit was reached, or not.&lt;br /&gt;
&lt;br /&gt;
To receive the next blocks hashes, one needs to issue getblocks again with a new block locator object. Keep in mind that some clients (specifically the Satoshi client) will gladly provide blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block; set to zero to get as many blocks as possible (500)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To create the block locator hashes, keep pushing hashes until you go back to the genesis block. After pushing 10 hashes back, the step backwards doubles every loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// From libbitcoin which is under AGPL&lt;br /&gt;
std::vector&amp;lt;size_t&amp;gt; block_locator_indices(int top_depth)&lt;br /&gt;
{&lt;br /&gt;
    // Start at max_depth&lt;br /&gt;
    std::vector&amp;lt;size_t&amp;gt; indices;&lt;br /&gt;
    // Push last 10 indices first&lt;br /&gt;
    size_t step = 1, start = 0;&lt;br /&gt;
    for (int i = top_depth; i &amp;gt; 0; i -= step, ++start)&lt;br /&gt;
    {&lt;br /&gt;
        if (start &amp;gt;= 10)&lt;br /&gt;
            step *= 2;&lt;br /&gt;
        indices.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    indices.push_back(0);&lt;br /&gt;
    return indices;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that it is allowed to send in fewer known hashes down to a minimum of just one hash. However, the purpose of the block locator object is to detect a wrong branch in the caller&#039;s main chain. If the peer detects that you are off the main chain, it will send in block hashes which are earlier than your last known block. So if you just send in your last known hash and it is off the main chain, the peer starts over at block #1.&lt;br /&gt;
&lt;br /&gt;
=== getheaders ===&lt;br /&gt;
&lt;br /&gt;
Return a &#039;&#039;headers&#039;&#039; packet containing the headers of blocks starting right after the last known hash in the block locator object, up to hash_stop or 2000 blocks, whichever comes first. To receive the next block headers, one needs to issue getheaders again with a new block locator object. The &#039;&#039;getheaders&#039;&#039; command is used by thin clients to quickly download the blockchain where the contents of the transactions would be irrelevant (because they are not ours). Keep in mind that some clients (specifically the Satoshi client) will gladly provide headers of blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block header; set to zero to get as many blocks as possible (2000)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the block locator object in this packet, the same rules apply as for the [[Protocol_specification#getblocks|getblocks]] packet.&lt;br /&gt;
&lt;br /&gt;
=== tx ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;tx&#039;&#039; describes a bitcoin transaction, in reply to &#039;&#039;getdata&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Transaction data format version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_in count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction inputs&lt;br /&gt;
|-&lt;br /&gt;
| 41+ || tx_in || tx_in[] || A list of 1 or more transaction inputs or sources for coins&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_out count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction outputs&lt;br /&gt;
|-&lt;br /&gt;
| 9+ || tx_out || tx_out[] || A list of 1 or more transaction outputs or destinations for coins&lt;br /&gt;
|-&lt;br /&gt;
| 4 || lock_time || uint32_t || The block number or timestamp at which this transaction is locked:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Always locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 500000000  || Block number at which this transaction is locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 500000000 || UNIX timestamp at which this transaction is locked&lt;br /&gt;
|}&lt;br /&gt;
If all TxIn inputs have final (0xffffffff) sequence numbers then lock_time is irrelevant. Otherwise, the transaction may not be added to a block until after lock_time (see [[NLockTime]]).&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
TxIn consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 36 || previous_output || outpoint || The previous output transaction reference, as an OutPoint structure&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || script length || [[Protocol_specification#Variable_length_integer|var_int]] || The length of the signature script&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature script || uchar[] || Computational Script for confirming transaction authorization&lt;br /&gt;
|-&lt;br /&gt;
| 4 || [http://bitcoin.stackexchange.com/q/2025/323 sequence] || uint32_t || Transaction version as defined by the sender. Intended for &amp;quot;replacement&amp;quot; of transactions when information is updated before inclusion into a block.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OutPoint structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || The hash of the referenced transaction.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || index || uint32_t || The index of the specific output in the transaction. The first output is 0, etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Script structure consists of a series of pieces of information and operations related to the value of the transaction.&lt;br /&gt;
&lt;br /&gt;
(Structure to be expanded in the future… see script.h and script.cpp and [[Script]] for more information)&lt;br /&gt;
&lt;br /&gt;
The TxOut structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || value || int64_t || Transaction Value&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || pk_script length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the pk_script&lt;br /&gt;
|-&lt;br /&gt;
| ? || pk_script || uchar[] || Usually contains the public key as a Bitcoin script setting up conditions to claim this output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example &#039;&#039;tx&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
000000	F9 BE B4 D9 74 78 00 00  00 00 00 00 00 00 00 00   ....tx..........&lt;br /&gt;
000010	02 01 00 00 E2 93 CD BE  01 00 00 00 01 6D BD DB   .............m..&lt;br /&gt;
000020	08 5B 1D 8A F7 51 84 F0  BC 01 FA D5 8D 12 66 E9   .[...Q........f.&lt;br /&gt;
000030	B6 3B 50 88 19 90 E4 B4  0D 6A EE 36 29 00 00 00   .;P......j.6)...&lt;br /&gt;
000040	00 8B 48 30 45 02 21 00  F3 58 1E 19 72 AE 8A C7   ..H0E.!..X..r...&lt;br /&gt;
000050	C7 36 7A 7A 25 3B C1 13  52 23 AD B9 A4 68 BB 3A   .6zz%;..R#...h.:&lt;br /&gt;
000060	59 23 3F 45 BC 57 83 80  02 20 59 AF 01 CA 17 D0   Y#?E.W... Y.....&lt;br /&gt;
000070	0E 41 83 7A 1D 58 E9 7A  A3 1B AE 58 4E DE C2 8D   .A.z.X.z...XN...&lt;br /&gt;
000080	35 BD 96 92 36 90 91 3B  AE 9A 01 41 04 9C 02 BF   5...6..;...A....&lt;br /&gt;
000090	C9 7E F2 36 CE 6D 8F E5  D9 40 13 C7 21 E9 15 98   .~.6.m...@..!...&lt;br /&gt;
0000A0	2A CD 2B 12 B6 5D 9B 7D  59 E2 0A 84 20 05 F8 FC   *.+..].}Y... ...&lt;br /&gt;
0000B0	4E 02 53 2E 87 3D 37 B9  6F 09 D6 D4 51 1A DA 8F   N.S..=7.o...Q...&lt;br /&gt;
0000C0	14 04 2F 46 61 4A 4C 70  C0 F1 4B EF F5 FF FF FF   ../FaJLp..K.....&lt;br /&gt;
0000D0	FF 02 40 4B 4C 00 00 00  00 00 19 76 A9 14 1A A0   ..@KL......v....&lt;br /&gt;
0000E0	CD 1C BE A6 E7 45 8A 7A  BA D5 12 A9 D9 EA 1A FB   .....E.z........&lt;br /&gt;
0000F0	22 5E 88 AC 80 FA E9 C7  00 00 00 00 19 76 A9 14   &amp;quot;^...........v..&lt;br /&gt;
000100	0E AB 5B EA 43 6A 04 84  CF AB 12 48 5E FD A0 B7   ..[.Cj.....H^...&lt;br /&gt;
000110	8B 4E CC 52 88 AC 00 00  00 00                     .N.R......&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                       - main network magic bytes&lt;br /&gt;
 74 78 00 00 00 00 00 00 00 00 00 00               - &amp;quot;tx&amp;quot; command&lt;br /&gt;
 02 01 00 00                                       - payload is 258 bytes long&lt;br /&gt;
 E2 93 CD BE                                       - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Transaction:&lt;br /&gt;
 01 00 00 00                                       - version&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 01                                                - number of transaction inputs&lt;br /&gt;
&lt;br /&gt;
Input 1:&lt;br /&gt;
 6D BD DB 08 5B 1D 8A F7  51 84 F0 BC 01 FA D5 8D  - previous output (outpoint)&lt;br /&gt;
 12 66 E9 B6 3B 50 88 19  90 E4 B4 0D 6A EE 36 29&lt;br /&gt;
 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 8B                                                - script is 139 bytes long&lt;br /&gt;
&lt;br /&gt;
 48 30 45 02 21 00 F3 58  1E 19 72 AE 8A C7 C7 36  - signature script (scriptSig)&lt;br /&gt;
 7A 7A 25 3B C1 13 52 23  AD B9 A4 68 BB 3A 59 23&lt;br /&gt;
 3F 45 BC 57 83 80 02 20  59 AF 01 CA 17 D0 0E 41&lt;br /&gt;
 83 7A 1D 58 E9 7A A3 1B  AE 58 4E DE C2 8D 35 BD&lt;br /&gt;
 96 92 36 90 91 3B AE 9A  01 41 04 9C 02 BF C9 7E&lt;br /&gt;
 F2 36 CE 6D 8F E5 D9 40  13 C7 21 E9 15 98 2A CD&lt;br /&gt;
 2B 12 B6 5D 9B 7D 59 E2  0A 84 20 05 F8 FC 4E 02&lt;br /&gt;
 53 2E 87 3D 37 B9 6F 09  D6 D4 51 1A DA 8F 14 04&lt;br /&gt;
 2F 46 61 4A 4C 70 C0 F1  4B EF F5&lt;br /&gt;
&lt;br /&gt;
 FF FF FF FF                                       - sequence&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
 02                                                - 2 Output Transactions&lt;br /&gt;
&lt;br /&gt;
Output 1:&lt;br /&gt;
 40 4B 4C 00 00 00 00 00                           - 0.05 BTC (5000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 1A A0 CD 1C BE  A6 E7 45 8A 7A BA D5 12  - pk_script&lt;br /&gt;
 A9 D9 EA 1A FB 22 5E 88  AC&lt;br /&gt;
&lt;br /&gt;
Output 2:&lt;br /&gt;
 80 FA E9 C7 00 00 00 00                           - 33.54 BTC (3354000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 0E AB 5B EA 43  6A 04 84 CF AB 12 48 5E  - pk_script&lt;br /&gt;
 FD A0 B7 8B 4E CC 52 88  AC&lt;br /&gt;
&lt;br /&gt;
Locktime:&lt;br /&gt;
 00 00 00 00                                       - lock time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;block&#039;&#039;&#039; message is sent in response to a getdata message which requests transaction information from a block hash.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A unix timestamp recording when this block was created (Currently limited to dates before the year 2106!)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated [[Difficulty|difficulty target]] being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| ? || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries&lt;br /&gt;
|-&lt;br /&gt;
| ? || txns || tx[] || Block transactions, in format of &amp;quot;tx&amp;quot; command&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and &#039;&#039;not&#039;&#039; from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the &#039;&#039;nonce&#039;&#039; field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed. However, a Bitcoin hash is the hash of the hash, so two SHA256 rounds are needed for each mining iteration.&lt;br /&gt;
See [[Block hashing algorithm]] for details and an example.&lt;br /&gt;
&lt;br /&gt;
=== headers ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;headers&#039;&#039; packet returns block headers in response to a &#039;&#039;getheaders&#039;&#039; packet. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of block headers&lt;br /&gt;
|-&lt;br /&gt;
| 81x? || headers || [[Protocol_specification#Block_Headers|block_header]][] || [[Protocol_specification#Block_Headers|Block headers]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the block headers in this packet include a transaction count (a var_int, so there can be more than 81 bytes per header) as opposed to the block headers which are sent to miners.&lt;br /&gt;
&lt;br /&gt;
=== getaddr ===&lt;br /&gt;
&lt;br /&gt;
The getaddr message sends a request to a node asking for information about known active peers to help with identifying potential nodes in the network. The response to receiving this message is to transmit an addr message with one or more peers from a database of known active peers. The typical presumption is that a node is likely to be active if it has been sending a message within the last three hours.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
=== mempool ===&lt;br /&gt;
&lt;br /&gt;
The mempool message sends a request to a node asking for information about transactions it has verified but which have not yet confirmed. The response to receiving this message is an inv message containing the transaction hashes for all the transactions in the node&#039;s mempool.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
It is specified in [[BIP_0035|BIP 35]]. Since [[BIP_0037|BIP 37]], only transactions matching the filter are replied.&lt;br /&gt;
&lt;br /&gt;
=== checkorder ===&lt;br /&gt;
&lt;br /&gt;
This message is used for [[IP Transactions]], to ask the peer if it accepts such transactions and allow it to look at the content of the order.&lt;br /&gt;
&lt;br /&gt;
It contains a CWalletTx object&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CMerkleTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || hashBlock&lt;br /&gt;
|-&lt;br /&gt;
| ? || vMerkleBranch&lt;br /&gt;
|-&lt;br /&gt;
| ? || nIndex&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CWalletTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || vtxPrev&lt;br /&gt;
|-&lt;br /&gt;
| ? || mapValue&lt;br /&gt;
|-&lt;br /&gt;
| ? || vOrderForm&lt;br /&gt;
|-&lt;br /&gt;
| ? || fTimeReceivedIsTxTime&lt;br /&gt;
|-&lt;br /&gt;
| ? || nTimeReceived&lt;br /&gt;
|-&lt;br /&gt;
| ? || fFromMe&lt;br /&gt;
|-&lt;br /&gt;
| ? || fSpent&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== submitorder ===&lt;br /&gt;
&lt;br /&gt;
Confirms an order has been submitted. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the transaction&lt;br /&gt;
|-&lt;br /&gt;
| ? || wallet_entry || CWalletTx || Same payload as checkorder&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== reply ===&lt;br /&gt;
&lt;br /&gt;
Generic reply for [[IP Transactions]]&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || reply || uint32_t || reply code&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Possible values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || SUCCESS || The IP Transaction can proceed (&#039;&#039;checkorder&#039;&#039;), or has been accepted (&#039;&#039;submitorder&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || WALLET_ERROR || AcceptWalletTransaction() failed&lt;br /&gt;
|-&lt;br /&gt;
| 2 || DENIED || IP Transactions are not accepted by this node&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== ping ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;ping&#039;&#039; message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || random nonce&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== pong ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;pong&#039;&#039; message is sent in response to a &#039;&#039;ping&#039;&#039; message. In modern protocol versions, a &#039;&#039;pong&#039;&#039; response is generated using a nonce included in the ping.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || nonce from ping&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== filterload, filteradd, filterclear, merkleblock ===&lt;br /&gt;
&lt;br /&gt;
These messages are related to Bloom filtering of connections and are defined in [[BIP 0037]].&lt;br /&gt;
&lt;br /&gt;
=== alert ===&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;alert&#039;&#039;&#039; is sent between nodes to send a general notification message throughout the network. If the alert can be confirmed with the signature as having come from the the core development group of the Bitcoin software, the message is suggested to be displayed for end-users. Attempts to perform transactions, particularly automated transactions through the client, are suggested to be halted. The text in the Message string should be relayed to log files and any user interfaces.&lt;br /&gt;
&lt;br /&gt;
Alert format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || var_str || Serialized alert payload&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature || var_str || An ECDSA signature of the message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The developers of Satoshi&#039;s client use this public key for signing alerts:&lt;br /&gt;
 04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284&lt;br /&gt;
 (hash) 1AGRxqDa5WjUKBwHB9XYEjmkv1ucoUUy1s&lt;br /&gt;
&lt;br /&gt;
The payload is serialized into a var_str to ensure that versions using incompatible alert formats can still relay alerts among one another. The current alert payload format is:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Version || int32_t || Alert format version&lt;br /&gt;
|-&lt;br /&gt;
| 8 || RelayUntil || int64_t || The timestamp beyond which nodes should stop relaying this alert&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Expiration || int64_t || The timestamp beyond which this alert is no longer in effect and should be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 4 || ID || int32_t || A unique ID number for this alert&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Cancel || int32_t || All alerts with an ID number less than or equal to this number should be canceled: deleted and not accepted in the future&lt;br /&gt;
|-&lt;br /&gt;
| ? || setCancel || set&amp;lt;int&amp;gt; || All alert IDs contained in this set should be canceled as above&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MinVer || int32_t || This alert only applies to versions greater than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MaxVer || int32_t || This alert only applies to versions less than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| ? || setSubVer || set&amp;lt;string&amp;gt; || If this set contains any elements, then only nodes that have their subVer contained in this set are affected by the alert. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Priority || int32_t || Relative priority compared to other alerts&lt;br /&gt;
|-&lt;br /&gt;
| ? || Comment || string || A comment on the alert that is not displayed&lt;br /&gt;
|-&lt;br /&gt;
| ? || StatusBar || string || The alert message that is displayed to the user&lt;br /&gt;
|-&lt;br /&gt;
| ? || Reserved || string || Reserved&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Sample alert (no message header):&lt;br /&gt;
 73010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee0000&lt;br /&gt;
 0064000000004653656520626974636f696e2e6f72672f666562323020696620796f75206861&lt;br /&gt;
 76652074726f75626c6520636f6e6e656374696e672061667465722032302046656272756172&lt;br /&gt;
 79004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b&lt;br /&gt;
 53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1&lt;br /&gt;
 &lt;br /&gt;
 Version: 1&lt;br /&gt;
 RelayUntil: 1329620535&lt;br /&gt;
 Expiration: 1329792435&lt;br /&gt;
 ID: 1010&lt;br /&gt;
 Cancel: 1009&lt;br /&gt;
 setCancel: &amp;lt;empty&amp;gt;&lt;br /&gt;
 MinVer: 10000&lt;br /&gt;
 MaxVer: 61000&lt;br /&gt;
 setSubVer: &amp;lt;empty&amp;gt;&lt;br /&gt;
 Priority: 100&lt;br /&gt;
 Comment: &amp;lt;empty&amp;gt;&lt;br /&gt;
 StatusBar: &amp;quot;See bitcoin.org/feb20 if you have trouble connecting after 20 February&amp;quot;&lt;br /&gt;
 Reserved: &amp;lt;empty&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripting ==&lt;br /&gt;
&lt;br /&gt;
See [[script]].&lt;br /&gt;
&lt;br /&gt;
== Wireshark dissector ==&lt;br /&gt;
A dissector for wireshark is being developed at https://github.com/blueCommand/bitcoin-dissector&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Network]]&lt;br /&gt;
* [[Protocol rules]]&lt;br /&gt;
* [[Hardfork Wishlist]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[zh-cn:协议说明]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Mini_private_key_format&amp;diff=42874</id>
		<title>Mini private key format</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Mini_private_key_format&amp;diff=42874"/>
		<updated>2013-12-04T18:41:13Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Example with SHA256 */ Add  command-line verification command, and formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:QR-privkeys-sidebyside.png|thumb|right|QR codes of the same private key, in mini versus regular private key format.  Both codes have the same dot density and error correction level, but the mini key is 57% of the full code&#039;s size.]]&lt;br /&gt;
The &#039;&#039;&#039;mini private key format&#039;&#039;&#039; is a method of encoding a Bitcoin private key in as few as 30 characters so that it can be embedded in a small space.  This private key format was first used in Casascius physical bitcoins, and is also favorable for use in QR codes.  The fewer characters encoded in a QR code, the lower dot density can be used, as well as more dots allocated to error correction in the same space, significantly improving readability and resistance to damage.  The mini private key format offers its own built-in check code as a small margin of protection against typos.&lt;br /&gt;
&lt;br /&gt;
An example key using this encoding is &#039;&#039;&#039;S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Usage on a physical bitcoin==&lt;br /&gt;
The way it might appear within a physical bitcoin is on a round card printed as follows:&lt;br /&gt;
&lt;br /&gt;
Side of discs showing mini private key: (from [[Casascius physical bitcoins]])&amp;lt;br/&amp;gt;&lt;br /&gt;
[[Image:Miniprivkeys.jpg|300px]]&lt;br /&gt;
&lt;br /&gt;
Side of discs showing prefix of bitcoin address (printed on the opposite side):&amp;lt;br/&amp;gt;&lt;br /&gt;
[[Image:Minipubkeys.jpg|300px]]&lt;br /&gt;
&lt;br /&gt;
The examples in this article use the private key and Bitcoin address of the leftmost circle in the above two photos.&lt;br /&gt;
&lt;br /&gt;
==Usage in bar codes==&lt;br /&gt;
The mini private key is suitable for use in QR codes.  The recommended settings for maximizing readability are: QR version 3, error correction level Q (near highest, 25% possible lost codeword recovery).  This results in a 29x29 grid.  A minikey QR code can also fit in a 25x25 grid with QR version 2, error correction level L (lowest, 7% possible lost codeword recovery).&lt;br /&gt;
&lt;br /&gt;
The sample private minikey encoded as a QR code on a 29x29 grid looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Private_minikey_in_2D_barcode.gif]]&lt;br /&gt;
&lt;br /&gt;
The mini private key is small enough to fit in a one-dimensional barcode while still remaining practical.  Among the most popular one-dimensional barcode symbologies, the one known as &amp;quot;Code 128&amp;quot; is best suited for encoding a minikey due to its favorable data density and support for mixed case strings.  The variant known as &amp;quot;Code 128-B&amp;quot; produces the shortest code for strings containing lowercase characters.&lt;br /&gt;
&lt;br /&gt;
The sample private minikey encoded with Code 128-B looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Private_minikey_in_1D_barcode.gif]]&lt;br /&gt;
&lt;br /&gt;
==Import==&lt;br /&gt;
Mini private keys can be imported through the following clients/services:&lt;br /&gt;
&lt;br /&gt;
===Applications===&lt;br /&gt;
* [[Armory]]&lt;br /&gt;
&lt;br /&gt;
The current mainline (&amp;quot;Satoshi&amp;quot;) client cannot currently be used to import minikeys.&lt;br /&gt;
&lt;br /&gt;
===Mobile===&lt;br /&gt;
&lt;br /&gt;
* Mt. Gox Mobile can redeem a private key scanned from a QR Code or is entered using the keyboard.  Upon importing, Mt. Gox sweeps the funds to a secondary address, and then a user must wait for six confirmations before the funds will appear in the Mt. Gox account.&lt;br /&gt;
&lt;br /&gt;
===Web===&lt;br /&gt;
&lt;br /&gt;
* [[BlockChain.info]]&lt;br /&gt;
** Private keys can be imported into a Blockchain.info wallet and bitcoins can be sent to another address immediately upon import without needing to wait for any confirmations.  Even after import, funds remain associated with the private key until they are actually spent to a different address.&lt;br /&gt;
* [[StrongCoin]]&lt;br /&gt;
* [[Mt. Gox]]&lt;br /&gt;
** Importing minikeys is done through the deposit screen using the &amp;quot;Import Private Key&amp;quot; deposit method.  Upon importing, Mt. Gox sweeps the funds to a secondary address, and then a user must wait for six confirmations before the funds will appear in the Mt. Gox account.  Removing the imported bitcoins from the Mt. Gox account is treated as a bitcoin withdrawal and counts against daily/monthly limits.&lt;br /&gt;
** Mt. Gox also permanently remembers any imported private key and automatically sweeps any future funds sent to it into the user&#039;s Mt. Gox account.&lt;br /&gt;
** Mt. Gox&#039;s import screen doesn&#039;t properly detect or reject typos. If you make a mistake, Mt. Gox will treat it as a valid entry and report that a private key with a balance of 0.00 BTC from a bitcoin address you won&#039;t recognize was &amp;quot;successfully&amp;quot; imported.&lt;br /&gt;
&lt;br /&gt;
==Decoding==&lt;br /&gt;
The private key encoding consists of 30 alphanumeric characters from the [[base58]] alphabet used in Bitcoin.  The first of the characters is always the uppercase letter S.&lt;br /&gt;
&lt;br /&gt;
To determine whether the minikey is valid:&lt;br /&gt;
&lt;br /&gt;
# Add a question mark to the end of the mini private key string.&lt;br /&gt;
# Take the SHA256 hash of the entire string.  However, we will only look at the first byte of the result.&lt;br /&gt;
# If the first byte is 00, the string is a well-formed minikey.  If the first byte is not 00, the string should be rejected as a minikey.&lt;br /&gt;
&lt;br /&gt;
===Example with SHA256===&lt;br /&gt;
Here is an example with the sample private key &amp;lt;tt&amp;gt;S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The string &amp;quot;&amp;lt;tt&amp;gt;S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy?&amp;lt;/tt&amp;gt;&amp;quot; has a SHA256 value that begins with 00, so it is well-formed.&lt;br /&gt;
&lt;br /&gt;
To obtain the full 256-bit private key, simply take the SHA256 hash of the entire string.  There is no encoding for line breaks in the string, even if the key is broken into multiple lines for printing.  The SHA256 should be taken of exactly thirty bytes.&lt;br /&gt;
&lt;br /&gt;
 SHA256(&amp;quot;S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy&amp;quot;) = 4C7A9640C72DC2099F23715D0C8A0D8A35F8906E3CAB61DD3F78B67BF887C9AB  &lt;br /&gt;
&lt;br /&gt;
This sample key in [[wallet export format]] is &amp;lt;tt&amp;gt;5JPy8Zg7z4P7RSLsiqcqyeAF1935zjNUdMxcDeVrtU1oarrgnB7&amp;lt;/tt&amp;gt;, and the corresponding [[Bitcoin address]] is &amp;lt;tt&amp;gt;1CciesT23BNionJeXrbxmjc7ywfiyM4oLW&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Command line verification ====&lt;br /&gt;
To calculate SHA256 from the command line on OSX or Linux devices:&lt;br /&gt;
&lt;br /&gt;
 echo -n &amp;quot;S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy?&amp;quot; | shasum -a 256&lt;br /&gt;
&lt;br /&gt;
That should output a line of text like &amp;quot;&amp;lt;tt&amp;gt;000f2453798ad4f951eecced2242eaef3e1cbc8a7c813c203ac7ffe57060355d  -&amp;lt;/tt&amp;gt;&amp;quot;. Since the first two characters are &amp;lt;tt&amp;gt;00&amp;lt;/tt&amp;gt; the verification passes for the mini key &amp;lt;tt&amp;gt;S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Check code==&lt;br /&gt;
The mini private key format offers a simple typo check code.  Mini private keys must be generated in a &amp;quot;brute force&amp;quot; fashion, keeping only keys that conform to the format&#039;s rules.  If a key is well-formed (30 Base58 characters starting with S), but fails the hash check, then it probably contains a typo.&lt;br /&gt;
&lt;br /&gt;
If the SHA256 hash of the string followed by &#039;?&#039; doesn&#039;t result in something that begins with 0x00, the string is not a valid mini private key.&lt;br /&gt;
&lt;br /&gt;
==Creating mini private keys==&lt;br /&gt;
Creating mini private keys is relatively simple.  One program which can create such keys is [[Casascius Bitcoin Utility]].&lt;br /&gt;
&lt;br /&gt;
Mini private keys must be created &amp;quot;from scratch&amp;quot;, as the conversion from mini private key to full-size private key is one-way.  In other words, there is no way to convert an existing full-size private key into a mini private key.&lt;br /&gt;
&lt;br /&gt;
To create mini private keys, simply create random strings that satisfy the well-formedness requirement, and then eliminate the ones that do not pass the typo check.  (This means eliminating more than 99% of the candidates.)  Then use the appropriate algorithm to compute the corresponding private key, and in turn, the matching Bitcoin address.  The Bitcoin address can always be computed from just the private key.&lt;br /&gt;
&lt;br /&gt;
It is strongly advisable to avoid using the digit &amp;quot;1&amp;quot; in minikeys unless it is being printed in such a way where a user is unlikely to mistake it for the lowercase letter &amp;quot;l&amp;quot;.  Few clients and redemption tools are prepared to tell the user that their entry containing the letter &amp;quot;l&amp;quot; should actually be the number &amp;quot;1&amp;quot; - rather, they will simply reject the code and may leave the user confused.&lt;br /&gt;
&lt;br /&gt;
In all cases, you &#039;&#039;&#039;must&#039;&#039;&#039; use a secure cryptographic random number generator to eliminate risks of predictability of the random strings.&lt;br /&gt;
&lt;br /&gt;
==Casascius Series 1 coins==&lt;br /&gt;
&lt;br /&gt;
Casascius Series 1 Physical Bitcoins use a 22-character variant of the minikey format, instead of 30 characters.  Everything is the same other than the length.  To properly implement minikey redemption, services and clients MUST support the 30-character format, but MAY support the 22-character format as well.  Use of the 22-character format for future applications is discouraged due to security considerations.&lt;br /&gt;
&lt;br /&gt;
==Python Code==&lt;br /&gt;
The following code produces sample 30-character SHA256-based mini private keys in Python.  For real-world use, &#039;&#039;random&#039;&#039; must be replaced with a better source of entropy, as the Python documentation for &#039;&#039;random&#039;&#039; states the function &#039;&#039;&amp;quot;is completely unsuitable for cryptographic purposes&amp;quot;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import random&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
BASE58 = &#039;23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz&#039;&lt;br /&gt;
&lt;br /&gt;
def Candidate():&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Generate a random, well-formed mini private key.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    return(&#039;%s%s&#039; % (&#039;S&#039;, &#039;&#039;.join(&lt;br /&gt;
        [BASE58[ random.randrange(0,len(BASE58)) ] for i in range(29)])))&lt;br /&gt;
&lt;br /&gt;
def GenerateKeys(numKeys = 10):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Generate mini private keys and output the mini key as well as the full&lt;br /&gt;
    private key. numKeys is The number of keys to generate, and &lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    keysGenerated = 0&lt;br /&gt;
    totalCandidates = 0&lt;br /&gt;
    while keysGenerated &amp;lt; numKeys:&lt;br /&gt;
        try:&lt;br /&gt;
            cand = Candidate()&lt;br /&gt;
            # Do typo check&lt;br /&gt;
            t = &#039;%s?&#039; % cand&lt;br /&gt;
            # Take one round of SHA256&lt;br /&gt;
            candHash = hashlib.sha256(t).digest()&lt;br /&gt;
            # Check if the first eight bits of the hash are 0&lt;br /&gt;
            if candHash[0] == &#039;\x00&#039;:&lt;br /&gt;
                privateKey = GetPrivateKey(cand)&lt;br /&gt;
                print(&#039;\n%s\nSHA256( ): %s\nsha256(?): %s&#039; %&lt;br /&gt;
                      (cand, privateKey, candHash.encode(&#039;hex_codec&#039;)))&lt;br /&gt;
                if CheckShortKey(cand):&lt;br /&gt;
                    print(&#039;Validated.&#039;)&lt;br /&gt;
                else:&lt;br /&gt;
                    print(&#039;Invalid!&#039;)&lt;br /&gt;
                keysGenerated += 1&lt;br /&gt;
            totalCandidates += 1&lt;br /&gt;
        except KeyboardInterrupt:&lt;br /&gt;
            break&lt;br /&gt;
    print(&#039;\n%s: %i\n%s: %i\n%s: %.1f&#039; %&lt;br /&gt;
          (&#039;Keys Generated&#039;, keysGenerated,&lt;br /&gt;
           &#039;Total Candidates&#039;, totalCandidates,&lt;br /&gt;
           &#039;Reject Percentage&#039;,&lt;br /&gt;
           100*(1.0-keysGenerated/float(totalCandidates))))&lt;br /&gt;
&lt;br /&gt;
def GetPrivateKey(shortKey):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Returns the hexadecimal representation of the private key corresponding&lt;br /&gt;
    to the given short key.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if CheckShortKey(shortKey):&lt;br /&gt;
        return hashlib.sha256(shortKey).hexdigest()&lt;br /&gt;
    else:&lt;br /&gt;
        print(&#039;Typo detected in private key!&#039;)&lt;br /&gt;
        return None&lt;br /&gt;
&lt;br /&gt;
def CheckShortKey(shortKey):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Checks for typos in the short key.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if len(shortKey) != 30:&lt;br /&gt;
        return False&lt;br /&gt;
    t = &#039;%s?&#039; % shortKey&lt;br /&gt;
    tHash = hashlib.sha256(t).digest()&lt;br /&gt;
    # Check to see that first byte is \x00&lt;br /&gt;
    if tHash[0] == &#039;\x00&#039;:&lt;br /&gt;
        return True&lt;br /&gt;
    return False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Electrum/Documentation&amp;diff=42712</id>
		<title>Electrum/Documentation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Electrum/Documentation&amp;diff=42712"/>
		<updated>2013-11-28T01:53:25Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* What is the &amp;quot;Seed&amp;quot; of a Deterministic Wallet in Electrum? */ Comparison number of atoms was off by an order of magnitude&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Documentation of Electrum Bitcoin Client (Focus on the GUI)==&lt;br /&gt;
This page tries to document certain aspects of the [[Electrum|Electrum]] Bitcoin Client. The focus is on explaining certain aspects of its GUI, such that it gets easier for the user to understand its use.&lt;br /&gt;
&lt;br /&gt;
More documentation, especially with regard to command line parameters, can be found at the parent page of this Wiki, i.e. [[Electrum|here]].&lt;br /&gt;
&lt;br /&gt;
===Version Info===&lt;br /&gt;
Unless stated otherwise in particular sub-sections, the present state of this documentation is based on&lt;br /&gt;
* &#039;&#039;&#039;Electrum version 0.58&#039;&#039;&#039;&lt;br /&gt;
As this documentation gets updated, this &amp;quot;version info&amp;quot; can be updated, too!&lt;br /&gt;
&lt;br /&gt;
Later versions of Electrum may add new features or deviate from this description to some extend.&lt;br /&gt;
&lt;br /&gt;
===Open/Unclear Points===&lt;br /&gt;
&lt;br /&gt;
Discussions about unclear points should take place on the [[Talk:Electrum/Documentation|Discussion page.]]&lt;br /&gt;
&lt;br /&gt;
==What is a &amp;quot;Wallet&amp;quot; and a &amp;quot;Bitcoin Address&amp;quot;?==&lt;br /&gt;
* (General, not specific to Electrum)&lt;br /&gt;
&lt;br /&gt;
Your wallet is a list of Bitcoin addresses (more precisely: a list of privat/public key pairs). Each address &amp;quot;contains&amp;quot; (or is associated with) a certain amount of Bitcoins at a given time.&lt;br /&gt;
&lt;br /&gt;
Your wallet&#039;s balance is the sum of all Bitcoins of all your wallet&#039;s Bitcoin addresses.&lt;br /&gt;
&lt;br /&gt;
Your wallet consists of both [[#Normal Addresses|normal addresses]] and [[#Change Addresses|change addresses]]. Although they are fully equivalent from the Bitcoin protocol&#039;s point of view, they are different in how they are used by Bitcoin clients like Electrum.&lt;br /&gt;
&lt;br /&gt;
===Normal Addresses===&lt;br /&gt;
* (More or less general, not too specific to Electrum)&lt;br /&gt;
====How are New &amp;quot;Normal Addresses&amp;quot; Created for my Wallet?====&lt;br /&gt;
A Bitcoin client allows you to trigger the generation of a new Bitcoin address either manually, or it generates new addresses automatically upon certain conditions. The latter applies to Electrum: Depending on the &amp;quot;[[#What is the &amp;quot;Gap Limit&amp;quot;?|gap limit]]&amp;quot; setting in Electrum&#039;s program preferences, there will always be a certain number of unused addresses showing up in your list of receive addresses (=your own wallet&#039;s addresses), and as these addresses get used, new ones will show up automatically.&lt;br /&gt;
&lt;br /&gt;
Typically you want to use a new address for receiving Bitcoins from somebody, instead of using any of your wallet&#039;s present addresses that have already been used for earlier transactions. This is to protect your privacy, because all Bitcoins transfers are published in the blockchain and can be read by anyone.&lt;br /&gt;
&lt;br /&gt;
Another way of adding addresses to your wallet is to [[#Imported Addresses|import]] private keys (with their addresses of course), using Electrum&#039;s [[Electrum|command line options]]. See section about [[#Imported Addresses|imported addresses]] for more details.&lt;br /&gt;
&lt;br /&gt;
===Change Addresses===&lt;br /&gt;
* (More or less general, not too specific to Electrum)&lt;br /&gt;
====What is a &amp;quot;Change Address&amp;quot;, and why is it useful?====&lt;br /&gt;
The concept of change addresses is a feature not of the Bitcoin protocol, but of a Bitcoin client. It is implemented not only in Electrum but in most Bitcoin clients, including the original &amp;quot;Satoshi&amp;quot; Bitcoin client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How it works:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Whenever your Bitcoin client (e.g. Electrum) sends Bitcoins from your wallet&#039;s address &amp;quot;A&amp;quot; to a foreing address &amp;quot;B&amp;quot;, a new change address &amp;quot;C&amp;quot; is created by Electrum and added to your wallet.&lt;br /&gt;
&lt;br /&gt;
Example: Address &amp;quot;A&amp;quot; has 20 BTC. Electrum sends 9 BTC from &amp;quot;A&amp;quot; to &amp;quot;B&amp;quot;. The change (20-9 = 11 BTC) is sent to the &amp;quot;change address&amp;quot; &amp;quot;C&amp;quot;. For this purpose, address &amp;quot;C&amp;quot; is created by Electrum at this moment and added to your wallet.&lt;br /&gt;
&lt;br /&gt;
Exception: If all the Bitcoins of &amp;quot;A&amp;quot; are sent to &amp;quot;B&amp;quot;, there is no need for creating a change address &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Actually, Bitcoin clients can also work without change addresses. In this case, the change would be sent back to &amp;quot;A&amp;quot; instead of the new address &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why the concept of &amp;quot;change addresses&amp;quot; is useful:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using a new change address makes it more difficult for other people (by analyzing the blockchain) to track how many Bitcoins you have or where you&#039;re spending them.&lt;br /&gt;
* It also conceals which output is the &amp;quot;spend&amp;quot; and which is the &amp;quot;change&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Imported Addresses===&lt;br /&gt;
Instead of generating new addresses in the default way from the wallet&#039;s [[#Seed|seed]], Electrum also allows you to import addresses (and their private keys of course) from external sources, e.g. from another Bitcoin client&#039;s wallet. For this, use Electrum&#039;s [[Electrum|command line]] options. Note that imported addresses cannot be recovered from your wallet&#039;s [[#Seed|seed]] and therefore need to be secured separately for a complete backup of your wallet.&lt;br /&gt;
&lt;br /&gt;
Imported addresses can be used like any other [[#Normal Addresses|normal]] receive address with Electrum for transmission or reception of Bitcoins, and can also be (un)tagged as [[#What does it mean to &amp;quot;Prioritize&amp;quot; or &amp;quot;Freeze&amp;quot; Addresses in Electrum?|&amp;quot;prioritized&amp;quot; or &amp;quot;frozen&amp;quot;]].&lt;br /&gt;
&lt;br /&gt;
===Deterministic Wallet===&lt;br /&gt;
====What is a &amp;quot;Deterministic Wallet&amp;quot; in Electrum?====&lt;br /&gt;
Traditionally, all new addresses (incl. the private keys of course) added to the wallet ([[#Normal Addresses|normal addresses]] or [[#Change Addresses|change addresses]]) are generated randomly. This is the case e.g. for the original &amp;quot;Satoshi Bitcoin Client&amp;quot; (at least as of today, version 0.6.2).&lt;br /&gt;
&lt;br /&gt;
Contrary to that, a Bitcoin client with a &amp;quot;Deterministic Wallet&amp;quot; will generate all new addresses accoding to a pre-defined (i.e. &amp;quot;deterministic&amp;quot;) algorithm as a function of a wallet-specific [[#Seed|seed]], which is a 128 bit number. This means, if the seed is known, all new addresses that Electrum will ever create for this wallet are known, because Electrum&#039;s algorithm is known (and open source).&lt;br /&gt;
This is a big advantage when it comes to making wallet backups:&lt;br /&gt;
* &#039;&#039;Traditionally&#039;&#039;, a wallet backup just contains the bitcoin addresses (and private keys of course) that have been created by the client by the time the backup was made. If the user performs transactions after the backup, new addresses ([[#Normal Addresses|normal]] or [[#Change Addresses|change]] addresses) will be generated and added to the wallet. These are not included in the backup yet. If the wallet in use gets lost, all the Bitcoins that are associated with the new addresses will also be lost. To avoid the risk of a too high loss, regular wallet backups are important.&lt;br /&gt;
* &#039;&#039;With a Deterministic Wallet&#039;&#039; (like with Electrum), the wallet backup only needs to contain the seed, and all new addresses generated in the future are already secured by the initial backup. Hence, regular new backups are not required!&lt;br /&gt;
&lt;br /&gt;
===Seed===&lt;br /&gt;
====What is the &amp;quot;Seed&amp;quot; of a Deterministic Wallet in Electrum?====&lt;br /&gt;
The Seed of a [[#Deterministic Wallet|deterministic wallet]] is a series of 128 random bits in Electrum.&lt;br /&gt;
For convenience, a seed can also be expressed by a sequence of 12 words in Electrum, and it also supports generation of a QR code to facilitate the backup of the seed.&lt;br /&gt;
&lt;br /&gt;
So there are 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; possible seeds for a deterministic wallet in Electrum.&lt;br /&gt;
For comparison, the total number of Bitcoin addresses is 2&amp;lt;sup&amp;gt;160&amp;lt;/sup&amp;gt;, and the number of atoms in the universe is 2&amp;lt;sup&amp;gt;166&amp;lt;/sup&amp;gt; ([http://en.wikipedia.org/wiki/Observable_universe#Matter_content_-_number_of_atoms ~10&amp;lt;sup&amp;gt;80&amp;lt;/sup&amp;gt;]).&lt;br /&gt;
So there exists one Bitcoin address per 64 atoms in the universe, and there exists one seed of Electrum wallets per 4.3 Billion Bitcoin addresses.&lt;br /&gt;
&lt;br /&gt;
===What is the &amp;quot;Gap Limit&amp;quot;?===&lt;br /&gt;
&lt;br /&gt;
The gap limit is the maximal number of contiguous unused addresses in your deterministic sequence of addresses.&lt;br /&gt;
&lt;br /&gt;
If you recover your wallet from seed, you will notice that the gap limit is asked by the recovery dialog.&lt;br /&gt;
It is used in order to decide when to stop the recovery procedure.&lt;br /&gt;
&lt;br /&gt;
If you need to have more receiving addresses in your wallet, you may increase your gap limit (expert mode).&lt;br /&gt;
This, however, means that you will need to remember the new limit in order to be able to recover your wallet from seed.&lt;br /&gt;
&lt;br /&gt;
==More on the Electrum GUI==&lt;br /&gt;
&lt;br /&gt;
===Send tab and completions===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;pay to&amp;quot; input line does not only accept bitcoin addresses. You may type a label from your list of contacts, or an alias.&lt;br /&gt;
&lt;br /&gt;
Completions are available based on the labels of your addressbook. Example: &lt;br /&gt;
&lt;br /&gt;
[[Image:Electrum completion 0.png|450px]]&lt;br /&gt;
[[Image:Electrum completion 1.png|450px]]&lt;br /&gt;
&lt;br /&gt;
===What does it mean to &amp;quot;Prioritize&amp;quot; or &amp;quot;Freeze&amp;quot; Addresses in Electrum?===&lt;br /&gt;
When sending Bitcoins to a foreign address, Electrum will by default use a built-in method to select the address(es) of the wallet used for sending these Bitcoins.&lt;br /&gt;
&lt;br /&gt;
* When you &#039;&#039;prioritize&#039;&#039; some of your wallet&#039;s addresses, these addresses will be used with preference. Other addresses will not be used until the prioritized addresses contain no more Bitcoins.&lt;br /&gt;
* When you &#039;&#039;freeze&#039;&#039; some of your wallet&#039;s addresses, these addresses will not be used for sending bitcoins. Instead, other addresses will be used. Sending Bitcoins is not possible if the non-frozen addresses of your wallet do not contain enough funds. &lt;br /&gt;
&lt;br /&gt;
The user can (de)prioritize or (un)freeze both [[#Normal Addresses|normal]] and [[#Change Addresses|change]] addresses.&lt;br /&gt;
&lt;br /&gt;
Note: Clearly, an address can not be &amp;quot;prioritized&amp;quot; and &amp;quot;frozen&amp;quot; at the same time.&lt;br /&gt;
&lt;br /&gt;
===What does the &amp;quot;Tx&amp;quot; column mean in Electrum?===&lt;br /&gt;
* Expert Mode only&lt;br /&gt;
* Applies to &amp;quot;Receive&amp;quot; tab (own wallet&#039;s addresses) and &amp;quot;Contacts&amp;quot; tab (foreing addresses).&lt;br /&gt;
&lt;br /&gt;
Tx stands for &amp;quot;Transaction&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Tx column in Electrum displays a number for each Bitcoin address in the address list, both for own addresses (&amp;quot;Receive&amp;quot; tab) and for foreing addresses (&amp;quot;Contacts&amp;quot; tab).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;In the &amp;quot;Receive&amp;quot; tab (own addresses):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The number in the Tx column indicates the total number of _incoming_ Bitcoin transactions that have ever been sent to this address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;In the &amp;quot;Contacts&amp;quot; tab (foreign addresses):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The number in the Tx column indicates the total number of Bitcoin transactions that have ever been carried out from addresses of the current wallet towards this contact address&lt;br /&gt;
&lt;br /&gt;
===What does the &amp;quot;Balance&amp;quot; column mean in Electrum?===&lt;br /&gt;
* Expert Mode only&lt;br /&gt;
* Applies to &amp;quot;Receive&amp;quot; tab  only (i.e. own wallet&#039;s addresses).&lt;br /&gt;
&lt;br /&gt;
The balance column indicates the amount of Bitcoins belonging to the given address.&lt;br /&gt;
The individual balances add up to the total balance of your wallet.&lt;br /&gt;
&lt;br /&gt;
===What does the &amp;quot;Flag&amp;quot; column mean in Electrum?===&lt;br /&gt;
* Expert Mode only&lt;br /&gt;
* Applies to &amp;quot;Receive&amp;quot; tab  only (i.e. own wallet&#039;s addresses).&lt;br /&gt;
&lt;br /&gt;
This column indicates certain properties of the different addresses:&lt;br /&gt;
* C = [[#Change Addresses|Change address]] (without a &amp;quot;C&amp;quot; it means it is a [[#Normal Addresses|normal address]])&lt;br /&gt;
* P = Prioritized address&lt;br /&gt;
* F = Frozen address&lt;br /&gt;
* I = [[#Imported Addresses|Imported address]]&lt;br /&gt;
&lt;br /&gt;
Note: P and F flags can be applied to both [[#Normal Addresses|normal]] and [[#Change Addresses|change]] addresses, and also to [[#Imported Addresses|imported addresses]].&lt;br /&gt;
&lt;br /&gt;
===What do colors mean?===&lt;br /&gt;
In the Receive tab:&lt;br /&gt;
*green = prioritized&lt;br /&gt;
*blue = frozen&lt;br /&gt;
In the Contacts tab:&lt;br /&gt;
*gray = alias&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
=== &#039;transaction rejected by memorypool&#039; errors ===&lt;br /&gt;
&lt;br /&gt;
When you send a transaction, there is a delay before the Electrum client displays the transaction in its history.&lt;br /&gt;
This is because the server polls bitcoind&#039;s memorypool every 10 seconds.&lt;br /&gt;
&lt;br /&gt;
If you create another transaction during this interval, during which the first tx is not displayed,&lt;br /&gt;
then your client will pick the same coins again, and the transaction will be rejected as a [[Double-spending|double spend]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using Electrum through a HTTP proxy ===&lt;br /&gt;
&lt;br /&gt;
When you are behind a firewall you can use a HTTP proxy to connect to an Electrum server with some limitations¹.&lt;br /&gt;
&lt;br /&gt;
On Linux (and other POSIX-like systems) set the &#039;&#039;http_proxy&#039;&#039; variable and start the Electrum client, e.g.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   $ export http_proxy=&amp;quot;http://&amp;lt;proxyname&amp;gt;:&amp;lt;proxyport&amp;gt;/&amp;quot;&lt;br /&gt;
   $ ./electrum&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once the client comes up you need to change your server connection to &#039;http&#039; and to adjust the port, afterwards your Electrum client should work as usual. &lt;br /&gt;
&lt;br /&gt;
¹ Limitations:&lt;br /&gt;
* Electrum server selection won&#039;t work; you must manually enter the connection data (server, port &amp;amp; protocol)  &lt;br /&gt;
* Exchange rates cannot be fetched/displayed.&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
* [http://electrum.org Electrum] project website&lt;br /&gt;
* [https://github.com/spesmilo/electrum Electrum] project source (github)&lt;br /&gt;
* [https://bitcointalk.org/index.php?topic=50936.msg950497#msg950497 Electrum Forum] - here this documentation was started&lt;br /&gt;
* [https://github.com/spesmilo/electrum/blob/master/docs Electrum Docs] updated documentation&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=42070</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=42070"/>
		<updated>2013-10-30T00:13:20Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: Use monospace font for functions and variable names to make lower-case variables stand out, and upper-case &amp;#039;i&amp;#039; and lower case &amp;#039;L&amp;#039; more distinguishable&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for &amp;lt;tt&amp;gt;i &amp;gt;= 0x80000000&amp;lt;/tt&amp;gt; (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; to addition of &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; (faster, easier implementation)&lt;br /&gt;
* [25 May 2013] Added test vectors&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Accepted&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes [[Deterministic Wallet|hierarchical determinstic wallets]] (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall denote the compressed form of point &amp;lt;tt&amp;gt;P&amp;lt;/tt&amp;gt; by &amp;lt;tt&amp;gt;&amp;amp;chi;(P)&amp;lt;/tt&amp;gt;, which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called &amp;lt;tt&amp;gt;G&amp;lt;/tt&amp;gt;. The public key &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; corresponding to the private key &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt; is calculated as &amp;lt;tt&amp;gt;k*G&amp;lt;/tt&amp;gt;. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as &amp;lt;tt&amp;gt;(k, c)&amp;lt;/tt&amp;gt;, with &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt; the normal private key, and &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt; the chain code. An extended public key is represented as &amp;lt;tt&amp;gt;(K, c)&amp;lt;/tt&amp;gt;, with &amp;lt;tt&amp;gt;K = k*G&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt; the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: private and public.&lt;br /&gt;
* Private derivation: knowledge of the private key &amp;lt;tt&amp;gt;k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; is required to compute both &amp;lt;tt&amp;gt;k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key &amp;lt;tt&amp;gt;K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; suffices to compute &amp;lt;tt&amp;gt;K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; (but not &amp;lt;tt&amp;gt;k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* &amp;lt;tt&amp;gt;CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr;  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt;, defined for both private and public derivation.&lt;br /&gt;
* &amp;lt;tt&amp;gt;CKD&amp;amp;prime;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt;, defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; to specify which type of derivation to use. &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define &amp;lt;tt&amp;gt;CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt;:&lt;br /&gt;
* Check whether the highest bit (&amp;lt;tt&amp;gt;0x80000000&amp;lt;/tt&amp;gt;) of &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; is set:&lt;br /&gt;
** If 1, private derivation is used: let &amp;lt;tt&amp;gt;I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i)&amp;lt;/tt&amp;gt; [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let &amp;lt;tt&amp;gt;I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Split &amp;lt;tt&amp;gt;I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; into two 32-byte sequences, &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* &amp;lt;tt&amp;gt;k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* &amp;lt;tt&amp;gt;c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
In case &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 0&amp;lt;/tt&amp;gt;, the resulting key is invalid, and one should proceed with the next value for &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt;.&lt;br /&gt;
[Note: this has probability lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;.]&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define &amp;lt;tt&amp;gt;CKD&amp;amp;prime;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt;:&lt;br /&gt;
* Check whether the highest bit (&amp;lt;tt&amp;gt;0x80000000&amp;lt;/tt&amp;gt;) of &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let &amp;lt;tt&amp;gt;I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Split &amp;lt;tt&amp;gt;I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; into two 32-byte sequences, &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
In case &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; is the point at infinity, the resulting key is invalid, and one should proceed with the next value for &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of &amp;lt;tt&amp;gt;CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i)&amp;lt;/tt&amp;gt; with public derivation (so with &amp;lt;tt&amp;gt;i &amp;lt; 0x80000000&amp;lt;/tt&amp;gt;) is identical to the evaluation of &amp;lt;tt&amp;gt;CKD&amp;amp;prime;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i)&amp;lt;/tt&amp;gt;, with &amp;lt;tt&amp;gt;K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; the extended public key corresponding to &amp;lt;tt&amp;gt;k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;. Symbolically, &amp;lt;tt&amp;gt;CKD((k, c), i)*G = CKD&#039;((k*G, c), i)&amp;lt;/tt&amp;gt;. This implies that &amp;lt;tt&amp;gt;CKD&#039;&amp;lt;/tt&amp;gt; can be used to derive all public keys corresponding to the private keys that &amp;lt;tt&amp;gt;CKD&amp;lt;/tt&amp;gt; would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several &amp;lt;tt&amp;gt;CKD&amp;lt;/tt&amp;gt; constructions to build a tree. We start with one root, the master extended key &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;. By evaluating &amp;lt;tt&amp;gt;CKD(m,i)&amp;lt;/tt&amp;gt; for several values of &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt;, we get a number of first-degree derivative nodes. As each of these is again an extended key, &amp;lt;tt&amp;gt;CKD&amp;lt;/tt&amp;gt; can be applied to those as well. To shorten notation, we will write &amp;lt;tt&amp;gt;CKD(CKD(CKD(m,0x8000003),0x2),0x5)&amp;lt;/tt&amp;gt; as &amp;lt;tt&amp;gt;m/3&amp;amp;prime;/2/5&amp;lt;/tt&amp;gt; now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: &amp;lt;tt&amp;gt;0x0488B21E&amp;lt;/tt&amp;gt; public, &amp;lt;tt&amp;gt;0x0488ADE4&amp;lt;/tt&amp;gt; private; testnet: &amp;lt;tt&amp;gt;0x043587CF&amp;lt;/tt&amp;gt; public, &amp;lt;tt&amp;gt;0x04358394&amp;lt;/tt&amp;gt; private)&lt;br /&gt;
* 1 byte: depth: &amp;lt;tt&amp;gt;0x00&amp;lt;/tt&amp;gt; for master nodes, &amp;lt;tt&amp;gt;0x01&amp;lt;/tt&amp;gt; for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (&amp;lt;tt&amp;gt;0x00000000&amp;lt;/tt&amp;gt; if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i&amp;lt;/tt&amp;gt;, with &amp;lt;tt&amp;gt;x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; the key being serialized. This is encoded in MSB order. (&amp;lt;tt&amp;gt;0x00000000&amp;lt;/tt&amp;gt; if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (&amp;lt;tt&amp;gt;0x02 + X&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;0x03 + X&amp;lt;/tt&amp;gt; for public keys, &amp;lt;tt&amp;gt;0x00 + k&amp;lt;/tt&amp;gt; for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2&amp;lt;sup&amp;gt;512&amp;lt;/sup&amp;gt;, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate &amp;lt;tt&amp;gt;I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Split &amp;lt;tt&amp;gt;I&amp;lt;/tt&amp;gt; into two 32-byte sequences, &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Use &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; as master secret key, and &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; as master chain code.&lt;br /&gt;
In case &amp;lt;tt&amp;gt;I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; is 0 or &amp;lt;tt&amp;gt;&amp;gt;=n&amp;lt;/tt&amp;gt;, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external [[keychain]] is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * &amp;lt;tt&amp;gt;m/i&amp;amp;prime;/0/k&amp;lt;/tt&amp;gt; corresponds to the &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt;&#039;th keypair of the external chain of account number &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; of the HDW derived from master m.&lt;br /&gt;
 * &amp;lt;tt&amp;gt;m/i&amp;amp;prime;/1/k&amp;lt;/tt&amp;gt; corresponds to the &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt;&#039;th keypair of the internal chain of account number &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of &amp;lt;tt&amp;gt;N&amp;lt;/tt&amp;gt; look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: &amp;lt;tt&amp;gt;M&amp;lt;/tt&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: &amp;lt;tt&amp;gt;m/i&amp;amp;prime;&amp;lt;/tt&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: &amp;lt;tt&amp;gt;M/i&amp;amp;prime;/0&amp;lt;/tt&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (&amp;lt;tt&amp;gt;M/i&amp;amp;prime;/0&amp;lt;/tt&amp;gt;) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: &amp;lt;tt&amp;gt;M/i&amp;amp;prime;/0&amp;lt;/tt&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt;, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key &amp;lt;tt&amp;gt;(k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt; and the integer &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt;, an attacker cannot find the parent private key &amp;lt;tt&amp;gt;k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (&amp;lt;tt&amp;gt;2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1&amp;lt;/tt&amp;gt;) of (index, extended private key) tuples (&amp;lt;tt&amp;gt;i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt;), with distinct &amp;lt;tt&amp;gt;i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a &amp;lt;tt&amp;gt;(p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt; such that for each &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;[0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;))&amp;lt;/tt&amp;gt;, cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key &amp;lt;tt&amp;gt;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt; and a child public key &amp;lt;tt&amp;gt;(K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt;, it is hard to find &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Given a parent extended public key &amp;lt;tt&amp;gt;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt; and a child private key &amp;lt;tt&amp;gt;(k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;)&amp;lt;/tt&amp;gt; using public derivation, it is hard to find &amp;lt;tt&amp;gt;k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
For more detailed information about these (such as intermediate values and other representations), see [[BIP_0032_TestVectors]]&lt;br /&gt;
&lt;br /&gt;
Test vector 1&lt;br /&gt;
&lt;br /&gt;
  Master (hex): 000102030405060708090a0b0c0d0e0f&lt;br /&gt;
  * [Chain m]&lt;br /&gt;
    * ext pub: xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8&lt;br /&gt;
    * ext prv: xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi&lt;br /&gt;
  * [Chain m/0&#039;]&lt;br /&gt;
    * ext pub: xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw&lt;br /&gt;
    * ext prv: xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7&lt;br /&gt;
  * [Chain m/0&#039;/1]&lt;br /&gt;
    * ext pub: xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ&lt;br /&gt;
    * ext prv: xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;]&lt;br /&gt;
    * ext pub: xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5&lt;br /&gt;
    * ext prv: xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;/2]&lt;br /&gt;
    * ext pub: xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV&lt;br /&gt;
    * ext prv: xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;/2/1000000000]&lt;br /&gt;
    * ext pub: xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy&lt;br /&gt;
    * ext prv: xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76&lt;br /&gt;
&lt;br /&gt;
Test vector 2&lt;br /&gt;
&lt;br /&gt;
  Master (hex): fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542&lt;br /&gt;
  * [Chain m]&lt;br /&gt;
    * ext pub: xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB&lt;br /&gt;
    * ext prv: xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U&lt;br /&gt;
  * [Chain m/0]&lt;br /&gt;
    * ext pub: xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH&lt;br /&gt;
    * ext prv: xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt&lt;br /&gt;
  * [Chain m/0/2147483647&#039;]&lt;br /&gt;
    * ext pub: xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a&lt;br /&gt;
    * ext prv: xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1]&lt;br /&gt;
    * ext pub: xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon&lt;br /&gt;
    * ext prv: xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1/2147483646&#039;]&lt;br /&gt;
    * ext pub: xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL&lt;br /&gt;
    * ext prv: xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1/2147483646&#039;/2]&lt;br /&gt;
    * ext pub: xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt&lt;br /&gt;
    * ext prv: xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j&lt;br /&gt;
&lt;br /&gt;
==Implementations==&lt;br /&gt;
&lt;br /&gt;
A Python implementation is available at https://github.com/richardkiss/pycoin&lt;br /&gt;
&lt;br /&gt;
A Java implementation is available at https://github.com/bitsofproof/supernode/blob/1.1/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java&lt;br /&gt;
&lt;br /&gt;
A C++ implementation is available at https://github.com/CodeShark/CoinClasses/tree/master/tests/hdwallets&lt;br /&gt;
&lt;br /&gt;
A Ruby implementation is available at https://github.com/wink/money-tree&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=38480</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=38480"/>
		<updated>2013-06-07T18:09:51Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Aux proof-of-work block */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction that is in the parent block, [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the &amp;lt;tt&amp;gt;parent_block&amp;lt;/tt&amp;gt; header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;block_hash&amp;lt;/tt&amp;gt; element is not needed as you have the full &amp;lt;tt&amp;gt;parent_block&amp;lt;/tt&amp;gt; header element and can calculate the hash from that. The current Namecoin client doesn&#039;t check this field for validity, and as such some AuxPOW blocks have it little-endian, and some have it big-endian.&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the &amp;lt;tt&amp;gt;scriptSig&amp;lt;/tt&amp;gt; of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(only required if over 20 bytes past the start of the script; optional otherwise)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;(Must be a power of 2)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;. If it were, it would be right after [https://blockchain.info/block-index/163650/00000000000004a59b7deb5c4e01b9786ea01ee8da000db77ce6035c2913be08 &amp;lt;tt&amp;gt;4a59b7deb5c4e01b&amp;lt;/tt&amp;gt;], since that&#039;s the &amp;lt;tt&amp;gt;previous_block&amp;lt;/tt&amp;gt; hash used)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                                                                        // Version&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88    // Merkle root&lt;br /&gt;
 8d 1a 90 4e                                                                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                                                                        // Bits&lt;br /&gt;
 00 00 00 00                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Parent Block Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                                                                 // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7    // Script&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44    // Script&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00    // Hash of parent block header&lt;br /&gt;
 05                                                                                                 // Number of links in branch&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb    // Hash #1&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34    // Hash #2&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06    // Hash #3&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56    // Hash #4&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b    // Hash #5&lt;br /&gt;
 00 00 00 00                                                                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block Header:&lt;br /&gt;
 01 00 00 00                                                                                        // Version&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5    // Merkle root&lt;br /&gt;
 9a 23 90 4e                                                                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                                                                        // Bits&lt;br /&gt;
 1c 65 50 86                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97    // Script&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=38380</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=38380"/>
		<updated>2013-06-04T19:37:40Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Merged mining coinbase */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction that is in the parent block, [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the &amp;lt;tt&amp;gt;scriptSig&amp;lt;/tt&amp;gt; of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(only required if over 20 bytes past the start of the script; optional otherwise)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;(Must be a power of 2)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;. If it were, it would be right after [https://blockchain.info/block-index/163650/00000000000004a59b7deb5c4e01b9786ea01ee8da000db77ce6035c2913be08 &amp;lt;tt&amp;gt;4a59b7deb5c4e01b&amp;lt;/tt&amp;gt;], since that&#039;s the &amp;lt;tt&amp;gt;previous_block&amp;lt;/tt&amp;gt; hash used)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                                                                        // Version&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88    // Merkle root&lt;br /&gt;
 8d 1a 90 4e                                                                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                                                                        // Bits&lt;br /&gt;
 00 00 00 00                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Parent Block Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                                                                 // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7    // Script&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44    // Script&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00    // Hash of parent block header&lt;br /&gt;
 05                                                                                                 // Number of links in branch&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb    // Hash #1&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34    // Hash #2&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06    // Hash #3&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56    // Hash #4&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b    // Hash #5&lt;br /&gt;
 00 00 00 00                                                                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block Header:&lt;br /&gt;
 01 00 00 00                                                                                        // Version&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5    // Merkle root&lt;br /&gt;
 9a 23 90 4e                                                                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                                                                        // Bits&lt;br /&gt;
 1c 65 50 86                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97    // Script&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37981</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37981"/>
		<updated>2013-05-23T20:45:00Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction that is in the parent block, [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the &amp;lt;tt&amp;gt;scriptSig&amp;lt;/tt&amp;gt; of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;. If it were, it would be right after [https://blockchain.info/block-index/163650/00000000000004a59b7deb5c4e01b9786ea01ee8da000db77ce6035c2913be08 &amp;lt;tt&amp;gt;4a59b7deb5c4e01b&amp;lt;/tt&amp;gt;], since that&#039;s the &amp;lt;tt&amp;gt;previous_block&amp;lt;/tt&amp;gt; hash used)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                                                                        // Version&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88    // Merkle root&lt;br /&gt;
 8d 1a 90 4e                                                                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                                                                        // Bits&lt;br /&gt;
 00 00 00 00                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Parent Block Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                                                                 // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7    // Script&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44    // Script&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00    // Hash of parent block header&lt;br /&gt;
 05                                                                                                 // Number of links in branch&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb    // Hash #1&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34    // Hash #2&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06    // Hash #3&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56    // Hash #4&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b    // Hash #5&lt;br /&gt;
 00 00 00 00                                                                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block Header:&lt;br /&gt;
 01 00 00 00                                                                                        // Version&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5    // Merkle root&lt;br /&gt;
 9a 23 90 4e                                                                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                                                                        // Bits&lt;br /&gt;
 1c 65 50 86                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97    // Script&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37980</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37980"/>
		<updated>2013-05-23T20:44:18Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction that is in the parent block, [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the &amp;lt;tt&amp;gt;scriptSig&amp;lt;/tt&amp;gt; of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;. If it were, it would be right after [https://blockchain.info/block-index/163650/00000000000004a59b7deb5c4e01b9786ea01ee8da000db77ce6035c2913be08 &amp;lt;tt&amp;gt;4a59b7deb5c4e01b&amp;lt;/tt&amp;gt;], since that&#039;s the &amp;lt;tt&amp;gt;previous_block&amp;lt;/tt&amp;gt; hash used)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                                                                        // Version&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88    // Merkle root&lt;br /&gt;
 8d 1a 90 4e                                                                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                                                                        // Bits&lt;br /&gt;
 00 00 00 00                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                                                                 // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7    // Script&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44    // Script&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00    // Hash of parent block header&lt;br /&gt;
 05                                                                                                 // Number of links in branch&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb    // Hash #1&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34    // Hash #2&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06    // Hash #3&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56    // Hash #4&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b    // Hash #5&lt;br /&gt;
 00 00 00 00                                                                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block:&lt;br /&gt;
 01 00 00 00                                                                                        // Version&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5    // Merkle root&lt;br /&gt;
 9a 23 90 4e                                                                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                                                                        // Bits&lt;br /&gt;
 1c 65 50 86                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97    // Script&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37979</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37979"/>
		<updated>2013-05-23T20:43:04Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Merged mining coinbase */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction that is in the parent block, [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the &amp;lt;tt&amp;gt;scriptSig&amp;lt;/tt&amp;gt; of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;. If it were, it would be right after [https://blockchain.info/block-index/163650/00000000000004a59b7deb5c4e01b9786ea01ee8da000db77ce6035c2913be08 &amp;lt;tt&amp;gt;4a59b7deb5c4e01b&amp;lt;/tt&amp;gt;], since that&#039;s the previous block hash used)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                                                                        // Version&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88    // Merkle root&lt;br /&gt;
 8d 1a 90 4e                                                                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                                                                        // Bits&lt;br /&gt;
 00 00 00 00                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                                                                 // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7    // Script&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44    // Script&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00    // Hash of parent block header&lt;br /&gt;
 05                                                                                                 // Number of links in branch&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb    // Hash #1&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34    // Hash #2&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06    // Hash #3&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56    // Hash #4&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b    // Hash #5&lt;br /&gt;
 00 00 00 00                                                                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block:&lt;br /&gt;
 01 00 00 00                                                                                        // Version&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5    // Merkle root&lt;br /&gt;
 9a 23 90 4e                                                                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                                                                        // Bits&lt;br /&gt;
 1c 65 50 86                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97    // Script&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37978</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37978"/>
		<updated>2013-05-23T20:39:57Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Aux proof-of-work block */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction that is in the parent block, [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;. If it were, it would be right after [https://blockchain.info/block-index/163650/00000000000004a59b7deb5c4e01b9786ea01ee8da000db77ce6035c2913be08 &amp;lt;tt&amp;gt;4a59b7deb5c4e01b&amp;lt;/tt&amp;gt;], since that&#039;s the previous block hash used)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                                                                        // Version&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88    // Merkle root&lt;br /&gt;
 8d 1a 90 4e                                                                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                                                                        // Bits&lt;br /&gt;
 00 00 00 00                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                                                                 // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7    // Script&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44    // Script&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00    // Hash of parent block header&lt;br /&gt;
 05                                                                                                 // Number of links in branch&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb    // Hash #1&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34    // Hash #2&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06    // Hash #3&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56    // Hash #4&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b    // Hash #5&lt;br /&gt;
 00 00 00 00                                                                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block:&lt;br /&gt;
 01 00 00 00                                                                                        // Version&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5    // Merkle root&lt;br /&gt;
 9a 23 90 4e                                                                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                                                                        // Bits&lt;br /&gt;
 1c 65 50 86                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97    // Script&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37977</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37977"/>
		<updated>2013-05-23T20:32:54Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;. If it were, it would be right after [https://blockchain.info/block-index/163650/00000000000004a59b7deb5c4e01b9786ea01ee8da000db77ce6035c2913be08 &amp;lt;tt&amp;gt;4a59b7deb5c4e01b&amp;lt;/tt&amp;gt;], since that&#039;s the previous block hash used)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                                                                        // Version&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88    // Merkle root&lt;br /&gt;
 8d 1a 90 4e                                                                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                                                                        // Bits&lt;br /&gt;
 00 00 00 00                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                                                                 // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7    // Script&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44    // Script&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00    // Hash of parent block header&lt;br /&gt;
 05                                                                                                 // Number of links in branch&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb    // Hash #1&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34    // Hash #2&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06    // Hash #3&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56    // Hash #4&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b    // Hash #5&lt;br /&gt;
 00 00 00 00                                                                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block:&lt;br /&gt;
 01 00 00 00                                                                                        // Version&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5    // Merkle root&lt;br /&gt;
 9a 23 90 4e                                                                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                                                                        // Bits&lt;br /&gt;
 1c 65 50 86                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97    // Script&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37976</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37976"/>
		<updated>2013-05-23T20:29:53Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Example */ Reformat to not be so tall&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                                                                        // Version&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88    // Merkle root&lt;br /&gt;
 8d 1a 90 4e                                                                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                                                                        // Bits&lt;br /&gt;
 00 00 00 00                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                                                                 // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7    // Script&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44    // Script&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00    // Hash of parent block header&lt;br /&gt;
 05                                                                                                 // Number of links in branch&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb    // Hash #1&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34    // Hash #2&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06    // Hash #3&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56    // Hash #4&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b    // Hash #5&lt;br /&gt;
 00 00 00 00                                                                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block:&lt;br /&gt;
 01 00 00 00                                                                                        // Version&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00    // Previous block hash&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5    // Merkle root&lt;br /&gt;
 9a 23 90 4e                                                                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                                                                        // Bits&lt;br /&gt;
 1c 65 50 86                                                                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                                                                 // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97    // Script&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37975</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37975"/>
		<updated>2013-05-23T20:21:29Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: Add example block&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This is the AuxPOW block at [http://explorer.dot-bit.org/b/19200 height 19200] in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of &amp;lt;tt&amp;gt;d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d&amp;lt;/tt&amp;gt;, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner&#039;s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000000000003d47277359fb969c43e3c7e7c0306a17f6444b8e91e19def03a9 -- parent block hash&lt;br /&gt;
000000000000b269000000000000000000000000000000000000000000000000 -- Namecoin difficulty target&lt;br /&gt;
00000000000009ee5d0000000000000000000000000000000000000000000000 -- Bitcoin difficulty target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting &amp;lt;tt&amp;gt;3d47277359fb969c&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Block Header:&lt;br /&gt;
 01 01 01 00                                        // Version&lt;br /&gt;
&lt;br /&gt;
 36 90 9a c0 7a 16 73 da f6 5f a7 d8 28 88 2e 66    // Previous block hash&lt;br /&gt;
 c9 e8 9f 85 46 cd d5 0a 9f b1 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 0f 5c 65 49 bc d6 08 ab 7c 4e ac 59 3e 5b d5 a7    // Merkle root&lt;br /&gt;
 3b 2d 43 2e b6 35 18 70 8f 77 8f c7 dc df af 88&lt;br /&gt;
&lt;br /&gt;
 8d 1a 90 4e                                        // Timestamp&lt;br /&gt;
 69 b2 00 1b                                        // Bits&lt;br /&gt;
 00 00 00 00                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Coinbase Transaction:&lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 35                                                       // Script size&lt;br /&gt;
 04 5d ee 09 1a 01 4d 52 2c fa be 6d 6d d8 a7 c3          // Script&lt;br /&gt;
 e0 1e 1e 95 bc ee 01 5e 6f cc 75 83 a2 ca 60 b7&lt;br /&gt;
 9e 5a 3a a0 a1 71 ed dd 34 4a da 90 3d 01 00 00&lt;br /&gt;
 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence Number&lt;br /&gt;
&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
&lt;br /&gt;
 60 a0 10 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                       // Script Size&lt;br /&gt;
 41 04 f8 bb e9 7e d2 ac bc 5b ba 11 c6 8f 6f 1a          // Script&lt;br /&gt;
 03 13 f9 18 f3 d3 c0 e8 47 50 55 e3 51 e3 bf 44&lt;br /&gt;
 2f 8c 8d ce e6 82 d2 45 7b dc 53 51 b7 0d d9 e3&lt;br /&gt;
 40 26 76 6e ba 18 b0 6e ae e2 e1 02 ef d1 ab 63&lt;br /&gt;
 46 67 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&lt;br /&gt;
Coinbase Link:&lt;br /&gt;
 a9 03 ef 9d e1 91 8e 4b 44 f6 17 6a 30 c0 e7 c7    // Hash of parent block header&lt;br /&gt;
 e3 43 9c 96 fb 59 73 27 47 3d 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 05                                                 // Number of links in branch&lt;br /&gt;
&lt;br /&gt;
 05 0a c4 a1 a1 e1 bc e0 c4 8e 55 5b 1a 9f 93 52    // Hash #1&lt;br /&gt;
 81 96 8c 72 d6 37 9b 24 72 9c a0 42 5a 3f c3 cb&lt;br /&gt;
&lt;br /&gt;
 43 3c d3 48 b3 5e a2 28 06 cf 21 c7 b1 46 48 9a    // Hash #2&lt;br /&gt;
 ef 69 89 55 1e b5 ad 23 73 ab 61 21 06 0f 30 34&lt;br /&gt;
&lt;br /&gt;
 1d 64 87 57 c0 21 7d 43 e6 6c 57 ea ed 64 fc 18    // Hash #3&lt;br /&gt;
 20 ec 65 d1 57 f3 3b 74 19 65 18 3a 5e 0c 85 06&lt;br /&gt;
&lt;br /&gt;
 ac 26 02 df e2 f5 47 01 2d 1c c7 50 04 d4 8f 97    // Hash #4&lt;br /&gt;
 ab a4 6b d9 93 0f f2 85 c9 f2 76 f5 bd 09 f3 56&lt;br /&gt;
&lt;br /&gt;
 df 19 72 45 79 d6 5e c7 cb 62 bf 97 94 6d fc 6f    // Hash #5&lt;br /&gt;
 b0 e3 b2 83 9b 7f da b3 7c db 60 e5 51 22 d3 5b&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                        // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Aux Blockchain Link:&lt;br /&gt;
 00             // Number of links in branch&lt;br /&gt;
 00 00 00 00    // Branch sides bitmask&lt;br /&gt;
&lt;br /&gt;
Parent Block:&lt;br /&gt;
 01 00 00 00                                        // Version&lt;br /&gt;
&lt;br /&gt;
 08 be 13 29 5c 03 e6 7c b7 0d 00 da e8 1e a0 6e    // Previous block hash&lt;br /&gt;
 78 b9 01 4e 5c eb 7d 9b a5 04 00 00 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 e0 fd 42 db 8e f6 d7 83 f0 79 d1 26 be a1 2e 2d    // Merkle root&lt;br /&gt;
 10 c1 04 c0 92 7c d6 8f 95 4d 85 6f 9e 81 11 e5&lt;br /&gt;
&lt;br /&gt;
 9a 23 90 4e                                        // Timestamp&lt;br /&gt;
 5d ee 09 1a                                        // Bits&lt;br /&gt;
 1c 65 50 86                                        // Nonce&lt;br /&gt;
&lt;br /&gt;
Transactions:&lt;br /&gt;
 01                                                       // Tx  Count&lt;br /&gt;
 &lt;br /&gt;
 01 00 00 00                                              // Version&lt;br /&gt;
&lt;br /&gt;
 01                                                       // TxIn Count&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    // Previous Out&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff&lt;br /&gt;
&lt;br /&gt;
 08                                                       // Script size&lt;br /&gt;
 04 69 b2 00 1b 01 01 52                                  // Script&lt;br /&gt;
&lt;br /&gt;
 ff ff ff ff                                              // Sequence number&lt;br /&gt;
&lt;br /&gt;
 01                                                       // TxOut Count&lt;br /&gt;
&lt;br /&gt;
 00 f2 05 2a 01 00 00 00                                  // Amount&lt;br /&gt;
&lt;br /&gt;
 43                                                       // Script size&lt;br /&gt;
 41 04 89 fe 91 e6 28 47 57 5c 98 de ea b0 20 f6          // Script&lt;br /&gt;
 5f df f1 7a 3a 87 0e bb 05 82 0b 41 4f 3d 80 97&lt;br /&gt;
 21 8e c9 a6 5f 1e 0a e0 ac 35 af 72 47 bd 79 ed&lt;br /&gt;
 1f 2a 24 67 5f ff b5 aa 6f 96 20 e1 92 0a d4 bf&lt;br /&gt;
 5a a6 ac&lt;br /&gt;
&lt;br /&gt;
 00 00 00 00                                              // Lock Time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0021&amp;diff=37974</id>
		<title>BIP 0021</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0021&amp;diff=37974"/>
		<updated>2013-05-23T18:45:40Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Appendix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 21&lt;br /&gt;
  Title: URI Scheme&lt;br /&gt;
  Author: Nils Schneider &amp;lt;nils.schneider@gmail.com&amp;gt;&lt;br /&gt;
          Matt Corallo &amp;lt;bip21@bluematt.me&amp;gt;&lt;br /&gt;
  Status: Accepted&lt;br /&gt;
  Type: Standards Track&lt;br /&gt;
  Created: 29-01-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This BIP is a modification of an earlier [[BIP 0020]] by Luke Dashjr. BIP 0020 was based off an earlier document by Nils Schneider. The alternative payment amounts in BIP 0020 have been removed.&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
This BIP proposes a URI scheme for making Bitcoin payments.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
The purpose of this URI scheme is to enable users to easily make payments by simply clicking links on webpages or scanning QR Codes.&lt;br /&gt;
&lt;br /&gt;
==Specification==&lt;br /&gt;
&lt;br /&gt;
=== General rules for handling (important!) ===&lt;br /&gt;
&lt;br /&gt;
Bitcoin clients MUST NOT act on URIs without getting the user&#039;s authorization.&lt;br /&gt;
They SHOULD require the user to manually approve each payment individually, though in some cases they MAY allow the user to automatically make this decision.&lt;br /&gt;
&lt;br /&gt;
=== Operating system integration ===&lt;br /&gt;
Graphical bitcoin clients SHOULD register themselves as the handler for the &amp;quot;bitcoin:&amp;quot; URI scheme by default, if no other handler is already registered. If there is already a registered handler, they MAY prompt the user to change it once when they first run the client.&lt;br /&gt;
&lt;br /&gt;
=== BNF grammar ===&lt;br /&gt;
&lt;br /&gt;
(See also [[#Simpler syntax|a simpler representation of syntax]])&lt;br /&gt;
&lt;br /&gt;
 bitcoinurn     = &amp;quot;bitcoin:&amp;quot; bitcoinaddress [ &amp;quot;?&amp;quot; bitcoinparams ]&lt;br /&gt;
 bitcoinaddress = base58 *base58&lt;br /&gt;
 bitcoinparams  = *bitcoinparam&lt;br /&gt;
 bitcoinparam   = amountparam | labelparam | messageparam | otherparam | reqparam&lt;br /&gt;
 amountparam    = &amp;quot;amount=&amp;quot; *digit [ &amp;quot;.&amp;quot; *digit ]&lt;br /&gt;
 labelparam     = &amp;quot;label=&amp;quot; *pchar&lt;br /&gt;
 messageparam   = &amp;quot;message=&amp;quot; *pchar&lt;br /&gt;
 otherparam     = pchar *pchar &amp;quot;=&amp;quot; *pchar&lt;br /&gt;
 reqparam       = &amp;quot;req-&amp;quot; pchar *pchar &amp;quot;=&amp;quot; *pchar&lt;br /&gt;
&lt;br /&gt;
=== Query Keys ===&lt;br /&gt;
&lt;br /&gt;
*label: Label for that address (e.g. name of receiver)&lt;br /&gt;
*address: bitcoin address&lt;br /&gt;
*message: message that describes the transaction to the user ([[#Examples|see examples below]])&lt;br /&gt;
*size: amount of base bitcoin units ([[#Transfer amount/size|see below]])&lt;br /&gt;
*(others): optional, for future extensions&lt;br /&gt;
&lt;br /&gt;
==== Transfer amount/size ====&lt;br /&gt;
&lt;br /&gt;
If an amount is provided, it MUST be specified in decimal BTC.&lt;br /&gt;
All amounts MUST contain no commas and use a period (.) as the separating character to separate whole numbers and decimal fractions.&lt;br /&gt;
I.e. amount=50.00 or amount=50 is treated as 50 BTC, and amount=50,000.00 is invalid.&lt;br /&gt;
&lt;br /&gt;
Bitcoin clients MAY display the amount in any format that is not intended to deceive the user.&lt;br /&gt;
They SHOULD choose a format that is foremost least confusing, and only after that most reasonable given the amount requested.&lt;br /&gt;
For example, so long as the majority of users work in BTC units, values should always be displayed in BTC by default, even if mBTC or TBC would otherwise be a more logical interpretation of the amount.&lt;br /&gt;
== Rationale ==&lt;br /&gt;
&lt;br /&gt;
===Payment identifiers, not person identifiers===&lt;br /&gt;
Current best practices are that a unique address should be used for every transaction.&lt;br /&gt;
Therefore, a URI scheme should not represent an exchange of personal information, but a one-time payment.&lt;br /&gt;
&lt;br /&gt;
===Accessibility (URI scheme name)===&lt;br /&gt;
Should someone from the outside happen to see such a URI, the URI scheme name already gives a description.&lt;br /&gt;
A quick search should then do the rest to help them find the resources needed to make their payment.&lt;br /&gt;
Other proposed names sound much more cryptic; the chance that someone googles that out of curiosity are much slimmer.&lt;br /&gt;
Also, very likely, what he will find are mostly technical specifications - not the best introduction to bitcoin.&lt;br /&gt;
&lt;br /&gt;
==Forward compatibility==&lt;br /&gt;
Variables which are prefixed with a req- are considered required.  If a client does not implement any variables which are prefixed with req-, it MUST consider the entire URI invalid.  Any other variables which are not implemented, but which are not prefixed with a req-, can be safely ignored.  &lt;br /&gt;
&lt;br /&gt;
==Backward compatibility==&lt;br /&gt;
As this BIP is written, several clients already implement a bitcoin: URI scheme similar to this one, however usually without the additional &amp;quot;req-&amp;quot; prefix requirement.  Thus, it is recommended that additional variables prefixed with req- not be used in a mission-critical way until a grace period of 6 months from the finalization of this BIP has passed in order to allow client developers to release new versions, and users of old clients to upgrade.&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
&lt;br /&gt;
=== Simpler syntax ===&lt;br /&gt;
&lt;br /&gt;
This section is non-normative and does not cover all possible syntax.&lt;br /&gt;
Please see the [[#BNF grammar|BNF grammar]] above for the normative syntax.&lt;br /&gt;
&lt;br /&gt;
[foo] means optional, &amp;lt;bar&amp;gt; are placeholders&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;bitcoin:&amp;lt;address&amp;gt;[?amount=&amp;lt;amount&amp;gt;][?label=&amp;lt;label&amp;gt;][?message=&amp;lt;message&amp;gt;]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
&lt;br /&gt;
Just the address:&lt;br /&gt;
 bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W&lt;br /&gt;
&lt;br /&gt;
Address with name:&lt;br /&gt;
 bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Luke-Jr&lt;br /&gt;
&lt;br /&gt;
Request 20.30 BTC to &amp;quot;Luke-Jr&amp;quot;:&lt;br /&gt;
 bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=20.3&amp;amp;label=Luke-Jr&lt;br /&gt;
&lt;br /&gt;
Request 50 BTC with message:&lt;br /&gt;
 bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=50&amp;amp;label=Luke-Jr&amp;amp;message=Donation%20for%20project%20xyz&lt;br /&gt;
&lt;br /&gt;
Some future version that has variables which are (currently) not understood and required and thus invalid:&lt;br /&gt;
 bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-somethingyoudontunderstand=50&amp;amp;req-somethingelseyoudontget=999&lt;br /&gt;
&lt;br /&gt;
Some future version that has variables which are (currently) not understood but not required and thus valid:&lt;br /&gt;
 bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?somethingyoudontunderstand=50&amp;amp;somethingelseyoudontget=999&lt;br /&gt;
&lt;br /&gt;
Characters must be URI encoded properly.&lt;br /&gt;
&lt;br /&gt;
== Reference Implementations ==&lt;br /&gt;
=== Bitcoin clients ===&lt;br /&gt;
* [[Bitcoin-Qt]] supports the old version of Bitcoin URIs (ie without the req- prefix), with Windows and KDE integration as of commit 70f55355e29c8e45b607e782c5d76609d23cc858.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:BIP|D]]&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37973</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37973"/>
		<updated>2013-05-23T18:43:15Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Aux proof-of-work block */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte &amp;lt;tt&amp;gt;var_int&amp;lt;/tt&amp;gt; indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes).&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37972</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37972"/>
		<updated>2013-05-23T18:42:22Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Aux proof-of-work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work block ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte var_int indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes.&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37971</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37971"/>
		<updated>2013-05-23T18:41:55Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Aux proof-of-work */ Show the standard block elements as well, for context&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is similar to a standard block, but extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements. In the below table, the shaded rows are the same as the standard block definition:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || version || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || prev_block || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 32 || merkle_root || char[32] ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || timestamp || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || bits || uint32_t ||&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| 4 || nonce || uint32_t ||&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txn_count || var_int || &lt;br /&gt;
|- style=&amp;quot;background-color:#DDD; color:#999;&amp;quot;&lt;br /&gt;
| ? || txns || tx[] || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte var_int indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes.&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37970</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37970"/>
		<updated>2013-05-23T18:35:44Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Terminology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
----&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
----&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is a standard block, but the below extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte var_int indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes.&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37969</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37969"/>
		<updated>2013-05-23T18:34:14Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Aux proof-of-work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is a standard block, but the below extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|Merkle branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|Block header]] || Parent block header&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte var_int indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes.&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37968</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37968"/>
		<updated>2013-05-23T18:33:38Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: /* Merkle Branch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is a standard block, but the below extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|merkle_branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|merkle_branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|block header]] || Parent block header&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte var_int indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes.&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37967</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37967"/>
		<updated>2013-05-23T18:31:07Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: Better explain a Merkle Branch and how it&amp;#039;s used in this context&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is a standard block, but the below extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction [[#Merged mining coinbase|linking]] the AuxPOW block to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_branch || [[#Merkle Branch|merkle_branch]] || The merkle branch linking the &amp;lt;tt&amp;gt;coinbase_txn&amp;lt;/tt&amp;gt; to the parent block&#039;s &amp;lt;tt&amp;gt;merkle_root&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ? || blockchain_branch || [[#Merkle Branch|merkle_branch]] || The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|block header]] || Parent block header&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;tt&amp;gt;coinbase_branch&amp;lt;/tt&amp;gt; merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given [[#Merkle Branch|below]]), the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; is always going to be all zeroes, because the branch hashes will always be &amp;quot;on the right&amp;quot; of the working hash.&lt;br /&gt;
&lt;br /&gt;
When only working on one auxiliary blockchain, the &amp;lt;tt&amp;gt;blockchain_branch&amp;lt;/tt&amp;gt; link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte var_int indicating a &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; of zero, and a 32-bit (4 byte) &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; of all zeroes.&lt;br /&gt;
&lt;br /&gt;
== Merkle Branch ==&lt;br /&gt;
Say Alice created a Merkle tree, and it&#039;s root element is publicly available. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             merkleRoot (0)&lt;br /&gt;
              /        \&lt;br /&gt;
             /          \&lt;br /&gt;
            1            2&lt;br /&gt;
           / \          / \&lt;br /&gt;
          /   \        /   \&lt;br /&gt;
         3     4      5     6&lt;br /&gt;
        / \   / \    / \   / \&lt;br /&gt;
       7   8 9  10  11 12 13 14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn&#039;t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that&#039;s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since &amp;lt;tt&amp;gt;hash(#9, #10) == #4&amp;lt;/tt&amp;gt;, but &amp;lt;tt&amp;gt;hash(#10, #9) != #4&amp;lt;/tt&amp;gt;). So Alice tells Bob &amp;quot;left, left, right&amp;quot; to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.&lt;br /&gt;
&lt;br /&gt;
That is the overall premise, and specifically for the AuxPOW protocol, it&#039;s been termed a &amp;quot;merkle branch&amp;quot; (since it&#039;s one pathway of a merkle tree), and is transmitted thusly:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_length || [[Protocol_specification#Variable_length_integer|var_int]] || The number of hashes making up the branch&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_hash[] || char[32] || Individual hash in the branch; repeated &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; number of times&lt;br /&gt;
|-&lt;br /&gt;
| 4 || branch_side_mask || int32_t || Bitmask of which side of the merkle hash function the &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; element should go on. Zero means it goes on the right, One means on the left.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is used first, and the least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt; determines its hash position. Then the second &amp;lt;tt&amp;gt;branch_hash&amp;lt;/tt&amp;gt; is applied with the second-least-significant bit of the &amp;lt;tt&amp;gt;branch_side_mask&amp;lt;/tt&amp;gt;, etc. So for Alice&#039;s example, &amp;lt;tt&amp;gt;branch_length&amp;lt;/tt&amp;gt; would be 3, the hashes would be given in the order #9, #3, then #2, and the mask would be &amp;lt;tt&amp;gt;0b011&amp;lt;/tt&amp;gt; = 3.&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || &amp;lt;tt&amp;gt;0xfa&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;0xbe&amp;lt;/tt&amp;gt;, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37934</id>
		<title>Merged mining specification</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Merged_mining_specification&amp;diff=37934"/>
		<updated>2013-05-22T22:19:41Z</updated>

		<summary type="html">&lt;p&gt;MidnightLightning: Updating with more technical information based on my dissection of vinced&amp;#039;s source&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NOTE: This standard is used by [[Namecoin]], but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool&#039;s merged mining.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
;Auxiliary Proof-of-Work (POW): a.k.a &amp;quot;AuxPOW&amp;quot;. This is the way that merged mining can exist; it is the relationship between two blockchains for one to trust the other&#039;s work as their own and accept AuxPOW blocks.&lt;br /&gt;
;Merged Mining: The act of using work done on one blockchain on more than one chain, using Auxiliary POW.&lt;br /&gt;
;Auxiliary Blockchain: The altcoin that is accepting work done on alternate chains as valid on its own chain. Client applications have to be modified to accept Auxiliary POW.&lt;br /&gt;
;Parent Blockchain: The blockchain where the actual mining work is taking place. This chain does not need to be aware of the Auxiliary POW logic, as AuxPOW blocks submitted to this chain are still valid blocks.&lt;br /&gt;
;Parent Block: Not to be confused with the &amp;quot;previous block&amp;quot;. This is a block that is structured for the parent blockchain (i.e. the &amp;lt;tt&amp;gt;prev_block&amp;lt;/tt&amp;gt; hash points to the prior block on the parent blockchain). The header of this block is part of the AuxPOW Block in the auxiliary blockchain.&lt;br /&gt;
;AuxPOW Block: This is a new type of block that is similar to a standard blockchain block, with two important differences. Firstly, the hash of the block header does NOT meet the difficulty level of the blockchain (so, if interpreted by a naive client, will be thrown out as not meeting the difficulty level). Secondly, it has additional data elements that show that the miner who created this block actually did mining activity (hashing) on the parent blockchain, and that work meets the difficulty level of the auxiliary blockchain, which is why this block should be accepted.&lt;br /&gt;
&lt;br /&gt;
== Aux proof-of-work ==&lt;br /&gt;
This is used to prove work on the auxiliary blockchain. In vinced&#039;s original implementation it&#039;s generated by calling the &amp;lt;tt&amp;gt;getworkaux&amp;lt;/tt&amp;gt; RPC method on the parent blockchain client (&amp;lt;tt&amp;gt;bitcoind&amp;lt;/tt&amp;gt;) and then the work is then submitted by passing it to the auxiliary chain client (&amp;lt;tt&amp;gt;namecoind&amp;lt;/tt&amp;gt;) as the second parameter to &amp;lt;tt&amp;gt;getauxblock&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When receiving an Aux proof-of-work block in a [[Protocol specification#block|&amp;quot;&amp;lt;tt&amp;gt;block&amp;lt;/tt&amp;gt;&amp;quot; network message]], the data received is a standard block, but the below extra data is inserted between the &amp;lt;tt&amp;gt;nonce&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;txn_count&amp;lt;/tt&amp;gt; elements:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || coinbase_txn || [[Protocol specification#tx|txn]] || Coinbase transaction linking the aux to its parent block&lt;br /&gt;
|-&lt;br /&gt;
| ? || merkle_link || [[#Merkle link|mrkllink]] || The merkle branch linking the coinbase (above) to its block&lt;br /&gt;
|-&lt;br /&gt;
| ? || aux_branch_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of merkle branches linking this aux chains to the aux root&lt;br /&gt;
|-&lt;br /&gt;
| 32* || aux_branch[] || char[32] || The merkle branch linking all auxiliary blockchains being mined against together&lt;br /&gt;
|-&lt;br /&gt;
| 4 || index || int32_t || Index of &amp;quot;this&amp;quot; blockchain in the auxiliary blockchain list&lt;br /&gt;
|-&lt;br /&gt;
| 80 || parent_block || [[Protocol specification#block|block header]] || Parent block header&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Merkle link ==&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the parent block header&lt;br /&gt;
|-&lt;br /&gt;
| ? || branch_count || [[Protocol_specification#Variable_length_integer|var_int]] || The number of links to bring the coinbase transaction to the parent block&#039;s merkle root&lt;br /&gt;
|-&lt;br /&gt;
| 32* || branch[] || char[32] || Linking merkle branches&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mask || int32_t || Bitmask of which &amp;quot;side&amp;quot; of the merkle tree hashing algorithm the branch elements need to be applied on&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Merged mining coinbase ==&lt;br /&gt;
Insert exactly one of these headers into the scriptSig of the coinbase on the parent chain.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || char[4] || 0xfa, 0xbe, &#039;m&#039;, &#039;m&#039; &#039;&#039;&#039;(required iff over 20 bytes prior to aux merkle root in coinbase)&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 32 || block_hash || char[32] || Hash of the AuxPOW block header&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_size || int32_t || Number of entries in aux work merkle tree. &#039;&#039;&#039;Must be a power of 2.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4 || merkle_nonce || int32_t || Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.&lt;br /&gt;
&lt;br /&gt;
==Aux work merkle tree==&lt;br /&gt;
If you&#039;re just mining a single auxiliary chain and using getauxblock, you don&#039;t have to worry about this - just set the merkle tree hash in the coinbase to the aux chain block&#039;s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you&#039;re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain&#039;s block hash must slot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int rand = merkle_nonce;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
rand += chain_id;&lt;br /&gt;
rand = rand * 1103515245 + 12345;&lt;br /&gt;
slot_num = rand % merkle_size&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea is that you can increment merkle_nonce until the chains you&#039;re mining don&#039;t clash for the same slot. The trouble is that this doesn&#039;t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they&#039;ll still clash for all possible nonces.&amp;lt;ref&amp;gt;https://bitcointalk.org/index.php?topic=51069.0&amp;lt;/ref&amp;gt; New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.&lt;br /&gt;
&lt;br /&gt;
Once you know where in the merkle tree the different chains go, &#039;&#039;reverse the bytes of each chain&#039;s block hash as given you by getauxblock&#039;&#039; (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to &#039;&#039;reverse the bytes of this again&#039;&#039; before inserting it into the coinbase. If you&#039;re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.&lt;br /&gt;
&lt;br /&gt;
The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block&#039;s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is &#039;&#039;never&#039;&#039; included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you &#039;&#039;don&#039;t&#039;&#039; need to reverse these hashes.)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>MidnightLightning</name></author>
	</entry>
</feed>