143 lines
12 KiB
Markdown
143 lines
12 KiB
Markdown
|
---
|
|||
|
title: "Cryptocurrencies from 10000 feet: the good, the bad, and the fixes"
|
|||
|
date: "2021-03-30"
|
|||
|
---
|
|||
|
|
|||
|
I've followed cryptocurrency for a long time. The first concept I read about was [Hashcash](https://en.wikipedia.org/wiki/Hashcash), which was a mechanism designed to reduce e-mail spam by acting as a sort of "stamp". The proof of work concept introduced by Hashcash of course lead to Bitcoin, which lead to Ethereum and the other popular Proof of Work consensus blockchain-based cryptocurrency platforms out in the world today. In fact, in the very early days of Bitcoin I mined around 50k BTC total, and well, looking at the price of Bitcoin today, obviously I wish I had hung on to them. With that said, I think Proof of Work consensus is a massively inefficient way to solve the problem of decentralized finance. Hopefully this essay convinces you of that too.
|
|||
|
|
|||
|
## Basic Concepts
|
|||
|
|
|||
|
Before we dive into the technical details of how these schemes work, I think it is important to discuss the basic concepts: there are unfortunately a lot of cryptocurrency advocates who fundamentally do not understand the technology. I believe that if you are going to invest in an investment vehicle that you should be fully literate in the concepts used to build that investment vehicle. If you disagree want want to just trade assets that you don't understand, fine -- but this blog will probably not be that helpful to you.
|
|||
|
|
|||
|
Most decentralized finance platforms, like Bitcoin and Ethereum, are built on top of a shared blockchain. In technical terms, a blockchain is an append-only binary log that is content-addressable. Content address-ability is achieved because the blockchain is composed in such a way that it acts as a [merkle tree](https://en.wikipedia.org/wiki/Merkle_tree), which is a type of acyclic graph where each node has a distinct identity (derived from a hash function). These nodes are grouped into blocks, which contain pointers to each element of the graph. When the blocks in the append-only log are replayed, you can reconstruct the entire tree. A good analogy for a blockchain would therefore be the ledger your bank uses to track all of its transactions, or the abstract for your house. However, the use of a blockchain is not required to have a functional decentralized finance system, it is just a common optimization used to provide _assayability_.
|
|||
|
|
|||
|
An asset is considered _assayable_ if a party can ascertain its value. For example, I can _assay_ the value of an options contract by examining the strike price and quantity of shares it covers. You can _assay_ the value of your purse or wallet by putting currency in only a purse or wallet you trust. Blockchains are used in many decentralized finance systems to provide _assayability_: anybody can examine the contents of any purse to determine the value of that purse by walking through the transactions that purse has been involved in.
|
|||
|
|
|||
|
An asset is considered _fungible_ if we can transfer it to others in exchange for goods and services. For example, currency is a fungible asset: you exchange currency for goods and services. However, the asset itself may hold direct value, or its value may simply be _symbolic_. Currency that is itself made from precious metal, such as a gold coin, would be considered fungible, but not symbolic. Paper money such as bank notes are considered both fungible and symbolic. Cryptographic assets are available in both forms, depending on how they are underwritten.
|
|||
|
|
|||
|
A _smart contract_ is a program which also acts as a financial instrument. Most people erroneously believe smart contracts were an invention of Ethereum, but in reality, [Mark S. Miller's seminal work on the topic](http://erights.org/elib/capability/ode/ode-bearer.html) dates all the way back to 2000. Bitcoin and other tokens like Ethereum and its subtokens are all the results of various forms of smart contract. Other forms of smart contracts also exist such as NFTs.
|
|||
|
|
|||
|
## The Current State of the World
|
|||
|
|
|||
|
At present, there are two main decentralized finance systems that most people have heard something about: Bitcoin and Ethereum. These are proof of work consensus blockchains, meaning that participant nodes have to solve a cryptographic puzzle (the work) in order to gain authorization (the proof) to append a block to the chain. Participants are rewarded for appending blocks to the chain by the program which maintains the chain.
|
|||
|
|
|||
|
As more participants join the network, contention over who is allowed to append to the chain increases. This is reflected by the _difficulty factor_, which controls the complexity of the work needed for a cryptographic proof to be accepted as authorization to append a new block to the chain.
|
|||
|
|
|||
|
The benefit to this design is that it keeps the rate that blocks are appended to the chain at a mostly stable pace, which is desirable in systems where transactions are validated by their depth in the blockchain, as it allows for participants to estimate how long it will take for their transaction to be validated to the level they deem appropriate (e.g. a confirmation that the transaction is N blocks deep in the blockchain will take X minutes to obtain).
|
|||
|
|
|||
|
However, because these platforms reward appending new blocks to the chain with non-trivial amounts of currency, the competition over rights to append to these blockchains is increasing exponentially: the estimated energy consumption from Bitcoin mining now rivals that of Western Europe. This obviously isn't sustainable.
|
|||
|
|
|||
|
## Proof of Stake Could Be A Solution
|
|||
|
|
|||
|
A different kind of blockchain governance model has emerged in recent history: proof of stake. These platforms work by choosing a random stakeholder who meets the staking criteria to have rights to append the next block to the blockchain. This mostly works well, but a lot of these blockchains still have other inefficiency problems, for example the staking requirements can effectively centralize authority in who can perform the appends if it is biased by size each stakeholder holds.
|
|||
|
|
|||
|
Proof of Stake, however, _does_ get rid of traditional block mining and the energy consumption associated with it. But these blockchains are still inefficient, because many of them store unnecessary data, which leads to slower lookups of data stored in the blockchain and slower tree building when the log is replayed.
|
|||
|
|
|||
|
There are many ways a proof of stake based platform can be optimized, including to not require a blockchain _at all_. But even in a system where the basic functionality of the network does not require a blockchain, they can still be helpful as an optimization.
|
|||
|
|
|||
|
Ethereum 2.0 is an example of a credible proof of stake based platform that is still heavily tied to a blockchain.
|
|||
|
|
|||
|
## Smart Contracts as Distributed Object Capabilities
|
|||
|
|
|||
|
Building on [Mark S Miller's seminal work on smart contracts](http://erights.org/elib/capability/ode/ode-bearer.html), we can describe a decentralized finance system as a set of distributed object capabilities. We will assume a PKI-based cryptographic system as the foundation of the network, such as djb's Curve25519. We also assume the presence of a distributed hash table running on participant nodes, [such as Kademlia](https://medium.com/coinmonks/a-brief-overview-of-kademlia-and-its-use-in-various-decentralized-platforms-da08a7f72b8f).
|
|||
|
|
|||
|
Each participant will have one or more keypairs which act as locators in the DHT, which act as pointers to _opaque capabilities_. An opaque capability may itself be a contract or a validation proof generated by execution of a contract.
|
|||
|
|
|||
|
In order to keep participants honest, the network will choose other participants to act as _validators_. These validators, when given a proof, will themselves re-execute the underlying contract with the inputs from the proof and validate that the output is the same. If it is, they will sign the proof and give it back to the party which requested validation.
|
|||
|
|
|||
|
Given this architecture, lets consider a very simple purse for a token that exists on the network:
|
|||
|
|
|||
|
struct Purse {
|
|||
|
address\_t m\_owner;
|
|||
|
int64\_t m\_tokens;
|
|||
|
|
|||
|
Purse(address\_t p, int64\_t t) : m\_owner(p), m\_tokens(t) {}
|
|||
|
|
|||
|
pair<Purse> sendToAddress(address\_t recipient, int64\_t tokens) {
|
|||
|
if (tokens >= m\_tokens)
|
|||
|
raise NotEnoughMoneyException();
|
|||
|
|
|||
|
m\_tokens -= tokens;
|
|||
|
return (Purse(m\_owner, m\_tokens), Purse(recipient, tokens));
|
|||
|
}
|
|||
|
|
|||
|
Purse combineFromPurse(Purse p) {
|
|||
|
if (p.m\_owner != m\_owner)
|
|||
|
raise NotOwnerException();
|
|||
|
|
|||
|
Purse newPurse = Purse(m\_owner, m\_tokens + p.m\_tokens);
|
|||
|
m\_tokens = p.m\_tokens = 0;
|
|||
|
|
|||
|
return newPurse;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
Given this library, we can write a smart contract which mints a purse for a given address with 100 initial tokens, and returns it as the output:
|
|||
|
|
|||
|
import Purse;
|
|||
|
|
|||
|
auto Contract::main(address\_t owner) -> Purse {
|
|||
|
return Purse(owner, 100);
|
|||
|
}
|
|||
|
|
|||
|
Given the output of this contract, we can send our friend some of our tokens:
|
|||
|
|
|||
|
import Purse;
|
|||
|
|
|||
|
auto Contract::main(Purse originalPurse,
|
|||
|
address\_t target, int64\_t tokens) -> pair<Purse> {
|
|||
|
auto \[ourNewPurse, theirPurse\] =
|
|||
|
originalPurse.sendToAddress(target, tokens);
|
|||
|
return (ourNewPurse, theirPurse);
|
|||
|
}
|
|||
|
|
|||
|
Now that we have minted a purse for our friend using some of our own tokens, we simply sign the output of that smart contract and send the message to our friend:
|
|||
|
|
|||
|
import SendToFriendContract;
|
|||
|
import Purse;
|
|||
|
import Message;
|
|||
|
import Wallet;
|
|||
|
|
|||
|
auto Contract::main(address\_t target, int64\_t tokens) -> Message {
|
|||
|
// Get our wallet.
|
|||
|
auto wallet = Wallet.getOurWallet();
|
|||
|
|
|||
|
// Get our purses from the wallet.
|
|||
|
auto ourPurses = Wallet.assetsFromIssuingContract(Purse);
|
|||
|
|
|||
|
// Mint the new purse for our friend.
|
|||
|
auto \[ourPurse, theirPurse\] =
|
|||
|
SendToFriendContract(ourPurses\[0\], target, tokens);
|
|||
|
|
|||
|
// Commit our purse to the top of the purse list in our wallet.
|
|||
|
wallet.prependAsset(ourPurse);
|
|||
|
|
|||
|
// Seal the result of our execution in an opaque message.
|
|||
|
auto message =
|
|||
|
Message(wallet.address, target,
|
|||
|
\[ourPurses\[0\], target, tokens\],
|
|||
|
SendToFriendContract,
|
|||
|
\[ourPurse, theirPurse\]);
|
|||
|
|
|||
|
return message;
|
|||
|
}
|
|||
|
|
|||
|
When our friend receives the message, they can request its validation by forwarding it along to a validator:
|
|||
|
|
|||
|
import Message;
|
|||
|
import ValidationContract;
|
|||
|
|
|||
|
auto Contract::main(Message input) -> Message {
|
|||
|
return ValidationContract(input);
|
|||
|
}
|
|||
|
|
|||
|
The validator then can respond with a message confirming or denying the validity. The validated message's purse would then be used as an input for future transactions.
|
|||
|
|
|||
|
Note that I have yet to discuss a blockchain here. In this case, a blockchain is useful for storing pointers to validations, which is helpful because it simplifies the need to maintain assayability by not needing to forward along a chain of previous validations as proof of custodianship.
|
|||
|
|
|||
|
While what I have outlined is a vast simplification of what is going on, there is a decentralized finance platform that operates like this: it's name is Tezos and it operates basically under this principle.
|
|||
|
|
|||
|
Using Tezos is extremely efficient: compiling a smart contract on Tezos uses the same energy as compiling any other program of the same complexity. Tezos is also capable of supporting sharding in the future should it become necessary, though the blockchain part itself is simply an optimization of how the network operates and Tezos could be adapted to operate without it.
|
|||
|
|
|||
|
Ultimately, I think if we are going to have decentralized finance, Tezos is the future, not Bitcoin and Ethereum. But we can still do even better than Tezos. Maybe I will write about that later.
|