The Hacken 2025 Yearly Security ReportCovers major Web3 breaches, their root causes, prevention insights, and key regulatory trends for 2026.
Learn more

Audit name:

[SCA] Merlin Protocol | DAO | Mar2024

Date:

Apr 25, 2024

Table of Content

Introduction
Audit Summary
System Overview
Risks
Findings
Appendix 1. Severity Definitions
Appendix 2. Scope
Disclaimer

Want a comprehensive audit report like this?

Introduction

We express our gratitude to the Merlin Protocol team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.

The Merlin protocol is a leading DeFi solution, integrating advanced blockchain tech with sophisticated investment strategies. It offers decentralized governance, admin tools, token allocation control, and automated rebalancing for dynamic adaptation to market conditions and investment goals

Document

NameSmart Contract Code Review and Security Analysis Report for Merlin Protocol
Audited BySeher Saylik
Approved ByAtaberk Yavuzer
Websitehttps://merlinprotocol.io/
Changelog02/04/2024 - Preliminary Report (Initial Version)
29/04/2024 - Final Report (Initial Version)
10/07/2024 - Secondary Report (New Structural Changes)
24/07/2024 - Final Report (Secondary Version)
PlatformEVM
LanguageSolidity
TagsAMM
Methodologyhttps://hackenio.cc/sc_methodology
  • Document

    Name
    Smart Contract Code Review and Security Analysis Report for Merlin Protocol
    Audited By
    Seher Saylik
    Approved By
    Ataberk Yavuzer
    Changelog
    02/04/2024 - Preliminary Report (Initial Version)
    29/04/2024 - Final Report (Initial Version)
    10/07/2024 - Secondary Report (New Structural Changes)
    24/07/2024 - Final Report (Secondary Version)
    Platform
    EVM
    Language
    Solidity
    Tags
    AMM

Audit Summary

28Total Findings
22Resolved
6Accepted
0Mitigated

The system users should acknowledge all the risks summed up in the risks section of the report

Documentation quality

  • Functional requirements are partially missed.

  • The technical requirements are provided.

  • NatSpec is provided.

Code quality

  • Some best practices were violated.

  • The naming conventions can be improved

  • The development environment is configured.

Test coverage

Code coverage of the project is 0% (branch coverage).

  • All of the tests provided were commented out.

System Overview

Merlin Protocol is a decentralized market that provides several features like decentralized governance, administrative management of the fund, token allocation control, and an automatic rebalancing process with the following contracts:

Lock — a simple lock mechanism that enables an owner to lock funds until a specified future time. After this time has passed, the owner can withdraw the funds.

MerlinERC20 — an ERC20 token contract that mints all the supply to msg.sender.

It has the following attributes:

  • Name: Merlin

  • Symbol: MRN

  • Decimals: 18

  • Total supply: 50.000.000

MerlinFaucet — is designed to distribute free tokens on a testnet for testing purposes. Users can request tokens from the faucet contract by calling the faucet() function.

MerlinFund — an ERC20 token contract with advanced fund management features. Users can deposit funds to receive Merlin Fund tokens, request withdrawals, and claim pending withdrawals. The contract maintains a basket of funds and periodically rebalances it based on withdrawal requests and market conditions. Fees are applied to deposits, and price calculations are performed to ensure accurate asset valuations. Overall, the contract facilitates decentralized fund management and asset allocation.

The price of Merlin Fund token is calculated based on the following formula:

  • Price of Merlin Fund token = (Total USD value of all different funds in the basket/platform + USDC balance of the contract) / total supply of Merlin Fund tokens

MerlinFundAdministrative — an admin contract that extends administrative functionalities for the Merlin Fund protocol. It allows setting addresses, managing whitelists, configuring fees, and facilitating ownership transfers.

MerlinFundModifier — a contract serves as the modifier storage of platform, defining key roles and restrictions. It manages access control for administrators, swap managers, and fee managers, while also enforcing conditions such as ensuring the fund's percentage allocation equals 100% and preventing swap processes from occurring simultaneously.

MerlinGovernor — a governance contract implements a governance system for the Merlin protocol, integrating various features such as voting, proposal execution, and timelock control. It extends several predefined contracts from the OpenZeppelin library to establish governance functionalities, including vote counting, quorum calculation, and timelock management.

RebalanceController — a contract that manages the automated rebalancing of token allocations within the Merlin protocol. It ensures timely rebalancing intervals, calculates token amounts for swaps 6 based on preset percentages, and executes swaps between different assets using external swap routers. This process helps maintain the desired portfolio composition within the protocol.

