Welcome to Part 4 of our Back to Basics series, 'Koselig with Cairo.' Hang on tight folks as we have got something exciting lined up for you ⚡️
By reading the title, you must have already started visualizing pyramids, mummies, and deserts. But today, we will not explore the deserts and the life of the Pharaohs but rather deep dive into Cairo, a programming language that has taken the L2 ecosystem by a storm 🌪
Cairo is a language invented by StarkWare, which was founded in 2018 to scale Ethereum using STARK proofs. We've also covered this in our previous blog, State of StarkWare. You can read it here.
Alright, now let's kickstart with Cairo!
The name Cairo comes from the term “CPU AIR” — an AIR implementing the concept of a CPU. It is an efficient and practical von Neumann architecture that can be used with the STARK proof system to generate proofs of computational integrity.
The Cairo program produces a trace that can then be sent to a trustless prover, which generates a STARK proof for the validity of the statement. The proof can then be verified using a verifier (which may or may not be on-chain).
Alright, now we've got the basic understanding of Cairo. So, let's dive deep and address the following questions one by one:
1. Why learn Cairo?
Today, most dApps are basically a Solidity contract implementing some sort of logic, some frontend, and maybe a backend. These dApps, when successful, inevitably face the scalability problem.
Now, dApps are solving their scalability problems by turning to proof-based L2 scalability solutions. An off-chain component takes over some of the more complex parts of the business logic and communicates with the on-chain smart contracts without giving up on security.
Before Cairo, creating a proof system that covers a specific business logic was hard. With Cairo, the barriers to using proofs to achieve scalability are much lower. You write your complex logic in Cairo, get it proved off-chain, and once that proof is validated on-chain, your smart contract application can use the result trustlessly.
The Cairo blog titled “Cairo for Blockchain Developers” mentions —
The role of the dApp's smart contract changes — from the component in charge of executing expensive business logic, it becomes the component in charge of dealing with the inexpensive consequences of that business logic.
Marquee investor Ryan Berckman also shared his views on StarkNet below:
2. How does Cairo work?
In Cairo, a new concept originated called The Shared Prover (or SHARP). It was released by StarkWare back on February 16, 2021.
The SHARP is the connecting link between the Cairo code and the Solidity smart contract. It has three main components — a prover (off-chain), a verifier smart contract (on-chain), and a fact registry contract (on-chain).
Below, ZK Daily explains SHARP in simple terms:
Now, let's see how the computation works under the hood:
Let's try to understand this concept via an example 🧐
Imagine a blockchain-based Wordle, where you'll get tokens for guessing the correct word. In today's tech, you'll have to write the entire game logic in Solidity. Needless to say, that's an expensive affair.
Instead, you can write this logic in Cairo and execute it off-chain. Here's how:
3. Advantages of Cairo
The Cairo WhitePaper gives us a detailed explanation of Cairo's benefits. Let us check out a few important ones below:
We think the best way to learn a programming language is by writing some code. We've also added comments beside every syntax and logic so that you can seamlessly understand the code.
Input
Output
BIG wins by Cairo
Cairo is fully functional and has already shown results at the production level for many applications!
Have a look at some of the achievements of Cairo ✨
Recently, StarkWare announced Cairo 1.0, a new version of Cairo. The update will have:
To know more about Cairo 1.0 check out this medium blog.
StarkCon
StarkCon is a community-driven conference by ZKX and StarkWare to raise awareness about Cairo and the StarkNet Ecosystem across the globe. The event brings together the leading voices of StarkNet and will have the best of developers, builders, founders, investors, and global media in attendance. Recently, they announced a $50K grant for developers and builders to boost Cairo's development and adoption in India.
Cairo repo
Now, you've got a brief about Cairo and realized the potential it holds!
But, we guess you don't want to stop your journey of learning Cairo here 🧐
So, we've collated some of the best resources to help you learn more about Cairo:
Alright, folks — That's a wrap for the fourth edition of our Back to Basics Series. For now, let's learn about Cairo and work towards a decentralized future. WAGMI 🙌
About ZKX
ZKX is a permissionless protocol for derivatives built on StarkNet, with a decentralized order book and a unique way to offer complex financial instruments as swaps. The protocol is powered by a DAO and will provide an elevated trading experience with gamified leaderboards and unique liquid governance. ZKX's mission is to democratize access to global yields through its offerings to anyone, anywhere.