In early 2024, the cryptocurrency community was shaken by a dramatic theft that saw a single wallet lose roughly $7.8 million worth of digital assets. While headlines initially pointed to a vulnerability in the popular multi‑signature wallet system known as Safe, deeper forensic analysis revealed a more nuanced story: the loss was not caused by a flaw in Safe’s core code, but rather by a seemingly innocuous mistake in a helper contract that the wallet’s owner had granted permission to interact with. This distinction is crucial for developers, auditors, and everyday users who rely on smart‑contract wallets to safeguard large sums of value.
### The Background: Multi‑Signature Wallets and Helper Contracts Safe (formerly Gnosis Safe) is a widely‑adopted smart‑contract based wallet that requires multiple signatures before a transaction can be executed. This multi‑sig architecture is designed to reduce the risk of a single compromised key draining the wallet. In practice, users often extend the functionality of their Safe by authorising auxiliary or "helper" contracts.
These helpers can automate tasks such as token swaps, batch payments, or interaction with DeFi protocols, and they operate under the authority granted by the Safe’s owners. In the case at hand, the victim—a high‑net‑worth individual managing a diversified portfolio of ERC‑20 tokens—had previously approved a helper contract to facilitate periodic token rebalancing. The helper was written by a third‑party developer and was meant to execute a series of predefined actions on behalf of the Safe, without requiring the owner to manually sign each transaction.
### The Coding Mistake: An Overly Permissive Delegatecall The root cause of the theft was a simple yet dangerous coding oversight in the helper contract’s implementation of `delegatecall`. In Solidity, `delegatecall` allows a contract to execute code from another contract while preserving the caller’s storage context. This is a powerful tool for modular design, but it also means that any vulnerability in the called contract can directly affect the caller’s state. The helper contract’s developer intended to use `delegatecall` to invoke a library that performed token swaps.
However, the contract failed to validate the address of the library before invoking it. Moreover, the function that performed the `delegatecall` was marked as `public` and lacked any access control modifiers.
Consequently, any external actor could call this function, specify an arbitrary library address, and cause the helper to execute malicious code under the Safe’s authority. ### Exploitation: How the Hacker Drained the Funds A malicious actor quickly identified the open `delegatecall` function.
By submitting a transaction that called the helper contract with a malicious library address, the attacker caused the helper to execute code that transferred all tokens held by the Safe to an address controlled by the attacker. Because the helper was operating under the Safe’s context, the transfer appeared legitimate to the blockchain and did not trigger any of the Safe’s internal checks that would normally require multiple signatures. The attacker’s steps can be summarized as follows: 1. **Discovery** – The attacker scanned public blockchain data for Safe wallets that had authorized helper contracts with publicly visible source code.
2. **Analysis** – They identified the helper’s `delegatecall` function and noted the lack of address validation and access control. 3. **Preparation** – The attacker deployed a malicious library contract containing a simple `transferAll` function that moved every token from the caller to the attacker’s address.
4. **Execution** – Using a single transaction, the attacker invoked the helper’s vulnerable function, passing the address of the malicious library. The helper, believing it was executing a legitimate library, performed the `delegatecall`, which in turn executed the `transferAll` logic. 5.
**Extraction** – The funds were instantly transferred out of the Safe, bypassing the multi‑signature requirement because the transaction was technically initiated by an authorized contract. ### Security Firms’ Findings Multiple security firms, including Trail of Bits and PeckShield, were engaged to trace the flow of funds and pinpoint the vulnerability. Their investigations confirmed that: - The Safe contract itself remained untouched; its codebase contains no known exploits that would allow a single‑signature drain.
- The compromised helper contract was the sole conduit for the theft, acting as a bridge that leveraged the Safe’s permissions. - The transaction logs showed a clean `delegatecall` from the helper to the malicious library, followed by token transfer events that moved the assets to the attacker’s wallet. These findings underscore the importance of rigorous code review for any contract that a Safe authorises, especially when that contract can execute low‑level calls like `delegatecall`.
### Lessons Learned and Best Practices 1. **Restrict Access to Sensitive Functions** – Functions that perform `delegatecall`, `call`, or `staticcall` should be protected by robust access controls, such as `onlyOwner` or multi‑signature checks, to prevent unauthorized usage.
2. **Validate External Addresses** – Before invoking external code, always verify that the address belongs to a trusted contract. Whitelisting approved libraries can mitigate the risk of arbitrary code execution. 3.
**Limit the Scope of Helper Contracts** – Design helpers to have the minimal set of permissions required for their task. Avoid granting them blanket authority over the entire wallet. 4. **Conduct Formal Audits** – Even seemingly trivial helper contracts should undergo third‑party audits.
Formal verification tools can detect missing checks and unsafe patterns. 5.
**Monitor Transaction Patterns** – Implement real‑time monitoring for unusual activity, such as large token transfers initiated by helper contracts, and set up alerts for multi‑signature wallets. 6. **Educate Users** – Wallet owners should be made aware that authorising external contracts expands the attack surface.
Clear documentation and warnings can help users make informed decisions. ### The Broader Impact on the Crypto Ecosystem The incident serves as a cautionary tale for the broader decentralized finance (DeFi) ecosystem. As more users adopt smart‑contract wallets for their security benefits, the reliance on auxiliary contracts will inevitably increase. Each additional contract introduces a new potential point of failure.
The community must therefore prioritize secure development practices, thorough audits, and continuous education. In the aftermath, Safe’s development team released a statement reaffirming the security of the core platform and announcing upcoming enhancements, including: - **Granular Permissioning** – Allowing wallet owners to specify which functions a helper contract can call. - **Contract Whitelisting** – Providing a built‑in mechanism to approve only vetted contracts for interaction.
- **Improved UI Warnings** – Highlighting the risks associated with authorising external contracts directly in the wallet interface. ### Conclusion The $7.8 million theft was not the result of a fundamental flaw in the Safe multi‑signature wallet, but rather a classic example of how a small coding oversight—an unchecked `delegatecall` in a helper contract—can have catastrophic consequences when combined with the high‑value permissions granted by a smart‑contract wallet.
By understanding the chain of events, implementing stricter access controls, and fostering a culture of rigorous security review, developers and users can significantly reduce the likelihood of similar exploits in the future.