Skip to content

Safe Smart Contracts ​

Overview ​

The Safe smart contract from Safe (formerly Gnosis Safe) is a foundational component for managing crypto assets with enhanced security through multi-signature control. The platform leverages Safe contracts that acts as a highly customizable, programmable account that can be used as a secure vault for any ERC-20 TRADE-S tokens.

It allows multiple pre-approved owners to control the funds, requiring a minimum number of confirmations (e.g., 2 out of 3 owners) for any transaction to be executed. This significantly reduces single points of failure and enhances the security of funds, making it an excellent choice for organizational treasuries, shared funds, or individual high-security storage.

This contract interacts with:

  • Owners: A set of addresses designated to control the Safe.
  • Modules: Optional contracts that can extend the Safe's functionality (e.g., for automated payments, spending limits).
  • Guardians: Optional contracts that can add extra security checks before transactions are executed.
  • Trade-S Token: The Safe can hold and manage TRADE-Stable tokens.

Key Functionalities ​

1. Multi-Signature Control ​

  • Requires a predefined number of confirmations from its owners for any transaction to be executed.
  • Customizable threshold (e.g., 2-of-3, 3-of-5) to suit different security needs.
  • Eliminates single points of failure, protecting against compromised private keys.

2. Asset Management ​

  • Securely holds and manages a user's TRADE-S tokens.
  • Enables sending, receiving, and interacting with tokens.
  • Supports batching multiple transactions into a single execution.

3. Programmable Asset Control ​

  • Allows for complex transaction logic through modules and guards.
  • Modules can enable features like recurring payments, spending limits, or custom access control.
  • Guards can enforce additional conditions (e.g., time locks, specific recipient whitelists) before transactions can pass.

4. Upgradeability ​

  • The Safe architecture is designed to be upgradeable, allowing for future improvements and bug fixes without requiring users to migrate funds to new contracts.
  • This ensures long-term security and adaptability.

5. Interaction with the treasury service ​

  • Allows interactions with the treasure service for supply management.
  • This allows a multi-signature controlled entity to participate in the controlled release of collateral.

Roles ​

  • Owners (owners):
    • A set of externally owned accounts (EOAs) or other smart contracts designated to control the Safe.
    • They propose and confirm transactions.
    • The number of owners and the required confirmation threshold are set during deployment and can be modified later by the owners.
    • The platform uses the treasury service, the individual user, and trusted third party verifiers as collateral vault owners.
  • Modules:
    • Optional smart contracts approved by the Safe owners to extend its functionality.
    • Can be used to enable advanced security features.
  • Guardians:
    • Optional smart contracts that add an extra layer of security by performing checks before transactions are executed.
    • Can act as circuit breakers or enforce specific rules.

Contract Structure ​

Key Internal State Variables & Concepts ​

  • address[] public getOwners(): Returns the list of addresses designated as owners.
  • uint256 public getThreshold(): Returns the number of owner confirmations required for execution.
  • mapping(bytes32 => uint256) public signedMessages: Tracks confirmed messages.
  • uint256 public nonce: A transaction counter to prevent replay attacks.

Key Internal Functions & Concepts ​

  • execTransactionFromModule(address to, uint256 value, bytes data, Enums.Operation operation):
    • Allows an approved module to execute a transaction without requiring owner confirmations (as the module itself is approved by owners).
  • execTransaction(address to, uint256 value, bytes data, Enums.Operation operation, uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures):
    • The main function for executing multi-signature transactions.
    • Takes parameters defining the transaction, gas limits, and a concatenated signatures byte string from the confirming owners.
  • approveHash(bytes32 hash):
    • Allows an owner to approve a specific transaction hash off-chain, which can then be included in the signatures for execTransaction.
  • changeThreshold(uint256 _threshold):
    • Allows owners to change the number of required confirmations.
  • addOwnerWithThreshold(address owner, uint256 _threshold):
    • Allows owners to add a new owner and potentially adjust the threshold.
  • removeOwner(address prevOwner, address owner, uint256 _threshold):
    • Allows owners to remove an existing owner and potentially adjust the threshold.

Security Considerations ​

  • Multi-Signature Security:
    • The core security model is based on distributed control, requiring multiple parties to authorize transactions.
    • Significantly reduces the risk of single private key compromise.
  • Audited Codebase:
    • Safe contracts are rigorously audited by leading security firms and are considered one of the most secure and battle-tested smart contract systems in Web3.
  • Upgradeability:
    • The proxy architecture allows for bug fixes and feature enhancements without requiring users to migrate funds, improving long-term security.
  • Module and Guard System:
    • Provides a flexible framework for implementing custom security logic and automating specific tasks, adding further layers of protection.
  • Event Logging:
    • Comprehensive event logging for all key actions (e.g., ExecutionSuccess, AddedOwner, ChangedThreshold) provides transparency and auditability.

Dependencies ​

  • Safe Contracts:
    • The entire suite of Safe core and extension contracts (e.g., GnosisSafe, GnosisSafeL2, GnosisSafeProxyFactory, CreateCall).
  • OpenZeppelin Contracts (indirectly):
    • While Safe has its own robust codebase, it leverages common patterns and best practices, some of which are standardized or inspired by OpenZeppelin's work.

Deployment ​

  • Network: Any EVM-compatible network, including Optimism.
  • Parameters:
    • owners: An array of addresses that will be designated as the initial owners.
    • threshold: The number of owner confirmations required for a transaction to be executed (e.g., 2 for a 2-of-3 Safe).
    • to: An optional address for an initial delegatecall (usually 0x0).
    • data: Optional data for an initial delegatecall (usually 0x).
    • fallbackHandler: An optional address for a fallback handler (usually 0x0 or a default handler).
    • paymentToken: Address of an ERC-20 token to pay for gas, or 0x0 for native currency (ETH).
    • payment: Amount to pay for gas.
    • paymentReceiver: Address to receive the gas payment.