Introduction
Clarity is a decidable smart contract language designed for the Stacks blockchain. Unlike Solidity, Clarity is interpreted (not compiled) and intentionally non-Turing complete. This design philosophy has significant implications for security.
The Decidability Advantage
Clarity's decidability means that the behavior of a contract can be fully analyzed before execution. This eliminates entire classes of vulnerabilities that plague Solidity contracts.
| Feature | Clarity | Solidity |
|---|---|---|
Turing Complete | No | Yes |
Recursive Calls | Limited | Unlimited |
Gas Estimation | Precise | Approximate |
Reentrancy Risk | None | High |
Formal Verification | Built-in | External Tools |
No Reentrancy by Design
One of Clarity's most significant security advantages is the complete elimination of reentrancy vulnerabilities. The language simply does not allow the patterns that enable reentrancy attacks.
;; Clarity - Reentrancy impossible(define-public (transfer (amount uint) (recipient principal)) (begin ;; State change happens atomically (try! (stx-transfer? amount tx-sender recipient)) (ok true) ))// Solidity - Classic reentrancy vulnerabilityfunction withdraw(uint amount) public { require(balances[msg.sender] >= amount); // External call before state update - VULNERABLE (bool success, ) = msg.sender.call{value: amount}(""); require(success); balances[msg.sender] -= amount;}Security Comparison
While Clarity eliminates many vulnerability classes by design, it's not a silver bullet. Logic errors, access control issues, and economic exploits are still possible.
Decidability
Full contract analysis before deployment
No Reentrancy
Impossible by language design
Precise Gas
Exact execution cost known upfront
Logic Bugs Remain
Still need careful auditing
