Starknet’s Cairo programming language: myths vs facts
Cairo enables L2 scalability reaching 10,000 TPS via StarkEx rollups, though a Code4rena audit of the Starknet Perpetual system revealed 5 unique vulnerabilities in 3,846 lines of code. Developers must balance Cairo's verifiable computation against the broader library support of Rust.
Scaling via ZK proofs
Developers building on Starknet trade a steep learning curve in ZK cryptography for the ability to reach 10,000 TPS via StarkEx rollups, a performance level that applications like dYdX achieved through Cairo-based rollups. I view the scaling philosophy of Cairo as building verifiable computation that settles on Ethereum. In contrast, Rust optimizes for execution efficiency within a single state machine, such as Solana’s Sealevel, which processes 4,000 TPS. I see the trade-off clearly: you choose Cairo for L2 scalability or Rust for the broadest library support and a larger developer pool. While Solidity uses explicit syntax and prioritizes ease of understanding, it contains security pitfalls. Solidity places the visibility keyword before or after names, whereas Cadence follows a visibility-type-name sequence. Cadence, used in the Flow blockchain, is an interpreted language that uses a resource-oriented approach where resources can only move between accounts and cannot be copied or discarded. Cadence also uses Capabilities to allow access to items, utilizing public or private permissions. Move, used in the Sui and Aptos blockchains, uses a module structure and a bytecode verifier to ensure scarcity.
The reality of Cairo audits
I find the lack of a compiler audit for the Cairo-to-Sierra pipeline a major oversight. While the Sierra-to-CASM compiler satisfies certain semantics, the Cairo-to-Sierra compiler lacks an end-to-end audit. During the Code4rena audit of the Starknet Perpetual system from March 19 to April 09, 2025, researchers found 5 unique vulnerabilities in 3,846 lines of Cairo code. These included 2 high severity and 3 medium severity issues. One high severity finding allowed an arbitrary signer key to bypass oracle signature validation because the system returned an empty packed asset instead of panicking, and another high severity bug in the risk engine allowed liquidators to turn a long position into a short position. If a liquidator purchases 25 ETH when the price sits at $1500, the position results in a synthetic balance of -10, breaking the protocol because it forces a change in market direction without user consent. I also find the funding index validation flawed because get_synthetic_price uses self.synthetic_timely_data without checking if the price is current. Because assets.price_tick() relies on this, invalid funding rate changes might pass validation if the price is stale. Furthermore, the _execute_transfer function applies an apply_diff state change before validating health via _validate_healthy_or_healthier_position. Finally, assets.add_oracle_to_asset() allows an arbitrary signer key to create a signature over packed asset and oracle names that are 0, which bypasses validate_oracle_signature().
Testing and infrastructure
Starknet Foundry provides unit, integration, property-based, and fork testing to help developers avoid the types of bugs that led to $100 million in DeFi losses in January 2024. You should use these tools to prevent the kind of errors that caused $3 billion in losses across DeFi protocols. Unit tests in the src/ directory use contract_state_for_testing, while integration tests in the tests/ directory verify cross-contract calls. Property-based testing uses fuzzing to find edge cases by testing invariants across random inputs. Fork tests fetch real mainnet or testnet data via RPC to test against deployed protocols. I notice the ecosystem still lacks a centralized index for verified Cairo code, which makes it difficult to know if changing a return value from bool to felt252 will break existing contracts. Building a complex AMM/DEX core costs between $40,000 and $120,000, and you should budget 15% to 20% of development costs for security audits. Most reputable audit firms have a 4 to 8 week wait list. I also recommend using audited, battle-tested libraries instead of rewriting what already exists. Does the industry need a repository of verified Cairo code to prevent future vulnerability assessments from becoming purely reactive?
Join the discussion