February 17, 2025

Introducing Safeguard

A Powerful Geth Extension to Monitor Essential Smart Contract Invariants in Real-Time

Author:

John Toman

Introduction

Smart contract exploits can put both funds and reputations at risk, leading to significant financial losses, damaging trust in DeFi protocols, and undermining the confidence of users and investors. Safeguard, a new open-source Go Ethereum (Geth) extension tool, mitigates these risks by offering real-time monitoring of crucial protocol invariants and violations, giving developers the ability to catch bugs and vulnerabilities before they lead to major issues.

Safeguard is an effective tool that helps developers and protocols monitor exploits and vulnerabilities that can potentially lead to hundreds of millions of dollars in financial losses. This article showcases how Safeguard checks complex invariants in milliseconds and briefly highlights its application to protocols like Aave V3, Uniswap v3, and Uniswap v4.

What Constitutes a Critical Protocol Invariant?

Decentralized Finance (DeFi) protocols rely on essential properties or invariants that must always hold true to ensure their security and operational integrity. A violation of these invariants can have significant repercussions, including financial losses or systemic collapse.

For instance, a core invariant in a lending protocol might be that the total value of borrowed assets must always be less than the total value of the collateral provided to back those assets.

Why is it Important to Monitor Essential Invariants?

While auditing, fuzzing, and formal verification are crucial for upholding invariants during development, the blockchain's dynamic nature introduces ongoing risks post-deployment. Fluctuating asset prices, integrations with other contracts, or unforeseen external events can compromise invariants.

Additionally, the open nature of blockchain systems and the ability for attackers to exploit private mempools create significant runtime detection challenges. Real-time monitoring of invariants becomes essential to:

  • Identify active attacks or vulnerabilities.
  • Enable rapid mitigation to protect user funds and protocol integrity.

Real-World Examples:

  • Ronin Bridge Attack: A delayed response worsened its impact and losses.
  • Olympus DAO: A timely alert helped mitigate the risk and protect users.

How does Safeguard differ from Existing Monitoring Frameworks?

Existing tools

Frameworks like Tenderly and Forta provide powerful monitoring capabilities. Developers can define invariants using Ethereum’s JSON-RPC API, and these tools eliminate the need to run Ethereum nodes.

Safeguard’s advantages

  • Low-Level Blockchain Access: Safeguard accesses blockchain state directly, enabling more precise and specialized invariant checks (e.g., Uniswap v4 pool liquidity).
  • Consistency: Unlike JSON-RPC calls prone to inconsistencies, Safeguard ensures a coherent view of the state after every block or transaction.
  • No False Positives: Safeguard focuses on absolute invariants—truths that must always hold—allowing for automatic mitigations when violated.

Supported protocols and codebases

Safeguard currently supports invariants for protocols such as:

  • Aave V3: Ensuring reserve solvency.
  • Uniswap v3 and Uniswap v4: Validating pool balance consistency.

Visualizing Safeguard in Action

The image below demonstrates how our detector could be integrated with a custom monitoring dashboard to track key metrics for Uniswap, including core protocol activity, specific pool data, and individual token metrics.

Figure 1: Example of Safeguard's Uniswap real-time monitoring dashboard

The User Interface (UI), designed to monitor and detect violations of specified invariants, presents these findings in a clear and actionable manner, empowering developers and protocol operators to understand and address issues promptly. Its real-time tracking and display of invariant violations are crucial for maintaining the health and security of a smart contract system. 

In a future blog post, we will provide a detailed, step-by-step guide on how to effectively apply Safeguard to complex protocols, using Uniswap and Aave as practical examples.

Future Enhancements

To simplify adding invariants, Safeguard will expand beyond Go plugins to support TypeScript properties executed by a dedicated Geth engine. Integration of the WASM execution engine will enable invariant checks in languages like Rust. 

We're also exploring compiling CVL specifications directly into Go. For compatibility, a Safeguard version for reth with consistent APIs for TypeScript and WASM detectors is planned.

Safeguard's potential for preventative applications, such as firewalls or transaction whitelisting within layer 2 environments, is substantial. We are actively collaborating with IronBlocks to integrate Safeguard into their on-chain firewall. This integration will include a new JSON RPC endpoint capable of simulating transactions against the current state, conducting invariant checks, and returning both transaction outcomes and invariant check results.

Our initial integration target is the Venn network, and the API for invariant checking will be enhanced with Forta-like features.

Safeguard Your Protocol Today

Safeguard redefines runtime security for Ethereum. With its low-level access, precise consistency, and compatibility with critical DeFi protocols, we are setting a new benchmark for runtime blockchain security. Join projects like Aave and Uniswap in adopting battle-tested, real-time protection.

We invite you to join the Safeguard community on Discord to connect with other users, share your insights, report any bugs you encounter, and contribute your ideas on Safeguard’s GitHub to enhance it for the benefit of DAOs further.

Get every blog post delivered

Certora Logo
logologo
Terms of UsePrivacy Policy