Get started with Nervos- An In-depth Overview of Nervos Network Architecture

Get started with Nervos- An In-depth Overview of Nervos Network Architecture

A guide about Nervos Architecture and its comparison to Ethereum! To help you make better dapps

·

8 min read

Introduction

Hey Blockchain peeps and non-peeps, You all might be working on ethereum or starting with it to build dapps in solidity. Ethereum is a great blockchain but still suffers from many problems like high gas fee, computation, etc. This is all due its architectural design. Today we will talk about Nervous network which solves all these problems.

Nervos network is a layer 1 blockchain, meaning its a new blockchain. Its core design principles prioritize security and decentralization. Its is also represented as CKB, same as ethereum is represented as ETH

Native Token of Nervos

The native token of nervous network is known as CKByte or you can say CKB in short. Same as Eth is native token of Ethereum.

The native token of nervos has a better and bigger usecase as compared to ethereum where eth is used only for paying transaction and computation fee. The CKB token not only is used to pay any fees associated with transactions and computation but it also entitles a user to hold one byte of data on nervous network. For example, If you want to store 100 bytes of data on nervous, you must own 100 CKB tokens, which will be locked till the time your data remains on the network and ones you free it, you get the remaining amount back.

Consensus Algorithm Of Nervos

The nervos blockchain uses Proof of Work(POW) based consensus algorithm with some changes and extra features which is now called as NC-MAX. Nervos’ NC-MAX builds on Nakamoto Consensus by improving block propagation, block throughput, and resistance to selfish mining. It provides 10x throughput increase as compared to Ethereum.

How NC-MAX is better

Improved Block Propagation

When a transaction is broadcasted it remains in queue for some time until it is included in a future block. A bottleneck can occur when transaction is not successful. Some nodes might be aware and some do not . This can cause network delays as we have to find the missing transactions and distribute them to all nodes that need them.

NC-MAX solves this by splitting the confirmation process into two steps: propose and commit. A transaction is first proposed to the network. A proposed transaction cannot be confirmed until several blocks later. This gives more time for transaction propagation without slowing down block propagation. Once a transaction has been proposed and fully propagated, then it can be committed. This eliminates transaction propagation as a delay factor to block propagation, eliminating the bottleneck and selfish mining attack.

Improved Block Throughput

A shorter block interval results in blocks being created more frequently. This results in faster transaction confirmation and higher throughput for the network. The downside of a lower block interval is that internet congestion has a greater effect on the ability of the network to properly synchronize. Blocks are sometimes created while the network not fully in sync, creating what is known as an Orphan Block. This means that the efforts towards network security are temporarily divided. Having some Orphan Blocks is unavoidable, but if too many occur in a short period it becomes counterproductive.

NC-MAX improves this by automatically adjusting the block interval based on network performance. The number of Orphan Blocks created within a time frame is tracked and taken into consideration by the consensus protocol. The network is then able to adjust the block interval to maximize throughput while maintaining an expected Orphan Rate. This results in dramatically shorter block times without sacrificing security.

Improved Resistance to Selfish Mining​

Selfish mining is a practice where certain miners are able to secretly gain a larger share of mining rewards while contributing less hash power to the network. This is discouraged because it weakens the overall network security and can lead to irregular block times while causing congestion problems.

NC-MAX offers the most accurate measurement of the network’s computing power by taking into account both external and internal factors. This new model makes all known selfish mining attacks unprofitable because the actions they would perform to exploit the computing power calculation are now properly accounted for.

The Hashing algorithm of Nervos

As you might be knowing that keccak256 is the hashing algorithm used in Ethereum, Bitcoin uses SHA256. Similarly the Nervos uses its own new hashing algorithm called Eaglesong.

The Virtual Machine(VM) of Nervos

Ethereum’s virtual machine-based programmability opened the door for Turing complete development on the blockchain. Nervos takes this one step further by utilizing the RISC-V instruction set to create the CKB-VM.

The CKB-VM is a virtual machine that executes smart contracts on Nervos. It is a full computer being emulated through software. It provides developers with the maximum amount of power and flexibility while maintaining a secure high-performance environment

Smart Contracts in Nervos

Nervos blockchain Supports smart contracts. You can write your smart contracts in general-purpose programming languages such as Javascript, Rust, and C. You just need to import modules in these languages to write code using that.

The model of Nervos - Cell Model

Let us now discuss how nervos store data under the hood. How it is different from ethereum.

What exactly is cell model

image.png A Cell is the most basic structure needed to represent a single piece of data in Nervos. The data contained in a Cell can take many forms, including CKBytes or tokens, code like Javascript, or even serialized data like JSON strings. There are no restrictions on the type of data included, so developers have complete flexibility in what they choose to work with.

Every Cell contains a tiny program called a Lock Script that defines who has permission to use it. Most commonly a Lock Script will define a single user as the owner of the Cell, but it can also do more complex operations such as having multiple owners (multi-sig) or time-locking for conditional usage within certain time-frames.

A Cell can optionally include a second program called a Type Script that enforces a set of rules on how the Cell can be used. This gives developers the ability to create complex smart contracts that have a wide range of use cases from CryptoKitties to tokens, DeFi, and everything in between.

image.png The cell model is inspired by UTXO model of Bitcoin, where we were just storing value but here we are storing data. Cells are immutable meaning they cannot be change once added to blockchain. If we have to update them we need to destroy them and create new ones with updated data, which we represent in a form of transaction. As cell represents single byte of data, so a transaction will mostly contain a group cells which represent some value or code in real world, which you will update by first getting the data, executing lock and type scripts and then putting back in a new cell. This model is really great and given many powers to blockchain in terms of efficiency and scalability.

Features of Nervos as compared to Ethereum

image.png

  • User Control : If you are creating a asset using smart contract on nervos, its owner will always be the real owner not any contract in any case. While in ethereum you know that you can transfer things using contract and some times contract are owners of users data which is not the case here. This increases security as if any exploit was found in the contract code still the attacker would not be able to do anything as assets lockscript needs the real owner.

  • Anyone can pay fee : In ethereum if you need to pay transaction fees on users behalf then you have to go for meta transactions and a lot of code is to be written to do so. But the nervos provide inbuilt feature where the transaction fees can be paid by anyone on the users behalf. This is a real advantage in terms of user experience.

  • Less Computation, only Validation : Ethereum when submits a transaction, let say a solidity function call, it is propagated to the network and then on all the nodes connected to the network that set of code is executed and then validated before including in the block. As you can see the computation is happening on all nodes which reduces performance of the blockchain. Nervos on the other hand separates the concepts of computation and validation for smart contract execution. Computation is the process of generating new data and it is done off-chain before a transaction is sent to the network. Validation ensures that the data conforms with the rules set by the developer and is done on-chain by full nodes after being received by the network.

So basically you do computation on your side and once you get the result you pack in a transaction with inputs and new output and send it to the network for validation. The nodes will validate whether for the input, the given output can be generated and if yes the transaction is complete.

  • Better VM Execution : Also, Smart contract execution is parallelised in the Cell Model. Every transaction runs independently in its own virtual machine, and multiple virtual machines run simultaneously instead of having to run one after the other. This allows the Cell Model dramatic scaling improvements on modern computers that increase the number of CPU cores they offer with every new generation.

  • Flexible Transactions : Transactions are very flexible in the Cell Model. Multiple smart contract operations can often be batched into a single transaction instead of having to construct multiple distinct transactions. This cuts down on the overhead involved with a transaction, streamlining the process by reducing the amount of processing and transaction fees required.

This was all about the Nervos network and I hope this will help you to get started with it.