Video summary

Re{solve} Hackathon Workshop: Cairo Programming Language

Main summary

Key takeaways

Technology

Summary of "Re{solve} Hackathon Workshop: Cairo Programming Language"

Overview: This workshop, led by David Barto (Developer Advocate at StarkWare) and Suton Chen, introduces the Cairo Programming Language, focusing on its general-purpose capabilities beyond just smart contracts on StarkNet. The session includes a detailed tutorial on setting up the development environment, basic programming concepts in Cairo, and testing methodologies.


Key Technological Concepts and Product Features:

  • Cairo Programming Language:
    • Used primarily for writing smart contracts on StarkNet but also supports general-purpose programming.
    • Syntax bears resemblance to Rust but differs fundamentally in compilation and proof generation.
    • Default numeric type is felt252 (field element with 252 bits), which is unique to Cairo and StarkNet's cryptographic foundations.
  • Development Environment Setup:
    • StarkUp: The main tool to install Cairo dependencies, including:
      • scarb: A package manager for Cairo (handles dependencies, compilation).
      • StarkNet Foundry: A testing framework inspired by Ethereum’s Foundry but for Cairo.
      • devnet, sierra compiler, and others.
    • ASDF: A version manager installed alongside to handle multiple Cairo versions per project without Docker.
    • Installation instructions provided for Mac OS, Linux, and Windows (via WSL).
  • Project Initialization and Management:
    • Use scarb init to create new Cairo projects.
    • scarb.toml file manages project configuration and dependencies, similar to Rust’s Cargo.
    • Extensions recommended for VS Code and Cursor editors for syntax highlighting and autocomplete:
      • toml and cairo 1.0.0 (by StarkWare).
  • Basic Cairo Programming Concepts:
    • Functions: Defined with fn, requiring explicit return types.
    • Modules: Files are modules; linked via mod declarations in lib.cairo.
    • Unit Testing: Use #[cfg(test)] and #[test] attributes with scarb test to run tests.
    • Shadowing and Mutability:
      • Variables immutable by default.
      • Shadowing allowed by redefining variables with the same name.
      • Explicit mut keyword enables mutability.
      • Constants declared with const keyword and uppercase naming convention.
  • Data Types and Arithmetic:
    • Unsigned integers: u8, u16, u32, u64, u128, usize.
    • Signed integers: i8, i32, i64, i128 (no i256 or isize).
    • Arithmetic operations supported with overflow and underflow protection that cause panics (tests use #[should_panic]).
    • Felt252 (Field Elements):
      • Default numeric type if no explicit type is given.
      • Supports addition, subtraction, multiplication.
      • No support for division or modulo (causes compilation errors).
      • No overflow or underflow protection due to modular arithmetic nature.
      • Used internally for cryptographic proofs.
      • Can encode "short strings" (up to 31 ASCII characters) by packing characters into a single felt.
    • Byte Arrays: For strings longer than 31 characters, supports unlimited length but only ASCII characters (no UTF-8 or accented characters).
  • Advanced Math with Dependencies:
    • Cairo supports importing external libraries via scarb package manager.
    • Example: alexandria_math package for advanced math functions like fast exponentiation and square root.
    • Demonstrated adding dependencies in scarb.toml and using use statements to bring functions into scope.
  • Gas Usage:
    • Gas metering is relevant only on StarkNet (not in vanilla Cairo).
    • Can be disabled for local testing (cairo_enable_gas = false).
    • Gas usage measures computational resources for smart contract execution on StarkNet.
  • Learning Resources:
  • Upcoming Workshop:
    • Workshop #2 will focus on building smart contracts and testing with StarkNet Foundry.

Summary of the Tutorial/Guide Elements:

  • Step-by-step installation of Cairo environment using StarkUp.
  • Creating and configuring a new Cairo project with scarb.
  • Writing simple functions, defining modules, and running unit tests.
  • Explaining mutability, shadowing, and constants.
  • Handling integers and felts, including

Rate this summary

Your feedback will help improve summaries.

Improve this summary

Reprocess with a stronger model when the summary feels incomplete or inaccurate.

Pro

Translate summary in another language

Pro

Ask questions to this video

Chat for follow-up questions, clarifications, and source-backed answers.

Coming soon

Share this summary

Original video