UniStaker Infrastructure - cudo's results

Staking infrastructure to empower Uniswap Governance.

General Information

Platform: Code4rena

Start Date: 23/02/2024

Pot Size: $92,000 USDC

Total HM: 0

Participants: 47

Period: 10 days

Judge: 0xTheC0der

Id: 336

League: ETH

Uniswap Foundation

Findings Distribution

Researcher Performance

Rank: 45/47

Findings: 1

Award: $22.02

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

22.023 USDC - $22.02

Labels

analysis-advanced
grade-b
A-17

External Links

1. Introduction

This is key about what the Uniswap V3 protocol, the UniSwap V3 protocol collects trading fees from trades executed on the platform. These fees are then distributed to liquidity providers (LPs) who contribute assets to the liquidity pools. To incentivize LP participation and provide additional benefits to the ecosystem, Uniswap V3 introduces UNI staking, allowing LPs to stake UNI tokens and earn rewards based on their contribution to the platform's liquidity. This mechanism encourages liquidity provision, enhances the protocol's decentralization, and aligns the interests of stakeholders within the Uniswap ecosystem.

  • Here is the table of scope contracts with necessary information.
<table> <thead> <tr> <th id="type" style="text-align:left;"> Type </th> <th id="file" style="text-align:left;"> File </th> <th id="logic_contracts" style="text-align:left;"> Logic Contracts </th> <th id="interfaces" style="text-align:left;"> Interfaces </th> <th id="lines" style="text-align:left;"> Lines </th> <th id="nlines" style="text-align:left;"> nLines </th> <th id="nsloc" style="text-align:left;"> nSLOC </th> <th id="comment_lines" style="text-align:left;"> Comment Lines </th> <th id="complex._score" style="text-align:left;"> Complex. Score </th> <th id="capabilities" style="text-align:left;"> Capabilities </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"><p>📝 </p></td> <td style="text-align:left;"><p>src/UniStaker.sol </p></td> <td style="text-align:left;"><p>1 </p></td> <td style="text-align:left;"><hr></td> <td style="text-align:left;"><p>810 </p></td> <td style="text-align:left;"><p>742 </p></td> <td style="text-align:left;"><p>360 </p></td> <td style="text-align:left;"><p>285 </p></td> <td style="text-align:left;"><p>242 </p></td> <td style="text-align:left;"><p><strong><abbr title="Uses Hash-Functions">🧮</abbr><abbr title="create/create2">🌀</abbr></strong> </p></td> </tr> <tr> <td style="text-align:left;"><p>📝 </p></td> <td style="text-align:left;"><p>src/DelegationSurrogate.sol </p></td> <td style="text-align:left;"><p>1 </p></td> <td style="text-align:left;"><hr></td> <td style="text-align:left;"><p>29 </p></td> <td style="text-align:left;"><p>29 </p></td> <td style="text-align:left;"><p>8 </p></td> <td style="text-align:left;"><p>19 </p></td> <td style="text-align:left;"><p>4 </p></td> <td style="text-align:left;"><hr></td> </tr> <tr> <td style="text-align:left;"><p>📝 </p></td> <td style="text-align:left;"><p>src/V3FactoryOwner.sol </p></td> <td style="text-align:left;"><p>1 </p></td> <td style="text-align:left;"><hr></td> <td style="text-align:left;"><p>205 </p></td> <td style="text-align:left;"><p>196 </p></td> <td style="text-align:left;"><p>78 </p></td> <td style="text-align:left;"><p>97 </p></td> <td style="text-align:left;"><p>47 </p></td> <td style="text-align:left;"><hr></td> </tr> <tr> <td style="text-align:left;"><p>🔍 </p></td> <td style="text-align:left;"><p>src/interfaces/IUniswapV3FactoryOwnerActions.sol </p></td> <td style="text-align:left;"><hr></td> <td style="text-align:left;"><p>1 </p></td> <td style="text-align:left;"><p>34 </p></td> <td style="text-align:left;"><p>13 </p></td> <td style="text-align:left;"><p>3 </p></td> <td style="text-align:left;"><p>23 </p></td> <td style="text-align:left;"><p>9 </p></td> <td style="text-align:left;"><hr></td> </tr> <tr> <td style="text-align:left;"><p>🔍 </p></td> <td style="text-align:left;"><p>src/interfaces/IUniswapV3PoolOwnerActions.sol </p></td> <td style="text-align:left;"><hr></td> <td style="text-align:left;"><p>1 </p></td> <td style="text-align:left;"><p>25 </p></td> <td style="text-align:left;"><p>12 </p></td> <td style="text-align:left;"><p>3 </p></td> <td style="text-align:left;"><p>16 </p></td> <td style="text-align:left;"><p>5 </p></td> <td style="text-align:left;"><hr></td> </tr> <tr> <td style="text-align:left;"><p>🔍 </p></td> <td style="text-align:left;"><p>src/interfaces/INotifiableRewardReceiver.sol </p></td> <td style="text-align:left;"><hr></td> <td style="text-align:left;"><p>1 </p></td> <td style="text-align:left;"><p>14 </p></td> <td style="text-align:left;"><p>13 </p></td> <td style="text-align:left;"><p>3 </p></td> <td style="text-align:left;"><p>9 </p></td> <td style="text-align:left;"><p>3 </p></td> <td style="text-align:left;"><hr></td> </tr> <tr> <td style="text-align:left;"><p>🔍 </p></td> <td style="text-align:left;"><p>src/interfaces/IERC20Delegates.sol </p></td> <td style="text-align:left;"><hr></td> <td style="text-align:left;"><p>1 </p></td> <td style="text-align:left;"><p>31 </p></td> <td style="text-align:left;"><p>10 </p></td> <td style="text-align:left;"><p>3 </p></td> <td style="text-align:left;"><p>7 </p></td> <td style="text-align:left;"><p>23 </p></td> <td style="text-align:left;"><hr></td> </tr> <tr> <td style="text-align:left;"><p>📝🔍 </p></td> <td style="text-align:left;"><p><strong>Totals</strong> </p></td> <td style="text-align:left;"><p><strong>3</strong> </p></td> <td style="text-align:left;"><p><strong>4</strong> </p></td> <td style="text-align:left;"><p><strong>1148</strong> </p></td> <td style="text-align:left;"><p><strong>1015</strong> </p></td> <td style="text-align:left;"><p><strong>458</strong> </p></td> <td style="text-align:left;"><p><strong>456</strong> </p></td> <td style="text-align:left;"><p><strong>333</strong> </p></td> <td style="text-align:left;"><p><strong><abbr title="Uses Hash-Functions">🧮</abbr><abbr title="create/create2">🌀</abbr></strong> </p></td> </tr> </tbody> </table>

