Ethena Labs - albahaca's results

Enabling The Internet Bond

General Information

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

Ethena Labs

Findings Distribution

Researcher Performance

Rank: 61/147

Findings: 1

Award: $88.73

Analysis:
grade-a

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

88.7348 USDC - $88.73

Labels

analysis-advanced
grade-a
sufficient quality report
A-19

External Links

Comments for the judge:

In analyzing the Ethena protocol, I followed a comprehensive approach, scrutinizing each contract for potential vulnerabilities and assessing its alignment with the outlined goals. My evaluation involves an in-depth examination of the architecture, code quality, centralization risks, mechanism review, and potential systemic risks. I've provided recommendations to enhance security, improve codebase quality, and address potential centralization concerns.

Approach taken in evaluating the codebase: I employed a systematic approach, examining each contract individually and assessing its functionality, security measures, and adherence to best practices. My goal was to identify any potential vulnerabilities and suggest improvements to enhance the overall robustness of the protocol.

Architecture recommendations: I recommend a thorough review of the centralization risks associated with key roles, ensuring that mechanisms are in place to prevent misuse. Additionally, considering the potential impact of external organizations having a GATEKEEPER role, careful consideration and monitoring are necessary to prevent abuse.

  1. Centralization Risks:

    • Conduct a thorough review of the roles, especially MINTER and REDEEMER, to identify any potential centralization risks. Consider implementing a multi-signature mechanism for these critical roles to distribute control and mitigate the impact of a compromised key.
  2. External GATEKEEPER Organizations:

    • Given the sensitivity of GATEKEEPER roles, carefully vet and establish criteria for external organizations to hold such privileges. Define strict guidelines to ensure that external entities only invoke GATEKEEPER functions in the event of genuine on-chain discrepancies, preventing potential abuse.
  3. Continuous Monitoring:

    • Implement a robust monitoring system, both on-chain and off-chain, to detect any unusual activities or deviations from expected behaviors. Set up alerts and automated responses to address potential security incidents promptly.
  4. Smart Contract Upgradability:

    • Evaluate the smart contract upgradeability strategy to ensure the protocol can adapt to changing security requirements. Consider implementing a transparent and decentralized upgrade mechanism, such as a proxy contract, to maintain user trust while allowing for necessary improvements.
  5. Emergency Response Plan:

    • Develop a detailed emergency response plan outlining steps to be taken in the event of a security incident. This plan should include communication protocols, role assignments, and specific actions to contain and mitigate potential threats.
  6. Address Type Verification:

    • Enhance the security of functions dealing with addresses by implementing checks to verify whether an address is a contract or an externally owned account (EOA). This can prevent potential issues arising from users inadvertently entering non-contract addresses.
  7. External Interactions Security:

    • Strengthen security measures for external interactions, especially when dealing with signatures and off-chain orders. Implement additional checks to validate the authenticity of orders and signatures, reducing the risk of potential exploits.

These refined recommendations aim to provide specific actions to enhance the architecture of the Ethena protocol.

Codebase quality analysis:

  1. EthenaMinting.sol:

    • Strengths:
      • Well-structured with clear functions and roles.
      • Implementation of a two-step admin transfer process in SingleAdminAccessControl.
    • Recommendations:
      • Implement checks for contract addresses in functions like addSupportedAsset and removeSupportedAsset to prevent potential issues.
      • Consider additional checks for the type of address (contract or EOA) in functions dealing with addresses.
  2. SingleAdminAccessControl.sol:

    • Strengths:
      • Simple and effective single admin role implementation.
      • Two-step admin transfer process for added security.
    • Recommendations:
      • Ensure careful management of admin private keys to prevent compromises.
  3. StakedUSDe.sol:

    • Strengths:
      • Role-based access control for different functions.
      • Implementation of vesting mechanism.
    • Recommendations:
      • Review the centralization risks associated with the owner's ability to rescue tokens and redistribute from fully restricted stakers.
  4. StakedUSDeV2.sol:

    • Strengths:
      • Introduction of a cooldown mechanism.
      • Clear roles for different functionalities.
    • Recommendations:
      • Implement checks for overflow/underflow in arithmetic operations using a library like SafeMath.
      • Monitor and evaluate the impact of allowing the contract owner to change the cooldown duration.
  5. USDe.sol:

    • Strengths:
      • Utilization of well-tested OpenZeppelin contracts.
      • Clear definition of the minter role.
    • Recommendations:
      • Consider implementing limits on the amount of tokens that can be minted to prevent potential inflation risks.
  6. USDeSilo.sol:

    • Strengths:
      • Utilization of OpenZeppelin for safe ERC20 token operations.
      • Clear use of modifiers for access control.
    • Recommendations:
      • Add a check in the withdraw function to ensure the amount is less than or equal to the contract's USDe balance.

