Table of Contents
Metamorphosis. Transfiguration. Reincarnation. Rebirth. The newer versions of the Starknet blockchain (now Alpha v0.11.2) and its native language Cairo (now Cairo 1.0) are here with a bang and they’re calling it Regenesis (which is so fitting 😍 you’ll know why as you read on).
What’s the news?
Earlier this year in January 2023, StarkWare Industries announced the first public version of Cairo 1.0. Before that, in September 2022, they shared their detailed Regenesis plan for the Starknet blockchain motivated by Cairo 1.0.
For starters, the updated programming language native to Starknet, Cairo 1.0 is everything that Cairo v0 was BUT also everything that it isn’t. By that we mean it takes several aspects of Cairo v0 but builds upon it with newer, improved features in Cairo 1.0.
As for Starknet, the blockchain has gone through 9 version updates so far. The latest version update known as Starknet Alpha or v0.11.2 is live on the mainnet. It took place on May 31st, 2023 and now requires its users to work with Cairo 1.0-based contracts only.
🔮 Also, we updated our course from Cairo v0 to Cairo 1.0 to match the occasion. Check it out.
What do builders on Starknet need to know?
After the Starknet Regenesis, the following changes are expected to take place within the blockchain.
1. Genesis block
Apart from being compatible with Cairo 1.0-based contracts, Starknet will start from a new genesis block with an existing state.
2. Wallet update
For the users of the current older version of Starknet to benefit from the newer version, they simply need to update their Starknet wallet.
3. No need for migration
Developers who are building dApps aboard Starknet will be required to port their contracts and dApps to Cairo 1.0. Porting will require following a simple upgrade guideline provided by the organization. There is no migration involved. No restart or clean slate either. Everything is streamlined. Applications that follow the given guidelines will be permitted to launch on the Alpha mainnet without any problem.
4. Forced transactions
Cairo 1.0 will support gas metering. This means that Starknet Regenesis will lead to a more intuitive gas fee market. Gas metering will also allow forced transactions from Layer 1 which will enhance the censorship resistance capabilities of the blockchain.
Why the shift to Cairo 1.0?
There is no doubt that newer programming languages have been fangirling over the Rust programming language, but not many have had the guts to pivot. Although Cairo v0 was also inspired by Rust, Cairo 1.0 shares more similarities with Rust.
And while Starknet Regenesis is in line with the changes in Cairo v0, it is important to understand why Cairo’s newer version happens to again use Rust as an inspiration.
Cairo’s version update was triggered by a few significant reasons. These reasons include:
Despite the fact that the Starknet blockchain had handled $790 billion worth of trades and processed over 300 million transactions, Cairo v0 was not inherently a fast language. 300 million transactions in 2 years is not a great number. There are more transactions, some 1.1 trillion, carried out on smart contracts written on Solidity in a year alone.
So the optimization of Cairo 1.0 and the change in its syntax allow it to write more and better smart contracts which will now subsequently increase the overall throughput of the applications deployed on the Starknet blockchain.
Cairo v0 had security vulnerabilities, memory leaks, and race conditions. This is another reason that triggered the advent of Cairo 1.0. It’s a strongly-typed language which provides more ownership and has a new type system.
It also has Sierra which is a new intermediate representation layer that ensures that each run code is proven. This increases security and helps prevent DOS attacks.
Moreover, apart from the genesis block and wallet update, Cairo 1.0 will allow Starknet to include reverted transactions in blocks. This will allow sequencers to be paid on the execution of reverted transactions.
Cairo v0 was not an expressive language. It was not easy to write concise and expressive codes on it. Cairo 1.0 has new functions that do the needful. These functions include but are not limited to pattern matching, nested functions, and generics.
What to expect.
What can developers expect of Cairo? While there have been a number of backend updates on the Cairo programming language, the major front-end update is the change in the syntax. You may expect some familiar concepts if you have been using Rust, since Cairo 1.0 is very similar to Rust both syntax-wise and concepts-wise.
On the backend, you may expect faster compilation, a better interface, ease of writing code, and an increase in overall speed and safety. Here are some pointers that give you a sneak peek into the latest Cairo version:
1. Updated syntax
The syntax of Cairo 1.0 is quite similar to that of Rust. Thus, you may expect familiar concepts and functions. An example is that of traits. It is a concept that allows sharing of a certain behavior across types. While traits don’t exactly behave the same way in Cairo as they do in Rust, there is a similarity.
Then there are generics. You can use generics in traits by specifying the generic type in the trait definition. For example, a code that defines a trait called Comparable can be used to compare any two values of the same type.
Other concepts like mutable variables and return statements that were previously found in Rust and can now be found in Cairo 1.0 too.
2. New tools
You may also expect a considerable improvement in the overall tooling. Cairo 1.0 has a range of tools which include code liner, debugger, etc. Moreover, there are dictionaries and a blazing-fast compiler, and much more.
3. Ownership and references
Cairo 1.0 also has ownership which is similar to Rust. How ownership works is that when doing assignments (let x = y), the ownership of the variable is transferred, which is known as a move. A variable that was moved can’t be accessed later in the scope, and the compiler will throw an Variable was previously moved error. This removes the margin of error while coding and increases efficiency.
All in all, Cairo 1.0 served as a motivation for Starknet to undergo the changes and become Starknet Alpha with its v0.11.2 update. Together, the new dynamic duo in town are here to enhance the security, scalability, and speed of the Ethereum blockchain. So, are you ready to write a smart contract on Starknet Alpha with Cairo 1.0?