Centrifuge - kaveyjoe's results

The institutional ecosystem for on-chain credit.

General Information

Platform: Code4rena

Start Date: 08/09/2023

Pot Size: $70,000 USDC

Total HM: 8

Participants: 84

Period: 6 days

Judge: gzeon

Total Solo HM: 2

Id: 285

League: ETH

Centrifuge

Findings Distribution

Researcher Performance

Rank: 27/84

Findings: 1

Award: $335.49

Analysis:
grade-a

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

335.4874 USDC - $335.49

Labels

analysis-advanced
grade-a
sufficient quality report
edited-by-warden
A-06

External Links

Centrifuge Liquidity Pools Advanced Analysis Report

Introduction

Centrifuge is a platform that allows people to use real-world assets, like property or invoices, to get digital currency. They were the first to do this with MakerDAO, and also launched a marketplace for these assets with Aave. They can work on different blockchain networks.

Centrifuge has a system where borrowers manage the real-world assets on a specific blockchain called Centrifuge Chain. Meanwhile, pools of digital currency are set up on other blockchain networks where there's demand for these assets. These pools talk directly to Centrifuge Chain through special messaging layers, making it easy to use real-world assets in the world of decentralized finance.

The Liquidity Pools system comprises several contracts including the Liquidity Pool, Tranche Token, Investment Manager, Pool Manager, Gateway, and Routers. The Investment Manager handles pool creation, tranche deployment, investment management, and token transfers, while the Pool Manager deals with currency bookkeeping and tranche token transfers. The Gateway serves as an intermediary for encoding and decoding messages and handles routing to/from Centrifuge. Routers are responsible for communication with the Centrifuge Chain.

. Contract Overview

Centrifuge's liquidity pools consist of several integral contracts:

Centrifuge
  • Liquidity Pool: An ERC-4626 compatible contract enabling investors to deposit and withdraw stablecoins into tranches of pools.

  • Tranche Token: An ERC-20 token linked to a RestrictionManager managing transfer restrictions. Prices for tranche tokens are computed on Centrifuge.

  • Investment Manager: The core business logic contract responsible for pool creation, tranche deployment, investment management, and token distribution to Escrow and UserEscrow.

  • Pool Manager: Manages currency bookkeeping and the transfer of tranche tokens and currencies.

  • Gateway: An intermediary contract encoding and decoding messages, handling routing to/from Centrifuge.

  • Routers: Contracts facilitating communication of messages to and from Centrifuge Chain.

- System Overview

** Scope ** :

1 . LiquidityPool.sol

LiquidityPool serves as an implementation of a liquidity pool for Centrifuge pools following the EIP4626 standard. This contract allows users to interact with the pool by issuing shares (tranche tokens) against currency deposits. Key functionalities include handling deposits, mints, withdrawals, and redemptions. Additionally, the contract introduces asynchronous extension methods for deposit and redemption requests. It also manages pricing updates and enforces transfer restrictions for the TrancheToken. Overall, this contract facilitates the interaction between liquidity providers and Centrifuge pools, enabling the issuance and redemption of shares based on deposited assets.

2 . InvestmentManager.sol

