This resource is a collection of use cases and patterns for assertions. The goal is to show how assertions can be used to prevent hacks and vulnerabilities in smart contracts and protocols. The content of the book is a great source for inspiration for how to write assertions for your own use cases and protocols. The book consists of two main parts: assertions that demonstrate specific assertion patterns and examples, and previous hacks that show how assertions could have prevented real-world exploits. Each entry shows code snippets of assertions accompanied by minimal interfaces for the protocols they protect. Full examples that include mock protocol code and test cases are available in the Phylax Assertion Examples Repository.

Getting Started

It’s a good idea to check out the two links below to get started with assertions, but it’s not required to understand the content of the book. If you have questions or issues, please reach out on telegram @phylax_credible_layer. If you think an assertion is missing, please don’t hesitate to open a PR or reach out. We love digging into new hacks and use cases and writing assertions for them!

Book Structure

This book is organized into two complementary sections:

Part 1: General Use Cases

The first part contains curated assertion patterns organized by security category. These examples demonstrate proactive security measures you can implement to protect your protocols. Each assertion shows how to prevent specific types of vulnerabilities before they can be exploited. View the complete use cases catalog →

Part 2: Previous Hacks

The second part analyzes real-world DeFi hacks and demonstrates how assertions could have prevented them. These case studies provide concrete examples of how assertions work as a safety net, catching vulnerabilities that might slip through traditional security measures like audits and testing. View the previous hacks analysis → Both sections include:
  • Assertion code examples
  • Explanations of the vulnerability or pattern being addressed
  • Minimal protocol interfaces for context