World
USD Vault

The USD Vault turns World App users' USDC into sDAI and back at the Dai Savings Rate. We looked at deposits, redemptions, how liquidity providers keep the pool balanced and the volume limits on each user.
report id
0290
category
DeFi & Yield
language
Solidity
final report
August 28, 2024
lines of code
473
Content

Download audit report

1

Executive Summary

This document outlines the security review conducted by Nethermind Security for the Worldcoin USD Vault. The Vault is a smart contract allowing World App users to deposit USDC tokens and receive sDAI tokens. After some time, the sDAI tokens can be redeemed back to USDC based on the current Dai Savings Rate. Liquidity providers ensure that there are enough tokens for the World App users by keeping the token pool balanced. The USDVault contract introduces volume limits, which constrain the number of tokens the user can deposit or redeem within a given timeframe.

The audited code comprises of 473 lines of code written in the Solidity language, and it was performed using (a) manual analysis of the codebase, (b) automated analysis tools, (c) simulation of the smart contract.

Audit assessment
Audit TypeSecurity Review
Initial ReportAug 23, 2024
Response from ClientRegular responses during audit engagement
Final ReportAug 28, 2024
Repositoryworldcoin-vault
Commit (Audit)4859515679
Commit (Final)f3c1865d2b
Documentation AssessmentLow
Test Suite AssessmentLow
Total findings
5
Fixed
4
Acknowledged
1
Mitigated
0
Unresolved
0

Findings by severity

  • Critical0
  • High0
  • Medium0
  • Low0
  • Informational2
  • Best Practices3

2

Audited Files

#ContractLoCCommentsRatioBlankTotal
1USDVault.sol47316534.9%141779
Total47316534.9%141779

4

System Overview

The USDVault contract allows World App users to deposit USDC tokens and earn interest over time. For their deposits, the vault pays the users with the Savings Dai token - sDAI, which over time can be redeemed for more USDC. The exact conversion ratio is provided by the DSR Oracle controlled by the Maker DAO governance.

The USDVault contract interacts with the WorldIDAddressBook contract to check the user’s verification status. This ensures that only verified users can earn yield based on their deposits.

4.1 Actors of the system

  • Owner is a privileged USDVault contract’s admin. The owner can control the withdrawal fee percentage and change the fee recipient address as well as the USDC token address.
  • Liquidity Providers are actors responsible for rebalancing the sDAI and USDC token reserves.
  • World App users deposit their USDC tokens into the USDVault contract and earn interest.
  • Relayer is a trusted third-party actor that can perform the redemption on behalf of the user so that the user does not have to pay for the gas.

4.2 Deposits and Redemptions

The USDVault contract’s entry point for the user is the depositUSDC(...) function. Verified World App users can call this function and receive sDAI tokens in exchange for USDC tokens. If during the USDVault contract’s deployment, the USDC_DEPOSIT_LIMIT_DURATION parameter was set to a non-zero value, then the user’s deposits are constrained by a deposit volume limit. Any deposits above the limit performed within a specified limit duration will be rejected.

The exchange rate between USDC and sDAI in deposit and redemption operations is based on the Dai Savings Rate controlled by Maker DAO governance. The USDVault contract queries the conversion ratio directly from the DSR Oracle contract.

Once the users decide to exit the investment, they sign an off-chain message to allow sDAI token transfers on their behalf. The Worldcoin relayer fulfills their request and calls the redeemSDAI(...) function. Token transfers are facilitated through the Permit2 contract, which ensures that the signed message can only be consumed by the USDVault contract.

Similarly to deposits, if the SDAI_WITHDRAWAL_LIMIT_DURATION parameter was set to a non-zero value, the redemptions are constrained by the volume limit.

4.3 Vault rebalancing

Over time, when users deposit and redeem funds from the USDVault contract, the USDC and sDAI token reserves become imbalanced. The liquidity providers contracted by the Worldcoin team are responsible for rebalancing the vault token holdings. To keep the token ratio around an ideal 1:1 distribution, liquidity providers can call the depositUSDCRebalance(...) and redeemSDAIRebalance(...) functions.

Liquidity providers supply the USDVault contract with initial liquidity by calling the join(...) function. They specify the number of shares they want to receive and provide an appropriate amount of USDC and sDAI tokens.

Liquidity providers can exit the system anytime by calling the exit(...) function. They will receive an equivalent worth of USDC and sDAI tokens in exchange for their shares.

4.4 Oracle risks