SwapController — a contract that facilitates token swaps within the Merlin protocol using Uniswap V3 routers. It includes functions to execute token swaps based on specified input parameters, such as token addresses and amounts.

TimeLock — is an implementation of a timelock mechanism using OpenZeppelin's TimelockController. It allows for the scheduling of transactions that can only be executed after a specified delay period, as set by the minDelay parameter.

TokenAllocationController — a contract that manages token allocations within a fund. It allows adding tokens, setting their percentages, adjusting percentages, and discarding tokens. Key features include adding tokens with associated addresses, adjusting percentages, and discarding tokens based on their current price.

Privileged roles

  • The owner of the Lock contract can withdraw the contract balance when the lock period is over.

  • The owner of MerlinFund contract can set the admin, add a new owner and transfer ownership.

  • The admin of MerlinFund contract can set the swap manager address, set the USDC address, set swap internal durations, set protocol fee, add funds to platform, set aggregator and router addresses of funds, specify percentages of system funds, discard funds from the contract and, set fee manager address.

  • The fee manager of MerlinFund contract can claim the accumulated protocol fees.

  • The swap manager of Merlin Fund contract can execute the swap operation to rebalance the funds.

Risks

Assuming a default of 18 decimal places for tokens lacking explicit decimal values can lead to price miscalculations, particularly for tokens without decimal precision, posing a significant risk within the system.

Administrative Key Control Risks: The digital contract architecture relies on administrative keys for critical operations. Centralized control over these keys presents a significant security risk, as compromise or misuse can lead to unauthorized actions or loss of funds.

All test cases were commented out in the latest commit hash.

Findings

Code
Title
Status
Severity
F-2024-4205Exhaustion Attack In Sale Demand May Lead To Incorrect basketRequestsSum Value
fixed

High
F-2024-1751changePercentage() Function Swaps Incorrect Amount
fixed

High
F-2024-1896Fee Manager Can Withdraw Infinitive Fee From the Contract
fixed

High
F-2024-4445Incorrect Token Swapping Due to Faulty swapCounter Reset Logic in resetSwapCounter() Function
fixed

Medium
F-2024-4206Partial Withdrawal Lock
fixed

Medium
F-2024-4154 Incorrect Comparison Between Token Amount and USDT Value in closeBasket() Function
fixed

Medium
F-2024-1900Incorrect Token Swapping in the swap() Function
fixed

Medium
F-2024-1898Chainlink’s latestRoundData() Might Return Stale or Incorrect Results
fixed

Medium
F-2024-1895Fees Are Not Restricted And They Can Be Frontrunned
fixed

Medium
F-2024-1893Missing Slippage Check
fixed

Medium
1-10 of 28 findings

Identify vulnerabilities in your smart contracts.

Appendix 1. Severity Definitions

When auditing smart contracts, Hacken is using a risk-based approach that considers Likelihood, Impact, Exploitability and Complexity metrics to evaluate findings and score severities.

Reference on how risk scoring is done is available through the repository in our Github organization:

Severity

Description

Critical
Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation.

High
High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation.

Medium
Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category.

Low
Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution, do not affect security score but can affect code quality score.
  • Severity

    Critical

    Description

    Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation.

    Severity

    High

    Description

    High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation.

    Severity

    Medium

    Description

    Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category.

    Severity

    Low

    Description

    Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution, do not affect security score but can affect code quality score.

Appendix 2. Scope

The scope of the project includes the following smart contracts from the provided repository:

Scope Details

Repositoryhttps://github.com/MerlinProtocol-Dev/merlin-protocol
Commitfd58e4f
WhitepaperN/A
RequirementsN/A
Technical RequirementsN/A

Contracts in Scope

Solidity
contracts
BasketsController.sol - Solidity › contracts › BasketsController.sol
Lock.sol - Solidity › contracts › Lock.sol
MerlinERC20.sol - Solidity › contracts › MerlinERC20.sol
MerlinFaucet.sol - Solidity › contracts › MerlinFaucet.sol
MerlinFund.sol - Solidity › contracts › MerlinFund.sol
MerlinFundAdministrative.sol - Solidity › contracts › MerlinFundAdministrative.sol
MerlinFundModifier.sol - Solidity › contracts › MerlinFundModifier.sol
MerlinGovernor.sol - Solidity › contracts › MerlinGovernor.sol
RebalanceController.sol - Solidity › contracts › RebalanceController.sol
SwapController.sol - Solidity › contracts › SwapController.sol
Timelock.sol - Solidity › contracts › Timelock.sol
TokenAllocationController.sol - Solidity › contracts › TokenAllocationController.sol

Disclaimer

Merlin Protocol audit by Hacken