a16z Crypto has called for decentralized finance protocols to shift from 'code is law' to 'spec is law' to enhance security amid rising exploits. In a January 11 post, senior researcher Daejun Park advocated for standardised specifications and invariant checks to prevent hacks. This approach aims to mature the $168 billion sector by hard-coding safety guarantees.
Decentralized finance, or DeFi, faces ongoing threats from code exploits, with hackers stealing over $649 million last year, according to blockchain security firm Slowmist. Even established protocols like Balancer, operational on Ethereum since 2021, suffered a $128 million loss in November due to a code vulnerability. Developers are increasingly concerned about hackers leveraging artificial intelligence to identify weaknesses.
In response, a16z Crypto's Daejun Park proposed moving beyond reactive 'patch-after-the-hack' methods. He recommended embedding safety through standardised specifications that limit protocol actions and automatically reverse violating transactions. 'Almost every exploit to date would have tripped one of these checks during execution, potentially halting the hack,' Park wrote. 'So the once-popular idea of “code is law” evolves into “spec is law.”'
This concept, known as runtime enforcement or invariant checks, is gaining traction. Protocols such as Kamino, a Solana-based lending platform, integrated checks using Certora Prover in March 2023. The XRP Ledger, supporting the $120 billion XRP token, has also implemented them to safeguard against undetected bugs. 'Invariants should not trigger, but they ensure the XRP Ledger’s integrity from bugs yet to be discovered or even created,' its developers stated.
However, experts caution that invariant checks are not foolproof. Gonçalo Magalhães, head of security at Immunefi, noted they could raise transaction fees, deterring users in a cost-sensitive market. 'It’s not the silver bullet,' he said. Felix Wilhelm of Asymmetric Research added that crafting effective checks is challenging, as they may falsely trigger during normal operations or fail to stop sophisticated attacks outright. While useful for anomaly detection, such as unusual fund flows, they often mitigate rather than prevent damage.
Park's ideas underscore DeFi's push toward principled security to foster growth, though implementation hurdles remain.