The DSR Oracle receives information from Ethereum Mainnet to updates its information. Some delay may occur between when the exchange rate changes in mainnet and it is pushed to the Optimism network.

The oracle is managed by the MakerDAO team in a non-fully-decentralized manner.

The oracle is just receiving message from Ethereum Mainnet so it’s address is not expected to be changed. However, because USDVault contract’s owner already have multiple ways that could compromise the contract in case of private key leaks, we consider adding a function to be able to change the oracle would not increase surface risk, and would account for possible scenario where Oracle address needs to be changed.

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 Incorrect comment

FileFix commitTypeStatus
USDVault.solPR #14InfoFixed

The NatSpec @notice comment above the updateUSDCAddress(...) states that the function reverts if the new USDC token contract does not have a sufficient liquidity to pay out the users. This is not the case since there is no such check in this function.

Recommendation

Consider changing the comment or introducing the missing checks in the updateUSDCAddress(...) function.

Resolution

Function removed in 6d2f23e8d6acf3e9f0b65365ba6b4d7d14443912.

6.2 Users don’t have any control over some parameters when using the relayer

FileFix commitTypeStatus
USDVault.sol—InfoAcknowledged

Users can redeem tokens without interacting with the contract directly. This can be done through the relayer provided by Worldcoin. For this, users need to generate a PERMIT2 signature that will later be used to transfer the sDAI tokens from the user to the contract. However, while using this approach, the users don’t have guarantees over params amountOutMin, expectedWithdrawalFeeBips, and performanceFeeBips. These parameters are set by the relayer, and they are not part of the sign message provided by the user. A malicious relayer could use these parameters to harm users.

Recommendation

Consider adding logic to allow the user to verify these parameters. Optionally, document this behavior so users are aware.

Update from Nethermind Security

The withdrawal and performance fee-related logic has been removed entirely in f3c186, but the issue still applies to the amountOutMin, which can be controlled by the relayer.

6.3 The USDVault rounds up when giving assets out

FileFix commitTypeStatus
USDVault.solPR #14Best PracticesFixed

The USDVault contract applies rounding to the nearest integer when depositing and withdrawing USDC and sDAI respectively. In scenarios where the conversion amount rounds up, the user receives slightly more sDAI when depositing or slightly more USDC when redeeming. In its current form the accounting logic can’t be abused by the user since the token gains caused by rounding are negligible. In the long run however, if no rebalancing were to happen, the last user to redeem his funds might receive a slightly worse exchange rate as compared to other users. As a best practice it is recommended to round in favor of the protocol to reduce the potential area for accounting errors. As described in EIP-4626, rounding down should be applied whenever assets are given to the user or when calculating how many shares the user should receive during the deposit.

If (1) it’s calculating how many shares to issue to a user for a certain amount
of the underlying tokens they provide or (2) it’s determining the amount
of the underlying tokens to transfer to them for returning a certain amount
of shares, it should round down.

Recommendation

Consider rounding down as described in the EIP-4626.

Resolution

Fixed in b3abf4feef3ba44237fd4417cb2c1f3b8963b9a0.

6.4 Unused events and errors

FileFix commitTypeStatus
USDVault.solPR #14Best PracticesFixed

The USDVault contract declares the EmptyPool error and FundsWithdrawn event, but they are not used in the codebase.

Recommendation

To keep the code clean and readable, consider evaluating if the unused event and error should be used and, if not, remove them from the codebase.

Resolution

Fixed in 180b0b79276abca4af3e6a6bab5fd2f104848c31.

6.5 SafeERC20 is declared but not used

FileFix commitTypeStatus
USDVault.solPR #14Best PracticesFixed

The USDVault contract declares the using SafeERC20 directive for the IERC20 interface to benefit from extra safety while transfering ERC20 tokens. The problem is that the "safe" counterparts of the transfer functions are not used.

Recommendation

Consider using the safeTransfer(...) and safeTransferFrom(...) functions as opposed to transfer(...) and transferFrom(...) when handling ERC20 tokens.

Resolution

Fixed in e37184051099a5edc3a4cfdb3f876d80d004d69e.

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 Worldcoin team has provided documentation about their protocol in the form of in-line comments within the code. However, these comments did not provide a comprehensive explanation of the architecture and decisions behind various functionalities. Despite this, the Worldcoin team was available to address any questions or concerns from the Nethermind Security team.

Test suite
88Tests passed1Failed

The complete test output is in the full report.

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.