Smart Contracts may be one of the biggest drive behind the enthusiasm for blockchain. The idea is to digitally facilitate, verify, and enforce the negotiation and execution of a contract, which is carried out simultaneously in a distributed fashion on multiple nodes in a blockchain. However, the current smart contract protocol is far from perfect, suffering from both limited computing capacity and flawed governance.
This article first appeared on Hacker Noon.
Smart contracts, known to be used with the blockchain technology, is a computer program that directly controls the transfer of digital currencies or assets between parties under certain conditions. However, there is one particular characteristic that is lacking which ceases a wider application for smart contracts. In spite of many games and pyramid scheme DApps, this feature is a prominent reason why smart contracts have not been very successful thus far — AI Smart Contracts.
Artificial Intelligence (AI) is not a new term, it has been around since the 1950s. Artificial Intelligence can be defined as human intelligence exhibited by Machines. Earlier works of AI used methods like A*, fuzzy logic, expert systems, and good old-fashioned AI (GOFAI), the same if-then rules that are used in coding most applications including smart contracts. Deep Blue, the AI created by IBM that defeated the world chess champion Garry Kasparov in 1997, used a method called search algorithms to evaluate millions of moves at every turn.
When we speak of AI nowadays, we are actually talking about Machine Learning, an approach to achieve Artificial Intelligence.
Machine Learning works by building models that capture weights and relationships between features from historical data and then use these models for predicting future outcomes.
In 1959, Arthur Samuel, one of the first pioneers of machine learning, developed the first-ever machine learning program that learned how to play checkers better than him. Nowadays, advanced statistics and data are readily available on the internet such as Basketball-Reference.com for NBA statistics and Kaggle, heaven for data scientists to discuss their findings and gather datasets. There are open-source courses like Fast.ai and deeplearning.ai that make deep learning, a technique for implementing machine learning, accessible to everyone. Which sports geek wouldn’t like to create their own system for predicting matches?
In 2016, Alpha Go defeated Go world champion Lee Sedol in board game Go (Go is a Chinese board game which the aim is to surround more territory than the opponent). Alpha Go, developed by Google, used a combination of machine learning and tree search techniques which was trained with a database of around 30 million moves then used reinforcement learning, a subset of machine learning, to play against itself to improve its play.
In a recent interview with MIT Technology Review, Yoshua Bengio, one of the fathers of AI, has expressed his concerns with just a few companies dominating the field of AI. He believes in democracy in AI research as AI research tends to lead to concentrations of power and money. Jeremy Howard, Kaggle master and CEO of Fast.ai, stated that "For its(AI) full potential to be met, the technology needs to be much easier to use, more reliable, and more intuitive than it is today."
It is not an easy task to allow machine learning models to run on the blockchain.
Let’s take an example, the parameters of the original deep learning neural network are float variables that need 32-bits storage space. If the model can be converted into a state with only three values (-1, 0, +1), the storage would only take up 2-bits, which significantly compresses the storage space. Moving from 32-bits to 2-bits, we get (almost) 16x reduction in memory. Lower bit-widths allows more data into the same caches which reduce the frequency to access from RAM. In addition, having floating-point arithmetic is not ideal as it is not well-supported on microcontrollers on some low-power embedded devices (like IoT devices).
And the answers suggest we could modify the models that require less storage and computation power but with lower precision — Compression and Quantization.
Compression modifies the large cumbersome models that reduce the memory requirements while retaining as much of its precision as possible. Lighter models mean less storage space and easier to share over smaller bandwidths.
Quantization is the process of reducing the number of bits needed to store an integer value by reducing the precision of the integer. Quantization in deep learning combines high performance with lightweight inference which reduces the computation and memory costs. Quantization allows models to be executed on the blockchain with relatively low cost but also provides consistent inferred results.
With model compression and quantization in place, Cortex proposed “Synapse”, an integer inference engine to do deterministic AI inference, to make machine learning accessible on the blockchain. One of the core Synapse capabilities is to guarantees exactly the same result of an AI model in heterogenetic computing environments (you can try out the TestNet now). determinacy is crucial in the blockchain, as consensus has to be formed upon smart contract outputs. It is non-trivial for widely-used AI inference engines (TVM, NNVM, etc.) to guarantee the determinacy because modern GPU introduces parallelism into the execution flow. Synapse utilizes both quantizations of AI models and deterministic GPU acceleration to make AI DApps available. With the help of GPU hardware acceleration, AI inference subroutines could behave like a dedicated SHA function in the blockchain’s virtual machine, public verifiable and deterministic.
If you are interested in learning deep learning, check out Jeremy Howard's Fast.ai and Andrew Ng's deeplearning.ai! There are also many GPU cloud services that offer a free trial (like Digital Ocean)and free cloud computational environments (like Google Colab and Kaggle Kernels)to get you started with ease.
There is a lot of excitement around smart contracts these days - the idea that you can run computer programs in a decentralized, transparent, immutable and censorship-resistant manner is a powerful one. However, one severe limitation to the current smart contracts / DApps is that they cannot realistically incorporate and execute AI programs.
Running AI on the blockchain has traditionally been thought unrealistic or impossible due to various factors: the design of virtual machines, nondeterministic behaviors of AI models, and slow transaction speed of on-chain AI inference. Solving these engineering challenges is a nontrivial task and requires extremely deep knowledge of both AI and blockchain.
However, after countless hours of innovation and hard work, on June 26, 6 PM +8 GMT, the Cortex Team is proud to announce the launch of its MainNet:
The first decentralized world computer capable of running AI and AI-powered Dapps on the blockchain.
For the first time in human history, we are now able to efficiently run AI on the blockchain. Instead of a black box, every step of the AI inference is verified by network consensus to ensure decentralization, immutability, and transparency. This has huge implications for the decentralized world into which we are entering, as now smart contracts have become truly smart with the addition of AI algorithms.
In this official announcement, we will first overview the core technical innovations that have made running AI on the Cortex blockchain possible, briefly discuss the applications of AI smart contracts as well as Cortex's vision for an open decentralized AI ecosystem on the blockchain, and then state the next steps in the development plan.
One of the biggest reasons that conventional blockchains like Ethereum cannot effectively incorporate AI is that their virtual machines run on the CPU, not suited for executing nontrivial AI programs. Our CVM, on the other hand, utilizes the GPU, ideal for effectively executing AI programs.
Besides the AI infer instructions, the primary innovation of the CVM is a deterministic inference engine, called Synapse or the CVM Executor, that guarantees exactly the same result of an AI model in different computing environments and thereby making network consensus on AI program executions possible.
In addition, the CVM is backward-compatible with the EVM; therefore, it can run all the Ethereum DApps, and on top of that, incorporate AI into these DApps.
Link for further technical details: https://github.com/CortexFoundation/CortexTheseus/tree/dev/infernet
Due to the nondeterministic behaviors of deep neural network models across different devices, it was not possible to reach network consensus during their execution on the blockchain.
To solve this problem, we developed a deterministic quantization framework, the MRT, designed to convert floating-point models supported by nnvm into fixed-point models executable on the CVM while preventing significant loss of precision. Our quantization method, which incidentally has gained support from the official MXNet team, ensures no overflow and guarantees the deterministic outcome of the model execution.
Link for further technical details: https://github.com/CortexFoundation/tvm-cvm
Cortex uses Cuckoo Cycle for its proof of work algorithm. Cuckoo Cycle is a graph theory-based algorithm that is far less energy-intensive than most other CPU, GPU or ASIC-bound PoW algorithms. The goal is to lower mining requirements, ensuring true decentralization and laying the foundation for future scalability.
The difficulty adjusts dynamically so that on average, a block is produced every 15 seconds, i.e., 15s block time. This rate ensures the synchronization of the system state while preventing double-spend and history alteration unless an attacker possesses more than 51% of the network's mining power.
Link for further technical details: https://github.com/CortexFoundation/CortexTheseus
Almost all traditional apps nowadays incorporate AI to some degree, it is therefore hard to imagine the future of DApps without AI. The benefits of AI smart contracts are as evident as the benefits of smart contracts themselves: transparency, decentralization, disintermediation, immutability, etc. Here we enumerate five use cases thought of by the Cortex team alone, although it is almost certain that the best use cases are yet to be conceived by the community.
For example, a decentralized lending app can run an AI algorithm to determine your interest rate based on your personal credit history. The AI used to analyze your credit score is not a black box, but instead, every step of the AI inference is transparent to prevent discrimination and ensure fairness.
Stablecoins governed by AI algorithms with a clear guideline and transparent coin-issuing/burning process, based on decentralized AI inference network to ensure the coin's validity and its value.
CryptoKitties would be much cuter, more life-like, and unique if they incorporated AI. Imagine these kitties moving dynamically and behaving uniquely depending on your personal experience interacting with them. While Ethereum is not able to execute AI models and allow for this user experience, this is something that Cortex can uniquely enable.
Blockchain finds many use cases in the insurance industry, where immutability, fairness, openness, and transparency are in high demand. AI can help improve underwriting decisions, better manage risks, and prevent fraud. An insurance DAO powered by on-chain AI can bring us better, cheaper, fairer, and less bureaucratic insurance.
Almost every aspect of Uber involves AI, from matching drivers and riders, route optimization, driver onboarding to determining fares. Therefore, if we want to build a decentralized Uber, it is necessary to be able to run AI on the blockchain.
The emergence of deepfakes (AI-manipulated videos that are indistinguishable to the human eye) poses a significant threat to society. Social stability will inevitably suffer if video recordings can simply be dismissed as untrustworthy in court. Anti-fake AI algorithms (algorithms that detect whether a video has been tampered with) will run on the blockchain to ensure their transparency and fairness, especially if they were to be used in court.
Besides enabling AI smart contracts, the other part of the Cortex project is the building of an open decentralized AI ecosystem on the blockchain.
Cortex brings an important new party into the blockchain ecosystem (which traditionally consists of only DApp developers, users, and miners): AI developers.
AI developers upload trained AI models onto the storage layer of the Cortex blockchain. These models can later be either inferred on their own or incorporated into smart contracts by DApp developers. Each time an AI model is called, it's model uploader gets rewards in CTXCs, coming from a part of the network transaction fees. (The transaction sender pays for the transaction fee by setting an endorphin limit and endorphin price, where endorphin is the unit that measures the computational effort required for the transaction, similar to the concept of Gas in Ethereum.)
This economic mechanism incentivizes AI developers to compete with each other in training and uploading better and better AI models, leading to an evolving decentralized AI ecosystem on the blockchain. Thus, good AI models will openly be distributed on the Cortex blockchain instead of being monopolized by a few big corporations.
To start, Cortex has 23 models, trained with four datasets, that serve 7 different purposes. All models have been quantized using MRT (see above), ready to be inferred on the Cortex Virtual Machine (CVM).
Next up, there will be three major milestones that we aim to reach.
First, we will upgrade the CVM + MRT. Right now, MRT is just a deterministic quantization framework - we hope to turn it into a full-fledged programming language that provides a complete instruction set and better deterministic support. Meanwhile, we want to upgrade the CVM to support more AI models, specifically dynamic models.
Second, we want to scale by working on possible layer 1 or 2 solution. Our initial target is to increase the TPS to 1000. We will also improve our DOPS (deterministic operations per second), which currently is at 1400.
Third, we will work to improve the privacy of the AI models. We are researching cryptographic solutions in order to implement shielded on-chain AI inferences. The current thinking is to use zk-starks or zk-snarks as one of the possible layer 1 solutions and trusted computing as a possible layer 2 solution.
Upon the MainNet Launch and the release of Cortex source code, the Cortex team is opening up the development to the decentralized open-source community around the world; however, the Cortex Foundation will continue to provide underlying support to the Cortex blockchain and its open-source ecosystem in many ways: we have established a developer forum (link)and will start to organize online and offline workshops to educate AI developers in navigating the Cortex ecosystem, set up bounty programs, and further develop the open-source technical collaboration mechanism (establish open model libraries and datasets); etc.
In terms of the AI Dapp ecosystem, the Cortex Foundation will work with Dapp developers and companies around the world to help implement more AI Dapps on the Cortex chain.
Meanwhile, we will work on cross-chain support: As programs in other blockchains may require running AI on-chain for reliability and transparency, they will be able to execute the AI models on our chain and get the results returned back to their chain for further processing.
Furthermore, we will closely collaborate with academia and industry for research partnerships and publications. Our unique core solutions to implement on-chain AI inference have already gained support from the official MXNet team. There will only be more of such collaborations and partnerships.
Cortex Wallet: https://www.cortexlabs.ai/wallet
Block Explorer: https://cerebro.cortexlabs.ai/
Cortex Remix IDE: https://cerebro.cortexlabs.ai/remix
Full Nodes: https://github.com/CortexFoundation/CortexTheseus
Cortex Miner: https://github.com/CortexFoundation/PoolMiner
Token Swap: https://medium.com/cortexlabs/cortex-mainnet-token-swap-announcement-c06769c40663
After the MainNet Launch, you can convert your tokens manually or through supported exchanges.
CTXC and ETH use the same public and private key system; thus, your CTXC wallet address will be the same as the ETH wallet address. Please keep your wallet address, private key, and recovery phrases somewhere safe. Follow the below steps carefully, as Cortex will not be able to retrieve your tokens if swap your tokens improperly.
Cortex supports two ways for Token Swap.
###Swap your tokens manually
Please download the official Cortex Wallet (Andriod/IOS/Web) from https://www.cortexlabs.ai/wallet before proceeding. DO NOT trust any unofficial downloading sources.
###Swap you tokens through Exchanges
If you store your CTXC ERC20 tokens in cryptocurrency exchanges, you should wait for the official announcement from the exchanges to carry out the Token Swap process. Cortex has cooperation with multiple exchanges for swapping ERC20 CTXC to MainNet CTXC tokens. The exact timelines will be different for different exchanges.
If the exchange you are using does not support Token Swap, DO NOT send your CTXC ERC20 tokens to the burning address on Ethereum directly from your exchange account. Centralized cryptocurrency exchanges are essentially using a centralized database to manage your account and assets, hense we can not track your wallet address.
Instead, please follow Swap your tokens manually to convert your CTXC ERC20 tokens to MainNet CTXC tokens.