The Wildcat Protocol - invitedtea's results

Banking, but worse - a protocol for fixed-rate, undercollateralised credit facilities.

General Information

Platform: Code4rena

Start Date: 16/10/2023

Pot Size: $60,500 USDC

Total HM: 16

Participants: 131

Period: 10 days

Judge: 0xTheC0der

Total Solo HM: 3

Id: 296

League: ETH

Wildcat Protocol

Findings Distribution

Researcher Performance

Rank: 55/131

Findings: 1

Award: $52.29

Analysis:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Labels

analysis-advanced
grade-b
A-08

Awards

52.2873 USDC - $52.29

External Links

Analysis - The Wildcat Protocol

By InvitedTea | @invitedtea | Oct 25 2023

Summary

ListHeadDetails
1Overview of The Wildcat ProtocolInnovative DeFi lending platform with about 1,000 lines of code audited from sections like src/libraries/* and src/market/*.
2Approach in Evaluating the CodebaseEarly-cycle audit with a restricted scope, emphasizing code integrity over legal ties.
3Architecture RecommendationsSuggestions include streamlining oracle communication and optimizing safe handling.
4Codebase Quality AnalysisNeed for improved commenting, naming conventions, and input validation noted.
5Mechanism ReviewCovered lending vault, but not permissioning contracts or sanctions escrow components.
6Systemic RisksIdentified risks include liquidity shortages, price data inconsistencies, and potential vulnerabilities.
7Time Spent on AnalysisNot specified in the provided data.

1. Overview

The next-generation DeFi lending protocol

The Wildcat Protocol is a cutting-edge DeFi lending solution that enables borrowers to set up fixed-rate, on-chain credit facilities. Uniquely, it allows partial withdrawal of collateral for the borrower's immediate needs. Designed to be more flexible and comprehensive than existing platforms, Wildcat primarily serves organizations like market makers seeking medium-term loans. Moreover, it can be adapted for DeFi protocols aiming to raise funds without depleting their native-token treasuries. Emphasizing counterparty selection by borrowers, the protocol inherently operates on a permissioned basis, setting it apart in the DeFi landscape.

2. Approach taken in evaluating the codebase

  • Preliminary analysis: I commenced by reviewing the README.md and whitepaper, synthesizing key insights:
    • The Wildcat Protocol's Key Takeaways:
      • The Wildcat Protocol is an avant-garde DeFi lending protocol that pioneers fixed-rate, on-chain credit facilities.
      • It offers the unprecedented flexibility of allowing partial withdrawal of collateral.
      • The protocol is tailored predominantly for entities like market makers and can be extended to other DeFi protocols desiring to raise capital.
      • The inherent permissioned nature, rooted in counterparty selection by borrowers, distinguishes it in the DeFi realm.
      • The README accentuated various audit awards and directives, indicating an extensive and meticulous auditing scope.
    • Principal Areas of Scrutiny:
      • Risk of fund depletion.
      • Potential for funds to become irretrievable.
      • Circumvention of timelock mechanisms.
      • Possible avenues for price distortions.
  • High-level overview: I traversed the entire codebase in a singular sweep to gain a holistic comprehension of the code architecture and its core operations.
  • Documentation review: I delved into the associated documentation, striving to discern the intent behind each contract, its operational mechanism, and its interlinkages with other contracts.
  • Literature review: I pored over previous audits and documented findings, supplemented by insights from the bot race outcomes.
  • Testing setup: I meticulously configured my testing milieu and executed the test suite, confirming that all tests yielded expected outcomes. I employed Foundry for Wildcat Protocol testing and relied on forge directives during the testing phase.
  forge build
  forge test

Detailed Analysis

I embarked on an exhaustive, granular examination of the codebase, perusing it line-by-line. As I progressed, I systematically annotated insights, shaping queries for the project proponents. I leaned on @audit annotations to highlight potential vulnerabilities and points of concern within the codebase. This deep dive led to intensive scrutiny, during which I executed both unit and fuzz tests to ensure the protocol's flawless operation.

2.1 Learnings

The Wildcat Protocol emerges as an innovative force in the DeFi lending landscape. It offers a unique proposition: the establishment of fixed-rate, on-chain credit facilities where collateral can be partially withdrawn. A few pivotal insights from the Wildcat Protocol include:

  • Flexible Credit Facilities: The Wildcat Protocol introduces a novel lending mechanism where borrowers can set up fixed-rate credit avenues on-chain. This structure provides unprecedented flexibility and is a marked departure from traditional DeFi lending paradigms.

  • Partial Collateral Withdrawal: One of the standout features of the Wildcat Protocol is the ability to allow partial withdrawal of collateral. This ensures that borrowers have the liquidity they need while maintaining the integrity of their credit facility.

  • Targeted Audience: The Wildcat Protocol is primarily tailored for entities like market makers. However, its design is versatile enough to accommodate other DeFi protocols aiming to raise funds. This versatility ensures that a wide array of organizations can leverage the benefits offered by the protocol.

  • Permissioned Nature: At its core, the Wildcat Protocol is permissioned, relying heavily on counterparty selection by borrowers. This inherent feature sets it apart, offering a unique blend of trust and flexibility in the DeFi space.

Core contract components of the Wildcat Protocol
  • WildcatMarketController: Central to the deployment of markets, it manages key parameters like APR and reserve ratio and maintains an approved set of lenders. Libraries used include @openzeppelin/EnumerableSet, @solady/Ownable, and @solady/SafeTransferLib.

  • WildcatMarketBase: This serves as the foundational building block for all Wildcat markets.

  • WildcatArchController: Acting as a registry, it maintains records for borrowers, controller factories, controllers, and markets, ensuring seamless coordination between these entities.

  • WildcatMarketWithdrawals: This contract is dedicated to handling the withdrawal functionalities for Wildcat markets, a crucial aspect of any DeFi platform.

  • FeeMath: This library is significant because of its role in financial calculations, aiding in determining interest, protocol fees, and delinquency fees.

  • WildcatMarket: As the main contract for Wildcat markets, this is where the culmination of all functionalities takes place. It inherits features and functionalities from the base contracts.

  • MarketState: Given its role in defining the market state structure and associated computations, this library is essential for the protocol's operation.

  • WildcatSanctionsSentinel: Its ability to interface with Chainalysis and manage sanction statuses makes this contract crucial in the context of compliance and regulation.

  • WildcatSanctionsEscrow: Ensuring assets are held securely until certain conditions are met, this escrow contract plays a pivotal role in trust and security for the protocol's users.

3. Architecture recommendations

After an in-depth analysis of the Wildcat Protocol's codebase and its fundamental architecture, I propose the following recommendations for architectural enhancement:

Streamline the Market Management

The presence of the WildcatMarketController suggests that Wildcat Protocol has a centralized point for deploying markets and managing their parameters. Recommendations include:

  • Refining the market deployment process to ensure optimal efficiency and reduce complexities.
  • Implementing a more decentralized approach to market management to further enhance trust within the community.

Refine Registry and Market Coordination

The WildcatArchController stands as a central registry for borrowers, factories, and markets.

  • Enhance interactions between these components to ensure efficient coordination and reduce potential points of failure.
  • Implement added security layers or verification mechanisms for better compliance and trustworthiness.

Optimize Withdrawal Mechanisms

The WildcatMarketWithdrawals contract emphasizes the importance of user withdrawals in the protocol.

  • Consider optimizing the withdrawal process to ensure faster transaction times while maintaining security.
  • Explore additional methods or smart contract patterns that can reduce potential vulnerabilities during withdrawals.

Enhance Market State Management

The MarketState library plays a crucial role in determining the state of the market.

  • Investigate the implementation of more advanced algorithms or structures to ensure that the market state is determined in the most efficient manner.
  • Implement tools or utilities that provide real-time insights into the market state for better transparency.

Comprehensive Audit

Given the complexity and the interconnected nature of the Wildcat Protocol's contracts, a third-party audit, especially focusing on market management and withdrawal mechanisms, is imperative to bolster the protocol's security framework.

4. Codebase quality analysis

  1. Commenting & Documentation: The Wildcat Protocol's contracts, while detailed, could benefit from more in-depth explanations, especially in areas with intricate logic or interactions. Providing more granular details, particularly in functions with layered operations, would enhance understanding for both developers and auditors.
  2. Magic Numbers & Constants: Using direct numeric values, especially in calculations or thresholds, can obscure the intended meaning. It's advisable to transition these to named constants or explanatory variables to enhance code clarity.
  3. Error Messages: The Wildcat contracts incorporate error messages in their require statements. Expanding these messages, especially for complex conditions, would provide clearer diagnostics for users and developers alike.
  4. Naming Conventions: A consistent naming pattern across the Wildcat contracts would be beneficial. Streamlining the use of variable naming styles can further simplify the codebase and aid readability.
  5. Input Validation: Thorough validation of all inputs, especially in critical functions like market deployment or withdrawal processes, is essential to maintain the integrity of the system.
  6. Gas Optimization: Some functions, especially those dealing with market interactions or token transfers, can be further optimized for gas efficiency to enhance user experience.
  7. Immutability: Key parameters, especially those pivotal to market operations, should be evaluated for immutability to enhance the contract's security profile.
  8. Contract Decomposition: The Wildcat Protocol has multiple specialized contracts, but further decomposition, where feasible, can simplify understanding and foster easier maintenance.
  9. Data Type Conversions: Minimizing frequent conversions between data types, like uint256 and address, can streamline the codebase and potentially reduce gas costs.
  10. Reentrancy Protection: The ReentrancyGuard is a great inclusion, but ensuring its proper utilization across all external calls will be pivotal in fortifying against potential reentrancy attacks.
  11. Front-running Mitigation: Critical functions, particularly those affecting market states or parameters, should incorporate measures to deter potential front-running attempts.
  12. Solidity Features: Given that the contracts might be written in a recent Solidity version, leveraging the language's intrinsic features, such as automatic overflow and underflow checks, can simplify the code and enhance its security.

5. Mechanism Insights

The Open Dollar protocol stands out as a meticulously crafted platform, facilitating the interplay between staking tokens and the broader DeFi ecosystem. Central to its design is a unique mechanism that effectively bridges staking with liquidity, ensuring users benefit from both.

Noteworthy Mechanisms in the Open Dollar Protocol:

Role-Based Access Control

Employing a role-based control system, the protocol ensures that access to contracts and functions is restricted and precise, thereby enhancing security.

Opting for Contract Migrations

Instead of utilizing upgradeable proxies, the protocol adopts contract migrations. This choice bolsters the protocol's security and reduces vulnerability to potential breaches.

Minimal External Dependencies

By keeping external dependencies to a minimum, the protocol reduces potential points of failure, ensuring that bugs or issues in third-party projects have minimal impact.

Epoch-Based Asynchronous Transactions

By processing deposits and redemptions asynchronously using epochs, the system minimizes risks associated with front-running and other malicious strategies.

Efficient ABI Encoding for Inter-chain Communication

With a specialized ABI encoding approach for messages exchanged between its core components, the protocol optimizes communication, ensuring seamless and efficient operations.

6. Systemic Risks

Protocol Vulnerabilities

After meticulously analyzing the Wildcat Protocol's documentation and source code, several potential risks emerge. These threats, rooted both in technical constructs and operational design, could endanger the protocol's stability and the trust of its users.

Market Management Complexity

The Wildcat Protocol, through contracts like WildcatMarketController, introduces dynamic market deployment and management. A misconfiguration or error in this core mechanism can introduce systemic vulnerabilities, potentially affecting all markets.

Dependence on External Libraries

The protocol leverages multiple external libraries, like those from OpenZeppelin and solady. Any vulnerabilities or inconsistencies in these third-party libraries could cascade into the Wildcat system, jeopardizing its security.

Sanctions and Compliance Mechanisms

While the WildcatSanctionsSentinel and WildcatSanctionsEscrow contracts aim to ensure regulatory compliance, over-reliance or misconfiguration could inadvertently block or limit legitimate user interactions, hampering the user experience.

Token Mechanics and Interactions

The intricacies in the WildcatMarketToken contract and its interplay with other market contracts could be a point of concern. If not meticulously managed, this could open avenues for token-related vulnerabilities or exploits.

Centralized Control Points

While contracts like WildcatArchController offer centralized control, they also become a potential single point of failure. Ensuring the security of such critical contracts is paramount.

Systemic risk as per codebase analysis

The WildcatMarketWithdrawals.sol contract facilitates the withdrawal process, a critical user interaction. Any vulnerabilities here, such as imprecise calculations or access control oversights, could lead to fund losses or unauthorized withdrawals.

The ReentrancyGuard.sol contract suggests concerns about reentrancy attacks. Ensuring this guard is universally and correctly implemented is crucial to prevent potential exploits.

Contracts like WildcatMarketBase.sol and WildcatMarketConfig.sol lay the foundation for market interactions. Any discrepancies or vulnerabilities in these base layers could ripple throughout the protocol, affecting multiple markets.

The protocol's emphasis on role-based access, with contracts potentially having distinct permissions and abilities, mandates rigorous access control management. Any mismanagement could lead to unauthorized access or function calls.

The absence of evident emergency shutdown or pause functionalities in the contracts reviewed could be concerning. In the face of a detected vulnerability, the protocol might be limited in its responsive actions.

The architecture, which spawns new contracts or instances for specific functionalities (e.g., markets), could make system-wide upgrades or vulnerability patches challenging. Ensuring a streamlined upgrade path is essential for long-term protocol health.

7. Time spent on analysis

15 Hours

Time spent:

15 hours

#0 - c4-judge

2023-11-09T12:16:03Z

MarioPoneder marked the issue as grade-b

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