Centralization risks: The protocol exhibits some centralization risks, especially with roles like MINTER and REDEEMER. The implemented safeguards such as the two-step admin transfer process and GATEKEEPER roles help mitigate these risks. However, careful consideration should be given to potential compromises of these roles, and continuous monitoring is essential to detect and respond to any unusual activities.

Mechanism review: The minting and redeeming mechanisms appear well-designed, with an emphasis on security measures such as EIP712 signature verification. The use of roles and access control provides a structured way to manage permissions. However, additional checks for address types and potential vulnerabilities in external interactions should be considered.

Systemic risks: The protocol addresses systemic risks by implementing mechanisms to prevent potential exploits, such as limiting mint and redeem amounts per block and the introduction of GATEKEEPER roles. The vesting mechanism in StakedUSDe.sol adds an extra layer of security. However, continuous monitoring and periodic reviews are crucial to adapt to evolving risks and ensure the protocol's resilience.

Gas Optimization

The code analysis has identified several opportunities for gas optimization and efficiency improvements in the provided smart contracts. The key recommendations include:

  1. Contract Existence Checks:

    • Utilize low-level calls for external function calls to avoid unnecessary contract existence checks.
  2. Loop Variable Declaration:

    • Declare loop variables outside the loop to save gas by avoiding unnecessary variable instantiation in each iteration.
  3. Loop Optimization:

    • Consider replacing for loops with do-while loops to reduce gas costs, especially when the loop condition is not checked in the first iteration.
  4. Inlining Modifiers:

    • Inline modifiers that are used only once and not inherited to eliminate the overhead of generated code and reduce gas costs.
  5. Immutable Constants:

    • Use immutable for constant values, especially when involving expensive operations like keccak256(), to optimize gas usage.
  6. Zero Amount Checks:

    • Ensure amounts are checked for non-zero values before making transfers to avoid unnecessary external calls and save gas.
  7. abi.encodePacked():

    • Replace abi.encode() with abi.encodePacked() for gas-efficient encoding of values.
  8. Unused Variable Deletion:

    • Delete variables that are no longer needed to take advantage of gas refunds.
  9. Assembly for Gas Optimization:

    • Use assembly for gas-optimized transfers and other operations, particularly in scenarios like value transfers.
  10. Address(0) Check with Assembly:

    • Utilize assembly for efficient checks on address(0) to save gas.
  11. Duplicated Checks Refactoring:

    • Refactor duplicated require()/if() checks into modifiers or functions to reduce the overall number of operations.
  12. Unchecked Subtractions:

    • Use unchecked for subtractions where the operands cannot underflow to optimize gas usage.
  13. Function Result Caching:

    • Cache the result of function calls rather than re-calling the function to save gas.

These optimizations collectively aim to enhance the gas efficiency, reduce unnecessary computations, and make the smart contracts more cost-effective. It's recommended to implement these changes iteratively and thoroughly test the modified contracts to ensure functionality is preserved while achieving gas savings.

conclusion, the Ethena protocol demonstrates a thoughtful approach to decentralized stablecoin design, with a focus on security and permissionless features. The outlined recommendations aim to further fortify the protocol against potential risks and enhance its overall robustness. Continuous vigilance and adaptation to emerging challenges will be key to the long-term success of the protocol.

Time spent:

18 hours

#0 - c4-pre-sort

2023-11-01T14:29:41Z

raymondfam marked the issue as sufficient quality report

#1 - c4-judge

2023-11-10T19:32:48Z

fatherGoose1 marked the issue as grade-a

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter