Platform: Code4rena
Start Date: 09/01/2024
Pot Size: $100,000 USDC
Total HM: 13
Participants: 28
Period: 28 days
Judge: 0xsomeone
Total Solo HM: 8
Id: 319
League: ETH
Rank: 16/28
Findings: 1
Award: $819.61
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: aariiif
Also found by: 0xepley, LinKenji, Sathish9098, ZanyBonzy, catellatech, fouzantanveer, hassanshakeel13, hunter_w3b, invitedtea, yongskiws
819.6092 USDC - $819.61
Opus Protocol is a cross-margin autonomous credit protocol that offers dynamic loan management based on each user's collateral profile. The whole diagram for the smart contracts is here. All the diagrams in this report are from Opus Official Doc:
Key features and highlights:
The Absorber is a component of the Opus protocol, designed as a stability pool that enables yin holders to contribute to liquidation processes, termed as "absorptions." By participating in the Absorber, users can:
The contract introduces specific terminologies like "provide" and "remove" for depositing and withdrawing yin to avoid confusion with similar operations in other parts of the protocol.
Supports the distribution of whitelisted rewards, vested based on internal shares, and distributed during user interactions or absorptions.
Includes a kill function to pause liquidity provision and reward distribution in emergencies, while still allowing liquidity removal.
The Purger
module serves as a crucial interface within the Opus protocol's multi-layered liquidation system. It enables the liquidation of unhealthy troves to maintain the protocol's solvency, utilizing either the user's own yin or the yin pooled in the Absorber. This dual-method approach ensures flexibility and efficiency in handling liquidations. Liquidation occurs when a trove's Loan-to-Value (LTV) ratio is higher than a certain threshold, indicating it is undercollateralized, and absorption is another form of liquidation where surplus assets are distributed to the stability pool or other troves.
The contract includes several components for access control and reentrancy protection, interfaces for interacting with other related modules (Shrine
, Sentinel
, Absorber
, Seer
), and a set of parameters that define liquidation behavior, penalties, and compensation for users who perform liquidations.
The diagram comes from the Opus Official doc
The diagram comes from the Opus Official doc
Both functions are designed to revert if the Shrine component of the protocol is not live, ensuring operations are halted during critical failures or maintenance periods.
The penalty structure is critical in balancing the risk and reward for participants, with distinct calculations for the liquidate
and absorb
functions. A penalty scalar is introduced in the absorption process to adjust the incentivization dynamically, based on the protocol's needs and the prevailing market conditions.
Compensation mechanisms are in place to encourage users to initiate the absorb
process, set to the lower of 3% of the trove's collateral value or a fixed USD amount. This ensures that there is always an incentive to support the protocol's stability, even in varying market conditions.
The Abbot module serves as the central interface for users to interact with their troves within the protocol, facilitating the opening, management, and closure of troves. Its design ensures immutability and sequential issuance of trove IDs, enhancing the integrity and traceability of user interactions.
The action of opening a trove is the entry point for users into the protocol's ecosystem, enabling them to deposit collateral and, if desired, mint synthetic assets. This process is critical for establishing the user's stake and capability within the protocol.
Collateral depositing is a flexible operation, allowing for the enhancement of a trove's health and borrowing capacity. The protocol's design ensures that collateral management is secure and directly tied to the user's control.
The withdrawal mechanism is designed with safeguards to ensure the trove's stability and the overall health of the protocol, such as maintaining minimum loan-to-value ratios and collateral values.
The forging process introduces synthetic assets into the ecosystem, directly tied to the collateralized troves. This mechanism is central to the protocol's functionality, enabling users to leverage their collateral effectively.
Melting represents the reduction of debt within a trove, a crucial aspect of maintaining balance and solvency within the protocol. This function allows for the dynamic management of debt positions, directly impacting the protocol's liquidity and stability.
The design of the Abbot module incorporates several security measures to maintain the integrity of troves and the overall protocol. Key considerations include:
The flash_mint
contract appears to implement a flash loan functionality compliant with EIP-3156 for Starknet. It allows for the minting of a synthetic asset represented by the contract shrine
. Users can flash borrow up to 5% of the total Yin supply (FLASH_MINT_AMOUNT_PCT
) within the constraints of the total debt ceiling. A reentrancy guard component is used to prevent reentrancy attacks during the flash loan process.
Flash loans are an innovative DeFi tool allowing for the borrowing of assets without upfront collateral, under the condition that the liquidity is returned within the same transaction block. The Flash Mint module's adherence to EIP-3156 ensures compatibility and standardization in its flash loan offering.
The Flash Mint module is designed with a crucial mechanism to interact with the protocol's debt ceiling, ensuring that the flash loan operations do not destabilize the system's solvency.
The introduction of flash loans, while adding utility and efficiency to the protocol, also brings specific risks and considerations:
The Sentinel module is designed as a central interface within the protocol, enabling other modules to interact with Gates without needing to know each Gate's specific address. It acts as an abstraction layer, simplifying access control and interactions involving collateral assets.
kill_gate()
function, allowing for the immediate halt of further deposits (enter
function) for a specific Gate through the Sentinel. This measure is critical in emergency scenarios where halting new deposits while allowing withdrawals (exit
function) is necessary for user protection and protocol stability.The Sentinel module's design incorporates several security measures to safeguard the protocol's integrity:
The Gate smart contract serves as an interface for users to deposit and withdraw assets in exchange for Yang, a credit system used within the Opus Autonomous Credit Protocol. The contract utilizes functions such as enter
and exit
to manage the asset and Yang balances. A Sentinel address is authorized to handle specific contract functions, while the Shrine address is associated with the credit system. This report provides an audit of the Gate smart contract, focusing on security, efficiency, and adherence to best practices.
The Gate module's approach to asset conversion does not rely on a fixed rate. Instead, it dynamically calculates the conversion rate based on the prevailing balance of collateral tokens within the Gate and the total amount of yang. This design allows for efficient redistribution of collateral via rebasing, where the value of each yang unit in terms of the underlying collateral can increase over time.
A notable aspect of the Gate module is its defense against the first depositor front-running vulnerability, common in mechanisms like ERC-4626. Rather than penalizing the first depositor, the protocol itself contributes a small initial deposit of collateral, which is converted to yang and dedicated to the Shrine. This preemptive measure shifts the burden from users to the protocol, ensuring fairness and security in the initiation of new collateral types.
Both the enter and exit functions implement rounding down as a default policy, favoring the protocol. This means that when users deposit collateral for yang, or withdraw collateral against their yang, the amounts are rounded down to the nearest whole number, ensuring minimal discrepancies in favor of the protocol's reserves.
The Gate module upholds several key properties to ensure consistency and reliability:
The Shrine module serves as the central accounting hub for the synthetic ecosystem, managing the intricate balance of deposited collateral (yang) and minted synthetic (yin) across all user debt positions (troves) and the protocol itself. It ensures the accurate calculation and application of interest on each trove, maintains the valuation of collateral types (yangs), and integrates the multiplier values from the Controller module. Additionally, the Shrine module adheres to the ERC-20 standard for the synthetic it represents, reinforcing its role in the ecosystem's liquidity and exchange mechanisms.
The Shrine module employs a discrete timekeeping system, defining intervals based on a constant time period. This system underpins the interest calculation mechanism, ensuring consistency and predictability in the accrual of debt over time. Troves are identified by unique IDs and are tracked through the Trove struct, which records their debt and interest accrual starting points.
Yang represents the internal abstraction of collateral tokens, normalized to a precision of 18 decimal places, allowing for flexible and efficient collateral management. The Shrine's design ensures that once a collateral type is accepted and integrated as yang, it becomes a permanent fixture of the ecosystem, though it can be suspended under specific conditions to manage risk and maintain protocol health.
Interest on troves is calculated dynamically, combining the base rates of deposited yangs with multiplier values over time. This system allows for the nuanced management of debt costs, reflecting the varying risk profiles and market conditions of different collateral types. The forge fee mechanism serves as a stabilizing force, discouraging excessive minting of yin during periods of volatility or devaluation, thus protecting the protocol's stability.
The Shrine module outlines a multi-tiered liquidation approach, including searcher liquidations, absorptions, and redistributions, to manage trove health and protocol solvency. Redistributions play a key role in maintaining the ecosystem's equilibrium, reallocating collateral and debt among troves to ensure a fair and balanced distribution of risk and reward.
In scenarios where the protocol's aggregate loan-to-value ratio breaches critical thresholds, the Shrine can enter recovery mode, adjusting operational parameters to safeguard solvency and encourage corrective user actions. The module also includes an emergency kill function, allowing for the decisive shutdown of user-facing operations in extreme circumstances.
The Equalizer plays a pivotal role in maintaining the financial equilibrium of the Shrine by addressing the budget variances through debt surplus minting or deficit reduction. This module ensures the synthetic ecosystem remains sustainable, avoiding the pitfalls of perpetual debt cycles by aligning the total debt with the circulating synthetic currency (yin).
A critical aspect of the Equalizer's operation is its ability to temporarily adjust the debt ceiling to accommodate the minting of debt surpluses. This ensures that the system can continue to mint yin as needed, without being hindered by a pre-existing debt ceiling, thus maintaining the protocol's liquidity and operational fluidity.
The Equalizer not only addresses the Shrine's budgetary needs but also plays a significant role in the distribution of income within the ecosystem. By minting yin to its address and allowing for its subsequent allocation, the Equalizer ensures that the benefits of debt surpluses are equitably shared among designated recipients, as per the Allocator module's directives.
The Caretaker module is designed to manage the protocol's deprecation, especially the Shrine, ensuring a structured and equitable process for yin holders to claim collateral corresponding to their holdings. It embodies the protocol's emergency shutdown mechanism, safeguarding the interests of participants by allowing for the redemption of yin and the withdrawal of collateral from troves post-shutdown.
The execution of the shut
function marks the beginning of the protocol's orderly deprecation. All debts within troves become irreparable, and the necessary collateral to back the total forged debt is moved to the Caretaker. This system-wide redistribution effectively finalizes each trove's collateral position, aligning it with the protocol's overall liquidity state at the time of shutdown.
The diagram comes from the Opus Official doc.
Following the shutdown, yin holders are entitled to exchange their yin for a share of the collateral now under the Caretaker's management. This process is governed by the total debt at shutdown, with each yin's redemption value being proportional to the remaining reclaimable yin supply.
Trove owners are permitted to withdraw the residual collateral from their troves post-shutdown. Given the equitable redistribution of collateral during shutdown, the remaining collateral available for withdrawal will reflect the trove's share of the total collateral post-redistribution.
The Controller module serves as an autonomous regulatory mechanism within the synthetic ecosystem, tasked with adjusting a global interest rate multiplier to minimize the deviation of yin's market price from its peg. By modulating the multiplier, the Controller indirectly influences trove owners' decisions regarding debt creation and repayment, aiming to stabilize the synthetic's value.
The core principle of the Controller is to respond to fluctuations in yin's market price with adjustments to the interest rate multiplier:
The Controller employs a Proportional-Integral (PI) control strategy, augmented with a nonlinear function to fine-tune its responsiveness to price deviations. This nonlinearity ensures that minor fluctuations are met with proportionate adjustments, while significant deviations prompt more substantial interventions to preemptively counteract potential market imbalances.
The seer
module operates as the linchpin in aggregating and validating price data for the synthetic ecosystem, interfacing with various oracle modules to ascertain the current market prices of collateral tokens (yangs). By standardizing the interaction through adapter modules that conform to the IOracle interface, the Seer ensures compatibility and reliability in price data acquisition.
To incorporate an oracle into the ecosystem, an adapter module adhering to the IOracle interface must be implemented. This approach standardizes the diverse functionalities and outputs of different oracles, allowing the Seer to seamlessly obtain price data from multiple sources without being encumbered by the intricacies of individual oracle implementations.
It is crucial to distinguish between the price of a yang and its underlying collateral token. The Seer is tasked with adjusting the raw oracle price data to reflect the yang's value, taking into account the conversion rate between a yang and its underlying collateral. This ensures that the price data accurately represents the yang's market value within the protocol's context.
Price updates within the Seer module can be initiated under two conditions:
At its inception, the protocol will primarily utilize the Pragma oracle, with plans to integrate additional fallback oracles as the Starknet ecosystem expands. This strategy ensures redundancy and reliability in price data, safeguarding against single points of failure and providing a robust foundation for the protocol's valuation mechanisms.
The audit focused on reviewing and analyzing the core functionality and security of the Opus Protocol's smart contracts. Specific areas of focus included:
The codebase demonstrates a coherent structure and systematic modularization. Each module encapsulates specific protocol functions, promoting clear delineation of responsibilities and readability.
The protocol relies on an honest admin for the integrity of its access control mechanisms, posing a centralization risk.
Overall, the Opus Protocol's smart contract suite is well-organized, featuring distinct components that handle specific aspects of the protocol logic. The autonomous nature of adjustments in response to market conditions shows significant promise for decentralized finance. To enhance trust and protocol resilience, a movement towards decentralized governance structures is recommended, coupled with the implementation of a fallback oracle system for improved data reliability.
32 hours
#0 - c4-pre-sort
2024-02-07T17:19:00Z
bytes032 marked the issue as sufficient quality report
#1 - c4-judge
2024-02-26T18:00:27Z
alex-ppg marked the issue as grade-a