user11567: From page https://en.bitcoin.it/wiki/Protocol_specification , I understand the merkle tree works like

merkle([a,b,c,d]) =  h( h(a,b), h(c,d) )

But when I do the stratum protocol http://mining.bitcoin.cz/stratum-mining/ , it works something like this 

merkle([a,b,c,d]) = h(h(h(a,b),c),d)

And here is the code
def build_merkle_root(self, merkle_branch, coinbase_hash_bin):
    merkle_root = coinbase_hash_bin
    for h in self.merkle_branch:
        merkle_root = doublesha(merkle_root + binascii.unhexlify(h))
    return binascii.hexlify(merkle_root)

Do I miss anything?

user12503: The Stratum server is delivering a partially hashed merkle branch in the response… for which the miner needs to provide, ‘A’ (the generation/coinbase transaction) concatenated with the ‘first’ transaction (B). The remaining elements of the array are ‘pre-computed’ portions of the merkle tree. As indicated on slush’s bitcoin.cz site (http://mining.bitcoin.cz/stratum-mining) “merkle_branch - List of hashes, will be used for calculation of merkle root. This is not a list of all transactions, it only contains prepared hashes of steps of merkle tree algorithm.”
The items returned by the Stratum server for the merkle branch are essentially [b,h(c,d)…] pre-computed to reduce the number of calculations required later to complete the merkle root.

11567: <p>From page <a href="https://en.bitcoin.it/wiki/Protocol_specification" rel="nofollow">https://en.bitcoin.it/wiki/Protocol_specification</a> , I understand the merkle tree works like</p>

<blockquote>
  <p>merkle([a,b,c,d]) =  h( h(a,b), h(c,d) )</p>
</blockquote>

<p>But when I do the stratum protocol <a href="http://mining.bitcoin.cz/stratum-mining/" rel="nofollow">http://mining.bitcoin.cz/stratum-mining/</a> , it works something like this </p>

<blockquote>
  <p>merkle([a,b,c,d]) = h(h(h(a,b),c),d)</p>
</blockquote>

<p>And here is the code</p>

<pre><code>def build_merkle_root(self, merkle_branch, coinbase_hash_bin):
    merkle_root = coinbase_hash_bin
    for h in self.merkle_branch:
        merkle_root = doublesha(merkle_root + binascii.unhexlify(h))
    return binascii.hexlify(merkle_root)
</code></pre>

<p>Do I miss anything?</p>
 12503: <p>The Stratum server is delivering a partially hashed merkle branch in the response… for which the miner needs to provide, ‘A’ (the generation/coinbase transaction) concatenated with the ‘first’ transaction (B). The remaining elements of the array are ‘pre-computed’ portions of the merkle tree. As indicated on slush’s bitcoin.cz site (<a href="http://mining.bitcoin.cz/stratum-mining" rel="noreferrer">http://mining.bitcoin.cz/stratum-mining</a>) “merkle_branch - List of hashes, will be used for calculation of merkle root. This is not a list of all transactions, it only contains prepared hashes of steps of merkle tree algorithm.”</p>

<p>The items returned by the Stratum server for the merkle branch are essentially [b,h(c,d)…] pre-computed to reduce the number of calculations required later to complete the merkle root.</p>