Investment manager facilitates interactions between liquidity pools, a gateway, and a pool manager. The contract includes functions for managing deposit and redemption requests, allowing liquidity pools to interact with Centrifuge for tranche token issuance and redemptions. It enforces restrictions on currency types and user eligibility for holding restricted tranche tokens. The contract also handles processing of deposit and redemption requests after execution epochs, ensuring proper asset transfers between users and the escrow. Additionally, it offers various view functions for calculating shares, assets, and maximum allowable transactions. The contract is designed to work with a specific pricing mechanism, `adjusting currency and tranche token amounts based on price changes from Centrifuge. Overall, this contract acts as a bridge between liquidity pools and Centrifuge, managing transactions and ensuring compliance with specified rules and restrictions.

3 . PoolManager.sol

The Pool Manager contract serves as a pivotal component in managing Centrifuge pools and their associated tranches. Its primary objective is to coordinate the creation, deployment, and interaction of pools and tranches within the Centrifuge ecosystem. By providing a centralized management system, this contract enables streamlined operations, such as adding pools, allowing supported currencies, and deploying tranches and liquidity pools. Through these functionalities, the Pool Manager contributes significantly to the efficient functioning of Centrifuge's decentralized finance infrastructure.

4 . Escrow.sol

This contract serves as an escrow system for holding tokens securely. Its core function is to allow authorized entities (wards) to approve the release of funds held in escrow. By providing this capability, the Escrow contract ensures that only trusted parties can manage the movement of tokens. This contract is an essential component in enabling controlled and secure token management within the associated system.

5 . UserEscrow.sol

This contract operates as a secure token holding mechanism designed for specific destinations. It guarantees that tokens transferred in can only be moved to pre-defined destinations, an action restricted to authorized entities (wards). This escrow contract serves as a fundamental component in ensuring controlled token management within the associated system, enhancing security and reliability in the token transfer process.

6 . Root.sol

The Root.sol contract is a pivotal component in a system of smart contracts, functioning as a core authority over all other deployed contracts. It employs a sophisticated governance mechanism that includes features like pausing, timelocked actions, and external contract ward management. The contract can be instantly paused or unpaused, potentially restricting certain functionalities. Moreover, it introduces a timelocked ward management system, enabling specific actions to be scheduled for execution after a predefined delay. This delay period is determined during deployment. The contract also facilitates external addresses (contracts) in granting or revoking ward permissions on any contract in the system. This operation is regulated by an authentication mechanism provided by the AuthLike interface. To ensure secure operations, the contract emits various events to log critical state changes. With an organized system of access control and thorough error handling through require statements, the Root.sol contract lays a foundation for secure and controlled interactions within the broader smart contract ecosystem

7 . PauseAdmin.sol

This contract operates as a mechanism to manage accounts with the authority to initiate a pause action on the associated Root contract. It establishes a crucial layer of control over specific functions, allowing for instant pausing of the Root contract when necessary. This contract's significance lies in enhancing the security and reliability of operations within the associated system, ensuring prompt response to critical events.

8 . DelayedAdmin.sol

This contract acts as a delayed administrative control center for the associated Root contract. Its core function is to allow authorized parties to promptly pause or unpause operations on the Root contract, as well as schedule or cancel new rely operations using a timelock mechanism. This contract plays a significant role in enhancing security and control within the system, enabling a measured approach to critical administrative actions.

9 . Tranche.sol

The TrancheToken.sol contract is a specialized token implementation that incorporates both ERC20 and ERC1404 standards. It manages liquidity pools and enforces specific transfer restrictions defined by the RestrictionManager. This contract is designed to be an integral part of a broader system that involves handling tranche tokens with precise restrictions and interactions with trusted liquidity pools.

10 . ERC20.sol

The ERC20.sol contract provides a standard implementation of an ERC20 token with additional functionalities like minting, burning, and permit logic. It is designed to be flexible and compatible with various DeFi applications and smart contracts. Additionally, it supports the ERC1271 standard for signature validation, enabling interaction with multiple liquidity pools.

11 . RestrictionManager.sol

The RestrictionManager.sol contract enforces transfer restrictions based on membership status. It ensures that transfers are only allowed to addresses that are considered valid members. Validity is determined by a timestamp associated with each member. The contract provides functions to update the list of valid members. It is designed to work in conjunction with ERC1404-compliant tokens, adding an additional layer of control over transfers.

12 . Gateway.sol

The Gateway.sol contract serves as a central hub for managing messages and interactions within the system. It handles incoming messages, ensuring they are directed to the correct manager for execution. It also formats and sends outgoing messages through the specified router. The contract plays a critical role in coordinating actions between different components in the system.

13 . Messages.sol

This contract defines a library called"Messages"that facilitates the encoding and decoding of different types of messages. These messages correspond to various actions that can be performed within a financial system. Each message is associated with a specific function and contains encoded parameters relevant to that function.

The contract includes several message types, each represented by an enumeration. These message types cover actions such as adding currencies, pools, tranches, updating prices, managing members, transferring assets, handling investment orders, collecting investments, and more`.

14 . Router.sol

The AxelarRouter contract is a Solidity smart contract designed to facilitate routing between different blockchain networks through integration with an Axelar Gateway. It relies on the use of two external interfaces, AxelarGatewayLike and GatewayLike, to interact with other contracts and validate commands. The contract establishes a set of predefined constants for addresses related to the Axelar system and features state variables like axelarGateway and gateway to manage contract addresses. The constructor initializes the contract with an Axelar Gateway address and authorizes the deployer. Custom modifiers, such as onlyCentrifugeChainOrigin and onlyGateway, enforce access control for specific functions. The contract can both receive incoming messages, validate them through the Axelar Gateway, and pass them to a designated gateway contract for execution. It also enables the gateway to send messages to other chains. Proper security and access control are essential to ensure the contract's safe operation in a multi-chain environment.

