Cairo language and Starknet: Why do they exist?


Learn why Cairo Lang was invented, how it can help in the blockchain world, and as a general-purpose language.

Let’s imagine we live in a country that wants to explore space! So, how does this exploration start? By having that country’s engineers do various calculations and experiments, for example, how to save fuel? What is the best launch window? What would be the best trajectory of our rocket?

To solve some of these questions, these engineers developed algorithms and programs that help give answers… They use one of the typical programming languages, let’s say, for example, Rust language!

All was fine and well until they realized that, for some calculations, they needed a supercomputer! But they don’t have such a machine!

And to add insult to injury, the only country with this supercomputer is the rival country!!

What can they do? If they send our algorithms to the rival’s supercomputer, how can they be sure there was no tampering or sabotage with the calculations?

And the answer is – unfortunately, it is not possible to know (verify) this… But wait a minute! Engineers are the ones who constantly work on inventing and building something you need, right?

Solution: Cairo Language

Fast forward a few months, and we have a solution! It is a new programming language called Cairo!

But how does this new language help?

Well, Cairo creates a provable program, meaning a cryptographic proof is generated alongside the result of the computation. But, one more thing that is very important, or crucial, is that the process of proof verification can detect cheating or malfunctioning without re-execution!! In other words, a regular computer can keep a supercomputer honest!

This is possible by relatively complex math (polynomial equations that satisfy certain constraints) and cryptography!

The Cairo language was invented by an Israeli company called Starkware as the first general-purpose provable language, and we will shortly see how Cairo can be used in other interesting ways that were not possible before!

The blockchain scaling problem

The famous blockchain scaling trilemma says that we cannot have optimal Scalability, Security, and Decentralization properties in a blockchain at the same time.

This is why various blockchains sacrifice one of these three properties in favor of the other two, based on their use cases.

The most popular blockchain, Ethereum, has sacrificed Scalability because of its design, that values decentralization and security. This resulted in very high fees during periods of high activity on Ethereum (especially during the bull market)!

On Ethereum, as we can see in the picture, a block producer creates some transactions, and then all the nodes in the network must validate these transactions!

To tackle this problem, various solutions have been considered, and it seems like one of them has emerged that solves this problem pretty nicely – the so-called Layer 2s or Rollups!

The point of “rollups” is to perform the bulk of the activity outside the original chain, meaning – process transactions off the main chain, batch, compress (replace data with computation), and deliver the transaction data to the main chain – Ethereum. This means we can take hundreds of transactions away from Ethereum to a Layer 2 chain, compress them into just one transaction, and send them back to Ethereum.

In this way, Ethereum provides Security and Decentralization, and Layer 2 chains provide Scalability!

But, you may ask, how does this story relate to our already-introduced Cairo language??


Starkware created its own Layer 2 blockchain, Starknet, where you can write smart contracts using the new Cairo language!

Let’s see how Starknet and Cairo help scale Ethereum!

So the idea is that with the power of Cairo Smart contracts, we can do whatever we want on Layer 2 (Starknet), and when we are done, we send only one transaction to Ethereum… But this time, together with proof! If you pay attention, you will see in the picture below that it takes much less time to validate this proof than to execute the hundreds of original transactions!

This can save us a ton of money on transaction fees and enable many more transactions than was originally possible on Ethereum itself, thus helping us solve the scalability problem!



In this article, we explored why Cairo Lang was invented, how it can help in the blockchain world, and as a general-purpose language. We learned about L2-s/rollups, particularly Starknet, and how they help scale the Ethereum blockchain.

But this is just the tip of the iceberg!
If you want to learn more about Starknet, here’s where you can start:

> subscribe shift-mag --latest

Sarcastic headline, but funny enough for engineers to sign up

Get curated content twice a month

* indicates required

Written by people, not robots - at least not yet. May or may not contain traces of sarcasm, but never spam. We value your privacy and if you subscribe, we will use your e-mail address just to send you our marketing newsletter. Check all the details in ShiftMag’s Privacy Notice