- Cairo’s
felt252type system andu256representation - Starknet storage model and component-based composition
- Transaction types, versions, and typed dispatcher calls
- Multi-call patterns for atomic configuration
- Resource bounds, fee estimation, and common gas pitfalls
- Reentrancy protections and clear-then-execute behavior
- Bytes32 address encoding for crosschain peers
VM Architecture
Starknet uses the Cairo programming language and a field-element-based type system. These fundamentals shape how LayerZero contracts represent addresses, amounts, and payloads.The felt252 Type
Starknet’s native type isfelt252 (field element), a ~251-bit unsigned integer:
- Native to the STARK proof system (efficient proving)
- Wraps around on overflow (unlike Solidity’s revert behavior)
- Can represent addresses, integers, and short strings
Common Types
u256 Representation
Unlike EVM’s native 256-bit integers, Starknet representsu256 as two felt252 values:
- Crosschain amount encoding must handle this difference
- OFT uses
u64for shared decimals to ensure compatibility
Message Flow Overview
LayerZero messages on Starknet flow through the Endpoint and verification system before reaching the destination OApp:- Send: OApp -> Endpoint -> message library -> workers (DVNs/Executor)
- Verify: DVNs verify and submit to the receive library
- Receive: Executor calls
lz_receiveon the destination OApp
Complete Protocol DetailsFor detailed send/verify/receive workflows with contract code and event flows, see Protocol Overview.
Transaction Execution Model
Starknet uses distinct transaction types and typed dispatchers. These patterns determine how LayerZero contracts are deployed, called, and configured.Transaction Types
Starknet has distinct transaction types for different operations:DECLARE
Publishes contract code to the network:class_hash - unique identifier for the contract code
When to use: First time deploying a new contract version
DEPLOY_ACCOUNT
Deploys an account contract:INVOKE
Executes contract functions:Transaction Versions
- v0/v1/v2: Deprecated and unsupported on current Starknet networks
- v3: Current transaction format with resource bounds (recommended)
Dispatcher Pattern
Starknet doesn’t support dynamic dispatch (nodelegatecall equivalent). Instead, cross-contract calls use typed dispatchers. For more details, see the Cairo Book: Dispatcher Pattern.
Interface Definition
Generated Dispatcher
The compiler generates a dispatcher for each interface:Using Dispatchers
- Compile-time type checking
- Automatic serialization/deserialization
- Clear error messages
| EVM | Starknet |
|---|---|
interface.function{value: x}(args) | dispatcher.function(args) |
| Dynamic dispatch via address | Typed dispatcher |
abi.encode/decode | Automatic Serde |
Multi-Call Transactions
Multicall is implemented at the account-contract level: a single INVOKE can execute multiple calls atomically when the account supports it. Most major account implementations (Ready Wallet, formerly Argent; Braavos; OpenZeppelin Account) expose multicall by default. If an account contract does not implement multicall, batching is not available for that account.Batching with Account.execute
Benefits
- Atomicity: All calls succeed or all fail
- Gas efficiency: Single transaction overhead
- Configuration safety: Set all config before enabling pathway
LayerZero Configuration Pattern
State Management Model
Starknet contracts use a key-value storage model and component-based composition rather than inheritance. These patterns shape how LayerZero contracts store configuration and expose functionality.Contract Storage Model
Storage Structure
Starknet contracts use a key-value storage model withfelt252 keys:
Storage Access
Storage Layout
Storage keys are computed deterministically:- Simple variables:
sn_keccak(variable_name) - Mappings:
h(h(variable_name), key1, key2, ...)
- Debugging storage reads/writes
- Computing storage proofs for crosschain verification
Component System
Cairo uses a component system instead of inheritance:Defining a Component
Using Components in a Contract
| Solidity | Cairo |
|---|---|
contract A is B, C | component!(path: B, ...) |
override | Trait impl |
| Diamond problem | No conflicts (explicit embedding) |
Security & Permission Model
Starknet’s execution model affects how reentrancy is handled in LayerZero contracts.Reentrancy Model
Unlike EVM, Starknet’s execution model provides some inherent reentrancy protections:Sequential Execution
Transactions are executed sequentially within a block, not concurrently. However, within a single transaction, reentrancy is still possible.ReentrancyGuard Component
LayerZero contracts use OpenZeppelin’s ReentrancyGuard:Clear-Then-Execute Pattern
The Endpoint uses this pattern forlz_receive:
Gas Model
Starknet’s fee model differs from EVM and uses explicit resource bounds.Gas Model
| Resource | Description |
|---|---|
| L1 Gas | Cost for DA on Ethereum L1 |
| L2 Gas | Compute cost on Starknet |
| L1 Data Gas | Calldata size on L1 |
Setting Resource Bounds
Estimating Fees
Common Issues
| Error | Cause | Solution |
|---|---|---|
| ”Insufficient max fee” | Resource bounds too low | Increase fee cap (--max-fee) or resource bounds |
| ”Insufficient balance” | Account underfunded | Add STRK/ETH |
| ”Transaction reverted” | Contract logic error | Check calldata |
Key Starknet Concepts for LayerZero
Address encoding is critical for crosschain peer verification.Address Encoding for Crosschain
Bytes32 for Cross-VM Compatibility
LayerZero usesBytes32 for addresses to support different address sizes:
Setting Peers
Key Takeaways
felt252andu256encoding affect how LayerZero represents amounts and addresses.- Storage and components replace inheritance; configuration lives in structured storage.
- Typed dispatchers provide safe cross-contract calls without dynamic dispatch.
- Multicall enables atomic configuration before opening pathways.
- Resource bounds and fee estimation require explicit handling on Starknet.
- Clear-then-execute prevents reentrancy during
lz_receive. - Bytes32 encoding standardizes peer addresses across chains.
Next Steps
- OApp Overview - Building OApps
- OFT Overview - Token transfers
- Technical Reference - Toolchain guide
- Troubleshooting - Common errors