15 . Auth.sol

The Auth contract provides a simple authentication pattern for managing permissions within a smart contract system. It features a mapping called wards that associates addresses with permission levels (0 or 1), where 1 indicates authorized and 0 indicates unauthorized. The contract emits two events, Rely and Deny, to log when permissions are granted or revoked for a specific user.

16 . Context.sol

The Context contract is an abstract contract that provides information about the current execution context in a Solidity smart contract. It specifically focuses on identifying the sender of the transaction and its associated data. This information is crucial for understanding the origin and parameters of a transaction.

The contract contains a single function called _msgSender, which is marked as internal and virtual. The function returns the address of the sender of the current transaction. It achieves this by accessing msg.sender, which is a standard variable in Solidity representing the sender's address.

17 . Factory.sol

Factories serve as utility contracts for deploying new instances of liquidity pools and tranche tokens. They employ a permissioning system, ensuring that the necessary access is granted to the relevant parties. Additionally, the deterministic addressing mechanism used in the TrancheTokenFactory enhances transparency and predictability in contract deployments. Please note that the exact functionality and security of these contracts depend on the implementations of the referenced contracts (LiquidityPool, TrancheToken, RestrictionManager, and Auth).

18 . SafeTransferLib.sol

The "SafeTransferLib" is a Solidity library designed to facilitate secure transfers of ERC20 tokens within smart contracts. It provides functions for transferring tokens from one address to another (safeTransferFrom), allowing the message sender to transfer tokens to a recipient (safeTransfer), and approving a contract to spend a specified amount of tokens (safeApprove). The library includes robust error handling to ensure the success of these operations, and it has been adapted from a specific source, indicating its potential use in contexts like decentralized exchanges. Overall, the library serves as a reusable and reliable utility for handling token transfers securely within a Solidity smart contract system.

Codebase Analysis Diagram

1 . LiquidityPool.sol

LiquidityPool

2 . InvestmentManager.sol

InvestmentManager

3 . PoolManager.sol

PoolManager

4 . Escrow.sol

Escrow

5 . UserEscrow.sol

userEscrow

6 . Root.sol

Root

7 . PauseAdmin.sol

pauseAdmin

8 . DelayedAdmin.sol

DelayedAdmin

9 . Tranche.sol

Tranche

10 . ERC20.sol

ErC20

11 . RestrictionManager.sol

Restrictionmanager

12 . Gateway.sol

Gateway

13 . Messages.sol

messages

14 . Router.sol

Router

15 . Auth.sol

Auth

16 . Context.sol

Context

17 . Factory.sol

Factory

18 . SafeTransferLib.sol

SafeTransferLib

Codebase Quality Analysis

Centrifuge Liquidity Pools codebase is designed with a focus on robustness, security, and composability. Here are some key points regarding the codebase quality:

  • Coding Style Inspired by MakerDAO: The codebase follows a coding style heavily inspired by MakerDAO. This suggests a commitment to established best practices and industry standards in smart contract development.

  • Composition over Inheritance: The codebase prioritizes composition over inheritance, which is generally considered a best practice in Solidity development. This can lead to more modular and maintainable code.

  • No Upgradeable Proxies: Instead of using upgradeable proxies, the codebase opts for contract migrations. This indicates a preference for a more straightforward approach to contract management.

  • Limited Dependencies: The codebase aims to have as few dependencies as possible. This can contribute to a more streamlined and less complex codebase.

  • Authentication using the Ward Pattern: The codebase employs the ward pattern for authentication, where addresses can be relied or denied access. This is a recognized approach to access control in Solidity.

  • Parameter Updates through File Methods: Key parameter updates of contracts are executed through file methods. This can lead to more controlled and auditable changes to the contract's behavior.

  • External General Message Passing Protocols: The communication between Liquidity Pools and Centrifuge Chain uses external general message passing protocols. This suggests a structured approach to inter-contract communication.

  • Support for Multiple Currencies: The codebase is designed to support deposits in multiple currencies, with each Liquidity Pool linked to one currency and tranche token. This flexibility in currency support adds to the versatility of the protocol.

  • Decimal Normalization for Price Calculations: The codebase accounts for potential differences in decimals between tranche tokens and investment currencies by normalizing balances and prices. This demonstrates attention to detail in handling various token standards.

  • Access Control Measures: The Root contract serves as a ward on all other contracts, with a PauseAdmin able to instantaneously pause the protocol. This shows a structured approach to access control.

