Starknet – The True ZK
Among all L2 networks, Starknet is the most unique. And it's not even about its incompatibility with EVM, but rather the reason why this compatibility is impossible. Now, let's talk about the Cairo language.
Cairo is Starknet's proprietary programming language, and it's precisely because of it that we have to go through nine circles of hell to top up our wallet, but it's also thanks to Cairo that Starknet has an advantage over its main competitor - ZkSync.
To put it briefly and without getting into the technical part, the difference between Starknet and ZkSync lies in the decentralization of the former and the centralization of the latter.
Starknet. Cairo allows the creation of programs that can generate zero-knowledge proofs used in STARK technology. That is, Zk-proof is embedded in the blockchain's operation.
ZkSync. Solidity does not support Zk-proof. In the case of zkSync, zero-knowledge proof technology is not used at the level of smart contracts written in Solidity, but at the protocol level of zkSync itself.
Now that we've got the basics covered, let's move on to the advanced level.
1. Data Handling Principles: Fixed Field vs. Variety of Types
Cairo (StarkNet) In Cairo, all data are represented as numbers within a finite field, which can be likened to a game where your movements are limited by the size of the playing field. You cannot go outside its boundaries, and every action must follow the rules of the field.
func add(x : felt, y : felt) -> (result : felt): let (result) = x + y return (result) end
Solidity (zkSync) Solidity offers the ability to use a variety of data types, similar to chess where you have different pieces such as pawns, rooks, knights, each with their unique movements and capabilities.
function add(uint x, uint y) public pure returns (uint) { return x + y; }
2. Approach to Security: Inherent Anonymity vs. Optional Anonymity
Cairo (StarkNet) Since Cairo is designed with zk-STARKs in mind, it effectively creates an "invisible" layer of security for transactions, which is comparable to sending encrypted letters where the recipient can verify that the letter is genuine without opening the envelope.
@view func transfer_proof_example{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(sender : felt, recipient : felt, amount : felt): # Function body that generates a zk-STARK proof # ... return () end
Solidity (zkSync) In Solidity, anonymity is not built-in; it is like sending regular letters with the option to use an envelope or not. If you need privacy, you must implement additional protective mechanisms, like the ZkSync platform itself.
contract Transfer { event Transfer(address indexed from, address indexed to, uint amount); function transfer(address to, uint amount) public { emit Transfer(msg.sender, to, amount); } }
3. Scalability and Efficiency
Cairo (StarkNet) Optimization under Cairo is a process aimed at reducing computational complexity, akin to trying to pack an airplane as compactly as possible to cut down on fuel consumption.
@view func get_optimized_sum{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(x : felt, y : felt) -> (sum : felt): # In Cairo, you need to work within a finite field, meaning all computations must be compatible with this field. # This implies that large numbers are handled in a special way to "fit" within this field without overflow. let (sum) = x + y return (sum) end
Solidity (zkSync) Solidity requires meticulous optimization for Ethereum, which can be likened to tuning a car for a race: every detail matters and can significantly impact fuel consumption. This contract uses less gas by employing gas-efficient operations and optimization patterns.
contract GasOptimized { uint public total; function sum(uint[] memory array) public { for(uint i = 0; i < array.length; ++i) { total += array[i]; } } }
We have only discussed some of the differences between StarkNet and ZkSync, but this should suffice to address questions about the distinctions between the projects. The first part of the article series on StarkNet has come to an end, and we hope it has been informative!