Cryptocurrencies came to the world to become an alternative to the current financial system. As such, users must be able to pay in a shop as fast as with credit cards. It means that a transaction must be settled within a few seconds. Visa network processes an average of 150 million transactions every day. It is approximately 2 000 transactions per second (TPS). Such throughput is unreachable for current blockchain networks. Normal throughput of PoW networks is usually only a few dozen TPS. PoS networks can reach several hundred TPS.

Distributed networks generally suffer from serious scalability limitations, low throughput, and excessive storage required to maintain the state of the system and its transaction history. After some 5 years of inter-disciplinary research effort in IOHK, the Hydra paper was released. Scientists and researches from networking, multi-party computation, programming language, and consensus branches had to work together to come up with a scaling solution that fits well with blockchain and smart contracts. It is a major scientific achievement and a significant milestone in the development of Cardano. Ouroboros Hydra breaks new ground in PoS scalability. With Hydra, Cardano can really become the alternative to current fiat money.

Hydra is the second layer solution on top of the Cardano first layer where PoS consensus is used. Hydra is designed in a way that fits well with a stake pool model. The IOHK team introduced an extended UTxO model that allows sharding of stake space without the need to shard ledger itself. It is still possible to shard on the ledger level and Hydra is a complementary part of the whole scaling solution. Every pool can create a new Hydra’s head so adding more pools mean that more head can be added. So by adding new heads to the protocol nearly linear scaling can be achieved. Simulations have been done and the results are great. Each Hydra head can process around 1000 TPS and there is room for further optimization. So with 1000 pools, Cardano could be theoretically able to scale up to 1 million TPS and the finality of transactions will be very fast. Hydra enables horizontal scaling. It means increasing performance by incorporating additional nodes. It is always easier than to add additional powerful hardware since there are HW limits.

Hydra will ensure low latency and minimal storage of data per node. Hydra is also able to execute smart contracts so developers can easily build dapps and utilizing micropayments, voting, and other things.

It does not matter if you do not understand all that was written above. Let’s now deep into technical details.

What is the relationship between blockchain and Hydra

The first layer options will always be limited in terms of the number of transactions processed in a given period of time. If decentralization is not to be sacrificed, throughput will never be sufficient to allow a large number of people to use a consensual distributed network. The solution may be to create a second layer above the first layer. The first layer is what we call blockchain. It is the most secure and decentralized network with lower throughput. Above this first layer, it is possible to create a quasi-independent network, a second layer. The second layer is built to scale as high as possible and make transactions fast and cheap. So Hydra is the second layer solution for Cardano’s first layer.

Because the security of the first layer is ensured by blockchain and distributed consensus, we say that transactions are processed on-chain. Users will be able to transfer funds to the second layer. Transactions in the second layer are thus processed off-chain, meaning outside the blockchain. So the first layer does not verify transactions that take place in the second layer.

Let’s show it by example. Alice, Bob, and Carol each have 10 ADA coins in the blockchain, in the first layer. Altogether 30 coins. There is a special mechanism that allows transferring of coins into the second layer. In our case, into Hydra. To be more precise, the Hydra’s head is opened. In the Hydra’s head, all participants exchange coins through transactions. The first layer does not verify these transactions. Once Hydra’s head is closed, the blockchain will only take over the last valid coin distribution from the second layer. Will will discuss the transferring of coins between layers later.

Blockchain can easily verify that from the Hydra’s head expected 30 ADA coins are returned back to the blockchain. So exactly the same amount that was transferred to blockchain during opening Hydra’s head. Coin ownership may have changed in the second layer, with Alice now having 20 coins and Bob with Carol 5 coins. The advantage is that a large number of fast transactions between many users can take place in the second layer and the blockchain does not have to worry about it directly.

o.221e5053241db7c430c979518d141911.png

Alice, Bob, and Carol transfer ADA coins from blockchain to Hydra. Hydra’s head is opened. In Hydra’s head parties can exchange as many fast transactions as they want. In the end, the final state of coins is transferred back to the blockchain.

Alice, Bob, and Carol can communicate with each other directly in the Hydra’s head. It happens in a way that it is possible to forget the history of transactions. Parties update each other about local states and once it is confirmed among all of them the transaction history can be deleted. Thus only the last valid state is maintained in Hydra’s head and used when funds are to be transferred back to the blockchain. We will also discuss it in more detail later.

Hydra’s state channels

Hydra uses state channels, that extends the concept of payment channels. Parties maintain state channels to keep common state and they are able to agree on it without interaction with the blockchain.

Hydra is not only about transferring funds, but also about the execution of smart contracts. Thus it is necessary to work with states. For example, it is possible to create a smart contract in the first layer and transfer it into the Hydra’s head where can be executed.

You can imagine a smart contract as a program or sequence of certain operations that are executed conditionally. This means that an operation is only performed if an expected event has occurred. If not, another operation may be performed. We can talk about the event-driven execution of a smart contract. The smart contract is in a certain state at any moment, which gradually changes conditionally as long as it is active and the events trigger the changes.

 

 

 

 

Imagine a betting office where people can bet on the outcome of matches. The smart contract will be able to lock the deposits of all participants and then fairly distribute winnings based on the results of the matches. If we simplify it, the contract will be in several states per match.