Directed Acyclic Graph in Cryptocurrency

A DAG is a unique type of data structure, similar to a database that links various pieces of information. The term “directed acyclic graph” can be a bit complex, so let’s break it down.

Visually, DAGs consist of vertices (the circles) and edges (the lines that connect them). They are directed, meaning they flow in one direction, which is indicated by the arrows. They are acyclic, meaning there are no cycles; once you start at a vertex and follow the connections, you cannot return to that same vertex. This concept will become clearer soon.

DAGs are often used to model data relationships. In fields like science or medicine, they can help illustrate how different variables interact and influence one another. For example, you might analyze factors like diet, sleep patterns, and physical symptoms to understand their effects on a patient’s health.

In this context, we are particularly focused on how DAGs can facilitate consensus in a distributed cryptocurrency network.

How Does Directed Acyclic Graph Work?

In a cryptocurrency that uses a Directed Acyclic Graph (DAG), each point in the graph stands for a transaction. There are no blocks involved, and you don’t need mining to add to the database. Instead of grouping transactions into blocks, each one is linked directly to another. There is a minor Proof-of-Work step when a node sends a transaction, which helps prevent spam and confirms earlier transactions.

When someone wants to add a new transaction, it has to connect to previous ones. For example, if Alice makes a new transaction, it needs to point to earlier transactions. It’s similar to how a Bitcoin block refers to its predecessor, but here, multiple transactions can be referenced.

In some setups, an algorithm decides which transactions (or “tips”) a new transaction should build upon. Tips that are more likely to be chosen are those with greater accumulated weight, which indicates how many confirmations the path to that tip has received.

The transactions Alice builds on are still unconfirmed. However, once she references them, they gain confirmation. Now, Alice’s transaction is unconfirmed until someone else builds on it to get it accepted.

Users tend to confirm transactions with a “heavier” weight to keep the system expanding. If not, there would be nothing to prevent users from endlessly building on older transactions.

With blockchains, preventing double spending is straightforward. The same funds can’t be spent twice in a block, and nodes can easily spot any attempts to do so, rejecting any block with conflicting transactions. Since miners invest a lot to create blocks, they have a strong incentive to act honestly.

DAGs have a way to stop double-spending, kind of like how blockchains work but without the need for miners. When a node checks older transactions, it looks back through the entire path to the very first transaction in the DAG to make sure the sender has enough balance. There might be several paths to check, but only one needs to be confirmed.

If users try to build on a path that’s not valid, their transaction could get ignored. Even if their transaction is legit, if the one before it wasn’t, no one will want to keep that path going.

At first, this might seem a bit odd—couldn’t you end up with different branches that don’t know about each other? And wouldn’t that mean people could spend the same funds on those separate branches?

It’s definitely a possibility, but there’s a selection algorithm in place that prioritizes tips with a greater accumulated weight. This means that, as time goes on, you’ll end up with a much stronger branch compared to the others. The weaker branches will get left behind, and the network will keep expanding on the heaviest one.

Just like with blockchains, there’s no absolute finality – you can never be completely certain that a transaction won’t be reversed. While it’s super unlikely, you could theoretically “undo” a block on Bitcoin or Ethereum, which would reverse all the transactions within it. The more blocks that get added after your transaction, the more secure you can feel about it. That’s why it’s a good idea to wait for six confirmations before you spend any funds.

In a DAG like IOTA’s Tangle, there’s this concept of confirmation confidence. The selection algorithm runs 100 times, and you check how many times your transaction has been directly or indirectly approved by the selected tips. The higher the percentage, the more assurance you have that your transaction will stay “settled.”

Conclusion

Directed Acyclic Graphs (DAGs) are a pretty cool tech for creating cryptocurrency networks. Right now, there aren’t many projects utilizing this data structure, and they still have a long way to go in terms of development.

However, if they manage to reach their full potential, they could enable super scalable ecosystems. DAG tech has tons of applications in fields that need high transaction speeds and zero fees, like the Internet of Things (IoT) and micropayments.