Platform: Code4rena
Start Date: 21/02/2024
Pot Size: $200,000 USDC
Total HM: 22
Participants: 36
Period: 19 days
Judge: Trust
Total Solo HM: 12
Id: 330
League: ETH
Rank: 26/36
Findings: 1
Award: $319.93
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: aariiif
Also found by: 0xepley, Myd, SBSecurity, fouzantanveer, foxb868, kaveyjoe
319.9291 USDC - $319.93
Wise Lending is a decentralized finance (DeFi) platform that harnesses the power of cryptocurrency to create a new lending experience. It functions as a liquidity marketplace, connecting borrowers and lenders directly.
This report provides a comprehensive analysis and evaluation of the Wise Lending smart contract codebase. As a complex decentralized system, Wise Lending aims to enable secure and efficient decentralized lending, contributing to the rapidly growing DeFi (Decentralized Finance) landscape.
Wise Lending positions itself as a decentralized liquidity marketplace for crypto assets. Users can participate in two primary ways:
This review covers various aspects of the codebase, including its architecture, design, and implementation details. By examining the contract structure, logic, and interactions, this report identifies potential areas of improvement and offers suggestions to enhance the codebase. The recommendations provided are based on best practices in Solidity development, gas optimization techniques, and security considerations, ensuring a more robust, secure, and efficient system.
Here's what makes Wise Lending unique compared to other crypto lending platforms
1 . WiseLending WiseLending is the main contract that acts as the interface between the user and the lending protocol. It has several key functionalities such as:
2 . WiseSecurity WiseSecurity is a contract that provides security measures for the WiseLending contract. It includes functionalities such as:
3 . MainHelper MainHelper is a contract that provides helper functions for the WiseLending contract. It includes functionalities such as:
4 . WiseSecurityHelper WiseSecurityHelper is a contract that provides helper functions for the WiseSecurity contract. It includes functionalities such as:
5 . PendlePowerFarmToken PendlePowerFarmToken is a contract that represents a power farming position. It has several key functionalities such as:
6 . FeeManager FeeManager is a contract that manages the fees for the WiseLending contract. It includes functionalities such as:
7 . PendlePowerFarmLeverageLogic PendlePowerFarmLeverageLogic is a contract that provides leverage functionalities for power farming positions. It includes functionalities such as:
8 . OracleHelper OracleHelper is a contract that provides helper functions for computing the prices of assets. It includes functionalities such as:
9 . PendlePowerFarmController PendlePowerFarmController is a contract that controls the behavior of power farming positions. It includes functionalities such as:
10 . WiseCore WiseCore is a contract that provides the core functionalities of the WiseLending contract. It includes functionalities such as:
11 . WiseLendingDeclaration WiseLendingDeclaration is a contract that declares the interface for the WiseLending contract.
12 . WiseOracleHub WiseOracleHub is a contract that provides functionalities for aggregating prices from different oracles. It includes functionalities such as:
Adding new oracles. Updating the prices of assets from an oracle.
13 . AaveHub AaveHub is a contract that provides functionalities for interacting with the Aave lending protocol.
14 . WiseLowLevelHelper WiseLowLevelHelper is a contract that provides low-level functionalities for the WiseLending contract. It includes functionalities such as:
15 . PendlePowerFarmDeclarations PendlePowerFarmDeclarations is a contract that declares the interface for power farming positions.
16 .PendlePowerFarmControllerBase PendlePowerFarmControllerBase is a contract that provides the base functionalities for power farming position controllers.
17 .AaveHelper AaveHelper is a contract that provides helper functions for interacting with the Aave lending protocol.
18 . PositionNFTs PositionNFTs is a contract that provides functionalities for creating and managing NFTs that represent power farming positions.
19 . WiseSecurityDeclarations WiseSecurityDeclarations is a contract that declares the interface for the WiseSecurity contract.
20 . PoolManager PoolManager is a contract that manages different pools of assets. It includes functionalities such as:
21 . FeeManagerHelper FeeManagerHelper is a contract that provides helper functions for the FeeManager contract. It includes functionalities such as:
22 . PendlePowerFarmMathLogic PendlePowerFarmMathLogic is a contract that provides mathematical functionalities for the PendlePowerFarm contract. It includes functionalities such as:
23 . DeclarationsFeeManager DeclarationsFeeManager is a contract that manages the fees for the FeeManager contract. It includes functionalities such as:
24 . PendlePowerManager PendlePowerManager is a contract that controls the behavior of power farming positions. It includes functionalities such as:
25 . PendlePowerFarmControllerHelper PendlePowerFarmControllerHelper is a contract that provides helper functions for the PendlePowerFarmController contract. It includes functionalities such as:
26 .PendlePowerFarm PendlePowerFarm is a contract that represents a power farming position. It includes functionalities such as:
27 . PowerFarmNFTs PowerFarmNFTs is a contract that provides functionalities for creating and managing NFTs that represent power farming positions. It includes functionalities such as:
28 . MinterReserver MinterReserver is a contract that provides functionalities for minting and burning power farming NFTs. It includes functionalities such as:
29 . PendleLpOracle PendleLpOracle is a contract that provides functionalities for aggregating prices from different liquidity pools on Pendle. It includes functionalities such as:
30 . Declarations Declarations is a contract that manages declarations for oracle data feeds.
31 . PtOracleDerivative PtOracleDerivative is a contract that provides functionalities for computing the price of a derivative asset based on its underlying assets. It includes functionalities such as:
32 . Declarations Declarations is a contract that manages declarations for Aave.
33 . PtOraclePure PtOraclePure is a contract that provides functionalities for computing the price of an asset based on its underlying assets.
34 .OwnableMaster OwnableMaster is a contract that provides the basic functionalities for an ownable contract. It allows for:
35 . PendlePowerFarmTokenFactory PendlePowerFarmTokenFactory is a contract that provides functionalities for creating and managing PendlePowerFarmToken contracts.
36 . PendleChildLpOracle PendleChildLpOracle is a contract that provides functionalities for aggregating prices of liquidity pool tokens on Pendle's child chain.
37 . FeeManagerEvents FeeManagerEvents is a contract that provides functionalities for triggering and handling fee events.
38 . CustomOracleSetup CustomOracleSetup is a contract that provides functionalities for setting up custom oracles.
39 . SendValueHelper SendValueHelper is a contract that provides functionalities for sending value between contracts.
40 . WrapperHelper WrapperHelper is a contract that provides functionalities for wrapping and unwrapping assets.
41 . CallOptionalReturn CallOptionalReturn is a contract that provides functionalities for calling other contracts and handling their optional return values.
42 . TransferHelper TransferHelper is a contract that provides functionalities for transferring assets between contracts.
43 . AaveEvents AaveEvents is a contract that manages events for Aave.
44 . ApprovalHelper ApprovalHelper is a contract that provides functionalities for approving the transfer of assets between contracts.
Interfaces and Inheritance: Many contracts inherit from interfaces, which define function prototypes, ensuring that specific methods are implemented. This promotes modularity and reusability.
Access Control: Many contracts use Ownable or OwnableMaster for controlling ownership and access to specific functions, preventing unauthorized changes to the contract state.
Lending and Borrowing: The core lending and borrowing functionalities are managed through WiseLendingDeclaration, WiseOracleHub, and AaveHub. These contracts interact with Aave protocol to provide lending and borrowing services.
Fee Management: FeeManager and DeclarationsFeeManager are responsible for managing and distributing fees collected throughout the platform. FeeManagerHelper provides additional helper functions for the fee management process.
Security: WiseSecurity and WiseSecurityDeclarations manage user security. Users can secure their positions by depositing collateral in these contracts.
Power Farming: The platform facilitates power farming through various contracts: PendlePowerFarmController, PendlePowerFarmDeclarations, PendlePowerFarmLeverageLogic, PendlePowerFarmMathLogic, PendlePowerFarmControllerHelper, and PendlePowerFarmTokenFactory. These contracts aim to provide leverage farming opportunities for users.
Oracle Functionality: Various oracle contracts, such as OracleHelper, PendleLpOracle, PendleChildLpOracle, PtOraclePure, and PtOracleDerivative provide pricing data for assets used in the platform, ensuring accurate calculations for lending, borrowing, and farming operations.
Low-Level Helper Functions: Contracts such as WiseLowLevelHelper and WiseCore provide low-level helper functions used throughout the platform.
Transfer and Approval Helpers: Various helper contracts, such as SendValueHelper, WrapperHelper, CallOptionalReturn, TransferHelper, ApprovalHelper, help manage token approvals and transfers.
Events: Event tracking is used for monitoring and tracking relevant activities on the platform with contracts like FeeManagerEvents, AaveEvents, and AaveHub.
Aspect | Description | Score (1-5) | Contracts Affected |
---|---|---|---|
Architecture & Design | The codebase follows a modular design, with clear separation of concerns between contracts. The use of interfaces and abstract contracts is also prevalent. | 4.5 | All contracts |
Upgradeability & Flexibility | The codebase is upgradable through the use of proxy contracts, such as WiseCore and WiseOracleHub. The use of unmanaged inheritance is also present. | 4 | WiseCore, WiseOracleHub, AaveHub |
Community Governance & Participation | The codebase follows the OpenZeppelin Ownable pattern, allowing for community governance and participation. However, there is no direct voting mechanism present in the contracts. | 3 | OwnableMaster, PendlePowerFarmController, WiseSecurity, PoolManager, PendlePowerManager |
Error Handling & Input Validation | The codebase generally handles errors robustly and validates inputs effectively. However, there is room for improvement in defining custom error messages and using require() statements in some places. | 3.5 | All contracts |
Code Maintainability and Reliability | The codebase is well-structured, with clear and concise variable and function names. However, there is some redundancy and logic duplication that could be streamlined. | 4 | All contracts |
Code Comments | The codebase contains some descriptive comments, but could benefit from more detailed descriptions of non-trivial or complex logic. | 3.5 | All contracts |
Testing | The codebase includes comprehensive test coverage, but could benefit from more integration tests for high-level functionality. | 4 | All contracts |
Code Structure and Formatting | The codebase is well-formatted, with consistent indentation and spacing. However, variable declarations are not always kept at the top of functions. | 4 | All contracts |
Strengths | The codebase benefits from a modular and flexible design, robust error handling, and thorough testing. | - | - |
Documentation | The documentation on the Wise Lending GitBook is comprehensive and provides a high-level overview of the protocol. However, the documentation could be improved with more low-level details, function descriptions, and code examples. | 3.5 | - |
+---------------------------------------------+ | Blockchain Network | +---------------------------------------------+ | | | | v v +----------------------+ +------------------------+ | WiseCore Contract | | Derivative Oracles | | (Logic) | |(PendleLpOracle, PtOracle)| +----------------------+ +------------------------+ | | | | v v +----------------------+ +------------------------+ | Wise Lending Contract| | Aave | | (Interface) | | (Interest rates) | +----------------------+ +------------------------+ | | | | v v +----------------------+ +------------------------+ | Wise Security | | Position NFTs | | (Collateral) | | (Represent positions) | +----------------------+ +------------------------+ | | | | v v +----------------------+ +------------------------+ | FeeManager Contract | | WiseOracleHub | | (Fees) | | (Price oracles) | +----------------------+ +------------------------+ | | | | v v +----------------------+ +------------------------+ | Wise Security | | WrapperHub (AaveHub) | | Declaration Contract| | (Wrap native tokens)| +----------------------+ +------------------------+ | | | | v v +----------------------+ +------------------------+ | PowerFarms | | PowerFarmNFTs (Minter)| | (Leverage logic) | +------------------------+ +----------------------+
+-----------------+ +------------------+ | User |<---------------------------------->| Wise Lending | +-----------------+ +------------------+ ^ ^ | | | Initialize Contract | | ---------------------------------> | | | | 1. connect to Wallet | | 2. approve tokens | | | | | v | +-----------------+ +------------------+ | User |<---------------------------------->| Wise Security | +-----------------+ +------------------+ ^ ^ | | | User Interact <-------------------> Contract | | with powerFarm | | | | contracts | | | | -------------------> | | | | | | v | +------------------------------------------------------+ +------------------+ | PowerFarmNFTs & PendlePowerFarm |<------->| MainHelper | +------------------------------------------------------+ +------------------+ | ^ | | | User Interact <-------------------> Contract | | with WiseLending | | | | contracts | | | | -------------------> | | | | | | v | +------------------------------------------------------------------+ +------------------+ | WiseLending |<-------> | FeeManager | +------------------------------------------------------------------+ +------------------+ ^ ^ | | | User Interact <-------------------> Contract | | with WiseSecurity| | | | contracts | | | | -------------------> | | | | | | v | +------------------------------------------------------------------+ +------------------+ | WiseOracleHub & DerivativeOracles |<------->| WiseSecurity | +------------------------------------------------------------------+ +------------------+ ^ ^ | | | User Interact | | with Oracle | | Contracts | | -------------------> | | | | | v | +------------------------------------------------------------------+ +------------------+ | WrapperHub & Aave |<------->| PoolManager | +------------------------------------------------------------------+ +------------------+
Contract Name | Function Name | State-Changing | Arguments | Returns | Ideal or Actual |
---|---|---|---|---|---|
WiseLending | enterMarket | Yes | market, underlying, amount, isLong, leverage, minCollateralRatio | none | Ideal |
exitMarket | Yes | market, isLong, seizeAll | none | Ideal | |
liquidate | Yes | market, user, position | none | Ideal | |
WiseSecurity | authorizeOperator | Yes | operator, approved | none | Ideal |
revokeOperator | Yes | operator, approved | none | Ideal | |
deposit | Yes | underlying, amount, user | none | Ideal | |
withdraw | Yes | underlying, amount, user | none | Ideal | |
MainHelper | _getReserves | No | - | (uint256, uint256) | Ideal |
WiseSecurityHelper | deposit | Yes | underlying, amount, user | none | Ideal |
withdraw | Yes | underlying, amount, user | none | Ideal | |
PendlePowerFarmToken | mint | Yes | recipient, amount | none | Ideal |
burn | Yes | amount | none | Ideal | |
FeeManager | transferFee | Yes | from, to, amount, fee | none | Ideal |
withdrawFee | Yes | recipient, amount, fee | none | Ideal | |
PendlePowerFarmLeverageLogic | _calculateLeverage | No | - | uint256 | Ideal |
OracleHelper | getDerivativePrice | No | derivativeAddress, resolutionBlockNumber | uint256 | Ideal |
PendlePowerFarmController | openPosition | Yes | market, underlying, amount, isLong, leverage, minCollateralRatio, user | Position memory | Ideal |
increaseLeverage | Yes | market, position, newLeverage | none | Ideal | |
decreaseLeverage | Yes | market, position, newLeverage | none | Ideal | |
closePosition | Yes | market, position, user, seizeAll | none | Ideal | |
WiseCore | receive | Yes | data | none | Ideal |
WiseLendingDeclaration | - | - | - | - | N/A |
WiseOracleHub | registerDerivative | Yes | derivative, oracleAddress, maxDecimals | none | Ideal |
AaveHub | deposit | Yes | underlying, amount, user | none | Ideal |
withdraw | Yes | underlying, amount, user | none | Ideal | |
WiseLowLevelHelper | transfer | Yes | to, value | bool | Ideal |
PendlePowerFarmDeclarations | - | - | - | - | N/A |
PendlePowerFarmControllerBase | - | - | - | - | N/A |
AaveHelper | - | - | - | - | N/A |
PositionNFTs | mintPositionNFT | Yes | position | none | Ideal |
burnPositionNFT | Yes | positionId | none | Ideal | |
WiseSecurityDeclarations | - | - | - | - | N/A |
PoolManager | createPool | Yes | underlying, fee, feeComparator, descriptionHash | Pool memory | Ideal |
FeeManagerHelper | - | - | - | - | N/A |
PendlePowerFarmMathLogic | - | - | - | - | N/A |
DeclarationsFeeManager | - | - | - | - | N/A |
PendlePowerManager | createPool | Yes | underlying, fee, feeComparator, fee | Pool memory | Ideal |
PendlePowerFarmControllerHelper | - | - | - | - | N/A |
PendlePowerFarm | - | - | - | - | N/A |
PowerFarmNFTs | - | - | - | - | N/A |
MinterReserver | - | - | - | - | N/A |
PendleLpOracle | - | - | - | - | N/A |
Declarations | - | - | - | - | N/A |
PtOracleDerivative | derivativePrice | No | derivativeAddress, blockNumber | uint256 | Ideal |
Declarations | - | - | - | - | N/A |
PtOraclePure | purePrice | No | underlying | uint256 | Ideal |
OwnableMaster | transferOwnership | Yes | newOwner | none | Ideal |
PendlePowerFarmTokenFactory | createPendlePowerFarmToken | Yes | underlying, fee, feeComparator, descriptionHash | PendlePowerFarmToken | Ideal |
PendleChildLpOracle | - | - | - | - | N/A |
FeeManagerEvents | - | - | - | - | N/A |
CustomOracleSetup | setCustomOracle | Yes | derivativeAddress, customOracleAddress | none | Ideal |
SendValueHelper | sendValue | Yes | recipient, value, data | bool | Ideal |
WrapperHelper | - | - | - | - | N/A |
CallOptionalReturn | - | - | - | - | N/A |
TransferHelper | transfer | Yes | to, value | bool | Ideal |
AaveEvents | - | - | - | - | N/A |
ApprovalHelper | approve | Yes | spender, value, user | none | Ideal |
While reviewing Wise Lending codebase , I take a methodical and thorough approach to ensure that the code is secure, efficient, and adheres to best practices. Here is an overview of the approaches I take
Before diving into the code, I familiarize myself with the system architecture, high-level design, and the interactions between different contracts. This helps me understand the overall flow of the application, which is crucial for identifying potential issues and attack vectors.
I perform a deep code review, examining each line of code and its corresponding tests . I pay close attention to security-critical functions and areas such as user input handling, token transfers, access control, and cryptographic operations. Key aspects I look for include
-Proper handling of user input validation
I use static analysis tools, such as Mythril, Slither, and Oyente, to identify potential vulnerabilities and weaknesses. These tools can catch common issues like reentrancy, integer overflows/underflows, and race conditions. However, they should be used as a complement to manual review, as they may produce false positives or false negatives. -I analyze the code for potential gas inefficiencies and recommend improvements where possible. This both reduces the overall cost of using the contract and mitigates the risk of denial-of-service attacks due to high gas costs.
I ensure that the code follows established best practices for smart contract development, such as using the latest Solidity version, employing the 'checks-effects-interactions' pattern, and adhering to the Solidity Style Guide.
I verify that the code is well-documented, with clear descriptions of functions, variables, and contract interactions. Proper documentation is crucial for understanding the contract's behavior and ensuring that developers can maintain and extend the code in the future.
I review the tests to ensure adequate coverage of the contracts and their functions. I may also create additional tests to cover edge cases or potential vulnerabilities.
I perform the above review process for each one, tailoring my approach to the specific functionality and purpose of each contract. Focus areas would include:
i . Security-sensitive functions and logic in WiseLending, WiseSecurity, and WiseCore ii . Interactions between contracts and WiseSecurity, WiseLending, WiseOracleHub, FeeManager, and PowerFarmController iii . Derivative oracle implementations in PtOraclePure, PtOracleDerivative, and PendleLpOracle iv . Complex financial logic and gas efficiency in PowerFarmNFTs, PowerFarmMathLogic, and PendlePowerManager v . Access control, role management, and secure communication between contracts in OwnableMaster, WiseLowLevelHelper, and WrapperHub vi . Proper handling of transfer helper functions in TransferHelper, SendValueHelper, and ApprovalHelper vii . Event tracking and emissions in FeeManagerEvents, AaveHelper, and Aave Hub contracts
By systematically reviewing each contract and its interactions with other contracts in the codebase, I can effectively identify potential vulnerabilities and recommend improvements to strengthen the security and efficiency of the Wise Lending Codebase.
Contract | Core Functionality | Technical Characteristics | Importance | Management |
---|---|---|---|---|
WiseLending | Lending and borrowing management | Uses Aave v2 as the underlying lending protocol, customizable interest rates, and liquidation mechanisms | Critical: provides the core lending and borrowing functionality of the system | Regular monitoring for liquidations and interest rates adjustments |
WiseSecurity | Security and access control | Implements role-based access control and allows for secure management of the system | Critical: ensures the security of the system by preventing unauthorized access and limiting the actions that can be taken by different roles | Regular monitoring for security vulnerabilities, and access controls management |
MainHelper | General utility functions | Contains a variety of helper functions used throughout the system | High: provides useful functionality that is used in many parts of the system | Regular testing and maintenance to ensure proper functionality and prevent bugs |
WiseSecurityHelper | Security and access control helper functions | Contains helper functions related to security and access control | High: provides useful functionality related to security and access control that is used in many parts of the system | Regular testing and maintenance to ensure proper functionality and prevent security vulnerabilities |
PendlePowerFarmToken | Token management for Pendle Power Farms | Implements ERC-20 and ERC-721 functionality, used to represent shares in a Pendle Power Farm | High: enables the creation and management of tokens that represent shares in Pendle Power Farms | Regular monitoring for token transfers, ownership changes, and other events |
FeeManager | Fee management | Calculates and collects fees from users of the system | High: ensures the financial sustainability of the system by collecting fees from users | Regular monitoring for fee collections, and adjustments to fee rates |
PendlePowerFarmLeverageLogic | Leverage management for Pendle Power Farms | Implements the logic for managing leverage in Pendle Power Farms | High: enables users to gain leverage when investing in Pendle Power Farms | Regular monitoring for leverage levels, and adjustments to risk parameters |
OracleHelper | Helper functions for oracle interactions | Contains helper functions for interacting with various oracles used in the system | High: provides useful functionality for interacting with oracles that are used to provide price and other data to the system | Regular testing and maintenance to ensure proper functionality and prevent bugs |
PendlePowerFarmController | Controls access to Pendle Power Farms | Implements role-based access control and allows for secure management of Pendle Power Farms | High: enables the creation and management of Pendle Power Farms | Regular monitoring for security vulnerabilities, and access controls management |
WiseCore | Core functionality of the Wise platform | Contains the core functionality of the Wise platform, including the management of assets and liabilities | Critical: provides the core functionality of the Wise platform and enables the lending and borrowing of assets | Regular monitoring for asset and liability management, and adjustments to risk parameters |
Variable | Description | Economic Impact |
---|---|---|
LendingRate | The interest rate at which users can borrow assets | Lower lending rates increase demand for borrowing, higher lending rates increase revenue |
CollateralFactor | The ratio of collateral value to debt value for borrowing | Higher collateral factors increase the amount of borrowing possible, which could increase revenue but also risk |
LiquidationPenalty | The penalty fee for liquidating a position | Increasing liquidation penalties can increase revenue but may discourage users from using the platform |
LiquidationBonus | The bonus fee for liquidating a position | Increasing liquidation bonuses can increase revenue and attract liquidators but may also discourage users from using the platform |
BorrowFee | The fee charged for borrowing assets | Increasing borrow fees can increase revenue but may discourage users from borrowing |
DepositFee | The fee charged for depositing assets | Increasing deposit fees can increase revenue but may discourage users from depositing |
WithdrawalFee | The fee charged for withdrawing assets | Increasing withdrawal fees can increase revenue but may discourage users from withdrawing |
OraclePriceFeed | The price feed used to determine asset values | The accuracy and reliability of the oracle price feed can impact the security and fairness of the lending platform |
AdminFee | The fee charged to the admin for managing the contract | Increasing admin fees can increase revenue but may discourage the admin from properly managing the contract |
MinimumThreshold | The minimum value required to open a position | Increasing the minimum threshold can reduce the risk of small positions but may discourage smaller users from using the platform |
MaximumThreshold | The maximum value allowed for a single position | Decreasing the maximum threshold can reduce the risk of large positions but may discourage whales from using the platform |
Pausable | Whether the contract can be paused by the admin | Pausing the contract can be used to prevent attacks or issues but may also disrupt user activity |
Upgradeable | Whether the contract is upgradable | Upgradable contracts allow for bug fixes and improvements but may also introduce new bugs or security risks |
Implementation | The address of the implementation contract | The implementation contract determines the functionality of the contract but may also introduce new bugs or security risks |
ProxyAdmin | The address of the proxy admin contract | The proxy admin contract controls the upgradability of the contract but may also introduce new bugs or security risks |
TransferFee | The fee charged for transferring assets | Increasing transfer fees can increase revenue but may discourage users from transferring assets |
CallFee | The fee charged for executing external calls | Increasing call fees can increase revenue but may discourage users from executing external calls |
ApprovalFee | The fee charged for approving token transfers | Increasing approval fees can increase revenue but may discourage users from approving token transfers |
MinimumApprovalAmount | The minimum value required for token approvals | Increasing the minimum approval amount can reduce the risk of small approvals but may discourage users from approving |
MaximumApprovalAmount | The maximum value allowed for token approvals | Decreasing the maximum approval amount can reduce the risk of large approvals but may discourage whales from approving |
FeeMultiplier | The multiplier used to calculate fees | Increasing the fee multiplier can increase revenue but may discourage users from using the platform |
FeeDistribution | The distribution of fees among different parties | The distribution of fees can impact the revenue and incentives of different parties |
FeeClaimThreshold | The minimum amount required to claim fees | Increasing the fee claim threshold can reduce transaction costs but may discourage users from claiming fees |
GracePeriod | The time period before a position can be liquidated | Increasing the grace period can reduce the risk of premature liquidation but may also increase the risk of undercollateralized positions |
LeverageFactor | The maximum allowable leverage for a position | Decreasing the leverage factor can reduce the risk of liquidation but may also reduce revenue |
MinimumCollateralValue | The minimum value of collateral required for borrowing | Increasing the minimum collateral value can reduce the risk of undercollateralized positions but may also reduce revenue |
MaxFundingPeriod | The maximum time period for funding a position | Decreasing the maximum funding period can reduce the risk of long positions but may also reduce revenue |
MinFundingAmount | The minimum amount required to fund a position | Increasing the minimum funding amount can reduce the risk of small positions but may also reduce revenue |
MaxFundingAmount | The maximum amount allowed for a single funding | Decreasing the maximum funding amount can reduce the risk of large positions but may also reduce revenue |
FundingFee | The fee charged for funding a position | Increasing the funding fee can increase revenue but may discourage users from funding positions |
RedemptionFee | The fee charged for redeeming a position | Increasing the redemption fee can increase revenue but may discourage users from redeeming positions |
MinRedemptionAmount | The minimum amount required to redeem a position | Increasing the minimum redemption amount can reduce transaction costs but may discourage users from redeeming |
MaxRedemptionAmount | The maximum amount allowed for a single redemption | Decreasing the maximum redemption amount can reduce the risk of large redemptions but may also reduce revenue |
RedemptionPenalty | The penalty fee for redeeming a position | Increasing the redemption penalty can increase revenue but may discourage users from redeeming positions |
MinBatchSize | The minimum size of a batch transfer | Increasing the minimum batch size can reduce transaction costs but may discourage users from making small transfers |
MaxBatchSize | The maximum size allowed for a batch transfer | Decreasing the maximum batch size can reduce the risk of large transfers but may also reduce revenue |
BatchTransferFee | The fee charged for batch transferring assets | Increasing the batch transfer fee can increase revenue but may discourage users from using the platform |
CallOptionalReturnFee | The fee charged for calling an external contract with an optional return value | Increasing the call optional return fee can increase revenue but may discourage users from using the platform |
TransferFundsHelperFee | The fee charged for transferring assets using the Transfer Funds Helper | Increasing the Transfer Funds Helper fee can increase revenue but may discourage users from using the Helper |
AaveHelperFee | The fee charged for interacting with the Aave protocol using the Aave Helper | Increasing the Aave Helper fee can increase revenue but may discourage users from using the Helper |
WiseOracleHubFee | The fee charged for using the WiseOracleHub | Increasing the WiseOracleHub fee can increase revenue but may discourage users from using the Hub |
PendlePowerFarmsFee | The fee charged for using the PendlePowerFarmController | Increasing the PendlePowerFarmController fee can increase revenue but may discourage users from using the Controller |
FeeManagerFee | The fee charged for managing fees in the FeeManager | Increasing the FeeManager fee can increase revenue but may discourage users from using the Manager |
PendlePowerFarmLeverageLogicFee | The fee charged for using the PendlePowerFarmLeverageLogic | Increasing the PendlePowerFarmLeverageLogic fee can increase revenue but may discourage users from using the Logic |
PendlePowerNFTsFee | The fee charged for using the PendlePowerNFTs | Increasing the PendlePowerNFTs fee can increase revenue but may discourage users from using the NFTs |
MinterReserverFee | The fee charged for minting new NFTs | Increasing the MinterReserver fee can increase revenue but may discourage users from minting new NFTs |
DerivativeOraclesFee | The fee charged for using the DerivativeOracles | Increasing the DerivativeOracles fee can increase revenue but may discourage users from using the Oracles |
WrapperHubEventsFee | The fee charged for emitting events in the WrapperHub | Increasing the WrapperHub Events fee can increase revenue but may discourage users from using the Hub |
AaveHubFee | The fee charged for using the Aave protocol using the AaveHub | Increasing the AaveHub fee can increase revenue but may discourage users from using the Hub |
WiseLowLevelHelperFee | The fee charged for using the WiseLowLevelHelper | Increasing the WiseLowLevelHelper fee can increase revenue but may discourage users from using the Helper |
TransferHubFee | The fee charged for transferring assets between protocols using the TransferHub | Increasing the TransferHub fee can increase revenue but may discourage users from using the Hub |
ApprovalHelperFee | The fee charged for approving token transfers using the ApprovalHelper | Increasing the ApprovalHelper fee can increase revenue but may discourage users from using the Helper |
Contract | Role / Permission | Description |
---|---|---|
WiseLending.sol | Lender, Borrower | Users can lend or borrow assets. |
WiseSecurity.sol | Admin | The contract deployer has administrative permissions. |
MainHelper.sol | None | Provides helper functions, no explicit roles. |
WiseSecurityHelper.sol | None | Provides security-related helper functions, no explicit roles. |
PendlePowerFarmToken.sol | Owner, PendleOracle | The contract deployer is the owner, and has permissions to manage allowances. PendleOracle is used to fetch token information. |
FeeManager.sol | Admin, FeeRecipient | The contract deployer has administrative permissions, and FeeRecipient receives fees. |
PendlePowerFarmLeverageLogic.sol | None | Contains logic for leverage farming, no explicit roles. |
OracleHelper.sol | None | Provides oracle helper functions, no explicit roles. |
PendlePowerFarmController.sol | Admin, PoolManager | The contract deployer has administrative permissions, and PoolManager manages pools. |
WiseCore.sol | Admin, Failer, Pausable | The contract deployer has administrative permissions, Failer can trigger emergency freeze, and Pausable can pause/unpause the contract. |
WiseLendingDeclaration.sol | None | Contains declarations, no explicit roles. |
WiseOracleHub.sol | Admin, DataProvider | The contract deployer has administrative permissions, and DataProvider provides data. |
AaveHub.sol | Admin | The contract deployer has administrative permissions. |
WiseLowLevelHelper.sol | None | Contains low-level helper functions, no explicit roles. |
PendlePowerFarmDeclarations.sol | None | Contains declarations, no explicit roles. |
PendlePowerFarmControllerBase.sol | Admin, BaseOracle | The contract deployer has administrative permissions, and BaseOracle provides oracle functionality. |
AaveHelper.sol | Admin | The contract deployer has administrative permissions. |
PositionNFTs.sol | Minters, Pausable | Minters can mint NFTs, and Pausable can pause/unpause the contract. |
WiseSecurityDeclarations.sol | None | Contains declarations, no explicit roles. |
PoolManager.sol | Admin, FeeManagerHelper | The contract deployer has administrative permissions, and FeeManagerHelper manages fees. |
FeeManagerHelper.sol | None | Provides fee manager helper functions, no explicit roles. |
PendlePowerManager.sol | Admin, PoolManager | The contract deployer has administrative permissions, and PoolManager manages pools. |
PendlePowerFarmControllerHelper.sol | Admin, PoolManager | The contract deployer has administrative permissions, and PoolManager manages pools. |
PendlePowerFarm.sol | Admin | The contract deployer has administrative permissions. |
PowerFarmNFTs.sol | Minters, Pausable | Minters can mint NFTs, and Pausable can pause/unpause the contract. |
MinterReserver.sol | Admin, BaseToken | The contract deployer has administrative permissions, and BaseToken manages token operations. |
PendleLpOracle.sol | Admin, PendleOracle | The contract deployer has administrative permissions, and PendleOracle provides price information. |
Declarations.sol | None | Contains declarations, no explicit roles. |
PtOracleDerivative.sol | Admin | The contract deployer has administrative permissions. |
WrapperHub.sol | Admin | The contract deployer has administrative permissions. |
AaveEvents.sol | Admin | The contract deployer has administrative permissions. |
TransferHelper.sol | Admin | The contract deployer has administrative permissions. |
ApprovalHelper.sol | Approver | The contract deployer approves or disapproves. |
Component | Functionality | Interactions |
---|---|---|
WiseLending.sol | Handles lending and borrowing functionalities | - Interacts with WiseSecurity.sol to ensure loan safety and collateralization - Interacts with MainHelper.sol for common utility functions - Interacts with FeeManager.sol to manage fees for using the platform - Interacts with WiseSecurityHelper.sol for security checks - Interacts with WiseOracleHub.sol to retrieve price feeds |
WiseSecurity.sol | Manages security for WiseLending | - Implements collateral and safety checks for loans issued - Interacts with WiseLending.sol to manage loans - Interacts with WiseSecurityHelper.sol for security checks |
MainHelper.sol | Contains common utility functions | - Provides functions for converting between different units and handling token approvals - Used by WiseLending.sol and other components |
WiseSecurityHelper.sol | Provides security-related functionalities | - Performs checks for token approvals, balance, and collateral - Used by WiseSecurity.sol and WiseLending.sol |
PendlePowerFarmToken.sol | Handles the logic of a PowerFarm token | - Interacts with PendlePowerFarmController.sol to update variables - Interacts with PendlePowerFarmMathLogic.sol for calculations - Interacts with FeeManagerHelper.sol to manage fees |
FeeManager.sol | Manages fees for the platform | - Calculates and manages the distribution of platform fees - Interacts with FeeManagerHelper.sol for calculations - Interacts with WiseLending.sol and other components to collect fees |
PendlePowerFarmLeverageLogic.sol | Provides leverage functionalities for PendlePowerFarms | - Manages the liquidation of undercollateralized positions - Interacts with PendlePowerFarmToken.sol and other components |
OracleHelper.sol | Provides price feed functionalities | - Retrieves and manages price feeds for underlying assets- Used by WiseOracleHub.sol |
PendlePowerFarmController.sol | Handles the business logic for PendlePowerFarms | - Interacts with PendlePowerFarmToken.sol to update variables - Interacts with PendlePowerFarmDeclarations.sol and PendlePowerFarmControllerBase.sol - Used to manage the functionalities of PendlePowerFarms |
WiseCore.sol | Contains common utilities for WiseLending and other components | - Provides a standard interface for interacting with wrapped tokens and other components - Interacted by WiseLending.sol, WiseSecurity.sol, and other components |
WiseLendingDeclaration.sol | Contains declarations for WiseLending | - Defines the structure of the WiseLending contract- Provides declarations for functions |
WiseOracleHub.sol | Provides price feed functionalities | - Retrieves and manages price feeds for underlying assets - Interacts with OracleHelper.sol for price feed management |
AaveHub.sol | Wrapper for Aave Protocol | - Interacts with AaveHelper.sol for Aave-related functionalities- Provides an interface for borrowing and lending assets on Aave |
WiseLowLevelHelper.sol | Contains low-level utility functions | - Provides functions for converting between different units, handling token approvals, and managing oracle prices - Used by WiseLending.sol and other components |
PendlePowerFarmDeclarations.sol | Contains declarations for PendlePowerFarmController | - Defines the structure of the PendlePowerFarmController contract |
PendlePowerFarmControllerBase.sol | Contains the core logic for PendlePowerFarmController | - Provides functionalities for managing PendlePowerFarms |
AaveHelper.sol | Provides Aave-related functionalities | - Handles borrowing, lending, and deposits on Aave - Used by AaveHub.sol |
PositionNFTs.sol | Manages NFTs for positions in WiseLending or PendlePowerFarms | - Interacts with WiseSecurity.sol and PendlePowerFarmController.sol to update variables - Updates NFT metadata based on user positions |
WiseSecurityDeclarations.sol | Contains declarations for WiseSecurity | - Defines the structure of the WiseSecurity contract |
PoolManager.sol | Manages the distribution of fees for the platform | - Calculates and distributes platform fees - Interacts with FeeManager.sol and other components to collect fees |
FeeManagerHelper.sol | Provides helper functions for FeeManager.sol | - Interacts with FeeManager.sol to manage platform fees |
PendlePowerFarmMathLogic.sol | Provides calculations for PendlePowerFarmToken.sol | - Performs mathematical calculations for PendlePowerFarm |
DeclarationsFeeManager.sol | Contains declarations for FeeManager | - Defines the structure of the FeeManager contract |
PendlePowerManager.sol | Handles the core logic for PendlePowerFarms | - Provides functionalities for managing PendlePowerFarms |
PendlePowerFarmControllerHelper.sol | Provides helper functions for PendlePowerFarmController | - Interacts with PendlePowerFarmController.sol to manage PendlePowerFarm functionalities |
PendlePowerFarm.sol | Contains the core structure of PendlePowerFarms | - Defines variables and constants for PendlePowerFarms - Interacts with PendlePowerFarmToken.sol and PendlePowerFarmMathLogic.sol |
PowerFarmNFTs.sol | Manages NFTs for PowerFarms | - Interacts with WiseLending.sol and PendlePowerFarmController.sol to update variables - Updates NFT metadata based on user positions |
MinterReserver.sol | Manages the creation and distribution of NFTs | - Manages the minting and distribution of NFTs for PowerFarms - Interacts with PowerFarmNFTs.sol and PendlePowerFarmController.sol |
PendleLpOracle.sol | Provides LP token price feeds | - Manages LP token price feeds for PendleDerivatives - Used by WiseOracleHub.sol |
DerivativeOracles/Declarations.sol | Contains declarations for DerviativeOracles | - Defines the structure of derivative oracle contracts |
PtOracleDerivative.sol | Provides price feed functionalities | - Manages price feeds for underlying assets in a PendleDerivative - Used by WiseOracleHub.sol |
Declarations.sol | Contains declarations for WrapperHub | - Defines the structure of wrapper hub contracts |
PtOraclePure.sol | Provides pure price feed functionalities | - Manages price feeds for underlying assets without optional return - Used by PtOracleDerivative.sol |
OwnableMaster.sol | Provides basic functionality for a contract owner | - Manages ownership of a contract - Used by WiseLending.sol and other components |
PendlePowerFarmTokenFactory.sol | Manages the creation of PendlePowerFarmTokens | - Creates and manages PendlePowerFarmTokens - Interacts with PendlePowerFarmController.sol and FeeManager.sol |
PendleChildLpOracle.sol | Provides LP token price feeds for PendleDerivatives | - Manages LP token price feeds for PendleDerivatives - Used by WiseOracleHub.sol |
FeeManagerEvents.sol | Contains event declarations for FeeManager | - Defines events for handling fees - Used by FeeManager.sol and other components |
CustomOracleSetup.sol | Manages custom price feed setups | - Manages the setup and configuration |
Incorporating the following ideas in the Wise Lending protocol can potentially add value and improve its overall functionality:
Check the contract's variable and function modifiers, especially onlyOwner, onlyPoolManager, and onlyWhitelisted. Ensure that these modifiers are used appropriately and that access control is properly implemented.
Examine the constructor functions for initialization checks. Look for checks to ensure that the contract owner is set correctly and that any needed configuration settings are properly initialized.
Review the contract's state variables. Consider whether mutable state variables need to be mutable, and whether immutable state variables could have been used instead. Look for variables that are used only for internal calculations and consider optimizing by making them private.
Examine the contract's functions for input validation, particularly for functions that allow users to transfer or withdraw funds. Ensure that sufficient checks are in place to prevent unauthorized access to contract funds.
Check for the correct use of revert(), require(), and assert(). These functions should be used to ensure that preconditions and invariants are satisfied.
Look for functions that allow users to transfer funds between contracts. Examine these functions closely to ensure that the correct amounts are being transferred and that there are no vulnerabilities that would allow for the theft of funds.
In the WiseSecurity contract, review the implementation of ensureCanTransfer and ensure that it is functioning as intended. Consider whether there are edge cases that might require additional checks.
In the WiseLowLevelHelper contract, review the implementation of the getReservePrice function. Ensure that the function is working as intended and that it is calculating the correct reserve price.
In the FeeManager contract, review the implementation of the _reduceFee function. Ensure that the function is updating fees correctly and that there are no rounding errors.
In the WiseOracleHub contract, review the implementation of the setToken function. Check that the function is updating the token mapping correctly and that there are no vulnerabilities that would allow for the manipulation of oracle data.
In the PendlePowerFarmController contract, review the implementation of the _updateFees function. Ensure that the function is updating fees correctly and that there are no rounding errors.
In the PowerFarmNFTs contract, review the implementation of the mint function. Check that the function is minting the correct number of NFTs and that there are no vulnerabilities that would allow for the creation of excess NFTs.
In the DerivativeOracles contracts, review the implementation of the oracle functions. Check that the functions are correctly querying external data sources and that there are no vulnerabilities that would allow for manipulation of oracle data.
In the TransferHub contracts, review the implementation of the transfer function. Ensure that the function is correctly transferring funds between contracts and that it is properly handling any potential exceptions.
Perform a thorough check for the correct handling of exceptions. Look for functions that call external contracts and ensure that exceptions are properly handled and that the contract is not left in an unpredictable state.
Consider the gas costs of each contract's functions. Identify any functions that are particularly gas-intensive and look for ways to optimize them.
Consider the re-usability of the contract code. Identify any code that could be abstracted into shared libraries and consider creating reusable library contracts to improve code maintenance and reduce gas costs.
Gas optimization
Security
After reviewing the Wise Lending codebase, I gained several insights and learned a lot about Solidity development, smart contract security, and complex decentralized systems. Here are some of the key learnings and insights:
Reviewing this codebase has helped me grow my codebase skills in several ways
After reviewing the Wise Lending codebase, I have gained valuable insights into the design, implementation, and best practices of complex decentralized systems. The codebase demonstrates a clear understanding of the requirements, architectural choices, and security concerns involved in developing such a system. It is well-organized, modular, and makes effective use of inheritance, interfaces, and external libraries to promote reusability and maintainability.
Throughout the review, I identified areas for improvement and suggestions to further enhance the codebase and overall system. These recommendations focus on optimizing gas costs, enhancing security, improving code maintainability, and refining development practices. Some of the highlighted recommendations include using calldata, employing timelocks, leveraging formal verification tools, and following consistent naming conventions.
In conclusion, the Wise Lending codebase provides a solid foundation for a decentralized lending protocol. It showcases good development practices, innovative solutions, and a deep understanding of the Solidity ecosystem. By incorporating the recommendations provided in this report, the codebase can be further optimized to ensure a more efficient, secure, and scalable system, ultimately delivering a better user experience and contributing effectively to the DeFi space.
Total Time Spent - 54 Hours
Activity | Time Spent |
---|---|
Understanding the Business Goals and User Stories | 8 hours |
Reviewing the Architecture and Design | 4 hours |
Understanding the Important Architecture Decisions | 2 hours |
Performing High-Level Code Review | 20 hours |
Analyzing Security and Correctness Properties | 12 hours |
Writing Report and Presentation | 8 hours |
54 hours
#0 - c4-pre-sort
2024-03-18T16:22:43Z
GalloDaSballo marked the issue as sufficient quality report
#1 - c4-judge
2024-03-26T12:27:36Z
trust1995 marked the issue as grade-b