# Interactions between Bitcoin and Altcoins

There are many interactions between Bitcoin and Altcoins. In fact, first of all they compete with each other in a sense. In addition, there could be other kind of connections. Think for example as a large Bitcoin mining pool with a lot of computation power. If there’s another small cryptocurrency with the same mining algorithm, this mining pool could be more powerful than 50% of this small cryptocurrency network and decide to influence it.

### Mining power based attacks

Actually, attacks based on mining power have already happened. There’s a famous story regarding an old coin called CoiledCoin. It was a small currency born in 2012. A large Bitcoin mining pool, Eligius decided that CoiledCoin was a scam and launched an attack to its network. This attack involved mining a lot of blocks in order to make and entire day of CoiledCoin transactions invalid. After this attack, all the user moved away from the network and this coin doesn’t exist anymore.
Similar attacks happened against other Altcoins, such as TerraCoin and WorldCoin. In these cases, the attacks lasted less time and the Altcoins survived.

### Merge mining

A clever technique, we have already seen in the previous lesson is merge mining. This feature allows to combine mining of different altcoins. With ordinary mining you can try to find a solution for a mining puzzle for a single cryptocurrency. So, your hash power can be divided among different currencies, but not used at the same time to mine both. For example, Bitcoin mining puzzle requires to compute the hash over a string that depends on the last block. Even if the Altcoin was a Bitcoin fork and shared Bitcoin mining puzzle, ordinarily its puzzle solution would be based on its last block and not Bitcoin’s one.

Otherwise, merge mining is a way of designing the mining puzzle such that every puzzle attempt is also a valid attempt in Bitcoin. This is possible because in Bitcoin blocks it is possible to insert arbitrary data which are not validated by Bitcoin network. For example, it is possible to put data in the scriptSig of the first block transaction, corresponding to minting. This is usually empty and is not checked by the miners.

#### How merge mining works

Suppose the miner puts here the data corresponding to the altcoin previous block and transaction merkle root tree. Now he’s computing a hash over a string which contains both the Bitcoin previous block information and the Altcoin ones. So, every time he computes a hash it could be a solution both for Bitcoin and the Altcoin. This is a way to mine one or more Altcoins onto Bitcoin. This encourages miners to work also on Altcoins with lower value and rewards. But it could also make attacks easier, since miners could use all their mining power for an Altcoin without the need to stop mining Bitcoin. That’s what happened to CoiledCoin.

Many large mining pools in Bitcoin actually provide services to help its members merge mine many compatible coins at once. The most popular Bitcoin mine merged cryptocurrencies are Namecoin, IXCoin and Devcoin. So these become the most popular Bitcoin compatible merge mined altcoins.

### Cross chain swaps

Now, let's see how is it possible to perform transactions between two unrelated blockchains. For example, suppose that Alice wants to send Bob some Bitcoins in exchange of Litecoins. How is it possible to perform this operation if they don't trust each other? Of course, both Alice and Bob don't want to make the first transfer on one blockchain. Since they would have no guarantees that the other would perform the opposite transaction on the other blockchain.

So, we need a method to guarantee that both transactions complete or neither of them. This will take a couple of steps.

#### STEP 1: Bitcoin blockchain

Alice generates a secret key and then Alice and Bob both sign a refund transaction which could have two outcomes. At the end the Bitcoin can go to Bob or come back to Alice. In details:

• Alice generates a secret key $x$ and compute its hash $h$.
• Alice creates a pair of transactions. The first one is a deposit $DepositA$ and the second is a refund transaction $RefundA$.
• The deposit transaction is a transaction that can be spent in two ways and it is published by Alice after she gets Bob signature on refund transaction. It can let Bob get the coins after he signes it. But, it also involves the publish of the secret key $x$. Bob will be able to take the money at the time $T+2$ only if he knows $x$. Otherwise the money will be sent back to Alice at time $T+2$ with the refund transaction.

#### STEP 2: Litecoin blockchain

Bob creates a similar pair of transactions on Litecoin network. In details:

• Bob generates a $DepositB$ and a $RefundB$ transactions and publish the deposit one only after Alice has signed its refund transaction.
• The deposit transaction even in this case has two possible outcomes. The coin goes to Alice only if she publishes the secret key $x$ before time $T+1$, otherwise the $RefundB$ transaction will send the money back to Bob at time $T+1$. Of course, it is possible to verify that Alice published the correct secret key,
since she revealed its hash.

This process guarantees that either both transaction go to the receiver of they both return to the sender. It gives the possibility to exchange securely any two cryptocurrencies that rely on different blockchains.

#### Disadvantages of cryptocurrency swap protocol

Even if this protocol is secure and guarantees the possibility to exchange different cryptocurrencies among untrusted parties, it's not widely used. In fact, it also has some cons:

• This protocol requires many transactions and every one of them will probably require fees and time. So,
it's a bit expensive and time consuming.
• There's still the risk of a service denial. So, you might waste a lot of time in trying to exchange currencies with a stranger and maybe he refuses to sign the refund transaction or doesn't reveal the secret key.

Back to main course page.