Decentralized exchanges are play an important role when it comes to the transfer of digital assets and governing rules.

Transactions are among the most crucial components of the cryptocurrency market. Yet contemporary, centralized exchanges that deal in transactions present an exceptionally weak link in the general philosophy of decentralization.

## Four Key Functions

There are four core functions that every exchange serves, whether centralized or decentralized:

1. Capital deposits - The deposit of financial assets
2. Order books -  An electronic list of buy and sell orders made for a specific security or financial tools that are organized by price level
3. Order matching -  The process in which exchanges match buy orders (or bids) with sell orders (or asks) in order to execute security trades
4. Asset exchange - When asset accounts are involved in a transaction

If one wanted to construct a fully functional decentralized exchange (DEX), then each of these four functions needs to be decentralized. In a majority of exchanges, it is only the asset exchange that is decentralized. This is due to the fact that the assets are cryptocurrencies, which are set up on the blockchain with no one entity controlling them. The other three functions - especially the capital deposits - are typically centralized.

Before we move forward, allow me to explain what KYC and AML regulations are because they play a part in what we discuss next.

## Two types of Decentralized Exchanges (DEX)

A decentralized exchange (DEX) revolves around transacting currencies, and there are two essential models of exchange: Currency-centric and Currency-neutral. Either one of these models can be centralized or decentralized, depending heavily on how the four basic functions of the exchange are handled.

### Currency - Centric DEX

Exchanges that are categorized as ‘currency-centric’ are built on top of singular blockchain platforms, such as Ethereum. A standard currency-centric exchange is limited to escrowing only the currency belonging to the platform that it is built on, an example of this being ERC20 assets and other contracts if the exchange is built on top of Ethereum. This is what is considered to be the traditional structure that exchanges are built on.

### Currency - Neutral DEX

The newer model is ‘currency-neutral’, which is designed specifically to connect different types of native cryptocurrencies. It also means that users do not have to live by any specific kind of currency ecosystem. These particular systems allow users to exchange cryptocurrencies without any coins underlying that trade. So it basically functions as a sort of additional ‘middleman’ to go through as it is technically no longer fully peer-to-peer.

These more recent projects allow the act of securely matching and managing order books and not just asset exchange, in a manner that is decentralized. This is carried out by utilizing the blockchain. Due to an exchange essentially being a community of users, there needs to be a way to broadcast and match orders.

One kind of method of trustless trading is through a system of cryptocurrency exchange that is made from one user to another, called ‘atomic swaps.’ However, these swaps on their own cannot create a trustless marketplace as it is done from one specific peer to another peer. It's more like a larger scale broadcast to pretty much anyone residing on the network.

For those who don’t know, atomic swaps are a piece of smart contract technology that allows the exchange of one cryptocurrency for another without the use of centralized intermediates. They typically take place between blockchains of different cryptocurrencies. Alternatively, they can be done off-chain and away from the blockchain. These swaps are sometimes called “peer-to-peer swaps” due to the fact that the trades are usually made wallet-to-wallet.

## Pros & Cons

Probably the most apparent benefit that a DEX offers is the exact same as with any type of decentralized application (DApp), which focuses very heavily on the philosophy of cutting out the middlemen and returning any related interactions to models that are peer-to-peer and permissionless without any real need for central authorities.

To be more specific, decentralization begets censorship-resistance, which in the general case of decentralized exchanges, basically means that no entity associated with central authority could forcibly impose rules and regulations. Nor could they ban currencies and/or the exchange itself. This point is especially important due largely in part to the fact that a great number of countries are clamping down on cryptocurrency trading. To shine more light on this, the two most populated counties in the world - China and India - have outlawed cryptocurrency exchanges, while countries such as Mexico, Russia, Saudi Arabia, and Brazil have restricted cryptocurrencies.

Without the existence of decentralized exchanges, the people's' ability to invest in crypto of any kind is subject to governments. Thus cryptocurrency transforms into something hardly more democratic than traditional asset markets. Governments can just as easily apply control over centralized exchanges, and users are subject to authority figures who may, at any given moment, track and tax users or even ban currencies.

Other notable merits of a DEX include a heightened level of security. Massive amount of security attacks, much like the roughly $470 million that was stolen from Mt. Gox, were only made possible because the centralized hot wallets (wallets that function on devices that are connected to the Internet, like computers and mobile phones) of the exchange were targeted. This presented a single key point of failure. In any conventional DEX, each user is in private control of their own funds. So there is absolutely no central point of the attack, making it much more difficult to hack. With that being said, as we will go further into later on, numerous exchanges claim to be decentralized - such as the case of Bancor - but are actually hybrid and their centralized aspects make for such noticeable vulnerabilities. For example, close to$23 million was stolen from Bancor not too long ago. The exchange responded with a freeze attempt that was built into their protocol, which is really only possible with an overall structure that is at least partially centralized.

DEXs typically use ‘smart contracts’ in order to facilitate transactions, such as utilizing these contracts as collateral for peer-to-peer transactions. For those of you who are unfamiliar with the concept, smart contracts are self-executing settlements with the terms of the agreement between the buyer and the seller being written directly into lines of code. These kinds of contracts permit reliable transactions and agreements to be carried out among anonymous parties without the need for a central authority, legal system, or outside enforcement.

If the contracts themselves are indeed highly secure, then the exchange will benefit from the cryptographic security of the underlying blockchain. In spite of that, this is usually not always the case. Smart contracts have the capacity to contain many vulnerabilities, including underflows, overflows, attacks on re-entry, and many others. As a matter of fact, studies have discovered over 34,000 contracts with known liabilities. These, along with recent hacks such as the previously discussed Bancor attack, reflect the need for smart contract auditing as a means to validate the security of the code written into the contract and seek out any other vulnerabilities.

Furthermore, a DEX could aid in the progress at a faster rate and supply cheaper transactions than a centralized exchange, seeing as how there is no participation of a third party authenticator. At this point in time, this is all just theoretical and has yet to actually be proven by exchanges on a much larger scale. This is because DEXs have not quite achieved the ‘network effect’ of reaching just enough users for critical mass.

Quite possibly the largest disadvantage of current DEXs is the complete lack of functionality, which is something relative to centralized exchanges. A majority of DEXs only support the most basic of market functions, and not even features like margin trading and stop loss. In actuality, the technology has not yet caught up with the ambitions associated with most decentralized exchanges, though DEXs like BlockDX are planning on providing support for additional functionality.