The Good Tech Companies - Expanding Smart Contracts With SQL
Episode Date: October 8, 2024This story was originally published on HackerNoon at: https://hackernoon.com/expanding-smart-contracts-with-sql. In 2008, the alarms on Wall Street rang as sophisticated... traders descended into a primal frenzy. Overleveraged financial institutions, collapsing under... Check more stories related to web3 at: https://hackernoon.com/c/web3. You can also check exclusive content about #smart-contracts, #blockchain, #postgresql, #ethereum, #solidity, #sql, #kwil, #good-company, and more. This story was written by: @kwilteam. Learn more about this writer by checking @kwilteam's about page, and for more stories, please visit hackernoon.com. Current blockchain platforms, like Ethereum, face limitations in handling complex data due to rigid key-value storage, hindering advanced applications. SQL smart contracts introduce flexibility, allowing developers to perform dynamic queries and manage intricate data models efficiently on a decentralized network. SQL Smart Contracts unlock the potential for more powerful decentralized apps, revolutionizing blockchain beyond cryptocurrency.
Transcript
Discussion (0)
This audio is presented by Hacker Noon, where anyone can learn anything about any technology.
Expanding smart contracts with SQL, by Quill.
Special thanks to Jun Zhang from DeFi Network and Ryan Sowery from Usher Labs for feedback and
insights. In 2008, the alarms on Wall Street rang as sophisticated traders descended into
a primal frenzy. Overleveraged financial institutions, collapsing under the weight
of subprime mortgage-backed
securities, left greedy bankers exposed and begging for bailouts. The central banks, desperate
to retain their grip on power, paid for the bankers' sins from the common man's checkbook.
This betrayal aid bare the centralized monetary system's flaws, revealing the need for a newer,
freer, and fairer financial system. Just as the American Revolution and THE Constitution that followed separated church
and state, a new revolution called Bitcoin emerged to separate money and state,
enabling many of the similibrities and freedoms fundamental to self-determination.
Blockchain technology is freedom technology. It enables us to build financial, identity,
information, and social
coordination systems that do not require trust in a centralized intermediary. Individual liberties
thrive in a world where the central bank does not control the flow of money, a single platform does
not control social discourse, and a single company does not control digital identities.
Many of the differences between this new world and where we are today lie in the technical capabilities of blockchain platforms. The first generation of smart contracts
was the tip of the iceberg that enabled these freedom systems, however, they are fundamentally
limited in their capabilities. In this article, I explain some of the critical limitations in
current smart contracts and how a new system, SQL smart contracts, provides a more technically
capable foundation to unlock human freedoms and realize blockchain's potential as a new
computing platform. Smart contracts. Programming the truth machine. Greater than, the root problem,
is all the trust that is required to make it work. To Satoshi Nakamoto a blockchain's initial
core property is immutability. Once a certain threshold of
stakeholders, or nodes, in a network agree that something is true, the blockchain will retain a
permanent record of that truth. Blockchains use a variety of proof mechanisms in which nodes expend
large amounts of value in the form of computing power, financial stake, or reputation to ensure
that malicious actors cannot manipulate the truth.
If Bitcoin is the truth machine for digital currency, Ethereum is the truth machine for
more complex financial products. Ethereum expands on Bitcoin's capabilities by creating a programmable
design space where developers can implement any logic to be deployed, verified, and executed
across a series of nodes. This means we can now
create systems that remove the need for trust in a central authority beyond just currency.
Any system requiring central authorities such as lending, real estate deeds, identity information,
social media, economic metrics, etc. can now operate without central intermediaries.
This is an entirely new world. A smart contract is a
program developers write and deploy on a blockchain, the canvas for developers to
create decentralized applications. The term smart contract does not mean a legal contract
where two parties are bound to certain rights and obligations. Instead, a smart contract simply
means that the application is guaranteed to function exactly how the code is
written indefinitely. Lending contracts guarantee that borrowers and lenders can always transact.
Real estate contracts guarantee that people can always verify and transfer property ownership.
A smart contract is an application where code becomes law. Steve Jobs called the computer
a bicycle for the mind. Smart contracts guarantee that the wheels
never fall off. Ethereum smart contracts, tip of the iceberg. Greater than crypto is not just
about trading tokens. It's part of a broader ethos of greater than protecting freedom and
privacy and keeping power in the hands of the little greater than guy. Vitalik Buterin,
although Ethereum smart contracts introduced a whole new world of decentralized products, fundamental limitations in their design and
data manipulation capabilities prevent them from being effective in many applications
beyond cryptocurrency.
In Solidity, a programming language for Ethereum, contract data is stored in key-value pairs.
Although structs, variable groupings, and mappings, collection of key value pairs, present helpful ways to organize data, all data is only retrievable by its key.
Consider a theoretical contract for storing user identity data in this contract.
A user's identity record can only be retrieved by knowing the user's country and wallet address. Unless the contract deployer redesigns the smart contract to have high gas cost data manipulation,
there are no other ways for the contract user to retrieve an identity record.
Storing data in key value pairs ultimately limits how the data can be accessed and manipulated.
In particular, data management in Ethereum smart contracts presents two fundamental problems,
index dependence and access path dependence. Index dependence
means that to access a specific piece of data, the data must be available in an index.
An index is a data structure that efficiently searches for a unique identifier within a
collection. In the example KYC contract above, records are only accessible through the exact
Ethereum address used for the key. This rigid indexing structure prevents contract users from querying the data based on other
criteria, such as, which users have this residential address? Or, what percentage
of users with this national ID were born after January 1, 1970? Without the ability to perform
such queries, developers lack the flexibility to aggregate, analyze, and build application logic
around contract data. When developers need this additional flexibility, such as retrieving an
identity record by full name, the entire contract needs to be restructured. In Ethereum, restructuring
indexes can also increase a contract's gas costs, further hampering the contract's usability.
Access path dependence Access path dependence
refers to data being accessible and understandable only through a specific retrieval path.
In the example contract, knowing Vitalik's country and wallet address would allow a developer to
retrieve his identity record. However, knowing only the wallet address would not allow a developer
to get Vitalik's country of origin. Furthermore, even if the
developer has Vitalik's wallet address, they cannot get his identity record unless they also
know the country of origin, the Canada key. The access path to Vitalik's identity record is fixed.
If a developer needed to try to retrieve his record by just the wallet address,
the entire contract would need to be restructured. Access path dependence means that data is
accessible and meaningful only in one direction, limiting the ability to query or interpret the
data from different perspectives. Index and access path dependence pose significant challenges for
applications requiring a complex or evolving data model. While cryptocurrencies have simple
data structures that can be implemented on Ethereum, ERC-20 tokens are essentially just a mapping of addresses to balances.
These challenges become problematic for more data-intensive applications.
When an application needs to store, query, and manipulate a complex data model,
Ethereum's basic key-value storage makes data management significantly more limiting,
making it challenging to build and maintain applications requiring complex data management. A brief history lesson, the relational model,
greater than, history doesn't repeat itself, but it often rhymes, Mark Twain in 1970, Edgar F. Codd,
a computer scientist at IBM, published a paper called, A Relational Model of Data for Large
Shared Data Banks. At the time, the most popular type of
application database was the hierarchical database, which you said a rigid tree like structure where
each piece of data was stored under a parent directory, similar to how files are organized
on a computer. Cod argued against the hierarchical database, proposing a newer, simpler, far more
capable relational database with a tabular structure.
The hierarchical database's tree-like structure means that data can only be accessed through the
rigid system of understanding each piece of data-sparent-child relationship.
In particular, COD identified three key problems with the hierarchical system 1.
Ordering dependence. The result of a query often depends on how the data is organized in storage.
If an application is built assuming that data will be queried in the same order it is stored,
then the order cannot be changed in the future.
2. Index Dependence
To access a specific piece of data, the application must know the parent, i.e. an index.
Otherwise, retrieving the requested data is impossible.
3. Access path dependence. Accessing or understanding data requires following a specific retrieval path. If the application is designed to retrieve data using one particular
access pattern, it cannot retrieve or interpret the same data using alternative paths.
Backslash dot. Does this sound familiar? Although Ethereum smart contracts do not have
ordering dependence, maps are unordered, the same index and access path dependence limitations that
held databases back in the 1960s and 1970s are holding backsmart contract platforms today.
Limitations at the database level are more than a trivial setback. They fundamentally
constrain developers and limit the types of applications built on a platform. Rather than focusing on implementing new features, developers fighting
index and access path dependence must spend an extraordinary amount of effort maintaining an
existing application's functionality. Through the 1960s and 1970s, database usage was primarily
reserved for rigid business tasks such as inventory management, accounting, and general data processing. Developers did not have the data flexibility
to create more sophisticated applications. However, after the introduction of relational
databases, significantly more expressive and data-intensive applications emerged,
leading to the rise of ERP systems, CRMs, and business intelligence tools.
Furthermore, with the advent
of the internet, these advancements paved the way for e-commerce platforms and social media
applications. Developers could implement features that would previously require an entire database
to be restructured with just a few lines of SQL. The relational database was more than a paradigm
shift. It was a category-creating platform that enabled
fundamentally new applications to cominto existence. Today, blockchain platforms are
similar to computers and databases in the 1970s. The lack of capable data processing at the
blockchain level means developers cannot implement more sophisticated, data-intensive decentralized
applications. If the primary use case for blockchains will
ever expand beyond cryptocurrency, we need blockchain platforms with more capable data
processing functionality. SQL smart contracts. A more flexible paradigm. Greater than.
The measure of intelligence is the ability to change. Albert Einstein just as the commercialization
of the relational database in the 1980s led to the proliferation of new applications, integrating relational databases into blockchain platforms
has the same potential to reshape the types of decentralized applications that can be created.
At Quill, we are building a blockchain platform in smart contract language that allows developers
to build decentralized applications that leverage SQL's full expressivity.
With Quill, developers can leverage the relational model flexibility to create more capable,
data-intensive decentralized applications. Consider the same identity storage example from earlier. Rather than storing identity records in a map where each record is only
accessible by its key, Quill allows developers to store the records in a table and leverage
a flexible SQL syntax to query over the table in the original Ethereum smart contract, there was no way
to search through the identities and return all users given a condition, such as national ID,
or to associate a wallet based on a specific attribute, such as a date of birth. Toneable
such functionality would require restructuring the contract to add costly,
gas-intensive functions. However, with the relational model, developers can execute these
queries without any restructuring required, thereby gaining more data manipulation flexibility
without incurring additional costs. For example, the IDOS network is a sovereign blockchain built
with Quill, allowing users and DAPPs to store user
credential information. Leveraging SQ Lover the IDOS network enables 1. Users to be associated
and retrievable by multiple wallets, credentials, and attributes. 2. DeFi protocols to perform
aggregate analyses of where their users are from. 3. Stablecoin protocols to assess which users are from high
risk areas. Backslash dot, enabling the relational model and SQL on a decentralized blockchain
platform allows us to create fundamentally new applications that cannot exist on existing
Ethereum smart contracts. Conclusion, the relational model that revolutionized the
computing industry 40 years ago has the same capabilities to revolutionize the blockchain industry today. In the 1960s and 1970s, index and access path
dependence limited the hierarchical database's usefulness in data-intensive applications.
Today, the same index and access path dependence limit Ethereum smart contracts and their ability
to power decentralized platforms with complex data models. However, by integrating the relational model into the blockchain and providing developers
with the same expressive SQL dialect, we can unlock new types of applications. Just as the
relational database accelerated business demand and helped computers attain mainstream adoption,
it may help blockchain platforms do the same, thereby unlocking a freer,
more decentralized, more trustworthy digital world.
Thank you for listening to this HackerNoon story, read by Artificial Intelligence.
Visit HackerNoon.com to read, write, learn and publish.