Chia Smart DataLayer: A Community Proposal
Disclaimer: The following does not represent the views of Chia Network, it’s not affiliated with Chia Network in any way and it is purely a hypothetical thought experiment on what could be built one day if the idea has merit. This document does not make any claims on future capability and roadmap for Chia Network.
The intended audience of this document are individuals that have an in-depth understanding on how Chia Blockchain already works and can make the distinction between what exists and what does not. While I will try to point out which features are merely hypothetical, there may be areas that convolute what exists and what is merely a proposal.
Introduction
Smart Contracts
The Ethereum network, introduced in mid-2015, introduced the concept of Smart Contracts to the world. Smart Contracts can be conceptualized as decentralized databases that require a monetary transaction to write to, but are free to read from. These contracts also feature a permissionless system for writing to the database, with the contract serving as the interface and rules for interacting with said database. This development represented a significant advancement in the capabilities of the cryptocurrency industry, as it enabled the creation of abstractions such as tokens and non-fungible tokens (NFTs) through interactions between the distributed database and programmed rules.
The architecture of Smart Contracts is based on the “Account Model,” in which each deployed contract functions as a miniature centralized database. Although it is not physically centralized in a single data center, the database is shared among all parties that interact with it.
The Account Model architecture of Smart Contracts enabled immense innovation on distributed ledgers, but it also had a critical flaw. While the Account Model itself is partly to blame, the main issue arose from the collective decision to use it to build financial instruments. On the surface, this may seem harmless, however, computer code is inherently prone to errors and bugs. A token on a Smart Contract is simply an entry in the database that controls which account can access it. The permissionless design of Smart Contracts, however, provides bad actors with endless opportunities to exploit vulnerabilities in the code and alter the database in unintended ways. Since all entries are shared on this single database, when an exploit is discovered, it grants access to everyone’s funds stored on that database. It is safe to assume that when it comes to computer code, discovering an exploit is a matter of “when” rather than “if.”
Smart Coins
One of Chia’s major innovations was the concept of a “Smart Coin” as a replacement for a “Smart Contract.” Recognizing that code is never 100% immune to exploits, Chia aimed to enhance security by limiting the impact when an exploit is found. To achieve this, Chia uses the “Coin Set Model,” in which programmability is embedded in the coin itself, rather than in a smart contract. In the traditional Smart Contract model, a token is an entry in a distributed database. In the Coin Set Model, the coin itself is a primitive on the blockchain and a token is an abstraction built on top of it. By embedding programmability in the coin primitive, when an exploit is discovered, it affects only that instance of the coin. All other coins of the same type remain unaffected. This makes it very difficult, if not impossible, to drain funds from multiple parties with the same exploit. When it comes to financial instruments, this represents a significant improvement in security over the Account Model.
DataLayer
Chia Network’s Data Layer is another major innovation that addresses the issue of storing large amounts of data on the blockchain. The traditional method of storing non-ledger data, such as images in the case of NFTs, on centralized servers can compromise the decentralization of the network and raises questions about the true ownership of the data.
Chia’s Data Layer solves this issue by creating a local database on the user’s machine and writing a “Proof of Inclusion” on the chain for each entry made to the database. This serves as a public receipt that verifies the authenticity and integrity of the data. The data is organized into instances called “Singletons” that are identified by a unique Singleton ID. These Singletons can be broadcasted to the network for other Full Nodes to subscribe to and mirror, allowing for easy access to mirror and read the data.
The Data Layer’s key/value store is highly flexible and can be adapted for various applications. I personally have used a “Document Model” similar to Mongo, where the entire document is stored as the value and the key is the identifier for the document. The Data Layer provides a secure and decentralized solution for storing large amounts of data on the blockchain.
Smart DataLayer: A Proposal
DataLayer, bears some resemblance to Smart Contracts in that it is a freely accessible database. However, the similarities end there. Smart Contracts, in contrast to DataLayer, are not only freely accessible for reading, but also for writing. The Smart Contract interface establishes the rules for interacting with the database, but it remains open to all. On the other hand, DataLayer Singletons can only be updated by the key of the owner.
Recently, Chia introduced a feature called “Offers” that allows any individual to propose changes to a database they do not own. However, it is still a permissioned system as the owner must accept the offer. Additionally, there is no native interface to set the rules for interacting with a specific Singleton. Typically, there is a desktop or mobile application that interacts with the DataLayer in a specific way, but nothing prevents the Singleton owner from bypassing the application and interacting with the DataLayer directly, circumventing all integrity rules that were established. Furthermore, a custom offer does not have to abide by these rules as they are not native. A valid offer would have to be generated by the application that enforces the rules, which requires a certain level of expertise to audit correctly. This is not as democratizing as one would hope. In practice, users often “trust” offers and blindly accept them, as I myself have done when interacting with “Offer Marketplaces” such as https://dexie.space.
This creates a vulnerability for malicious actors. Social engineering has already proven to be an effective means of tricking individuals into approving transactions in Smart Contracts that they do not intend. In the case of Smart Contracts, this often results in the loss of funds for the victim. I believe that Chia Offers on DataLayer can fall victim to the same type of exploit. Although financial instruments have not yet been built on DataLayer, it does not mean that real damage cannot be done to a database that is considered a public good. The benefit of DataLayer is that each change is stored on its own Merkle root, making it easy to audit changes and rollback data. However, this can be difficult if a large number of changes are being made rapidly and the socially engineered root must be hunted down.
If we could enforce custom rules per Singleton on the blockchain natively, this would ensure data integrity for the Singleton. This additional layer would make working with DataLayer offers easier, as the data itself may change, but the structure of the data cannot change. Applications that are considered public goods with many sovereign actors would greatly benefit from natively enforced rules.
The Account Model on DataLayer?
The Account Model, which is utilized by Smart Contracts, presents certain advantages over the Coin Set Model, particularly in the realm of decentralized applications and the utilization of a shared database.
It is important to note that these advantages do not extend to financial instruments, but rather to the potential of utilizing the technology for web3 applications. The Chia Network is currently the only blockchain that is fully equipped to fully embrace the full potential of web3 and it could benefit from a hybrid Coin Set / Account Model as it applies to Data Layer.
Consider the following thought experiment:
Video Game Utilizing Hybrid Coin Set Model / Account Model
Video Game: Socket Monsters
- The backend consists of a Singleton on the data layer that manages World State.
- A singleton(s) representing each bot/npc in the world.
- In game items, and user players/profiles are represented as Chia NFT’s
- In game currency is represented as a CAT token.
- Player interactions can affect world state. (defeating enemies, changing the landscape)
This example describes a game that uses a centralized game state with decentralized actors, where financial instruments are represented using the Coin Set Model and the overarching “world” is represented using the Account Model. Players interact with the world by creating Chia Offers, which are requests for the main world Singleton to commit an interaction. However, without any built-in rules for creating offers, there is a risk of rogue offers that could damage the database. To address this risk, the example suggests using smart contracts on top of the Chia Datalayer to ensure that offers follow the rules of the game and can be accepted rapidly and securely.
Self Executing Offers
The concept of “Self Executing Offers” or “Offer Pre-authorization” would provide a solution to the risk of rogue offers corrupting the game’s database. With this concept, the Singleton would pre-authorize all offers made to it, meaning that as long as the offer follows the smart contract rules, it would be automatically accepted and the database would be updated. This would allow for truly permissionless access to the DataLayer Singleton, as long as a programmable set of rules are followed. The Smart Contract would ensure that the offers follow the rules before it is accepted, and the game world would be updated accordingly.
Conclusion
The idea of a “Smart Datalayer” combines the ability to program rules that dictate how a DataLayer singleton can be interacted with, and “Offer Preauthorization” to allow permissionless write access to a DataLayer Singleton. This concept is similar to a Smart Contract, but it is important to note that the DataLayer is not meant to be a financial instrument. Instead, it is intended for non-financial use cases, such as building decentralized applications on the web3 platform. By providing options for how the DataLayer can be used, it can fully live up to its potential in the web3 ecosystem. It’s important to note that while the same vulnerabilities that apply to smart contracts may also apply to a Smart Datalayer, there would be no loss of funds in the event of an exploit. In the worst case scenario the database can be rolled back to the correct merkle root.
In an ideal world a DataLayer Singleton could be configured in the following ways depending on your use case:
- Free to read database, only the owner can modify
- Free to read database, only the owner can modify it as long as you follow programmed rules.
- Free to read database, Permissionless to write to as long as you followed programmed rules.
With the above capabilities, the Chia Ecosystem can be a complete replacement for a huge chunk of the application space currently deployed on the web.