Typefully

Introduction to Cairo 1.0: A Rust-like Language for STARK-Provable Programs

Avatar

Share

ย โ€ขย 

3 years ago

ย โ€ขย 

View on X

Psst ๐Ÿคซ... let's play with Cairo 1.0 ๐ŸŽฎ ๐Ÿงต:
Cairo: Turing-complete programming language for efficiently writing STARK-provable programs Cairo 1.0: Improved language and compiler built from the ground up making it safer, more usable and more rust-like
To run examples:
What does "more rust-like" mean? - Great question Thanks - You're welcome
Function Return Values: In Rust, the return value of the function is synonymous with the value of the final expression in the block of the body of a function
Type System: 1.0 extends the single scalar type 'felt' with a static typing system that includes some abstract "rust-like" data types like Enums, Traits, and literals. The core library includes support for u128 and u256 along with native range checking and arithmetic operations
Variable Declaration: ADIOS to 'local' and 'tempvar' declarations! We now rely completely on 'let' ๐Ÿ‘๐Ÿ‘๐Ÿ‘. It's now also possible employ "rust-like" variable shadowing in the same scope. Even though Cairo's underlying memory is immutable it is hidden from the developer
Arrays: The Cairo 1.0 std library exposes helpful array utils to make manipulating arrays much easier. Looping and iter mechanics will also be supported
Assert/Tests: Similar to rust's 'assert!' macro we have 'assert' to verify various conditions are satisfied. Asserts can be coupled with the 'test' macro to build out robust test coverage NOTE: the utility has been changed to 'cairo-test' here
Borrow Checking: No value of an owned type(e.g. dict or builtin) can be used by a function without taking ownership
Okay "rust-like" WE GET IT! What's new under the hood?
Sierra: (S)afe (I)nt(E)rmediate (R)ep(R)esent(A)tion is the new compilation phase that allows Cairo 1.0 code to be provable. This means that reverted transactions can now be proven, included in a block and protects sequencers from being spammed with bad transactions
Cairo 0.x Compilation: - Cairo -> CASM(Cairo Assembly) Cairo 1.0 Compilation: - Cairo -> Sierra -> CASM
Cairo 1.0 is still under active development: t.co/RbWABh71ws
If there is something you would like to see make sure to let us know here: t.co/IRRWS712iW
or even better CONTRIBUTE! Thanks a lot to @eniwhere_ (some syntax deprecated): t.co/hFsVsSMgML Check the 'ALT/Descriptions' for copyable text
Who wrote this? - Great question Thanks - @DrSpacemn
Avatar

Starknet ๐Ÿบ๐Ÿฑ

@Starknet

Shaping the future with scale and integrity.