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: 55/113
Findings: 1
Award: $23.41
🌟 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
23.4096 USDC - $23.41
Decent stands as a robust cross-chain DeFi protocol designed to facilitate one-click transactions utilizing any token across diverse blockchain networks. At its core, Decent employs two vital libraries, UTB and decent-bridge, to streamline cross-chain transactions. UTB, or Universal Token Bridge, orchestrates the routing of cross-chain transactions through selected bridges, offering the flexibility for transactions on any chain, paid for from any source chain or token. The custom bridge, decent-bridge, is constructed upon layerzero's OFT standard, providing a foundation for cross-chain interoperability.
A pivotal feature of Decent is its ability to enable one-click transactions using any token on any chain through a set of hooks and embeddable React components collectively referred to as "The Box." Developers can leverage The Box to create seamless transaction experiences, abstracting complexities related to bridging and swapping. The motivation behind The Box lies in its role as critical infrastructure for a multi-chain future, fostering user-friendly crypto payments accessible across various chains.
The Decent protocol showcases a well-thought-out architecture with a suite of functionalities that aim to simplify cross-chain transactions. While the foundation is strong, a thorough analysis has revealed potential areas of improvement, particularly in terms of decentralization, gas optimization, and input validation. Addressing these concerns will not only bolster the security of the protocol but also enhance its overall efficiency and user experience.
The assessment of the codebase involved an in-depth examination of key contracts, libraries, and interfaces within the Decent protocol. Each component, such as UTB, UTBExecutor, UTBFeeCollector, BaseAdapter, DecentBridgeAdapter, StargateBridgeAdapter, and associated libraries like SwapParams, UniSwapper, DcntEth, DecentBridgeExecutor, and DecentEthRouter, underwent scrutiny. The focus was on identifying security vulnerabilities, evaluating gas efficiency, and ensuring adherence to best practices. Additionally, the overall architecture was analyzed, with an emphasis on proposing enhancements for decentralization and user experience.
UniSwapper
and DecentBridgeExecutor
to optimize gas efficiency, especially in segments with repetitive code. This can involve identifying and consolidating duplicated code to reduce gas consumption.UniSwapper
related to token swaps. Consider leveraging gas-efficient algorithms and data structures to improve overall performance.SwapParams
, UniSwapper
, and DecentBridgeAdapter
. Implement robust checks on parameters to mitigate potential vulnerabilities arising from malicious inputs.DecentBridgeExecutor
and DecentEthRouter
to ensure that only valid and secure inputs are processed. This includes validating addresses, amounts, and other relevant parameters.DecentBridgeAdapter
, especially concerning fee collection. Consider using standardized libraries for signature verification and conduct additional checks to ensure the integrity of signed data.DecentBridgeAdapter
, StargateBridgeAdapter
, and DecentEthRouter
. Clearly define roles and permissions, ensuring that only authorized entities can execute sensitive operations.UTBFeeCollector
to prevent potential replay attacks. Nonce management adds an additional layer of security by ensuring that transactions are processed in the intended order and are not subject to replay attacks.This section provides a detailed analysis of the codebase quality for various smart contracts within a cross-chain bridge or DeFi platform. Each contract's functionality, security issues, and recommendations are outlined, aiming to enhance the overall security and reliability of the smart contracts. The analysis covers key concerns such as reentrancy vulnerabilities, gas limit specifications, access controls, and other potential risks. The provided recommendations offer actionable steps to mitigate identified security issues and ensure robust smart contract implementations.
Contract | Explanation | Security Issues | Recommendations |
---|---|---|---|
UTB.sol | UTB is a smart contract for a cross-chain bridge or DeFi platform. It handles token swaps, bridging assets, and executing transactions. It uses external contracts/interfaces for various operations. | 1. Swapping Functionality: performSwap approves the maximum amount of tokens without validation. <br> 2. Swap and Execute: Fee collection relies on ECDSA signatures. <br> 3. Bridge Functionality: Bridging function sends native tokens along with the call. <br> 4. General Security Concerns: Centralization risk, potential reentrancy issues, trust assumptions in external contracts. | 1. Limit approved amounts in performSwap and audit swapper contract. <br> 2. Strengthen signature verification and review the signing process. <br> 3. Ensure the bridge adapter is secure and correctly implemented. <br> 4. Implement decentralized control, use reentrancy guards, and perform thorough audits. |
UTBExecutor.sol | UTBExecutor executes payment transactions with native Ether or ERC20 tokens. It has two execute functions for different transaction types. | 1. Reentrancy: Lack of reentrancy protection during external calls. <br> 2. Gas Limit: No specified gas limit for call operations. <br> 3. ERC20 Return Values: Missing check on return values of ERC20 transfer functions. <br> 4. Solidity Version: Locked to a specific Solidity version. | 1. Implement reentrancy guards. <br> 2. Specify gas limits to prevent out-of-gas errors. <br> 3. Check and handle return values appropriately. <br> 4. Consider keeping the version up-to-date for security fixes. |
UTBFeeCollector.sol | UTBFeeCollector collects and redeems fees, likely for a bridge service. It uses a signer address for fee collection verification. | 1. Signature Replay Attack: Lack of nonce management may lead to replay attacks. <br> 2. ERC20 transferFrom Authorization: Assumes authorization to transfer fees may fail. <br> 3. Inline Assembly: Use of inline assembly may introduce errors. <br> 4. Lack of Event Logging: No events for critical actions. | 1. Implement nonce management to prevent replays. <br> 2. Ensure proper authorization for fee transfers. <br> 3. Carefully review inline assembly usage. <br> 4. Implement events for transparency and tracking. |
BaseAdapter.sol | BaseAdapter works with a bridge executor for certain actions. It uses UTBOwned for ownership functionality. | 1. Trust in the bridgeExecutor: Assumes trust in the bridgeExecutor. <br> 2. Single Point of Failure: bridgeExecutor represents a single point of failure. <br> 3. No Event Logging: Lack of event emission for critical changes. | 1. Ensure trustworthiness of the bridgeExecutor. <br> 2. Implement measures to mitigate risks associated with a single point of failure. <br> 3. Implement events for transparency. |
DecentBridgeAdapter.sol | DecentBridgeAdapter bridges assets using the Decent bridge protocol. It inherits from BaseAdapter, implements IBridgeAdapter interface. | 1. Access Control: Owner-only functions may pose a risk if not correctly implemented. <br> 2. Reentrancy: External calls in bridge function may be vulnerable to reentrancy. <br> 3. Contract Upgrades: No clear indication of upgradeability. <br> 4. Input Validation: Assumes encoded data is valid. | 1. Ensure proper implementation of owner-only functions. <br> 2. Implement reentrancy guards and use Checks-Effects-Interactions pattern. <br> 3. If upgradeability is intended, implement a secure upgrade mechanism. <br> 4. Implement comprehensive input validation. |
StargateBridgeAdapter.sol | StargateBridgeAdapter facilitates cross-chain token swaps using the Stargate protocol. It inherits from BaseAdapter, IBridgeAdapter, and IStargateReceiver. | 1. Reentrancy: sgReceive calls an external contract, potentially exposing reentrancy risks. <br> 2. Centralization Risks: Owner-only functions introduce centralization risks. <br> 3. Input Validation: Assumes encoded data is correctly formatted. <br> 4. Contract Upgrades: No clear indication of upgradeability. | 1. Ensure onlyExecutor modifier mitigates reentrancy risks. <br> 2. Minimize owner privileges and consider decentralized governance. <br> 3. Implement comprehensive input validation. <br> 4. If upgradeability is intended, implement a secure upgrade mechanism. |
SwapParams.sol | The SwapParams.sol Solidity code defines a library (SwapDirection ) and a struct (SwapParams ). It is used for token swap operations in a decentralized finance (DeFi) application. | 1. Path Parameter Validation: The path parameter lacks validation, potentially exposing the swap function to vector attacks. <br> 2. Token Address Validation: No explicit checks on the legitimacy of tokenIn and tokenOut addresses. <br> 3. Missing User or Transaction Identifiers: The SwapParams struct lacks user or transaction identifiers. <br> 4. Access Control Mechanisms: Lack of access control mechanisms. <br> 5. Event Logging: Absence of events makes it challenging to track swap operations. | 1. Strengthen input validation for parameters like path , tokenIn , and tokenOut . <br> 2. Include user or transaction identifiers in the struct for comprehensive swap operations. <br> 3. Implement access controls to prevent unauthorized calls to sensitive functions. <br> 4. Introduce event logging for transparency and tracking purposes. |
UniSwapper.sol | UniSwapper.sol is a Solidity contract designed for token swapping, interacting with Uniswap, a decentralized exchange. It inherits from UTBOwned and implements the ISwapper interface. | 1. Reentrancy Vulnerability: The contract lacks reentrancy protection. <br> 2. Token Approval Risks: Approval of the Uniswap router to spend tokens lacks proper validation. <br> 3. Error Handling: Failure to check return values in private helper functions. <br> 4. Access Control: The onlyUtb modifier is referenced but not defined. <br> 5. Gas Usage Optimization: The contract's gas usage could potentially be optimized. | 1. Implement reentrancy guards using the nonReentrant modifier. <br> 2. Ensure correct and secure validation before approving the Uniswap router for token spending. <br> 3. Implement proper error handling, check return values, and consider using the SafeERC20 library. <br> 4. Define and thoroughly review the onlyUtb modifier for robust access control. <br> 5. Refactor code to optimize gas usage and enhance efficiency. |
DcntEth.sol | DcntEth.sol is a Solidity contract inheriting from OFTV2 , likely representing version 2 of an OmniFungible Token (OFT) designed for cross-chain interactions. | 1. Unrestricted setRouter Function: The setRouter function lacks access control. <br> 2. Assumed Parent Contract Security: The contract assumes the security of the inherited OFTV2 contract without explicit validation. <br> 3. Missing Checks on Minting and Burning: The contract lacks checks or limits on minting and burning. <br> 4. Event Logging Absence: The contract does not emit events for critical actions. | 1. Restrict the setRouter function to the contract owner or another trusted role. <br> 2. Conduct a thorough audit of the OFTV2 and other inherited contracts for security. <br> 3. Implement checks and limits on minting and burning functions. <br> 4. Introduce event logging for critical actions to enhance transparency. |
DecentBridgeExecutor.sol | DecentBridgeExecutor.sol defines a smart contract facilitating transactions in WETH or native ETH on behalf of users, intended for use on Ethereum or any EVM-compatible blockchain. | 1. Reentrancy Vulnerability: The contract appears susceptible to reentrancy attacks. <br> 2. Unbounded Token Approval: _executeWeth function approves the target contract to spend the entire amount of WETH without checking the existing allowance. <br> 3. Unchecked Return Values: The contract does not check the return values of weth.transfer and weth.transferFrom calls. <br> 4. Gas Limit for External Calls: External calls via target.call(callPayload) lack a specified gas limit. <br> 5. Centralization Risk: The execute function can only be called by the owner. | 1. Implement reentrancy protection using the checks-effects-interactions pattern or the nonReentrant modifier. <br> 2. Check the existing allowance before approving token spending to avoid potential issues. <br> 3. Ensure secure token transfers by checking return values of weth.transfer and weth.transferFrom . <br> 4. Set a reasonable gas limit for external calls to prevent unexpected gas consumption. <br> 5. Evaluate the need for decentralization and consider additional access controls to mitigate centralization risks. |
DecentEthRouter.sol | DecentEthRouter.sol serves as a bridge between Ethereum and other chains, using WETH as the bridging asset. It enables users to send ETH or WETH across chains, manage liquidity, and interact with an external executor contract. | 1. Reentrancy Vulnerability: The contract might be susceptible to reentrancy attacks. <br> 2. Lack of Gas Limit for External Calls: External calls to other contracts are made without specifying a gas limit. <br> 3. Ownership Manipulation: The contract inherits from Owned , potentially providing owner-only functions that could manipulate critical aspects. <br> 4. Limited Error Handling: The contract uses require statements for error handling, but the specificity and coverage of error conditions are not clear without reviewing external contract behavior. | 1. Implement reentrancy protection using the checks-effects-interactions pattern or the nonReentrant modifier. <br> 2. Specify reasonable gas limits for external calls to prevent unexpected gas consumption. <br> 3. Thoroughly review and audit owner-only functions inherited from Owned for security. <br> 4. Enhance error handling with clear and comprehensive messages in require statements. |
The execute
function in DecentBridgeExecutor.sol
can only be called by the owner, introducing a central point of control and failure. This design choice may pose a risk if the owner account is compromised or acts maliciously.
Consider decentralizing control by implementing multi-signature schemes or decentralized governance. Alternatively, introduce additional access controls to mitigate centralization risks.
BaseAdapter
relies on trust in the bridgeExecutor
contract. This centralized trust introduces a potential single point of failure if the bridgeExecutor
is compromised.
Implement measures to verify and ensure the trustworthiness of the bridgeExecutor
. Consider diversifying or decentralizing control to reduce the impact of a single point of failure.
The UTBFeeCollector
contract lacks clear access controls on critical functions. Any address can potentially interact with these functions, leading to centralization risks.
Introduce access controls to restrict critical functions to authorized users. This can help prevent unauthorized interactions and mitigate centralization risks.
The UniSwapper.sol
contract is designed for token swapping on Uniswap. Below is a detailed review of the mechanisms implemented:
Reentrancy Vulnerability:
Token Approval Risks:
Error Handling:
_refundUser
and _sendToRecipient
could introduce potential vulnerabilities.Access Control:
onlyUtb
modifier is referenced but not defined in the provided code, raising uncertainty about its security implementation.onlyUtb
modifier for robust access control.Gas Usage Optimization:
swapExactIn
and swapExactOut
where refactoring may reduce duplicate code.The DcntEth.sol
contract represents an OmniFungible Token (OFT) designed for cross-chain interactions. A detailed review of the mechanisms is provided below:
setRouter
function lacks access control, allowing any user to change the router address, posing a significant security risk.setRouter
function tothe contract owner or another trusted role to prevent unauthorized changes.
Assumed Parent Contract Security:
OFTV2
contract without explicitly validating or auditing its security.OFTV2
contract and any other inherited contracts to ensure overall security.Missing Checks on Minting and Burning:
Event Logging Absence:
The UTB.sol
contract, serving as a cross-chain bridge or DeFi platform, exhibits potential systemic risks related to various functionalities.
Swapping Functionality:
performSwap
function and conduct a thorough audit of the swapper contract to ensure its security.Swap and Execute:
swapAndExecute
function.Bridge Functionality:
General Security Concerns:
The UTBExecutor.sol
contract, responsible for executing payment transactions, exhibits systemic risks that should be addressed.
Reentrancy:
Gas Limit:
ERC20 Return Values:
Solidity Version:
The DecentEthRouter.sol
contract, serving as a bridge between Ethereum and other chains, introduces systemic risks that should be mitigated.
Reentrancy Vulnerability:
Lack of Gas Limit for External Calls:
Ownership Manipulation:
Owned
for potential security risks.Limited Error Handling:
require
statements, and ensure all error conditions are appropriately checked.15 hours
#0 - c4-pre-sort
2024-01-26T17:45:21Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2024-02-03T14:50:19Z
alex-ppg marked the issue as grade-b