Cairo: A new hope for scalable trustless applications

The latest release of Cairo brings new hope to developers to build secure and efficient trustless applications for billions of users. Cairo is a programming language explicitly designed for writing efficient provable programs. It has demonstrated reliability and durability by processing over 300 million transactions worth more than $1 trillion and minting over 90 million NFTs. These statistics emphasize the suitability of Cairo for developers who prioritize security and efficiency while building trustless applications.

With the recent update to Cairo 1.0, Starkware introduced several promising improvements to enable developers to write safer and more expressive code. One notable improvement was the addition of Sierra, a new intermediate representation that ensures every Cairo run can be proven. It makes Cairo particularly well-suited for use in a permissionless network like Starknet, where it can provide robust DoS protection and censorship resistance.

Sierra enables the possibility of collecting fees on failed transactions, which serves as a deterrent to malicious actors attempting to spam the network with failed transactions.

In a panel interview hosted by StarkWare that featured Vitalik Buterin, Eli Ben Sasson (Co-founder & President of StarkWare) highlighted that Cairo smart contracts can be up to 10 times faster than Cairo 0 smart contracts. It showcases the performance boost Cairo has to offer.

Why Cairo?

People in the JediSwap community frequently ask why anyone should care about Cairo. Isn’t it too difficult to learn a new programming language? What’s the point of this language? Can’t we write everything in Solidity?

We decided to write an article explaining why we need Cairo.

A single language for privacy-preserving programs:

Until now, DeFi has driven the majority of blockchain use cases. But as we desire to bring web3 to everyone, we must build apps covering more use cases like games and social applications. And we need to support privacy for many of these apps. These kinds of applications need client-side ZK proof creation/verification. To achieve that, even after using an EVM-based system, you must use a ZK language like Circom. You can not create ZK circuits in solidity. So you end up writing code in two different languages (Solidity and Circom). And maintaining a project in two different programming languages becomes increasingly complicated. Using Cairo, you can write your application logic, including the proof creation/verification part, in a single codebase.

A dev-friendly language:

Until now, to write ZK circuits, you needed to learn a low-level language like Circom. Low-level assembly languages present challenges in terms of readability and writability. They rely on mnemonic codes and low-level constructs that are less familiar to programmers, hindering such languages' learning process and usage.

In contrast, Cairo has taken inspiration from Rust to create a more developer-friendly language that is easier to read and write. Like Rust, it is intended to allow developers to write efficient and safe code quickly. It incorporates well-known programming concepts like variables, loops, and functions, making it simpler for programmers to grasp and effectively utilize.

Additionally, Cairo provides a rich library of built-in functions, eliminating the need for programmers to delve into low-level details when writing complex programs. By leveraging these functions, developers can focus on the higher-level logic of their applications, resulting in increased productivity and reduced development time.

Cairo makes deploying scalable, safe, and verifiable off-chain applications easy and cost-effective

Validity proofs are uniquely positioned to solve scalability for general computation. An off-chain prover can process a large computation (like a batch of multiple turns in a game of poker) and produces an exponentially smaller validity proof, which can be verified on-chain. But, generating STARK proofs for some computations is a relatively complicated process. Developers need to describe their computations in a STARK-specific format. This format is called algebraic intermediate representation, or AIR, for short.

Creating a custom “hand-written” AIR is time-consuming. It is like building a dedicated “ASIC'' for your app. Cairo comes with a single AIR, which is a CPU that can process and prove any Cairo program. It enables a single Verifier smart contract to verify any Cairo application. With this, you only have to write the logic of your app, and you can share the proof with other applications built with Cairo.

Cheaper deployment cost: Because Cairo has a single AIR, we can rely on a single Verifier smart contract. There is no need to deploy a custom Verifier for your custom app. It saves the cost of deploying a verifier smart contract. Cairo’s AIR also leads to efficiency for the off-chain proving service.

Safer application: Since we can rely on a single verifier contract, we only have to audit this single contract. A single set of audits for this contract protects any application from the proof system risk, leaving them to audit only the business logic. Understanding and auditing the business logic is much easier than auditing an application-specific AIR.

Scalability: Since you can share the proof with other applications, and the verification cost is almost constant regardless of the complexity of the computation, it reduces the cost for each application. You can create a single proof for an order book system, a poker game, and an NFT platform and verify it on Ethereum. The verification cost gets divided among the users of all three applications bringing individual tx costs significantly lower.

Conclusion

Applications like DyDx, Sorare, and Immutable have shown the potential of Cairo as a language to build scalable trustless applications. These were just the 1st set of applications built using Cairo. With the ongoing developments of Cairo and Starknet, we will see the development of new exciting applications opening up newer categories. Gaming is the next category ready to be disrupted by Cairo and Starknet. Other than gaming, a few smart teams are working on creating AI, Social media, and payment applications using Cairo.

We can't wait to see what kind of innovation developers create using Cairo, and we’re eager to explore them all. The possibilities seem endless.

Thanks to Henri (Starkware) for helping with the review of this article.


Subscribe to stay tuned for the latest updates and research by JediSwap.

For any immediate questions or requests, feel free to reach out on JediSwap Discord.To delve deeper into these exciting new features, follow the links below.

JediSwap is a 100% community-led, fully permissionless, and composable AMM on Starknet to enable lightning-fast, near-gasless exchange of assets in a trustless manner.

Subscribe to stay tuned for the latest updates and research by JediSwap.

Subscribe to JediSwap
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.