StarkNet
Starknet Overview¶
Starknet is a Layer 2 scaling solution for Ethereum that uses ZK-Rollup technology and the STARK proof system to achieve high-performance and low-cost smart contract execution. As a general-purpose Layer 2, Starknet supports complex DApp development and provides native scalability and security through the Cairo language. Starknet inherits Ethereum's security while achieving throughput of thousands of TPS and transaction costs of just a few cents, making it one of the most innovative scaling solutions in the Ethereum ecosystem.
Official Website: https://www.starknet.io/
Core Technology¶
1. STARK Proofs¶
Transparent zero-knowledge proofs:
- No Trusted Setup Required: Does not rely on a trusted third party
- Post-Quantum Secure: Resistant to quantum computing attacks
- Transparency: Completely public parameters
- Efficient Verification: Extremely fast verification time
- Scalable: Supports large-scale computational proofs
2. Cairo Language¶
A language designed specifically for proofs:
- Turing Complete: Supports arbitrary computation
- Efficient Proving: Optimized proof generation
- Safety: Type safety and memory safety
- Verifiability: All computations are verifiable
- Abstraction: Powerful abstraction and composition capabilities
3. ZK-Rollup Architecture¶
Layer 2 scaling solution:
- Off-Chain Execution: Transactions execute on L2
- Batch Proving: Multiple transactions are proved together
- Data Availability: State changes are published to L1
- Instant Finality: Immediately final after proof verification
- Ethereum Security: Inherits L1 security
4. Account Abstraction¶
Native account abstraction:
- Smart Contract Wallets: All accounts are contracts
- Custom Verification: Flexible signature verification logic
- Multisig Support: Native multisig functionality
- Social Recovery: Convenient account recovery
- Gas Abstraction: Flexible Gas payment methods
Technical Architecture¶
Sequencer¶
Transaction processing node:
- Receives user transactions
- Executes Cairo programs
- Generates execution traces
- Orders transactions
- Generates state updates
Prover¶
Generates STARK proofs:
- Processes execution traces
- Generates STARK proofs
- Optimizes proof size
- Batch proof generation
- Submits proofs to L1
Verifier¶
L1 contract verification:
- Receives STARK proofs
- Verifies proof validity
- Updates state root
- Processes L1-L2 messages
- Finalizes state
Development Guide¶
Install Development Environment¶
# Install Scarb (Cairo package manager)
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh
# Install Starknet Foundry
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
# Verify installation
scarb --version
snforge --version
Cairo Smart Contracts¶
Simple ERC20 token:
#[starknet::contract]
mod ERC20 {
use starknet::ContractAddress;
use starknet::get_caller_address;
#[storage]
struct Storage {
name: felt252,
symbol: felt252,
total_supply: u256,
balances: LegacyMap<ContractAddress, u256>,
allowances: LegacyMap<(ContractAddress, ContractAddress), u256>,
}
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
Transfer: Transfer,
Approval: Approval,
}
#[derive(Drop, starknet::Event)]
struct Transfer {
from: ContractAddress,
to: ContractAddress,
value: u256,
}
#[constructor]
fn constructor(
ref self: ContractState,
name: felt252,
symbol: felt252,
initial_supply: u256,
recipient: ContractAddress
) {
self.name.write(name);
self.symbol.write(symbol);
self.total_supply.write(initial_supply);
self.balances.write(recipient, initial_supply);
}
#[external(v0)]
fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) -> bool {
let sender = get_caller_address();
self._transfer(sender, recipient, amount);
true
}
#[external(v0)]
fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
self.balances.read(account)
}
}
Deploy Contract¶
# Compile contract
scarb build
# Declare contract class
sncast --profile testnet declare --contract-name MyContract
# Deploy contract
sncast --profile testnet deploy \
--class-hash <CLASS_HASH> \
--constructor-calldata <ARGS>
Interact with Contracts¶
Using starknet.js:
import { Account, Contract, Provider, cairo } from 'starknet'
// Connect to Starknet
const provider = new Provider({ sequencer: { network: 'goerli-alpha' } })
// Create account
const account = new Account(provider, address, privateKey)
// Contract instance
const contract = new Contract(abi, contractAddress, provider)
contract.connect(account)
// Call contract
const balance = await contract.balance_of(userAddress)
console.log('Balance:', balance.toString())
// Send transaction
const tx = await contract.transfer(recipient, cairo.uint256(1000000))
await provider.waitForTransaction(tx.transaction_hash)
Ecosystem¶
DeFi Protocols¶
- Ekubo: AMM DEX
- Jediswap: Uniswap V2 fork
- zkLend: Lending protocol
- Nostra: Money market
- Carmine: Options protocol
NFT and Gaming¶
- Aspect: NFT marketplace
- Pyramid: NFT platform
- Realms: On-chain game
- Influence: Space strategy game
- Dope Wars: NFT game
Infrastructure¶
- Argent: Smart contract wallet
- Braavos: Mobile wallet
- Voyager: Blockchain explorer
- Starkscan: Explorer
- StarkGate: L1-L2 bridge
Advantages¶
1. Performance¶
- TPS reaching thousands
- Transaction costs of just a few cents
- Efficient proof verification
- Continuously scalable
2. Security¶
- Inherits Ethereum security
- Mathematically secure STARK proofs
- No trusted setup required
- Post-quantum secure
3. Developer Experience¶
- Expressive Cairo language
- Complete development tools
- Native account abstraction
- Active developer community
Token Economics¶
STRK Token¶
- Gas Fees: Pay transaction fees
- Staking: Sequencer staking
- Governance: Protocol governance voting
- Ecosystem Incentives: Developer incentives
Best Practices¶
1. Contract Development¶
- Learn Cairo language features
- Leverage account abstraction features
- Optimize proof generation
- Conduct security audits
- Write comprehensive tests
2. Gas Optimization¶
- Reduce storage operations
- Batch process transactions
- Optimize computational logic
- Use efficient data structures
3. Security Recommendations¶
- Validate all inputs
- Handle reentrancy correctly
- Implement access controls
- Conduct regular security audits
- Stay updated on security patches
Related Concepts and Technologies¶
- Ethereum: Starknet's Layer 1
- ZK-Rollup: The technology Starknet uses
- Cairo: Starknet's smart contract language
- zkSync: Another ZK-Rollup solution
- STARK vs SNARK: Comparison of two zero-knowledge proof technologies
Summary¶
Starknet provides Ethereum with a secure, efficient, and scalable Layer 2 solution through STARK proofs and the Cairo language. Its native account abstraction, post-quantum secure STARK proofs, and growing ecosystem make Starknet an ideal platform for building next-generation DApps. As the technology matures and the ecosystem flourishes, Starknet will play an increasingly important role in Ethereum scaling and Web3 development.