2. Architectural Improvement

I will come up with finest architectural improvements of these contracts in scope which shown in below:

<a href="https://imgur.com/jsmG18R"><img src="https://i.imgur.com//jsmG18R.png" title="source: imgur.com" /></a>

2.1 DelegationSurrogate.sol

The provided contract, DelegationSurrogate, is a simple Solidity smart contract designed to facilitate delegation of governance tokens to a specific delegatee address. It allows users to delegate their voting power to a designated address by transferring their tokens to this contract. This contract simplifies the process of governance token delegation, particularly useful when multiple token holders wish to delegate their voting power to the same delegatee.

The contract introduces a modular approach to token delegation, separating the process of holding tokens and delegating voting power. This architectural improvement enables flexibility and scalability, as it allows for the creation of multiple instances of DelegationSurrogate contracts, each managing token delegation independently.

<a href="https://imgur.com/65BeC4d"><img src="https://i.imgur.com//65BeC4d.png" title="source: imgur.com" /></a>

2.2 UniStaker.sol

The provided contract code appears to be a part of a staking protocol smart contract. Staking protocols enable users to lock up their tokens as collateral to participate in various network activities, such as governance voting or earning rewards.

The contract implements a modular architecture by separating different functionalities into distinct functions. This enhances readability, maintainability, and reusability of the code.

