Platform: Code4rena
Start Date: 19/01/2024
Pot Size: $36,500 USDC
Total HM: 9
Participants: 113
Period: 3 days
Judge: 0xsomeone
Id: 322
League: ETH
Rank: 31/113
Findings: 1
Award: $186.24
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: fouzantanveer
Also found by: 0xAadi, 0xSmartContract, 0xepley, SAQ, SBSecurity, albahaca, catellatech, clara, foxb868, hunter_w3b, ihtishamsudo, yongskiws
186.2387 USDC - $186.24
The approach and steps we employed to examine the underlying code.
Our approach to analyzing the source code of the Decent Protocol was to simplify the information provided by the protocol, using a variety of diagrams to visually clarify the project's key contracts and break down each important part of these contracts. This enhances understanding for developers, security researchers, and users alike. We identified the fundamental concepts and employed simpler language to explain the functionality and goals of the Decent Protocol. Furthermore, we organized the information logically into separate sections, each with identifying titles, to provide a clear overall picture of the subject. Our primary goal was to make the information more accessible and easy to understand.
NOTE: The provided diagrams are based on our interpretation of the protocol. In the event that any of them is not 100% accurate but aligns with the protocol's initial concept, we invite you to reach out to us via Discord (catellatech). We are willing to share the diagrams for the project team to make any necessary modifications. If the diagrams are deemed accurate, they are fully available for the protocol to use in its documentation.
Decent is a platform that enables one-click transactions across different blockchains. It uses UTB for transaction routing and decent-bridge for cross-chain functionality. Users can seamlessly perform transactions, even if their funds are on a different blockchain. The platform supports same-chain transactions (swapAndExecute) and cross-chain transactions (bridgeAndExecute). Swappers handle same-chain transactions, while bridge adapters manage communication with specific bridges. UTBExecutor executes additional logic for UTB, like minting NFTs. In essence, Decent streamlines cross-chain transactions with flexibility and generality.
Overview diagram: <img src="https://github.com/catellaTech/Decent/blob/main/Decent.Over.drawio.png?raw=true">
This contract provides the infrastructure to execute one-click transactions across different blockchains using swappers and bridge adapters. It also handles the collection of fees associated with these transactions. <img src="https://github.com/catellaTech/Decent/blob/main/Decent.UTB.drawio.png?raw=true>">
The UTBExecutor contract enables the secure execution of payment transactions with native or ERC-20 tokens, ensuring proper fund handling and allowing for refunds in case of failures.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.UTBExecutor.drawio.png?raw=true">This contract is responsible for collecting, verifying, and managing fees associated with transactions in the protocol, whether in native Ether or ERC-20 tokens. Fee verification is done through digital signatures, and the collected fees can be redeemed by the owner in the specified form and quantity.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.UTBFeeCollector.drawio.png?raw=true">This BaseAdapter contract is like a starting point for making bridge adapters. Think of a bridge adapter as a helper that lets different parts talk to each other in the blockchain world. By using UTBOwned, it makes sure that only the person who owns it can decide who the bridge helper is (bridge executor). Also, it sets things up so that only this bridge helper can use specific functions, keeping things safe and controlled when connecting to the bridge.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.BaseAdapter.drawio.png?raw=true">This contract makes sure the Decent protocol and other bridges can chat smoothly. It helps figure out fees, keeps track of different IDs, and does the actual work of moving things around in the blockchain.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.DecentBridgeAdapter.drawio.png?raw=true">This contract serves as a middleman, connecting the Decent protocol with various bridge adapters in a standardized way. Its role involves handling configurations, overseeing the bridging process, and maintaining smooth communication among different parts of the blockchain system.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.StargateBridgeAdapter.drawio.png?raw=true">This contract play a crucial role in reNFT system responsible for creating and verifying rental orders within a digital asset framework. The detailed functionality relies on how other contracts, like Zone, Policy, Signer, and others, are implemented and integrated into the system.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.SwapParams.drawio.png?raw=true">This contract lets you swap ERC-20 tokens and, if you want, ETH too. It uses the Uniswap V3 router for these swaps and deals with various swap situations, like when you want an exact input or an exact output. It takes care of moving funds around in the right way.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.UniSwapper.drawio.png?raw=true">This contract provides a basic ERC-20 token that can be managed by a specific router. The router has control over key functions, such as token creation and burning, while the owner has certain additional privileges.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.DcntEth.drawio.png?raw=true">It functions as an intelligent intermediary that assists in the transfer and management of assets between Ethereum and the Decent protocol, ensuring everything runs smoothly.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.DecentEthRouter.drawio.png?raw=true">This contract acts as a transaction executor, handling the necessary logic to interact with contracts on different blockchains and managing both WETH and Ether as needed.
<img src="https://github.com/catellaTech/Decent/blob/main/Decent.DecentBridgeExecutor.drawio.png?raw=true">DecentEthRouter:
DcntEth:
UniSwapper:
DecentBridgeExecutor:
Given the level of control that these
roles
possess within the system, users must place full trust in the fact that the entities overseeing theseroles
will always act correctly and in the best interest of thesystem
and itsusers
.
Overall, we consider the quality of the Decent protocol codebase to be Good. The code appears to be mature and well-developed. We have noticed the implementation of various standards adhere to appropriately. Details are explained below:
Codebase Quality Categories | Comments |
---|---|
Code Maintainability and Reliability | The Decent Protocol contracts demonstrates good maintainability through modular structure, consistent naming, and efficient use of libraries. It also prioritizes reliability by handling errors, conducting security checks. However, for enhanced reliability, consider professional security audits and documentation improvements. Regular updates are crucial in the evolving space. |
Code Comments | During the audit of the Decent contracts codebase, we found that some areas lacked sufficient internal documentation to enable independent comprehension. While comments provided high-level context for certain constructs, lower-level logic flows and variables were not fully explained within the code itself. Following best practices like NatSpec could strengthen self-documentation. As an auditor without additional context, it was challenging to analyze code sections without external reference docs. To further understand implementation intent for those complex parts, referencing supplemental documentation was necessary. |
Documentation | The documentation of the Decent project is quite comprehensive and detailed, providing a solid overview of how Decent protocol is structured and how its various aspects function. However, we have noticed that there is room for additional details, such as diagrams, to gain a deeper understanding of how different contracts interact and the functions they implement. With considerable enthusiasm. We are confident that these diagrams will bring significant value to the protocol as they can be seamlessly integrated into the existing documentation, enriching it and providing a more comprehensive and detailed understanding for users, developers and auditors. |
Testing | The audit scope of the contracts to be reviewed is 75%, with the aim of reaching 100%. |
UTB and Derivatives (UTBOwned, UniSwapper, StargateBridgeAdapter):
StargateBridgeAdapter:
SwapParams and Derivatives (UniSwapper, StargateBridgeAdapter):
DcntEth:
DecentEthRouter:
DecentBridgeExecutor:
The Anomalies of ERC-20 Tokens:
ERC-20 Tokens come in all shapes and sizes. Here's a glimpse into some of the variants and potential problems that lurk in the shadows:
Centralized Ownership:
Dependency on External Contracts:
Missing Implementation Details:
Insufficient Validation in Bridge Contracts:
Gas Currency Assumption:
Limited Error Handling in Bridge Execution:
Insecure Calls in Bridge Contracts:
Assumptions about Wrapped Ether (WETH) Usage:
Incomplete Swap Parameter Validation:
💡 A robust model is indispensable for systematically evaluating project risks. One highly recommended approach involves employing effective risk modeling techniques. https://www.notion.so/Smart-Contract-Risk-Assessment-3b067bc099ce4c31a35ef28b011b92ff#7770b3b385444779bf11e677f16e101e
💡 We suggest establishing a foundational architecture with a System.sol contract, serving as a central registry where all contracts are registered. The entire system can be organized around a singular contract, such as SystemRegistry. This contract acts as a cohesive entity that interconnects all other contracts, allowing for a comprehensive listing of all contracts within the system. Essentially, it functions as a registry, providing a centralized point to access information about all contracts in the system..
💡Evaluate the gas consumption of each function across different scenarios during testing to ensure optimal efficiency and identify potential areas for optimization.
💡Consider decentralized ownership models or implement multi-signature control for critical functions.
💡Ensure proper validation and handling of cross-chain interactions.
Some attack ideas can be tested as invariants, for example:
With an understanding of these attack vectors, the protocol must implement more robust test suites.
Start by crafting "invariant.t.sol," where you define your tests by laying the foundation for the 'invariant.'
Now, let's focus on creating your handler.t.sol file. This contract serves as an intermediary to control the contract that captures the state of the Fuzz stateful.
Through the handler, you instruct your Foundry and the Stateful Fuzzing test suite to align correctly with the contract capturing the state of the Fuzz stateful. Essentially, you provide guidelines to Foundry on when to call specific functions for testing, all with precise instructions to prevent excessive function calls.
Once your tests are configured, the next step is to write the "handler.sol" While you could embed assertions directly into your invariants, a cleaner approach is to compute them in the "handler.sol" This ensures that your assertions condense into a single line, maintaining logic validity regardless of variable input parameters. In the development of more intricate software or systems, invariants play a pivotal role in ensuring correctness.
Attackers are becoming increasingly sophisticated, targeting protocols and their users not only through code vulnerabilities but also exploiting their social media presence, such as X. In these times more than ever, it is crucial to maintain robust layers of security. To enhance project security, it is imperative to establish control policies mandating Two-Factor Authentication (2FA) for all staff accounts and ensuring its widespread utilization whenever possible. It's important to acknowledge that achieving 100% foolproof security solely through smart contract codes is unattainable. To fortify security measures, consider implementing a more comprehensive policy that advocates for the use of non-SMS 2FA methods. For additional information, you can explore the recent Simswap attack on Code4rena detailed in this Article.
The contracts showcase a complex architecture with diverse functionalities, including Uniswap swaps, cross-chain interoperability, and token minting/burning. Noteworthy is the integration with Uniswap V3 and the handling of Wrapped Ether (WETH). The cross-chain interoperability, especially through the DecentEthRouter contract, suggests the need for careful handling to prevent fund loss in case of failures on the destination chain. The contracts implement security mechanisms, such as swap path validation and authorization control, while the DecentBridgeExecutor contract takes care of executing actions in other contracts. There is proper use of common patterns like approvals and authorizations.
17 hours
#0 - c4-pre-sort
2024-01-26T17:43:08Z
raymondfam marked the issue as high quality report
#1 - c4-sponsor
2024-01-30T16:25:22Z
wkantaros (sponsor) acknowledged
#2 - c4-judge
2024-02-03T14:50:30Z
alex-ppg marked the issue as grade-a