Lagoon
Synchronous Deposits

Scope was a pull request adding synchronous deposits and a burn function to Lagoon's Gnosis Safe and Zodiac Roles Modifier-based vault factory.
report id
0534
category
DeFi & Yield
language
Solidity
final report
May 13, 2025
lines of code
1177
Content

Download audit report

1

Executive Summary

This document presents the security review performed by Nethermind Security for Lagoon factory contract. Lagoon Protocol is a decentralized asset management platform that enables asset managers to create Lagoon Vaults. These Vaults provide efficient, non-custodial, and risk-managed asset management solutions.

Built on a foundation of smart contract standards, Lagoon Protocol leverages the power of Gnosis Safe, Zodiac Roles Modifier, and other key components to create highly customizable and secure vaults for managing digital assets.

The audit focuses on the PR #200 which introduces new features like synchronous deposits and a burn functionality. The audit was performed using (a) manual analysis of the codebase, (b) automated analysis tools, and (c) creation of test cases.

Audit assessment
Audit TypeSecurity Review
Initial ReportMay 9, 2025
Final ReportMay 13, 2025
Repositorylagoon-v0
Commit84e43bf30c
Final Commitca04ed2b51
Documentation AssessmentMedium
Test Suite AssessmentMedium
Total findings
5
Fixed
4
Acknowledged
0
Mitigated
1
Unresolved
0

Findings by severity

  • Critical0
  • High1
  • Medium1
  • Low1
  • Informational2
  • Best Practices0

2

Audited Files

4

System Overview

The recent protocol modifications introduce notable changes to existing vault processes and enable new avenues for user interaction. Key updates include:

  • syncDeposit(...): This new function facilitates synchronous deposits. The availability of this feature relies on the time of the last settlement and totalAssetsLifespan state variable; synchronous deposits are enabled immediately following a NAV settlement and remain permissible for the duration specified by totalAssetsLifespan. This mechanism allows users to deposit assets at the prevailing share price and receive their corresponding shares without delay. Upon a synchronous deposit, the contributed assets are transferred into the safe, and the vault's totalAssets variable is increased to reflect this addition.
  • requestDeposit(...): The behavior of this existing function has been altered. If synchronous deposits are currently permissible (i.e., within the active window defined by totalAssetsLifespan post-settlement), requestDeposit(...) will now preferentially execute an immediate synchronous deposit rather than creating an asynchronous deposit request.
  • burn(...): This is a newly introduced function that grants users the ability to destroy their vault shares. Burning shares reduces the totalSupply of shares in circulation.

5

Risk Rating Methodology

The risk rating methodology used by Nethermind Security follows the principles established by the OWASP Foundation. The severity of each finding is determined by two factors: Likelihood and Impact.

Likelihood measures how likely the finding is to be uncovered and exploited by an attacker. This factor will be one of the following values:

  1. High: the issue is trivial to exploit and has no specific conditions that need to be met;
  2. Medium: the issue is moderately complex and may have some conditions that need to be met;
  3. Low: the issue is very complex and requires very specific conditions to be met.

When defining the likelihood of a finding, other factors are also considered. These can include but are not limited to motive, opportunity, exploit accessibility, ease of discovery, and ease of exploit.

Impact is a measure of the damage that may be caused if an attacker exploits the finding. This factor will be one of the following values:

  1. High: the issue can cause significant damage, such as loss of funds or the protocol entering an unrecoverable state;
  2. Medium: the issue can cause moderate damage, such as impacts that only affect a small group of users or only a particular part of the protocol;
  3. Low: the issue can cause little to no damage, such as bugs that are easily recoverable or cause unexpected interactions that cause minor inconveniences.

When defining the impact of a finding, other factors are also considered. These can include but are not limited to data and state integrity, loss of availability, financial loss, and reputation damage. After defining the likelihood and impact of an issue, the severity is determined according to the table below.

Impact / LikelihoodLowMediumHigh
HighMediumHighCritical
MediumLowMediumHigh
LowInfo / Best PracticesLowMedium
UndeterminedUndeterminedUndeterminedUndetermined

To address issues that do not fit a High, Medium or Low severity, Nethermind Security also uses three more finding severities: Informational, Best Practices, and Undetermined.

  1. Informational findings do not pose any risk to the application, but they carry some information that the audit team intends to pass to the client formally;
  2. Best Practice findings are used when some piece of code does not conform with smart contract development best practices;
  3. Undetermined findings are used when we cannot predict the impact or likelihood of the issue.

6

Issues

6.1 Native token deposits are lost if synchronous deposits are available

FileFix commitTypeStatus
src/v0.5.0/Vault.sol—HighFixed

