In this post we want to take you on a deep dive into the technology behind the Elrond network. First of all, a broad overview on Elrond will be given which illustrates why this is a highly interesting project. Then the actual implementation of the introduced features will be discussed. This includes Sharding, the consensus algorithm as well as smart contracts on the Elrond Blockchain.
Background, History and Numbers
The Elrond project is one of the youngsters in the world of blockchain projects, yet it has been growing with a tremendous speed in the last year. Since the mainnet went live on July 30th 2020, Elrond has registered over 1 million addresses and more than 15 million transactions on the blockchain (as of November 2021) . A special boost to the number of addresses was given by the release of the Maiar App which offers a simple and intuitive way to interact with the blockchain.
Now one of the fascinating parts of this project is how much effort has been put into the development of a mobile wallet (aforementioned Maiar App). It does not only allow for an easy wallet setup and is highly secured, but it gives access to EGLD and other assets to not-that-technically-adept users. And if you have been around for some time, you know what we are talking about.
Wallets have become easier to use, but overall the complicated usage, along with the fact that for most assets you need different wallets, makes it hard for beginners to become part of the space.
At the heart of the Elrond project lies a blockchain which tries to solve the classic blockchain trilemma:
The interesting solution the Elrond team came up with includes a Secure Proof of Stake consensus mechanism built on top of a chain which uses sharding with redundant states. (Keep on reading, we’ll explain in a bit!)
Since the blockchain is based on Proof of Stake, blocks are added in epochs of 24 hours and rounds of ~5s. In each round one new block can be proposed per shard.
First Things First: Sharding?
Buzzword alarm: Sharding. The term sharding is generally used to describe a decomposition of a database into multiple smaller units. Those units are then able to handle requests on their own. Sounds like black magic in the case of a blockchain? Here is how it works on Elrond.
The whole address space is divided into multiple parts, the shards. Which shard your address is being assigned to depends solely on the last bit of the address. Say there are 2 shards in the network and your address ends with a 0, congrats! You are part of shard 0.
Assuming your address would end with a 1, you’d be part of shard 1. (don't blame us that it starts counting at 0!)
Since this process is deterministic you can fetch a random address from a block explorer and be able to tell which shard it belongs to, given you know how many shards there are.
This gives a tree that looks somewhat like the following:
What the State?
The state boxes explain the redundant states mentioned above. Each shard stores the state of its neighbor shard in order to add more security to the network in case a shard fails.
How do you compute the number of shards now? Well, the number of shards is computed using the number of nodes in the next epoch and the number of shards in the current epoch. If there are more nodes per shard than a certain threshold, a new shard will be added.
At this point you might ask yourself: if I’m on shard 1 and want to send some EGLD to an address on shard 2, how does that work?
In a nutshell, there exists actually an extra shard, the metachain, which records transactions between shards. The two shards in question synchronize with the metachain to know transactions that include accounts in their address range. The metachain uses so-called miniblocks to do that.
Here is a sketch of what it looks like for the scenario from above.
It works basically the same way for smart contract calls across shards.
Secure Proof of Stake
Elrond uses a consensus mechanism called Secure Proof of Stake. This type of mechanism selects the next node that will be able to propose a block using a combination of stake, randomness and age. The Secure part in this case comes from the selection process which is random (which makes it impossible to predict the next selection) but also includes a rating. Ratings can be increased for being an honest block proposer or decreased or dishonest acts.
To make it even more secure, the signing of the blocks is based on modified practical Byzantine Fault Tolerance. That's a mouthful but in a nutshell it says that one third of the signers must be honest to prevent an attack.
One more security feature: challenges (bear with me it's the last point before moving on). Nodes can raise challenges if they detect an invalid block. To avoid having challenges against all blocks all the time, raising an invalid challenge costs the entire stake of the node. If you, however, raise a valid challenge, you will be rewarded with a part of the amount that will be slashed from the validator node that proposed the block. (worth it)
Last but not least: Elrond has Smart Contracts. And they are set up in a clever way. Because the VM infrastructure (which is responsible for the Smart Contract executions) is based on the K Framework, interpreters in any language defined in K are an option.
Long story short, the Elrond VM hides the underlying structure and is happy with any Smart Contract written for the Ethereum Virtual Machine and even in WASM. That in turn enables Smart Contracts written in C/C++, Rust and C#. In case you are not a programmer: this opens the blockchain to a large number of developers!
How is it going then?
The Elrond team made huge progress in the last year and just launched its own Decentralized Exchange, the Maiar DEX.
It remains an exciting project with a lot of possibilities. And as such, it is the perfect Layer 1 Blockchain for us to build upon, with low transaction fees and fast interaction times.
If you made it that far: congrats, we hope you learned something! If you have any questions or want to discuss other aspects of the Elrond project, feel free to leave us a comment.
And stay tuned: in the next post we will discuss the tokenomics of Elrond.
If you want to dive deeper, you can have a look at the following resources we used to write this article.