Get confused on the merkle tree algorithm 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?
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.