Centralization Risks:

  • Emergency Scenarios: There are scenarios where control over critical functions could be compromised. For example, a malicious ScheduleUpgrade message from a rogue router could potentially disrupt operations. Additionally, if someone gains control over the PauseAdmin, they could potentially halt the system.

  • Escrow Contract Vulnerability: While funds locked in the Escrow contract are not fully protected from transfers, there are mitigating factors. Liquidity is constantly transferred between different blockchains, and funds are typically only temporarily held in the Escrow. Additionally, tokens held in the UserEscrow contract are locked to a specific destination, providing an extra layer of security.

Systematic Risks:

  • Epoch Mechanism: The asynchronous nature of deposits and redemptions, due to the epoch mechanism, introduces complexity and potential delay in executing transactions. This could impact user experience and liquidity management.

  • Message Passing Protocol: The reliance on external general message passing protocols may introduce a degree of unpredictability or potential vulnerabilities if not implemented or handled correctly.

Learning and insights

Through the audit of Centrifuge Liquidity Pools, I've gained valuable knowledge and insights that have significantly enhanced my understanding of decentralized finance (DeFi) protocols and blockchain-based systems. Here's what I've learned and how it will help me grow my skills:

  • Smart Contract Expertise: I've deepened my knowledge of smart contracts, particularly in analyzing and understanding complex contracts like the Investment Manager, Pool Manager, Gateway, and Routers. This hands-on experience has sharpened my ability to navigate intricate contract interactions.

  • DeFi Architecture: The audit exposed me to the architecture and inner workings of DeFi protocols. Understanding how these systems manage real-world assets and offer multiple tranches for investors is crucial for auditing and working on similar DeFi projects in the future.

  • Risk Assessment: I've honed my skills in identifying and evaluating risks within blockchain systems. This includes recognizing centralization and systematic risks and devising strategies to mitigate them, which is invaluable for assessing the security of DeFi projects.

  • Message Passing Protocols: I now have a better grasp of external message passing protocols and their importance in blockchain systems. This knowledge will enable me to assess and ensure proper implementation of communication mechanisms in future projects.

  • Access Control and Security: The audit provided insights into access control mechanisms and security measures. This knowledge will help me design and implement robust security measures to protect against potential vulnerabilities in blockchain applications.

  • Handling Multiple Currencies: Understanding the challenges and solutions for supporting multiple currencies within a protocol has expanded my skill set. I now have a better understanding of how to manage diverse assets and ensure consistency in price calculations.

  • Transaction Flow Management: Dealing with the asynchronous nature of transactions due to the epoch mechanism has improved my ability to manage complex transaction flows in DeFi systems, which is crucial for optimizing user experiences.

  • Code Style and Best Practices: Analyzing the code style inspired by MakerDAO and the use of best practices, such as composition over inheritance and dependency minimization, has reinforced my understanding of coding best practices and design principles.

  • Real-World Asset Integration: The protocol's interaction with real-world assets and integration with Centrifuge Chain provided insights into how blockchain systems can bridge the gap between the digital and physical worlds, a skill that will be increasingly relevant in blockchain development.

  • Identifying Centralization Risks: I've gained the ability to recognize potential centralization risks within a protocol, helping me identify critical points of failure and design safeguards against them in future projects.

Conclusion

The Centrifuge Liquidity Pools protocol is a well-designed platform for managing pools of real-world assets with multiple tranches. Its architecture and functionality demonstrate a thoughtful approach to decentralized finance. While potential centralization and systematic risks have been identified, the protocol's design choices and security measures provide a strong foundation for safe operation.

The audit process has contributed significantly to the understanding of DeFi protocols and their associated risks. The protocol's composition over inheritance, use of contracts migrations, and minimal dependencies align with best practices. The ward pattern for authentication and key parameter updates through file methods further bolster security.

It is recommended that the Centrifuge team continues to vigilantly monitor and address any potential vulnerabilities, particularly in emergency scenarios involving control over critical functions. Additionally, ongoing testing and evaluation of the epoch mechanism and message passing protocol will be crucial to ensure smooth and efficient operations.

Overall, the Centrifuge Liquidity Pools protocol shows promise in revolutionizing the management of real-world assets in the DeFi space. With careful attention to security and continued refinement, it has the potential to be a valuable addition to the ecosystem.

Time spent:

55 hours

#0 - c4-pre-sort

2023-09-17T02:08:45Z

raymondfam marked the issue as sufficient quality report

#1 - c4-judge

2023-09-26T17:15:08Z

gzeon-c4 marked the issue as grade-a

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter