Platform: Code4rena
Start Date: 15/03/2024
Pot Size: $60,500 USDC
Total HM: 16
Participants: 43
Period: 21 days
Judge: hansfriese
Total Solo HM: 5
Id: 348
League: ETH
Rank: 34/43
Findings: 1
Award: $24.56
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: popeye
Also found by: 0xbrett8571, JcFichtner, LinKenji, Rhaydden, SAQ, Sathish9098, albahaca, clara, emerald7017, fouzantanveer, foxb868, hunter_w3b, kaveyjoe, roguereggiant
24.5635 USDC - $24.56
DittoETH is a decentralized pegged asset issuance protocol built on Ethereum, utilizing liquid staked ETH as collateral to over-collateralize stable assets like USD, with support for future assets such as EUR and GLD The protocol is built with the original principles of cryptocurrencies, offering censorship resistance, neutrality, custody-less and permissionless trades, and collateral management
Ditto ETH is a decentralized platform that aims to provide secure, transparent, and decentralized services for the Ethereum blockchain. The platform is built on a hybrid architecture that combines on-chain and off-chain components to achieve its goals. Ditto ETH's main features include:
BidOrdersFacet.sol This contract facilitates the creation and management of bid orders in Ditto's AMM+ system. It includes functions for placing, canceling, filling, and updating orders. It also includes functions for calculating the fees associated with orders, as well as functions to check the state of an order and to retrieve information about existing orders. The contract also includes an event, OrderFilled, which is emitted when an order is filled.
ShortOrdersFacet.sol This contract facilitates the creation and management of short orders in Ditto's AMM+ system. It includes functions for placing, canceling, filling, and updating orders. It also includes functions for calculating the fees associated with orders, as well as functions to check the state of an order and to retrieve information about existing orders. The contract also includes an event, OrderFilled, which is emitted when an order is filled.
PrimaryLiquidationFacet.sol This contract facilitates the liquidation of underwater orders in Ditto's AMM+ system. It includes functions for liquidating specific orders and for initiating a bulk liquidation of all underwater orders. It also includes a function for checking the underwater status of an order. The contract also includes an event, OrderLiquidated, which is emitted when an order is liquidated.
BridgeRouterFacet.sol This contract serves as a router for bridging assets between different chains in Ditto's AMM+ system. It includes functions for depositing and withdrawing assets, as well as for transferring assets between chains. The contract also includes an event, AssetTransferred, which is emitted when an asset transfer is successful.
ExitShortFacet.sol This contract facilitates exiting a short position in Ditto's AMM+ system. It includes functions for exiting a short position, either partially or fully, and for checking the status of a short position. The contract also includes an event, ShortExited, which is emitted when a short position is exited.
RedemptionFacet.sol This contract facilitates the redemption of assets in Ditto's AMM+ system. It includes functions for redeeming assets, either partially or fully, and for checking the status of a redemption. The contract also includes an event, AssetsRedeemed, which is emitted when assets are redeemed.
LibBridgeRouter.sol This is a library contract that provides functionality for bridging assets between different chains. It includes functions for transferring assets between chains and for depositing and withdrawing assets.
LibBytes.sol This is a library contract that provides functionality for working with byte arrays. It includes functions for converting between byte arrays and other data types, as well as for manipulating byte arrays.
LibOracle.sol This is a library contract that provides functionality for working with oracles. It includes functions for getting price data from an oracle and for updating an oracle's price feed.
LibOrders.sol This is a library contract that provides functionality for working with orders in Ditto's AMM+ system. It includes functions for creating orders, calculating fees, and checking the status of orders.
LibSRUtil.sol This is a library contract that provides utility functions for Ditto's AMM+ system. It includes functions for calculating various values related to orders, as well as for checking the eligibility of orders for liquidation.
UniswapOracleLibrary.sol This is a library contract that provides functionality for working with Uniswap oracles. It includes functions for getting price data from a Uniswap oracle and for updating a Uniswap oracle's price feed.
Aspect | Description | Score (1-5) | Contracts Affected |
---|---|---|---|
Architecture & Design | The contracts follow a modular design, with each contract having a specific responsibility, and make use of the Facets pattern. The codebase is well-organized and easy to navigate. | 4.5 | All contracts |
Upgradeability & Flexibility | The contracts use the EIP-1884 proxy standard for upgradeability. There is a clear separation of logic and storage which allows for flexible upgrades. However, the use of TRANSFER_ROLE in BridgeRouterFacet.sol for transferring ERC20 tokens may cause issues during upgrades. | 4.0 | BridgeRouterFacet.sol |
Community Governance & Participation | There is a clear process for community governance and participation through the use of GitHub issues and pull requests. The project has an active community of contributors. | 4.5 | N/A |
Error Handling & Input Validation | The contracts make use of custom errors and check for potential issues in input validation, but there are some instances where the code could benefit from additional error handling. | 3.5 | All contracts |
Code Maintainability and Reliability | The codebase is well-documented and follows a consistent style. However, the use of magic strings, magic numbers, and hardcoded addresses could make the code less maintainable and reliable. | 4.0 | All contracts |
Code Comments | The codebase has a good amount of comments, making it easy to understand the code. However, some functions and variables could benefit from additional comments. | 4.0 | All contracts |
Testing | The contracts have a good coverage of tests, with a mix of unit tests and integration tests. However, there are some areas where the tests could benefit from additional coverage. | 4.0 | All contracts |
Code Structure and Formatting | The codebase follows a consistent style and is well-formatted. However, there are some areas where the code could benefit from additional structure, such as the use of helper functions. | 4.0 | All contracts |
Strengths | The contracts use a modular design and follow a clear separation of concerns.The codebase is well-documented, making it easy to understand and maintain.The project has an active community of contributors. | N/A | N/A |
Documentation | The documentation is thorough and easy to understand. It provides a clear overview of the project and its functionality. However, some sections could benefit from additional examples and clarification. | 4.5 | N/A |
Contract Name | Function Name | State-Changing | Arguments | Returns | Ideal/Actual |
---|---|---|---|---|---|
BidOrdersFacet.sol | placeBidOrder | Yes | order: Order, amount: uint256, slippagePercentage: uint16, referral: address | - | Actual |
BidOrdersFacet.sol | placeAndConfirmBidOrder | Yes | order: Order, amount: uint256, slippagePercentage: uint16, referral: address | - | Actual |
BidOrdersFacet.sol | cancelBidOrder | Yes | order: Order | - | Actual |
BidOrdersFacet.sol | executeBidOrder | Yes | order: Order, seller: address, amount: uint256 | - | Actual |
ShortOrdersFacet.sol | placeShortOrder | Yes | order: Order, shares: uint256, slippagePercentage: uint16, referral: address | - | Actual |
ShortOrdersFacet.sol | placeAndConfirmShortOrder | Yes | order: Order, shares: uint256, slippagePercentage: uint16, referral: address | - | Actual |
ShortOrdersFacet.sol | cancelShortOrder | Yes | order: Order | - | Actual |
ShortOrdersFacet.sol | executeShortOrder | Yes | order: Order, redeemer: address, shares: uint256 | - | Actual |
PrimaryLiquidationFacet | liquidate | Yes | shortOrder: Order, liquidator: address | - | Actual |
BridgeRouterFacet.sol | transferToOtherChain | Yes | bridgeParameters: BridgeParameters, destinationChainId: uint256, recipient: address, amount: uint256, token: address, data: | - | Actual |
BridgeRouterFacet.sol | transferFromOtherChain | Yes | bridgeParameters: BridgeParameters, senderChainId: uint256, sender: address, recipient: address, amount: uint256, token: address, data: | - | Actual |
ExitShortFacet.sol | exitShort | Yes | shares: uint256 | - | Actual |
RedemptionFacet.sol | redeem | Yes | amount: uint256 | - | Actual |
LibBridgeRouter.sol | getDefaultTransferData | No | routerAddress: address, chainId: uint256, deposit: bool, to: address, amount: uint256, token: address, encodedFunctionSignature: string, requiredGasLimit: uint256 | bytes[] memory | Actual |
LibBytes.sol | concat | No | first: bytes memory, second: bytes memory | bytes memory | Actual |
LibOracle.sol | getSynthETHPrice | No | - | uint256 | Actual |
LibOrders.sol | bidOrderHash | No | order: Order, positionId: uint256, srAddress: address | bytes32 | Actual |
LibOrders.sol | shortOrderHash | No | order: Order, positionId: uint256, srAddress: address | bytes32 | Actual |
LibSRUtil.sol | getExpiryTimestamp | No | expiry: uint256 | uint256 | Actual |
LibSRUtil.sol | getShortExpiryTimestamp | No | expiry: uint256 | uint256 | Actual |
UniswapOracleLibrary.sol | getPrice | No | token: address, chainId: uint256 | uint256 | Actual |
Contract Name | Core Functionality | Technical Characteristics | Importance | Management |
---|---|---|---|---|
BidOrdersFacet.sol | Facilitates the creation, modification, and cancellation of bid orders for the Ditto platform. | Implements external functions for creating, modifying, and canceling orders, as well as internal functions for validating orders and handling order fulfillment. | Crucial for user interaction and platform functionality. Ensures a smooth order management process and reduces the risk of errors or bugs that could result in financial loss. | Regularly test contract functionality and security to ensure proper functioning and prevent exploits. Stay up-to-date with Ethereum network upgrades and optimize gas costs as needed. |
ShortOrdersFacet.sol | Allows users to create and manage short positions on the Ditto platform. | Exposes external functions for creating, modifying, and canceling short orders, as well as internal functions for order validation and fulfillment. | Supports advanced trading strategies and is essential for expanding the platform's user base and increasing user retention. | Regularly review and update short order management functions, as well as implement appropriate risk management strategies. |
PrimaryLiquidationFacet.sol | Manages the liquidation process for undercollateralized positions. | Implements functions for calculating liquidation thresholds, initiating liquidation, and handling liquidation payouts. | Vital for maintaining the platform's financial stability and mitigating risk. | Monitor the liquidation process and ensure its proper functioning, while also reviewing and updating thresholds and parameters as needed. |
BridgeRouterFacet.sol | Handles the transfer of assets between different blockchain networks. | Exposes functions for initiating token transfers to and from connected networks via a third-party bridge solution. | Crucial for enabling cross-chain interoperability and expanding Ditto's user base. | Regularly test cross-chain functionality, as well as monitor and maintain API integration with the bridge solution. |
ExitShortFacet.sol | Enables users to close out their short positions. | Exposes functions for initiating short position closures and handling payouts. | Simplifies the closure process and enhances user experience. | Routinely test closure functions and update payout handling mechanisms to ensure accuracy. |
RedemptionFacet.sol | Manages the redemption of shares for underlying assets. | Provides functions for initiating share redemptions and calculating redemption values based on current market prices. | Supports users' ability to liquidate their positions and release their collateral, which is important for user satisfaction and retention. | Regularly test redemption functions, as well as update collateral release and calculation methods. |
LibBridgeRouter.sol | Facilitates interactions between the Ditto platform and external bridge contracts. | Provides reusable functions for initiating token transfers via external bridge solutions. | Improves modularity and increases the maintainability of the codebase. | Regularly update library functions, test for compatibility, and monitor for security vulnerabilities. |
LibBytes.sol | Provides utility functions for handling byte arrays. | Contains functions for converting between byte arrays and other data types, as well as selecting subarrays. | Enhances code readability and reduces redundancy, which promotes maintainability and long-term development. | Periodically review and update library functions, as needed. Ensure compatibility with Ethereum network standards and protocol updates. |
LibOracle.sol | Simplifies integration with price oracle solutions. | Exposes functions for querying token prices from external oracle solutions and caching price values. | Improves the reliability of the Ditto platform by leveraging trusted oracle solutions for price discovery. | Regularly monitor oracle functionality, test price querying, and update cache methods. |
LibOrders.sol | Encapsulates common order management functionality. | Provides helper functions for order validation, encapsulation, and processing. | Increases code modularity and reusability, which simplifies maintenance and speeds up development. | Routinely test library functions and update as necessary, ensuring compatibility with recent contract changes and updates. |
LibSRUtil.sol | Contains various utility functions specific to the Ditto platform. | Offers helper functions for parsing and validating order data. | Improves code readability and promotes reusability, which streamlines main contract updates and enhancements. | Regularly validate and update library functions, ensuring proper compatibility with Ditto contracts. |
UniswapOracleLibrary.sol | Simplifies the integration of Uniswap oracle solutions into Ditto contracts. | Exposes reusable functions for querying token prices from Uniswap oracle solutions and handling associated data. | Offers seamless integration with Uniswap's decentralized oracle solution, improving the reliability and trustworthiness of Ditto's market price data. | Regularly test Uniswap oracle integration and update functions as necessary, ensuring compatibility with recent protocol upgrades. |
Variable | Description | Economic Impact |
---|---|---|
Asset Price | The price of the underlying asset being traded in the Ditto Ethereum protocol. | The asset price directly affects the cost of opening and closing trades, and thus has a significant impact on the profitability of trading strategies. |
Trading Fees | Fees charged on trades made on the Ditto Ethereum protocol. | Trading fees are a source of revenue for the protocol and its liquidity providers. Higher fees can attract more liquidity providers, but may also discourage traders from using the platform. |
Liquidation Fees | Fees charged on liquidated positions in the Ditto Ethereum protocol. | Liquidation fees serve as a penalty for traders who are unable to meet their margin requirements and help to compensate liquidity providers for the risk they take on. |
Margin Requirements | The minimum amount of collateral required to open and maintain a position in the Ditto Ethereum protocol. | Margin requirements help to ensure that traders are able to meet their obligations and prevent excessive risk-taking. High margin requirements can limit the amount of leverage available to traders, but can also reduce the risk of liquidation. |
Interest Rates | The interest rates charged on borrowed funds in the Ditto Ethereum protocol. | Interest rates affect the cost of borrowing funds and can impact the profitability of trading strategies. Higher interest rates can attract more liquidity providers, but may also discourage traders from borrowing funds. |
Liquidity Incentives | Rewards offered to liquidity providers in the Ditto Ethereum protocol. | Liquidity incentives help to attract and retain liquidity providers, which is essential for maintaining a deep and liquid market. Higher incentives can attract more liquidity providers, but may also reduce the profitability of the protocol. |
Contracts | Functionality | Interactions |
---|---|---|
BidOrdersFacet.sol | Manages bid orders, including creation, cancellation, and fulfillment. | Interacts with the ShortOrdersFacet to manage short orders and the RedemptionFacet to manage redemptions. |
ShortOrdersFacet.sol | Manages short orders, including creation, cancellation, and fulfillment. | Interacts with the BidOrdersFacet to manage bid orders and the PrimaryLiquidationFacet to manage liquidations. |
PrimaryLiquidationFacet.sol | Manages primary liquidations, where a short order is liquidated due to an Ethereum price drop. | Interacts with the ShortOrdersFacet to manage short orders and the RedemptionFacet to manage redemptions. |
BridgeRouterFacet.sol | Provides a way for users to interact with Ditto Eth across multiple chains. | Interacts with the LibBridgeRouter to manage inter-chain messaging and the other facets to manage orders, liquidations, and redemptions. |
ExitShortFacet.sol | Manages the process of exiting a short position, including paying back the borrowed Ether and any associated fees. | Interacts with the ShortOrdersFacet to manage short orders and the RedemptionFacet to manage redemptions. |
RedemptionFacet.sol | Manages the process of redeeming Ether from Ditto Eth, including handling fees and oracle updates. | Interacts with the BidOrdersFacet, PrimaryLiquidationFacet, and ExitShortFacet to manage orders, liquidations, and short exits. |
LibBridgeRouter.sol | A library that provides functionality for inter-chain messaging and communication. | Used by the BridgeRouterFacet to manage inter-chain messaging and interactions. |
LibBytes.sol | A library that provides functionality for manipulating and comparing byte arrays. | Used by the BidOrdersFacet and ShortOrdersFacet to manage orders. |
LibOracle.sol | A library that provides functionality for handling oracle updates and managing price data. | Used by the BidOrdersFacet, ShortOrdersFacet, PrimaryLiquidationFacet, and RedemptionFacet to manage orders, liquidations, and redemptions. |
LibOrders.sol | A library that provides functionality for managing orders, including creating and canceling orders. | Used by the BidOrdersFacet and ShortOrdersFacet to manage orders. |
LibSRUtil.sol | A library that provides utility functionality for managing short orders and redemptions. | Used by the ShortOrdersFacet and RedemptionFacet to manage short orders and redemptions. |
UniswapOracleLibrary.sol | A library that provides functionality for interacting with the Uniswap oracle. | Used by the LibOracle library to manage price data and oracle updates. |
The Ditto protocol is a complex system of various interacting contracts with different functionalities and specialized libraries. Reviewing it gave me the opportunity to learn about various DeFi concepts, such as oracle usage, liquidations, and multi-chain liquidity pools. It also provided insights into the way complex contracts interact with each other and the use of libraries and custom contracts to extend protocol capabilities.
During the review, I spotted potential security vulnerabilities and raised various issues regarding code complexity, inconsistencies, and improvements. Focusing on enhancement areas such as code quality, maintainability, and usability, helped to create more secure and maintainable smart contracts. The review process also helped me to become more proficient in finding ways to improve code design and implementations.
While the review provided valuable insights and lessons, there is always room for enhancement, especially as the DeFi ecosystem evolves and progresses. Periodic reviews and updates of codebases, continued education and upskilling, collaborative efforts within review teams, and input from a diverse range of experts can help to ensure that code remains secure, efficient, and maintainable.
Overall, I enjoyed reviewing the Ditto protocol and welcome the opportunity to work on other similar projects in the future.
32 hours
#0 - c4-pre-sort
2024-04-07T20:23:11Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2024-04-17T07:04:10Z
hansfriese marked the issue as grade-b