Understanding the Cortex Blockchain

In a previous post, I argued that enabling smart contracts to be more compatible with AI would unlock a host of useful new designs. There have already been some steps in this direction from other projects, notably by Cortex, which is attempting to build a system for executing AI smart contracts. In this post, I’ll do a brief review of the Cortex design.

The Cortex technical documentation provides a useful overview of the Cortex system. At a high level, Cortex is similar to Ethereum, with a set of nodes running smart contracts on top of the CVM (Cortex Virtual Machine). The network is secured with proof-of-work based on the Cuckoo cycle algorithm. An “AI smart contract” on Cortex is a program which runs on the CVM.

Cortex allows users to upload trained machine learning models onto the blockchain. These models are stored on Cortex’s storage layer, a distributed hash table. Storage capacity is tied to blocks. Each block adds an additional 64 kilobytes of storage. Users who want to use this revealed storage space bid for their needs via transaction fees. These fees are called endorphins and are roughly analogous to Ethereum gas fees. One difference is that any invocation of a model uploaded to Cortex nets the model uploader a portion of the endorphin fee. It’s worth noting that the actual storage space isn’t on-chain. Rather, the storage model is integrated into the on-chain contract system, similar to the design advocated here.

The CVM has support at the instruction set level for calling model inference with uploaded models. It’s worth digging into this a bit, since model inference can be quite expensive, requiring many large matrix multiplication operations. The CVM stack attempts to work around this by having full node clients run inference on GPUs. In addition, the CVM provides a set of operators which allow for invocation of common deep learning layers such as Conv2D from within AI smart contracts. At present, it appears as if models are only capable of being invoked for inference; training models doesn’t appear to be feasible on Cortex. In addition, it appears that Cortex currently doesn’t have native support for floating point. The Cortex team has developed a tool, MRT, which quantizes floating point MXNet models into quantized integer models which can be run on the blockchain in a deterministic fashion. Cortex launched on mainnet recently.

The Cortex docs suggest a number of interesting possibilities for ai-dapps, but it’s not clear which of these have been deployed to the mainnet chain yet. It does look like a gaming dapp, digital clash has been developed by 3rd party developers on the Cortex testnet, but it seems that the Cortex community is still looking for a breakthrough use case.

There are a number of intriguing innovations made by Cortex. The implementation of an off-chain storage layer natively integrated with the smart contract layer could enable interesting new types of applications. At the same time though, it seems this design isn’t yet ready for primetime since data availability isn’t guaranteed. I suspect that for now, the Cortex storage layer will a trusted participant, much like datatrusts are at present for Computable. In addition, the design adding 64 KB of storage per block could prove problematic. Assuming block times comparable to Ethereum’s (not unreasonable since the Cortex client started as a fork of geth), there would be roughly 2 million new blocks per year adding 128 GB per year. This might be too small for heavy duty machine learning applications which might require access to more state. In addition, the lack of support for training models or storing data might limit the applicability of AI smart contracts, since contracts would not be capable of aggregating history or retraining themselves.

These caveats aside, I’m excited to see what applications the Cortex community manages to develop in the coming months and years.