Download audit report
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 Type | Security Review |
| Initial Report | Aug 23, 2024 |
| Response from Client | Regular responses during audit engagement |
| Final Report | Aug 28, 2024 |
| Repository | worldcoin-vault |
| Commit (Audit) | 4859515679 |
| Commit (Final) | f3c1865d2b |
| Documentation Assessment | Low |
| Test Suite Assessment | Low |
Findings by severity
| # | Contract | LoC | Comments | Ratio | Blank | Total |
| 1 | USDVault.sol | 473 | 165 | 34.9% | 141 | 779 |
| Total | 473 | 165 | 34.9% | 141 | 779 |
| # | Finding | Severity | Update |
| 1 | Incorrect comment | Info | Fixed |
| 2 | Users don’t have any control over some parameters when using the relayer | Info | Acknowledged |
| 3 | The USDVault rounds up when giving assets out | Best Practices | Fixed |
| 4 | Unused events and errors | Best Practices | Fixed |
| 5 | SafeERC20 is declared but not used | Best Practices | Fixed |
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.
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.sDAI and USDC token reserves.USDC tokens into the USDVault contract and earn interest.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.
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.
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.
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:
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:
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 / Likelihood | Low | Medium | High |
| High | Medium | High | Critical |
| Medium | Low | Medium | High |
| Low | Info / Best Practices | Low | Medium |
| Undetermined | Undetermined | Undetermined | Undetermined |
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.
| File | Fix commit | Type | Status |
USDVault.sol | PR #14 | Info | Fixed |
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.
| File | Fix commit | Type | Status |
USDVault.sol | — | Info | Acknowledged |
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.
USDVault rounds up when giving assets out| File | Fix commit | Type | Status |
USDVault.sol | PR #14 | Best Practices | Fixed |
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.
| File | Fix commit | Type | Status |
USDVault.sol | PR #14 | Best Practices | Fixed |
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.
SafeERC20 is declared but not used| File | Fix commit | Type | Status |
USDVault.sol | PR #14 | Best Practices | Fixed |
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.
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:
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.
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.
| 88Tests passed | 1Failed |
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.
The Leading Engineers of Blockchain Infrastructure