<a href="https://imgur.com/47cXmDv"><img src="https://i.imgur.com//47cXmDv.png" title="source: imgur.com" /></a>

2.3 V3FactoryOwner.sol

The V3FactoryOwner contract serves as a critical component within the Uniswap v3 ecosystem, designed to manage ownership and privileged actions for the Uniswap v3 factory. It introduces an additional layer of control by allowing an admin address to execute privileged functions, such as enabling fee amounts on the factory and setting protocol fees on individual pools. Additionally, it provides a mechanism for claiming protocol fees from pools in exchange for a designated payout token.

The contract improves the architecture of the Uniswap v3 ecosystem by centralizing ownership and control functions within a single contract. This modular approach enhances flexibility and scalability, as it enables easy management of factory-wide settings and individual pool configurations through a single admin interface.

<a href="https://imgur.com/6X2xCIO"><img src="https://i.imgur.com//6X2xCIO.png" title="source: imgur.com" /></a>

3. Main Features Of Protocol

Here the main features of protocol contracts are given sequentially.

3.1 DelegationSurrogate.sol

The main features of the DelegationSurrogate contract include:

Delegated Staking: Allows depositors to delegate their staking rights to another address, enabling efficient management of staked assets.

Proxy Contract Functionality: Acts as a proxy contract to facilitate delegated staking, ensuring seamless interaction with the staking protocol.

Security Measures: Implements robust security measures to safeguard staked assets and prevent unauthorized access or misuse.

Gas Efficiency: Optimizes gas usage to minimize transaction costs associated with staking and delegating staking rights.

Flexibility: Provides flexibility for depositors to manage their staked assets and delegate staking rights according to their preferences and requirements.

3.2 UniStaker.sol

The main features of the UniStaker contract include:

Staking Functionality: Users can stake tokens to participate in the Uniswap V3 protocol and earn rewards.

Delegate Management: Users can delegate their voting power and rewards to other addresses, enabling delegation of participation in governance activities.

Reward Claiming: Users can claim earned rewards from staking activities, providing incentives for continued participation.

Beneficiary Alteration: Users can change the address to which staking rewards accrue, offering flexibility in managing earned rewards.

Withdrawal Capability: Users can withdraw their staked tokens at any time, ensuring liquidity and accessibility of staked assets.

Authorization and Signature Verification: The contract includes mechanisms for authorization checks and signature verification to ensure the security and integrity of staking and reward distribution processes.

3.3 V3FactoryOwner.sol

The V3FactoryOwner contract in Uniswap V3 protocol facilitates the creation and management of liquidity pools for various token pairs. Its main features include:

Liquidity Pool Creation: Allows users to create new liquidity pools for trading different token pairs within the Uniswap V3 ecosystem.

Ownership Management: Enables the management of ownership rights over the liquidity pools and associated assets, providing control and governance functionalities to designated administrators.

Fee Configuration: Allows customization of trading fees for each liquidity pool, providing flexibility in fee structures to optimize trading and incentivize liquidity provision.

Security Measures: Implements security features to ensure the integrity and safety of liquidity pool assets, protecting against potential vulnerabilities and malicious attacks.

Upgradeability: Supports upgradeability mechanisms to incorporate future protocol enhancements and optimizations, ensuring the protocol remains adaptable and responsive to evolving market dynamics and user needs.

4. System Overview In Diagrams

Here is the overview how each and every componenet is intracting with each other in protocol.

4.1 DelegationSurrogate.sol

The contract serves as a straightforward custodian for governance tokens, enabling stakers to delegate their voting power to a designated delegatee. Its primary function is to hold governance tokens on behalf of stakers and facilitate the delegation of voting rights to a specified delegatee.

<a href="https://imgur.com/ZJt8U32"><img src="https://i.imgur.com//ZJt8U32.png" title="source: imgur.com" /></a>

4.2 V3FactoryOwner.sol

The contract acts as the designated owner of the Uniswap v3 factory, overseeing the configuration and collection of protocol pool fees. Its responsibilities include managing the Uniswap v3 factory's settings and mechanisms for collecting protocol pool fees.

