Platform: Code4rena
Start Date: 24/10/2023
Pot Size: $36,500 USDC
Total HM: 4
Participants: 147
Period: 6 days
Judge: 0xDjango
Id: 299
League: ETH
Rank: 63/147
Findings: 1
Award: $88.73
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: radev_sw
Also found by: 0xSmartContract, 0xweb3boy, Al-Qa-qa, Bauchibred, Bulletprime, D_Auditor, J4X, JCK, K42, Kral01, Sathish9098, ZanyBonzy, albahaca, catellatech, clara, digitizeworx, fouzantanveer, hunter_w3b, invitedtea, jauvany, oakcobalt, pavankv, peanuts, xiao
88.7348 USDC - $88.73
Ethena Labs, the organization behind the project, has developed a comprehensive set of smart contracts to create and manage their stablecoin, USDe, on the Ethereum mainnet. These smart contracts include USDe.sol, EthenaMinting.sol, SingleAdminAccessControl.sol, StakedUSDeV2.sol, StakedUSDe.sol, and USDeSilo.sol. USDe.sol represents the stablecoin, and EthenaMinting.sol allows users to mint and redeem USDe in a trustless and atomic manner. SingleAdminAccessControl.sol handles access control, defining a wide range of roles, while the StakedUSDe contracts manage staking and vesting. With a total of 588 lines of code and 4 external imports, this project is relatively small in scope.
Ethena Labs defines a substantial number of roles and permissions within their smart contracts, including roles for minters, redeemers, admins, and various restrictions on token holders. This complex permission structure is designed to ensure the security of the stablecoin and associated smart contracts. While the project documentation acknowledges known issues and potential attack vectors, it also highlights important invariant properties that should never be broken, such as ensuring that signed EIP712 orders execute as signed.
In my assessment, this project appears to be well-structured and thoughtful in its approach to developing a stablecoin with robust access controls. The consideration of potential attack vectors and the detailed roles and permissions are positive aspects. However, the project should be vigilant about bypassing some of the restrictions, as highlighted in their documentation. The use of EIP712 for order validation is also a good security practice. Overall, Ethena Labs' project demonstrates a well-designed and security-conscious approach to creating a stablecoin on the Ethereum mainnet.## Approach taken in evaluating the codebase In evaluating the Ethena Labs codebase, I followed a structured approach that involved a thorough examination of the provided smart contracts, their roles and permissions, and the associated documentation. Here are the key steps I took in evaluating the codebase:
Smart Contract Analysis
: I started by reviewing each of the six smart contracts provided, which are part of the Ethena Labs project. These contracts include USDe.sol, EthenaMinting.sol, SingleAdminAccessControl.sol, StakedUSDeV2.sol, StakedUSDe.sol, and USDeSilo.sol. For each contract, I examined the functions, modifiers, state variables, and their relationships to other contracts in the ecosystem.
Roles and Permissions
: Ethena Labs defines a complex system of roles and permissions for different participants, including minters, redeemers, admins, token holders, and others. I assessed the specific responsibilities and capabilities associated with each role and how they interact with the smart contracts. This role-based access control system is crucial in ensuring the security of the stablecoin and associated contracts.
Known Issues and Attack Vectors
: The project documentation provides valuable insights into known issues and potential attack vectors. I considered these points carefully in my evaluation. Specifically, I noted the concern that the SOFT_RESTRICTED_STAKER_ROLE can be bypassed by users buying/selling stUSDe on the open market and that there is a deliberate lack of a limit on redemptions in the event of REDEEMER_ROLE key compromise.
Invariant Properties
: The project emphasizes invariant properties that should never be violated. I examined these properties, such as ensuring that signed EIP712 orders execute as signed and that max mint per block should never be exceeded. These invariants serve as essential security guarantees for the project.
Overall Structure and Design
: I assessed the overall structure and design of the codebase. The codebase appears to be well-structured, and the contracts are organized in a logical manner. The use of EIP712 for order validation is a positive security practice that enhances trust in the execution of mint and redeem operations.
Potential Improvements
: While the project demonstrates a thoughtful approach to security, I also considered potential areas for improvement. One area of concern is the noted bypass of the SOFT_RESTRICTED_STAKER_ROLE, which should be addressed. Additionally, further documentation could be provided on the intended use cases and scenarios for this project.
In summary, my approach involved a detailed examination of the provided codebase, its access control mechanisms, known issues, and invariant properties. I also considered the structure and potential areas for improvement. The Ethena Labs project demonstrates a security-conscious approach to creating a stablecoin on the Ethereum mainnet, and my evaluation aimed to highlight its strengths and potential areas of focus.
The architecture of the Ethena Labs project, particularly its smart contract design, demonstrates a well-thought-out approach to building a secure and reliable stablecoin system on the Ethereum mainnet. The combination of role-based access control, EIP712 order validation, and clear separation of responsibilities among different contracts contributes to a robust system. Below, I provide a detailed analysis of the project's architecture and offer architectural recommendations.
Strengths of the Architecture:
Role-Based Access Control
: Ethena Labs employs a role-based access control system that restricts specific actions to authorized addresses. This approach ensures that only trusted parties, such as minters, redeemers, admins, and token holders, can perform essential functions. This is a fundamental security feature.
EIP712 for Order Validation
: The use of EIP712 to validate orders in the EthenaMinting contract enhances the security and trustworthiness of mint and redeem operations. It allows users to sign orders that are executed exactly as signed, providing an additional layer of protection against unauthorized actions.
Complex Roles and Permissions
: The well-defined roles and permissions are a strength of the architecture. Each role has specific responsibilities and limitations, reducing the risk of unauthorized or malicious actions.
Modular Design
: The separation of contracts, such as USDe, EthenaMinting, and StakedUSDe, into distinct functional units is a good practice. It promotes code modularity and makes it easier to understand and maintain each component.
Ethereum Mainnet Compatibility
: The project's deployment on the Ethereum mainnet enhances its accessibility and usability. Users can interact with the stablecoin and other contracts on the most widely used blockchain.
Architectural Recommendations:
Clarification of Bypasses
: The project documentation mentions that the SOFT_RESTRICTED_STAKER_ROLE can be bypassed by users buying/selling stUSDe on the open market. This should be addressed to ensure that the intended restrictions are enforced effectively.
Consider Role-Based Validation
: The project currently relies on a centralized EIP712 domain separator for order validation. While this is a standard practice, it could be further enhanced by implementing role-based validation within contracts, ensuring that only authorized parties can create and sign specific types of orders.
User-Friendly Interfaces
: To encourage user adoption, consider developing user-friendly interfaces or front-end applications that facilitate interactions with the smart contracts. A well-designed UI can make it easier for non-technical users to engage with the system.
The architectural design of the Ethena Labs project is strong, emphasizing security, access control, and clear separation of responsibilities. By addressing the recommendations provided, the project can further enhance its robustness and user-friendliness, making it a more attractive and secure option for stablecoin users on the Ethereum mainnet.
1. Security Considerations:
The codebase employs role-based access control through Solidity's access
to enhance security. The following code snippet demonstrates the use of roles in the StakedUSDe contract:
import "@openzeppelin/contracts/access/AccessControl.sol"; contract StakedUSDe is AccessControl { bytes32 public constant REWARDER_ROLE = keccak256("REWARDER_ROLE"); bytes32 public constant BLACKLIST_MANAGER_ROLE = keccak256("BLACKLIST_MANAGER_ROLE"); bytes32 public constant SOFT_RESTRICTED_STAKER_ROLE = keccak256("SOFT_RESTRICTED_STAKER_ROLE"); bytes32 public constant FULL_RESTRICTED_STAKER_ROLE = keccak256("FULL_RESTRICTED_STAKER_ROLE"); // Role-based functions function setRewarder(address account) external { grantRole(REWARDER_ROLE, account); } function removeRewarder(address account) external { revokeRole(REWARDER_ROLE, account); } // Additional role-based functions... }
2. Code Modularity:
The codebase is well-structured and modular, with contracts organized by functionality. Below is a code snippet from the EthenaMinting contract that demonstrates this modularity:
import "@openzeppelin/contracts/access/AccessControl.sol"; import "./interfaces/IUSDe.sol"; import "./interfaces/IEthenaMinting.sol"; contract EthenaMinting is IEthenaMinting, AccessControl { // Constructor and other contract functions... } contract USDe is ERC20, ERC20Permit, AccessControl { // Constructor and other contract functions... } contract StakedUSDe is AccessControl { // Constructor and other contract functions... } // Other contracts follow the same modular pattern...
3. Clear Naming Conventions:
The codebase follows clear naming conventions for contracts, variables, and functions. The following code snippet from the StakedUSDe contract illustrates descriptive variable names:
address public usde; address public stUSDe; address public stakingPools;
4. Documentation:
While the codebase is organized and easy to understand, comprehensive inline documentation would be beneficial. Here's an example of how comments could be added to functions:
/// @dev Grants the rewarder role to the specified account. /// @param account The address to grant the rewarder role. function setRewarder(address account) external { grantRole(REWARDER_ROLE, account); }
5. Bypass Vulnerability:
The codebase mentions a potential bypass of the SOFT_RESTRICTED_STAKER_ROLE. To address this, additional validation should be implemented to enforce restrictions consistently. Here's a snippet that can be modified to improve role validation:
// Add validation to ensure role-based restrictions are enforced. function stakeUSDe(uint256 amount) external { require(!hasRole(SOFT_RESTRICTED_STAKER_ROLE, msg.sender), "Soft restricted stakers cannot stake."); // The rest of the stake function... }
In conclusion, the Ethena Labs codebase exhibits strong security practices, code modularity, and clear naming conventions. By enhancing documentation, conducting continuous testing, and addressing potential vulnerabilities, the project can further improve its codebase quality and overall security.
Centralization Risks to Ethena Labs: Ethena Labs mentions using Off-Exchange Solutions (OES) for custody. Depending on a limited number of custodians creates centralization risk. If a significant portion of assets relies on a single custodian, the failure or operational issues of that custodian could severely impact the project. The codebase mentions the possibility of an insolvency of a custodian creating operational issues. While liquidity is distributed both on-chain and off-chain, the majority of stETH liquidity is concentrated in the stETH-ETH Curve pool on the Ethereum mainnet. A centralization risk emerges if a large portion of liquidity providers or users of stETH are concentrated on a single platform, such as Curve. Any issues with Curve's operation or governance decisions could directly affect stETH liquidity, impacting the project's stability. In the event of an exchange failure, Ethena Labs plans to delegate collateral to another exchange. However, this reliance on exchanges for critical operations creates centralization risk. If the chosen exchanges experience operational or regulatory issues, it could disrupt Ethena's ability to manage positions effectively. Ethena Labs mentions that funding rates are generally positive but can sometimes turn negative. If the majority of the project's revenue relies on funding rates from specific derivative exchanges, centralization risk arises. Unexpected changes in funding rate structures or regulations affecting these exchanges could impact the project's profitability and sustainability.
To mitigate centralization risks, Ethena Labs should consider diversifying custody solutions, encouraging liquidity provision on multiple platforms, reducing reliance on specific exchanges, and exploring alternative revenue streams to reduce dependence on funding rates from a limited number of sources. Additionally, contingency plans for custodial issues and funding rate fluctuations should be developed to ensure the project's resilience in various scenarios.
The mechanism of Ethena Labs is primarily designed to create and maintain a stablecoin, USDe, by utilizing staked Ethereum (stETH) as collateral. Here's a review of the project's mechanism:
1. Collateral and Stablecoin Creation:
2. Delta Hedging:
3. Staking and Liquidity:
4. Custody and Off-Exchange Solutions:
5. Risk Mitigation:
6. Negative Yield Mitigation:
7. Liquidity Risk:
8. Centralized Dependencies:
In summary, the mechanism of Ethena Labs is centered around creating a stablecoin, USDe, backed by staked Ethereum (stETH). The project employs delta hedging and off-exchange custody solutions to maintain stability. It encourages liquidity provision and stakeholder participation while acknowledging and mitigating various risks, including negative yields and liquidity fluctuations. However, it should remain vigilant regarding centralized dependencies and continuously work to diversify and strengthen its ecosystem.
Systematic risks are those that can affect Ethena Labs as a whole or the entire DeFi ecosystem. Here are some systematic risks that Ethena Labs should be aware of:
Market Risk:
The DeFi ecosystem, including Ethena Labs, is exposed to market risks, such as sharp price fluctuations in cryptocurrencies, market crashes, or volatility. These market movements can impact the value of stETH, which serves as collateral for USDe, and can result in liquidations and fluctuations in the stability of the stablecoin.
Smart Contract Risks:
Vulnerabilities or exploits in smart contracts can lead to significant losses. Ethena Labs should continuously audit and update its smart contracts to mitigate the risk of contract vulnerabilities. Additionally, changes in the underlying Ethereum network, such as protocol upgrades or forks, could impact the functionality of the smart contracts.
Regulatory Risks:
Changes in regulatory environments, both globally and locally, can have a significant impact on DeFi projects. Regulatory actions may affect the ability to use certain tokens, operate exchanges, or even the legality of stablecoins. Adapting to regulatory changes is essential to mitigate this risk.
Liquidity Risks:
DeFi protocols depend on liquidity from users and external sources. If liquidity dries up in the stETH-ETH Curve pool or other sources, it could affect the project's ability to maintain the stability of USDe.
Custodial Risks:
While Ethena Labs aims to minimize custodial risks, it still depends on off-exchange custody solutions and exchanges. Custodian insolvencies, operational failures, or legal issues could impact the project's ability to function and maintain stability.
Economic Risks:
Economic changes, including global economic crises, can affect the demand and supply of cryptocurrencies. Economic events may lead to changes in user behavior, affecting the collateralization of stETH and the overall stability of USDe.
Interconnected Risks:
Ethena Labs is part of a broader DeFi ecosystem. Risks and failures in other DeFi projects can have spillover effects on Ethena Labs. For example, a hack or exploit in a major DeFi protocol may lead to adverse market conditions or trigger a cascade of liquidations across the ecosystem.
Infrastructure Risks:
Dependencies on third-party services, such as oracles, can introduce infrastructure risks. Failures or inaccuracies in these services can lead to incorrect data being used for decisions within the Ethena Labs ecosystem.
Adoption Risks:
The success of the project depends on user adoption. A lack of interest or adoption by the community can pose a risk to the project's long-term sustainability.
Black Swan Events:
Unpredictable events, often referred to as "black swan" events, are another systematic risk. These are rare, extreme events that can disrupt financial markets and the broader economy. While the likelihood of such events is low, their potential impact is significant.
Ethena Labs should continuously monitor and address these systematic risks as part of its risk management strategy. Diversification, contingency planning, and responsive governance are essential to mitigating the impact of these risks on the project's stability and long-term success.
14 hours
#0 - c4-pre-sort
2023-11-01T14:28:55Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2023-11-10T19:33:55Z
fatherGoose1 marked the issue as grade-a