Moonwell - 0xSmartContract's results

An open lending and borrowing DeFi protocol.

General Information

Platform: Code4rena

Start Date: 24/07/2023

Pot Size: $100,000 USDC

Total HM: 18

Participants: 73

Period: 7 days

Judge: alcueca

Total Solo HM: 8

Id: 267

League: ETH

Moonwell

Findings Distribution

Researcher Performance

Rank: 43/73

Findings: 1

Award: $69.77

Analysis:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: Sathish9098

Also found by: 0xSmartContract, K42, Udsen, berlin-101, catellatech, cryptonue, hals, jaraxxus, kodyvim, kutugu, solsaver

Labels

analysis-advanced
grade-b
A-10

Awards

69.7664 USDC - $69.77

External Links

Analysis - Moonwell Project

Summary

ListHeadDetails
a)The approach I followed when reviewing the codeStages in my code review and analysis
b)Analysis of the code baseWhat is unique? How are the existing patterns used?
c)Test analysisTest scope of the project and quality of tests
d)ArchitecturalArchitecture feedback
e)DocumentsWhat is the scope and quality of documentation for Users and Administrators?
f)Centralization risksHow was the risk of centralization handled in the project, what could be alternatives?
g)Systemic risksPotential systemic risks in the project
h)Competition analysisWhat are similar projects?
i)Security Approach of the ProjectAudit approach of the Project
j)Other Audit Reports and Automated FindingsWhat are the previous Audit reports and their analysis
k)Gas OptimizationGas usage approach of the project and alternative solutions to it
l)New insights and learning from this auditThings learned from the project

a) The approach I followed when reviewing the code

First, by examining the scope of the code, I determined my code review and analysis strategy. https://github.com/code-423n4/2023-07-moonwell#scope

Accordingly, I analyzed and audited the subject in the following steps;

NumberStageDetailsInformation
1Compile and Run TestInstallationTest and installation structure is simple, cleanly designed
2Architecture ReviewMoonwell ProtocolProvides a basic architectural teaching for General Architecture
3Graphical AnalysisGraphical Analysis with Solidity-metricsA visual view has been made to dominate the general structure of the codes of the project.
4Slither AnalysisSlither
5Test SuitsTestsIn this section, the scope and content of the tests of the project are analyzed.
6Manuel Code ReviewScope
7InfographicFigmaI made Visual drawings to understand the hard-to-understand mechanisms
8Special focus on Areas of ConcernAreas of Concern

b) Analysis of the code base

The main most important contracts of the project;

MultiRewardDistributor.sol:

MultiRewardDistributoris that manages the distribution of rewards to users of the Moonwell protocol. The contract tracks the supply and borrows of mTokens, which are tokens that represent a user's share of a particular market. The contract then uses this information to calculate the user's rewards and distribute them to the user's address.

Comptroller.sol

Comptroller.sol is a contract that manages the operations of the Moonwell protocol. The contract tracks the supply and borrows of mTokens, which are tokens that represent a user's share of a particular market. The contract also manages the minting and redeeming of mTokens, as well as the distribution of rewards to users.

TemporalGovernor.sol

TemporalGovernor.sol is a contract that governs the Base deployment of moonwell leveraging the wormhole bridge as the source of truth. Wormhole will be fed in actions from the moonbeam chain and this contract will execute them on base.

Unitroller.sol

Unitroller.sol is a contract that manages the operations of the Comptroller contract. The Comptroller contract is a core contract in the Compound protocol, and it manages the supply and borrows of cTokens, which are tokens that represent a user's share of a particular market.

The _setPendingImplementation function allows the current admin of the contract to set a new pending implementation. The new pending implementation will become the active implementation once it calls the _acceptImplementation function.

The _acceptImplementation function allows the pending implementation to accept its role as the active implementation. Once this function is called, the new implementation will be able to perform all of the actions that the Comptroller contract can perform.

The _setPendingAdmin function allows the current admin of the contract to set a new pending admin. The new pending admin will become the active admin once it calls the _acceptAdmin function.

The _acceptAdmin function allows the pending admin to accept its role as the active admin. Once this function is called, the new admin will be able to perform all of the actions that the Unitroller contract can perform.