The requestDeposit(...) function is designed to handle deposits, including those made with native tokens (e.g., ETH). A recent modification causes requestDeposit(...) to fallback to an internal synchronous deposit mechanism, _syncDeposit(...), if synchronous deposits are enabled in the vault.

The vulnerability arises because _syncDeposit(...) is exclusively designed to handle ERC20 token deposits and does not account for msg.value if the initial call to requestDeposit(...) was made with native tokens.

The relevant internal _syncDeposit(...) logic is:

function _syncDeposit(...) internal onlyOpen returns (uint256 shares) {
ERC7540Storage storage $ = _getERC7540Storage();

shares = _convertToShares(assets, Math.Rounding.Floor);
$.totalAssets += assets;
SafeERC20.safeTransferFrom(IERC20(asset()), owner, safe(), assets);
_mint(receiver, shares);

emit DepositSync(msg.sender, receiver, assets, shares);
}

If a user tries to execute a native token deposit through requestDeposit(...) and synchronous deposits are available the native tokens sent wont be taken into account through the deposit operation.

Recommendation

Consider modifying _syncDeposit(...) to manage native token deposits.

Resolution

We added the native token deposit to the syncDeposit(...) function.

Update from Nethermind Security

The issue is fixed in commit 85ab53.

6.2 NAV proposals may disregard increases to totalAssets from synchronous deposits

FileFix commitTypeStatus
src/v0.5.0/ERC7540.sol—MediumMitigated

The totalAssets variable within the ERC7540 contract, which is critical for share price calculation, is updated through two distinct mechanisms:

  • NAV Settlements: During a settlement, the totalAssets variable is set to the newTotalAssets value proposed by the NAV committee based on their off-chain valuation;
  • Synchronous Deposits: The introduction of synchronous deposits allows totalAssets to be incremented directly upon a successful deposit, reflecting the immediate inflow of new assets;

A race condition vulnerability exists due to the potential timing mismatch between these two update paths. If the NAV committee performs a valuation and submits a newTotalAssets proposal before recent synchronous deposits are made (or before they are aware of them), this proposed value will not reflect the assets added by those deposits.

When a settlement subsequently occurs, the totalAssets variable will be overwritten with the NAV committee's proposed (and now outdated) value. This action effectively negates the totalAssets increments from any synchronous deposits that occurred between the NAV committee's valuation time and the settlement execution. While the shares minted from these synchronous deposits remain valid, the totalAssets backing them is temporarily unrepresented in the contract's state, leading to a deflated share price.

Recommendation

To address this vulnerability, it is crucial to ensure that any proposed new valuation accurately incorporates the impact of all synchronous deposits made up to the valuation point. Two primary approaches can be considered:

  • Operational Safeguards: Managers could implement a procedural control by delaying the computation of a new NAV until the period for synchronous deposits relevant to that valuation cycle has definitively closed. This would ensure the valuation is based on the most current asset totals. However, it's important to note that such operational measures cannot be enforced at the smart contract level with the existing implementation and rely on consistent off-chain adherence.
  • Contract-Level Modification (Delta-Based Updates): A more robust solution involves modifying how totalAssets is updated during NAV settlements. Instead of overwriting totalAssets with an absolute value proposed by the NAV committee, the system could be designed to apply a delta (i.e., the change in value of the managed assets, excluding synchronous deposits already accounted for on-chain). This approach would ensure that increases to totalAssets from synchronous deposits are preserved, as the NAV committee's reported change would be added to the already updated totalAssets figure, thus preventing the inadvertent exclusion of these deposited assets.

Resolution

In order to solve this issue, we opted for a solution close to the operationnal safeguards. We offer the vault.safe() role (curator) the capacity to expire totalAssets. By doing so he will disable the capacity to do synchronous deposit until next complete totalAssets update, offering the ValuationManager and himself the liberty to update the valuation without risks.

Update from Nethermind Security

The issue is mitigated at commit ca04ed.

6.3 Share price can be artificially inflated through synchronous deposits coupled with share burning

FileFix commitTypeStatus
src/v0.5.0/Vault.sol—LowFixed

The vault's share price is implicitly determined by the ratio totalAssets / totalSupply. TThe interaction between the two recently introduced features allow users to inflate the share's price:

  • Synchronous Deposits: Whitelisted users can directly deposit assets into the vault. This action increases the totalAssets value and mints a corresponding number of shares to the depositor;
  • Share Burning: The burn(...) function allows users to destroy a specified amount of their own shares, thereby decreasing totalSupply;

A malicious (whitelisted) user can exploit this by performing the following sequence:

  • Deposit Assets: The attacker deposits a quantity of assets ( X) into the vault. This increases totalAssets by X and mints Y shares for the attacker;
  • Burn Shares: The attacker then immediately calls the burn(...) function to destroy all or a significant portion of the Y shares they just received;

