Introduction
Phylax’s real-time security system detects and pre-emptively removes exploits before losses can be realized.
- Invariants (or other rules such as KYC/AML, etc.) are mapped and defined by the dApp team, then converted into assertions
- The Credible Layer smart contracts act as a registry that tracks which assertions are linked to which contract addresses
- The network node reads the registry and validates all transactions against the relevant assertions before they’re added to blocks
- Transactions are included in blocks only if all assertions pass; otherwise they’re dropped
Mapping and Defining Invariant Rules

Why Use Invariants?
Invariants are statements about your contract that must remain true no matter how users interact with it. They express the essential conditions that keep your system secure and functional—the business logic that must always hold. Instead of exhaustively predicting every exploit path, you define the states that must never occur. If one of these states is violated, something fundamental has gone wrong. Beyond Invariants While invariants are commonly used for security properties, assertions enable a broader range of use cases:- Compliance Rules: Enforce KYC/AML requirements by validating that transaction participants meet regulatory criteria
- Timelocks and Access Control: Add time-based restrictions or multi-factor authentication requirements for sensitive functions like contract upgrades
- Business Logic Enforcement: Ensure operational rules are followed, such as transaction limits or authorized contract interactions
Understanding Invariants vs. Assertions
While these terms are often used together, there’s an important distinction: Invariants are the core security properties or rules you want to maintain. Think of them as the “what” – what condition must always be true. For example: “The total supply must equal the sum of all balances.” Assertions are smart contracts that verify those invariants hold true. They are the “how” – how you check and enforce those rules at the network level. An assertion is a Solidity smart contract that:- Implements the invariant as executable code
- Specifies when to check it (trigger conditions)
- Defines what data to examine (pre/post transaction states)
- Uses special capabilities (cheatcodes) to access information not available in standard Solidity
Example Walkthrough Using a Previous Hack
Here is a way to visualize the journey of creating invariants and converting them into assertions. In this example, Bunni’s protocol must ensure that when users withdraw funds, the share of ownership is updated to match the amount removed from the pool. The invariant can be expressed in plain English as follows:“Pool balance decrease must match the percentage of shares being withdrawn”And mathematically like this: To express this as an assertion, we can declare that withdrawals must decrease the pool’s balance proportionally. If someone withdraws 10% of shares, the pool balance should decrease accordingly.
This code is truncated for simplicity; read on for the full explanation on how the Bunni hack could have been prevented with an assertion.
Network Enforcement of Assertions
Now that we have our assertion and the target contract that triggers it, we have to let the network sidecar know the contract should be protected by the provided assertion. We call this submitting the assertion for enforcement. As seen in the diagram below, the dapp submits the assertions to the Credible Layer Smart Contracts. These smart contracts are the source of truth and supply the sidecar with the relevant assertion when a transaction interacts with a protected contract:
How Enforcement Works
A network node running Phylax’s sidecar system does not care how a transaction violates the protocol’s rule. All that matters is whether the assertion returns true or false after the transaction. If the assertion returns false, the node drops the transaction before it can be included in a block. You can read the full technical flow in Architecture. To illustrate it better, when a user opens a position on a yield protocol, the transaction touches multiple contracts:

Assertion Validation
Once the transaction is sent by the user, it is seen by the network node. The node then passes it to the sidecar to check if the transaction’s final state would violate an assertion in a separate replica environment called the PhEVM. When completed, the sidecar returns the result to the node so it can include or drop the transaction. This validation process never exceeds the time to produce a block. In other words, the transaction will be included into the block only if every assertion across all touched contracts evaluates to true. If even one assertion fails, the network node will see this failed assertion and exclude it from finalization. While the core concept remains the same across all networks (validate transactions against assertions before finalization), the exact architecture depends on the underlying technology stack. For example, on OP Stack chains, validation is implemented as part of an external block builder that integrates via Rollup-Boost. The key takeaway: the Credible Layer adapts to each network’s architecture while maintaining the same security guarantees. For network-specific implementation details, see the Architecture documentation. Continue reading in technical detail in Architecture.The Credible Layer is designed as neutral middleware that preserves decentralization for both dApps and networks. Learn more about why neutrality matters.
Use Cases
Assertions open up a wide range of use cases, some that aren’t even possible in pure Solidity:- Parameter Protection: Prevent unauthorized changes to critical protocol parameters such as owner and implementation addresses
- Market Integrity: Ensure market prices don’t move beyond specified thresholds inside of a single transaction
- Lending Protocol Safety: Guarantee lending positions maintain the required collateralization ratios
- Oracle Monitoring: Verify oracle prices stay within specified ranges to detect price manipulation
- Total Balance Invariants: Ensure that the sum of all positions match the total balance of a protocol