<a href="https://imgur.com/Irerggr"><img src="https://i.imgur.com//Irerggr.png" title="source: imgur.com" /></a>

5. Security Improvement

Securing our system is a top priority, so let's kick off our security improvements with a solid plan. Here i'll explain security improvements contract by contract in the sequence.

5.1 DelegationSurrogate.sol

The contract enhances security by simplifying token delegation, reducing the likelihood of errors or vulnerabilities associated with manual delegation processes. Additionally, by using Solidity's built-in access control mechanisms, it ensures that only authorized parties can reclaim tokens from the contract.

5.2 UniStaker.sol

The contract incorporates various security measures to protect users' funds and ensure the integrity of the protocol, such as:

  • Role-based access control to restrict certain operations to authorized users.
  • Signature verification to validate actions performed on behalf of others.
  • Safe transfer functions to prevent loss of funds during token transfers.
5.3 V3FactoryOwner.sol

The contract enhances security by centralizing ownership and control functions, reducing the potential attack surface compared to directly exposing these functionalities in individual contracts. Access to privileged functions is restricted to the admin, mitigating the risk of unauthorized actions.

6. Systematic Risk

Let's dive into identifying and addressing systematic risks. We'll start by evaluating our system from different angles.

6.1 DelegationSurrogate.sol

The contract minimizes systematic risk by providing a standardized approach to token delegation. This reduces the potential for discrepancies or inconsistencies in the delegation process, promoting fairness and transparency within governance systems.

6.2 UniStaker.sol

The contract may be susceptible to systematic risks inherent in smart contract systems, such as:

Vulnerabilities in external dependencies, such as ERC-20 token contracts or signature verification libraries. Risks associated with on-chain governance, such as centralization of voting power.

6.3 V3FactoryOwner.sol

The contract mitigates systematic risk by providing standardized methods for managing fee-related parameters across the Uniswap v3 ecosystem. This reduces the likelihood of inconsistencies or discrepancies in fee settings, promoting stability and reliability within the protocol.

7. Centralisation Risk

Centralization risks in these contracts:

7.1 DelegationSurrogate.sol

While the contract itself does not inherently introduce centralization risk, its effectiveness relies on the trustworthiness of the designated delegatee address. Centralization risk may arise if a single delegatee accumulates significant voting power from multiple DelegationSurrogate contracts.

7.2 UniStaker.sol

The protocol may face centralization risks due to:

Concentration of governance power in a few addresses if users delegate their voting power to a small number of entities. Control of the admin address over critical protocol functions, which could lead to centralized decision-making.

7.3 V3FactoryOwner.sol

While the contract centralizes ownership and control functions, the risk of centralization is mitigated by the ability to transfer admin privileges to different addresses. Additionally, the contract's design facilitates decentralized governance over time, as ownership can be transferred to community-controlled entities.

8. Approach Evaluating CodeBase

Day 1

  • Provide an overview of the Uniswap V3 protocol and its significance in the DeFi ecosystem.
  • Analyze the architectural improvements of Uniswap V3 compared to previous versions, focusing on scalability, capital efficiency, and flexibility.

Day 2

  • Identify and list the main features of the Uniswap V3 protocol, focusing on key functionalities provided by the contracts.
  • Create diagrams illustrating the high-level system architecture, including interactions between contracts and stakeholders.

Day 3

  • Evaluate the security measures implemented in the protocol, such as access controls, input validation, and protection against common vulnerabilities. Assess potential systematic risks and propose mitigation strategies.
  • Investigate centralization risks within the protocol, such as governance concentration or reliance on key infrastructure providers, and discuss ways to decentralize or mitigate these risks.

Day 4

  • Merge the approaches used to evaluate each contract, considering factors like code readability, modularity, gas efficiency, and adherence to best practices.
  • Summarize the time spent on each aspect of the evaluation process, highlighting areas of focus and any challenges encountered.

9. Time Spent

  • 24 Hours of focused work.

Time spent:

24 hours

#0 - c4-judge

2024-03-14T18:25:57Z

MarioPoneder marked the issue as grade-b

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