Introduction

Compared to traditional Blockchain, implementing smart contracts based on a DAG (Directed Acyclic Graph) ledger is undoubtedly more challenging. So what exactly are these difficulties and where do they come from?

Cryptocurrency

First, let’s start with most basic scenario — cryptocurrency. The concept of a cryptocurrency is a distributed database that stores the balance information for each account. The computers running in a cryptocurrency network are referred to as Nodes. Each node stores a piece of data about the account balance, which is often referred to as State.

Unlike traditional centralized banking systems, the distributed ledger requires all nodes to reach consensus on the state. In other words, the balance for each account stored on each computer in the network is the same. Since state data may be large in certain systems, transmitting full states causes huge network overhead, therefore, in such systems only events that change states are transmitted, called Transactions. To extrapolate on this fact, your money will not increase or decrease without. The account balance will only change when you pay someone or you are paid. Therefore, as long as you have all the historical transaction records of an account, you can calculate the balance at ease.

In the cryptocurrency system, all transactions are recorded in a data structure called the ledger. The ledger is encrypted by cryptography so that each node can verify whether the data transmitted from other nodes have been tampered with. Blockchain is a classic book structure, and DAG is another.

Blockchain-Based Cryptocurrency

Here the question comes, if the ledger obtained by each node is exactly the same, are they able to calculate out the same states? First let’s look at the ledger structure of the blockchain. In this structure, all transactions are ordered. Changing the order of any two arbitrary transactions will crash the hash reference relationship of the blockchain, thus creating an invalid ledger. Therefore, starting from the same initial state no matter which node performs the calculation, the same result will always present after the same transaction sequence. Exactly perfect, isn’t it? No matter whether it is Bitcoin or Ethereum, there is no need to transfer and compare huge state data between nodes, instead, all that is necessary to do is to reach a consensus on the ledger data. The information contained in the ledger is adequate for a node to calculate the correct state.