Before we dive into what first-class assets are and why they matter, I think it’s important to talk first about value. How we assign value, and thus what is valuable, drives all of our life decisions. Our value assignments stem from our habits, attitudes, thoughts, and actions. We buy home insurance because we assign value to our homes. Marriage is an institution due to the value put on our relationships with others, and so on. One could almost say that our homes and relationships with others are the best examples of first-class assets that matter most to us.
The idea of first-class assets in software development comes from functional programming. In functional programming, functions are just as important as data, which is not true with all languages. Without going into the details, think about the ability to pass functions into other functions, just like you do data. This equal treatment makes functions “first-class” in functional programming.
In blockchains, first-class assets are defined by ownership. Today, a smart contract can own assets separately from a user. Therefore, we define first-class assets as those digital assets, such as CKBytes (in the case of Nervos Network), tokens, and digital collectibles, under their owner’s exclusive control. The ability to have 1st class assets in any blockchain is related to the blockchain’s transaction model.
Today, there are two main transaction models: the account model and the Unspent Transaction Output (UTXO) model. Ethereum uses an account model, Bitcoin uses the UTXO model, and Nervos uses a version of UTXO called Extended UTXO, essentially Bitcoin + generalized smart contracts that can hold any digital asset. The difference is like having money of various denominations (as in UTXO) in your pocket vs. having a bank account (as in the account model) at a bank. This might seem subtle, but as you’ll see, the difference matters.
This article aims to demonstrate that first-class digital assets on a blockchain matter for the same reason your home or relationships matter–they are valuable.
What is a UTXO?
To define a UTXO, we can use gold as an analogy.
Consider this gaming analogy where you are an adventurer in a world where 1 CKByte (Common Knowledge Byte, the native token for Nervos Network) = 1 Ounce of Gold.
- Let’s say you receive 1.5 ounces of gold (same as 1.5 CKByte) in your leather pouch (same as a UTXO in a Nervos Wallet).
- Now you’d like to spend 0.2 ounces of gold to buy a magic helmet for your next quest. However, the shopkeeper will only accept the exact price and will not give you any change. Also, there are no other shops open on this day.
- Luckily, you have a companion skilled in smelting gold and carrying a melting pot. Great! Your companion can melt the 1.5 ounces of gold down (put your 1.5 CKByte into a transaction)
- This process will mint (UTXO creation) three new gold coins and destroy the 1.5-ounce gold coin (the UTXO is destroyed):
- One 0.2-oz gold coin —> paid to the shopkeeper for the helmet.
- One 1.299-oz gold coin —> your change.
- One 0.001-oz gold coin —-> paid to your companion (analogous to paying miners for mining CKBytes.)
The UTXO model differs from the other main form of ownership, the account model. In an account model, things are more straightforward. In the Ethereum network, for instance, transferring assets is done via two accounts. An asset in one account is reduced while another account is increased. Simple, just like a bank account works.
So why do we want to destroy and create UTXOs every time we want to do something? It does seem like a lot of work, doesn’t it? To explain this further, we need to define why UTXOs are uniquely identified as 1st-class assets and why most assets other held in account-based blockchain are not.
Why is a UTXO a 1st-Class Asset?
What is a First-Class Asset?
We have already defined first-class assets in a UTXO-based system where users can directly access their assets without going through a smart contract.
Let’s use the prior scenario with the Shopkeeper and magic helmet as an example. In the account model, you must go to the shop, put your gold coins in a vault stored in another room, allow the clerk to go out-of-site to access that vault with your coins, then reappear later with the helmet.
In this scenario, we don’t know what happens when they go into that other room to get the coins. We trust things will go smoothly, but we can’t be sure. The analogy here is that the shopkeeper is the smart contract, and the programming in the contract is whatever happens between the time after they leave the room and re-appear again.
With a UTXO model, they don’t get to leave the room to get the gold we’ve deposited in the vault. We melt the gold down in whatever way we need, then hand over the gold pieces. We also give the miner their cut for producing the new coins and leave some change for ourselves as needed. In the Account model, the shopkeeper (smart contract) has control of the account state (producing the helmet). In a UTXO model, the user (and their trusty companion with the melting pot) has control.
Wait a Minute… ETH on Ethereum is a 1st-Class Asset, right?
Correct! But as this clever article points out, ETH is actually the ONLY 1st-class asset on Ethereum. The author says, “Smart contract developers will know that you can have users send ETH along with a transaction and that the amount transferred can be accessed with msg.value.” Remember in the introduction when we discussed the ability to pass functions as objects in functional programming as a criterion for first-class functions? Like functional programming, the equivalent for Ethereum is the ability to pass ETH as an object.
So what about ERC20 tokens on the Ethereum network? Can you send an ERC20 token along with a transaction like ETH? The answer is no.
Instead, ERC20 tokens reassign ownership by updating a shared smart contract. In UTXO-based models, all digital assets are independently owned by the user, not the smart contract, and nothing is “virtual.” We will see why this subtle but essential difference can make a big difference, especially regarding future-proofing blockchains and the dApps living on them.
What Are the Advantages of 1st-Class Assets?
The Nervos cell model allows all digital assets, such as CKBytes, tokens, and digital collectibles, to be their owner’s exclusive property and responsibility. Assets must adhere to smart contract rules when being included in transactions, but the asset inherently belongs to the user instead of the smart contract.
When a user owns an asset, then only that user has permission to use the asset. As mentioned, even the smart contract that defines the token has no permission to access the asset. This means that even if an attacker found an exploit in the contract code, they would remain locked out of the asset because the asset is under user control. The impact of the attack is fully mitigated.
Having defined ownership of the asset also clarifies who is responsible for its upkeep. As assets take up space on Nervos, there will be a small recurring upkeep fee, commonly known as state rent. The user is the owner and responsible, not the smart contract. Other articles cover state rent in detail, so we won’t discuss it in depth here.
So how does a cell allow for 1st-class assets in the Nervos Network? Let’s dissect a cell to find out:
A Cell is defined as the following:
The four fields are as follows:
- capacity: how many bytes of data this cell can hold
- lock: a script; essentially the equivalent of a lock.
- type: a script; think of this like a smart contract.
- data: an unformatted string where any type of data can be stored.
Because every cell can (1) be unlocked (using the lock field), separately from running its business logic (the type field), and (2) store any data it wants (in the data field), a cell can be considered a 1st-class asset. This is because each cell can contain its own unique attributes and behavior. This level of flexibility makes assets held in a Nervos cell different from those in an account model. In an account model, the smart contract controls the attributes and behavior of all digital assets locked in that smart contract. In a cell, it is the user.
Here, with cells, we are forming the basis for a more flexible programming model, best described as a blockchain “primitive.” These primitives are like characters in the alphabet, allowing developers to achieve an ever-increasing level of flexibility and complexity of expression.
For contrast, let’s look at an example where in Ethereum, a user would like to reference two digital assets in one transaction involving two different shards. For reference, sharding is a scaling mechanism that breaks up the Ethereum blockchain into separate chunks to speed up transactions.
Ooops… It’s not possible.
This is because, on Ethereum, each shard and its associated set of account balances and smart contracts are separate from every other shard. With 1st-Class assets, there is no such problem. We can easily put primitives into batch transactions because cell primitives are independent of one another and not isolated like assets on different shards.
This all matters when it comes to scaling a blockchain for world-level adoption. In some sense, scalability is already built in with UTXO-based models like the Cell model–no sharding is necessary.
What Do 1st-Class Assets Matter?
First-class assets matter for many other reasons and have advantages like the following.
- …transfer ownership of their digital assets more easily.
The Cell Model separates the authorization logic (key to unlock the cell) from the business logic (smart contract as you’d typically think of one.) Using the cell model, holders of an asset can easily reassign ownership by updating just the authorization portion of the cell. This is a feature that developers and users alike find attractive.
- …have more security for their digital assets and prevent double-spend attacks.
Going one step further, because authorization logic is separated from business logic, even if a hacker finds an exploit in the business logic, they remain locked out because the asset is only accessible via the authorization logic. Even the smart contract that defines the token is denied permission to the user’s cell and the contents within. UTXO-based assets like the Cell model also prevent double-spend attacks by ensuring that the unspent contents of a cell are only used once, then destroyed, creating an inherent security mechanism.
- …have less state rent “risk” for their digital assets.
We covered state rent in the last section. Each user has separate assets and independent asset states with the cell model. The problem with account models is that state rent is shared amongst all smart contract users. Let’s say, for instance, that maintainers of an account-based smart contract who are normally responsible for paying state rent for the contract itself simply stop paying! Who will then pay for state rent on that smart contract?
Other issues with account models and state rent include:
1. How do you continually collect rent from your users?
2. If the state rent isn’t paid, the contract could get archived, meaning the users can’t use it.
3. Data on Ethereum is rarely removed since there is no incentive to do so, even if you stopped using a potential contract. Bloat can run rampant.
4. If data isn’t removed, active users carry the burden of state rent for all users, including old users who have stopped using the contract but still have data there.
With the cell model, the state rent problems mentioned above are all addressed by design. State rent becomes the user’s full responsibility, giving them greater control of their assets. With the cell model, there is no mixing, and thus sharing, of state rent with other users.
- …have more ownership of their digital assets.
One of the unique features of the cell model is the separation between the definition of an asset and the asset itself. With an account model like Ethereum, the definition (via smart contract) also contains the collection of user assets. With the cell model, these two are separate. This means that you can tell your users that only they have ownership of their assets–not the issuers, developers, or the asset definition contract. Users can feel that only they get to say what happens to their assets and nobody else.
- …have predictable gas fees, and transactions can’t fail due to insufficient gas.
With the cell model, transactions are deterministic. Transactions get validated on-chain, and the actual computation is done off-chain. This means that when transactions get sent to the chain for validation, the inputs and outputs are already known, including the transaction gas fee. From a users perspective, this is awesome because (1) their transaction fee won’t change; what they see is what they get, and (2) the transaction cannot fail (like often happens on the Ethereum network when network congestion is high) because the required gas fee is known and won’t change.
- … allow for faster transactions.
Due to the UTXO-based architecture of the cell model, Nervos Layer 1 can operate at 200 Transactions Per Second (TPS), which is ten times the TPS of Ethereum 1.0. This is possible for a few reasons. One is because of the deterministic design choices Nervos has made where computation gets done off-chain and only submits transactions for on-chain validation. Secondly, similar transactions can be batched. Third, because of the independence of UTXOs from one another, it is possible to have both parallel computation and workload distribution. These “genetic” superiority advantages of UTXO-based systems over account-based systems allow for faster transactions and, thus, better scalability and UX.
As we’ve seen, the UTXO model gives rise to the equivalent of a 1st-class Asset, just like in functional programming languages. The Nervos Cell model extends the UTXO model by allowing programmatic flexibility and separation of authorization via its lock script from the business logic of its type script. These two small but subtle shifts allow digital assets stored in cells a tremendous number of benefits.
These benefits include easily transferring a digital asset, enhanced security, less state rent risk, true ownership of assets, and faster transactions through a more scalable network. We also saw how cells could be viewed as blockchain primitives and allow developers a great deal of flexibility and programmatic expression. Through 1st-class assets, you achieve a 1st-class blockchain architecture.
The only question now is why aren’t all blockchains UTXO-based? Don’t we all want our digital assets, regardless of what they are, to be considered 1st-class?