1. Home
  2. StarkNet
  3. Uncovering StarkNet: Understanding Cairo

Uncovering StarkNet: Understanding Cairo

With StarkNet’s mainnet launch in November 2021 and future plans to further decentralize, StarkNet is well-poised to be a leader within the realm of both blockchain development and ZK (zero-knowledge) Rollup technology. Aiming to offer increased transaction speeds and exponentially lowered costs within a secure Ethereum-like environment, StarkNet is one of the more notable Layer 2 (L2) chains in the market right now. 

It does come with a catch for developers interested in building on the chain. StarkNet primarily uses Cairo as the main programming language, unlike other ZK-Rollups like zkSync2.0, which allows developers to recompile their smart contracts or L1 applications that used programming language such as Viper and Solidity into the L2 execution environment without any change to the base code. 

StarkNet reports that Cairo ranks fourth in terms of TVL (total value locked) among smart contract languages. Applications built on Cairo have reportedly facilitated more than 300 million transactions, created 90 million nonfungible tokens, and facilitated trades valued at $790 million on the Ethereum network.

Clearly, building on Cairo does bring about some unique benefits, as we will be going over in this article. 

What is Cairo?

Cairo is a high-level programming language that is designed to be easy to use and accessible for developers who are familiar with mainstream programming languages like Python and JavaScript. Specifically designed to be used with the StarkNet platform, Cairo includes features that enable developers to take advantage of the unique capabilities of StarkNet, such as its high scalability and the ability to perform off-chain computations.

Von Neumann Artchitecture

As the first universal Von Neumann STARK architecture for any blockchain on the Ethereum mainnet, Cairo is often described as an MVL (minimum viable language) for producing STARK systems. Having a Von Neumann-type architecture suggests that Cairo has a high level of flexibility as memory is shared between instructions and data, so that the level assigned to each can fluctuate depending on the task assigned.

Source: StarkWare 

The Von Neumann architectural form is structurally different from its counterpart, Harvard architecture. The latter is often characterized as having comparatively limited flexibility as there is only a certain amount of memory that can be used for data and a certain amount for instructions. 

Goldilocks Principle 

Cairo also maintains a “Goldilocks principle” in securing a balance between code expressibility as well as STARK prover efficiency. It only contains a “not-too-hot” register list of PC, allocation pointer, and frame pointer, with a minimal instruction set that is able to perform low-level operations efficiently. With a small instruction set, the cost of saving, executing, and reading the program lines is a lot faster as space is no longer required to save the code. However, it is also “not-too-cold” as it supports functions, recursions, random memory and more. 

Cairo is also considered production-ready, meaning that beyond a specification of language, there is also a vast tool chain behind Cairo, such as compiler, virtual machine, tracer, IDE extensions, and application code. As the primary language for StarkNet, any DApps that wish to scale with StarkNet has to be written in Cairo as well. 

Computational Integrity 

One of the primary selling points of Cairo as a programming language is its Computational Integrity (CI). It can be achieved through aspects such as reputation and delegated accountability, as in the case for large banks, or through fraud proofs, such as in the case of Optimistic rollups, where “challenge periods” are made available for the public to dispute suspicious or malicious transactions. Cairo however, aims to generate a computational integrity statement through cryptographic proofs. A cryptographic proof is a consolidation of transactions that is generated by a prover, which is then sent over to a verifier to achieve CI. 

Cairo 1.0

In an announcement in January 2023, StarkWare Co-Founder Eli Ben-Sasson explained the incoming re-genesis of Cairo on StarkNet, coined Cairo 1.0. The incoming upgrade is meant to have Cairo emulate popular programming language Rust, in order to allow developers with general coding experience to begin building decentralized applications on StarkNet’s Ethereum layer-2 network.

The upgrade introduces various enhancements to Cairo’s language, such as improved syntax and language constructs, a comprehensive type system, user-friendly libraries, optimized code, and the requirement to specify data types for strong typing. As part of Cairo’s revamp, StarkNet identified Sierra, or Safe Intermediate Representation, as the primary addition, which functions as an intermediate representation layer between Cairo 1.0 and Cairo byte code.

With this upgrade, it is expected that Cairo will be better eased into the mainstream, such that more builders will be incentivized to bring their projects on to StarkNet. 

It is now possible for developers to begin writing, compiling, and testing programs using Cairo 1.0. It is also worth noting that Cairo 1.0 is continuously being improved and updated with new features, so the latest updates can be found on the Cairo repository.

Related Articles

Leave a Reply

Your email address will not be published.