The consequence is that the X assets contributed by the attacker remain within the vault (increasing totalAssets, but the corresponding shares that claim those assets are removed from circulation (decreasing totalSupply). This effectively acts as a "donation" of the attacker's deposited assets to the remaining pool, concentrating the vault's total asset value over fewer shares and thereby inflating the price of each remaining share.

Artificially inflating the share price can lead to several adverse consequences. Malicious actors could exploit this vulnerability, particularly early in the vault's operation or when total share supply is low, to conduct "first deposit attacks"; this would cause subsequent legitimate depositors to receive disproportionately fewer shares for their assets, unfairly benefiting the attacker. Furthermore, if the vault's share price is utilized as an oracle by other DeFi protocols for functions like collateral valuation, this manipulation could be leveraged to deceive or exploit those external systems for an attacker's gain. Such potential for manipulation can also undermine user confidence and deter legitimate participation in the vault.

Recommendation

Reconsider the addition of the shares burning feature. The removal of this feature would remove the current possibility of donations through synchronous deposits and burn.

Resolution

We removed the capacity to burn shares.

Update from Nethermind Security

Fixed in commit d05006.

6.4 The requestDeposit(...) function is inconsistent depending on the executed branch

FileFix commitTypeStatus
src/v0.5.0/Vault.sol—InfoFixed

The requestDeposit(...) function has been modified to serve a dual purpose: it initiates an asynchronous deposit request or, if synchronous deposits are currently available, it falls back to executing a synchronous deposit directly. This conditional branching within a single function leads to several inconsistencies in its behavior and outputs, making it more difficult for developers and integrating systems to reliably predict and handle its execution.

The observed inconsistencies include:

  • Return Value Discrepancy:
    • Asynchronous Path: When initiating an asynchronous deposit, requestDeposit(...) returns the unique request ID associated with the pending operation.
    • Synchronous Path: If the function executes a synchronous deposit, it returns 0 (zero), as no asynchronous request ID is generated. Callers must be prepared to handle these two distinct return value meanings.
  • Referral Processing:
    • Asynchronous Path: Referral parameters are processed and accounted for.
    • Synchronous Path: Referral parameters are ignored, and no referral logic is triggered.
  • Handling of Existing Pending Requests:
    • Asynchronous Path: The function is expected to fail if the caller already has a pending asynchronous deposit request.
    • Synchronous Path: If a synchronous deposit is possible, the function may proceed with the synchronous deposit, potentially bypassing or altering the logic that checks for and handles existing pending asynchronous requests for the user. This means the pre-condition regarding pending requests is not consistently enforced.

Recommendation

Consider maintaining requestDeposit(...) exclusively for asynchronous deposit requests and syncDeposit(...) for synchronous deposits.

Resolution

We gave up the "overload" of the requests functions. They will remain as before, and synchronous deposits are only possible by calling the function syncDeposit(...).

Update from Nethermind Security

Fixed in commit d05006.

6.5 syncDeposit(...) function lacks operator and referral features present in asynchronous deposits

FileFix commitTypeStatus
src/v0.5.0/Vault.sol—InfoFixed

The recently introduced syncDeposit(...) function enables users to perform synchronous deposits when this operational mode is active. This provides an immediate deposit pathway, contrasting with the existing asynchronous requestDeposit(...) function.

However, syncDeposit() currently does not implement two features available in the asynchronous deposit flow:

  • Operator Feature: The asynchronous requestDeposit(...) allows for an owner parameter, distinct from msg.sender. This enables an approved operator ( msg.sender) to initiate a deposit request on behalf of the owner of the assets. The syncDeposit(...) function lacks an owner parameter; assets are taken directly from msg.sender, meaning msg.sender is always the owner of the deposited assets. Thus, the pattern of an operator depositing assets on behalf of another distinct owner is not supported;
  • Referral Feature: The requestDeposit(...) function includes a referral parameter, allowing for on-chain tracking and potential incentivization of referrals. This parameter is absent in the syncDeposit(...) function signature and its associated logic;

This difference means that users and integrated systems cannot utilize operator-based deposits or referral tracking when using the synchronous deposit method.

  • Native Token Deposits: The asynchronous deposit mechanism may support deposits of the chain's native token (e.g., ETH). The syncDeposit(...) function, as currently implemented, appears to be primarily designed for ERC20 token deposits and lacks a clear mechanism or explicit handling for native token deposits;

Recommendation

To promote consistency and broader utility, consider aligning the feature set of syncDeposit(...) more closely with requestDeposit(...).

Resolution

We added the referral system to the syncDeposit(...) function and use 0 as the requestId. We decided not to support the "operator" feature in synchronous deposits.

Update from Nethermind Security

The Lagoon team has added the desired features. The issue is fixed at commit ca04ed.

7

Documentation Evaluation

Software documentation refers to the written or visual information that describes the functionality, architecture, design, and implementation of software. It provides a comprehensive overview of the software system and helps users, developers, and stakeholders understand how the software works, how to use it, and how to maintain it. Software documentation can take different forms, such as user manuals, system manuals, technical specifications, requirements documents, design documents, and code comments. Software documentation is critical in software development, enabling effective communication between developers, testers, users, and other stakeholders. It helps to ensure that everyone involved in the development process has a shared understanding of the software system and its functionality. Moreover, software documentation can improve software maintenance by providing a clear and complete understanding of the software system, making it easier for developers to maintain, modify, and update the software over time. Smart contracts can use various types of software documentation. Some of the most common types include:

  • Technical whitepaper: A technical whitepaper is a comprehensive document describing the smart contract’s design and technical details. It includes information about the purpose of the contract, its architecture, its components, and how they interact with each other;
  • User manual: A user manual is a document that provides information about how to use the smart contract. It includes step-by-step instructions on how to perform various tasks and explains the different features and functionalities of the contract;
  • Code documentation: Code documentation is a document that provides details about the code of the smart contract. It includes information about the functions, variables, and classes used in the code, as well as explanations of how they work;
  • API documentation: API documentation is a document that provides information about the API (Application Programming Interface) of the smart contract. It includes details about the methods, parameters, and responses that can be used to interact with the contract;
  • Testing documentation: Testing documentation is a document that provides information about how the smart contract was tested. It includes details about the test cases that were used, the results of the tests, and any issues that were identified during testing;
  • Audit documentation: Audit documentation includes reports, notes, and other materials related to the security audit of the smart contract. This type of documentation is critical in ensuring that the smart contract is secure and free from vulnerabilities.

These types of documentation are essential for smart contract development and maintenance. They help ensure that the contract is properly designed, implemented, and tested, and they provide a reference for developers who need to modify or maintain the contract in the future.

8

Remarks & Test Suite

The Lagoon team explained the use cases and expected behavior of the newly added features.

As auditors, we recommend that any changes or updates made to the audited codebase undergo a re-audit or security review to address potential vulnerabilities or risks introduced by the modifications. By conducting a re-audit or security review of the modified codebase, you can significantly enhance the overall security of your system and reduce the likelihood of exploitation. However, we do not possess the authority or right to impose obligations or restrictions on our clients regarding codebase updates, modifications, or subsequent audits. Accordingly, the decision to seek a re-audit or security review lies solely with you.

This report is based on the scope of materials and documentation provided by you to Nethermind in order that Nethermind could conduct the security review outlined in 1. Executive Summary and 2. Audited Files. The results set out in this report may not be complete nor inclusive of all vulnerabilities. Nethermind has provided the review and this report on an as-is, where-is, and as-available basis. You agree that your access and/or use, including but not limited to any associated services, products, protocols, platforms, content, and materials, will be at your sole risk. Blockchain technology remains under development and is subject to unknown risks and flaws. The review does not extend to the compiler layer, or any other areas beyond the programming language, or other programming aspects that could present security risks. This report does not indicate the endorsement of any particular project or team, nor guarantee its security. No third party should rely on this report in any way, including for the purpose of making any decisions to buy or sell a product, service or any other asset. To the fullest extent permitted by law, Nethermind disclaims any liability in connection with this report, its content, and any related services and products and your use thereof, including, without limitation, the implied warranties of merchantability, fitness for a particular purpose, and non-infringement. Nethermind does not warrant, endorse, guarantee, or assume responsibility for any product or service advertised or offered by a third party through the product, any open source or third-party software, code, libraries, materials, or information linked to, called by, referenced by or accessible through the report, its content, and the related services and products, any hyperlinked websites, any websites or mobile applications appearing on any advertising, and Nethermind will not be a party to or in any way be responsible for monitoring any transaction between you and any third-party providers of products or services. As with the purchase or use of a product or service through any medium or in any environment, you should use your best judgment and exercise caution where appropriate. FOR AVOIDANCE OF DOUBT, THE REPORT, ITS CONTENT, ACCESS, AND/OR USAGE THEREOF, INCLUDING ANY ASSOCIATED SERVICES OR MATERIALS, SHALL NOT BE CONSIDERED OR RELIED UPON AS ANY FORM OF FINANCIAL, INVESTMENT, TAX, LEGAL, REGULATORY, OR OTHER ADVICE.