The fallback function is the default function that is called when the Unitroller contract receives a message. This function simply delegates the execution of the message to the current implementation of the Comptroller contract.

c) Test analysis

What did the project do differently? ; There are quality and detailed Unit and Integration tests in the project.

What could they have done better?;

It seems that the scope of the test has 80%. Test coverage must be 100%, remember that the weakest part of the project in terms of security may be the remaining 20%.

When designing the tests, I recommend modeling the project with the Threat Model, writing the tests accordingly, and documenting these threat models, this way the test coverage will be more understandable.

d) Architectural

<img width="1518" alt="image" src="https://github.com/code-423n4/2023-07-moonwell/assets/104318932/390abb5b-1bc5-4013-ba03-0fbc98082156">

e) Documents

Documentation should be increased further, it is recommended to add the architectural design to the documents as infographic

f) Centralization risks

There is a risk of centrality in the project as the onlyOwner The owner role has a single point of failure and onlyOwner can use critical functions, posing a centralization issue. There is always a chance for owner keys to be stolen, and in such a case, the attacker can cause serious damage to the project due to important functions.

The code detail of this topic is specified in automatic finding; https://gist.github.com/liveactionllama/0a27b77de2aa56abd2e215c82a39f86d#m04-the-owner-is-a-single-point-of-failure-and-a-centralization-risk

g) Systemic risks

The most important system risk in the project; Risks arising from the use of Oracle, the project uses Chainlink, oracles, security exploits from oracles have been increasing recently, so using Oracle is a risk in itself and it is important to minimize this risk.

h) Competition analysis

The Moonwell Protocol is a fork of Benqi, which is a fork of Compound v2 with things like borrow caps and multi-token emissions.

BENQI Liquid Staking is a liquid staking protocol built on Avalanche.

It tokenizes staked AVAX and allows users to freely use it within Decentralized Finance dApps such as automated market makers (AMMs), lending & borrowing protocols, yield aggregators, etc.

i) Security Approach of the Project

Successful current security understanding of the project; 1- The first audit was conducted in a reputable audit firm such as Halborn and all security concerns were resolved, this is the case in both audit reports;

https://github.com/code-423n4/2023-07-moonwell/blob/main/audits/Moonwell_Finance_Smart_Contract_Security_Audit_Report_Halborn_Final.pdf

https://github.com/code-423n4/2023-07-moonwell/blob/main/audits/Moonwell_Finance_Contracts_V2_Smart_Contract_Security_Assessment_Report_Halborn_Final.pdf

2- They manage the 2nd audit process with an innovative audit such as Code4rena, in which many auditors examine the codes.

What the project should add in the understanding of Security; 1- By distributing the project to testnets, ensuring that the audits are carried out in onchain audit. (This will increase coverage) 2- After the project is published on the mainnet, there should be emergency action plans (not found in the documents) 3- After the inspection, the concept of "continuous inspection" should be adhered to with bug bounty programs such as ImmuneFi.

j) Other Audit Reports and Automated Findings

Automated Findings: https://gist.github.com/liveactionllama/0a27b77de2aa56abd2e215c82a39f86d

Especially Medium detections in the Automated Finding Report should be taken into account;

Medium Risk Issues

IssueInstances
[M‑01]Unsafe use of transfer()/transferFrom() with IERC202
[M‑02]Insufficient oracle validation2
[M‑03]Missing checks for whether the L2 Sequencer is active2
[M‑04]The owner is a single point of failure and a centralization risk2
[M‑05]Some tokens may revert when zero value transfers are made2

Audit Reports : Halborn Audit v1

Halborn Audit v2

k) Gas Optimization

The project is generally efficient in terms of gas optimizations, many generally accepted gas optimizations have been implemented, gas optimizations with minor effects are already mentioned in automatic finding, but gas optimizations will not be a priority considering code readability and code base size

l) New insights and learning from this audit

  • Provided a detailed look at Compound v2 with features like borrow caps and multi-token emissions systems

  • The project is a fork of BENQI Liquid Staking, in this context, the general codes of the BENQI project were examined.

  • Allowed me to get a broad overview of the Comptroller architecture

Time spent:

10 hours

#0 - c4-judge

2023-08-11T21:03:23Z

alcueca 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