Download audit report
This document presents the security review conducted by Nethermind Security for the Savings contract developed by Worldcoin. The new functionality enables the World App users to earn interest on their stablecoins. The users can deposit USDC.e or USDC tokens into the Savings contract and receive the savings DAI token (sDAI) in return. Users can redeem their initial deposit with the accrued interest at any time. The Savings contract will be deployed on the Optimism network. The conversion between the stablecoins and the sDAI token will use the rate returned from the DAI Savings Rate Oracle contract deployed on Optimism by MakerDAO.
Initially, the Worldcoin team plans to pre-fund about a year’s worth of interest for the users. This involves the initial deposit of funds into the Savings contract, including the USDC.e and bridged sDAI tokens. The contract defines two different fees: The withdrawal fee, which is applied for each redemption operation and computed as a percentage of the withdrawn amount, and the performance fee, which is applied to the accrued interest for each user. Currently, the performance fee is hard-coded as an input to the function, and the logic handling its computation is not yet implemented.
The audited code comprises 115 lines of code in Solidity. The Worldcoin team has provided the necessary explanations to assist the audit. The audit was performed using: (a) manual analysis of the codebase, (b) automated analysis tools, and (c) simulation of the smart contracts.
| Audit assessment | |
| Audit Type | Security Review |
| Initial Report | Apr 22, 2024 |
| Final Report | Apr 29, 2024 |
| Methods | Manual Review, Automated Analysis |
| Repository | helper-contracts |
| Commit Hash | c48a2953ae |
| Final Commit Hash | 4001cdd068 |
| Documentation | PR description |
| Documentation Assessment | Medium |
| Test Suite Assessment | Medium |
Findings by severity
| # | Contract | LoC | Comments | Ratio | Blank | Total |
| 1 | src/Savings.sol | 115 | 78 | 67.8% | 49 | 242 |
| Total | 115 | 78 | 67.8% | 49 | 242 |
| # | Finding | Severity | Update |
| 1 | Possible phishing attack due to the use of tx.origin in the onlyRelayer(...) modifier | Info | Acknowledged |
| 2 | Possible underflow within redeem functions | Info | Fixed |
| 3 | The onlyRelayer(...) modifier reverts with an incorrect relayer address | Info | Fixed |
| 4 | Withdrawal fee can be bypassed for small sDAI amounts | Info | Acknowledged |
| 5 | A frequently used number literal 10_000 could be made constant | Best Practices | Fixed |
| 6 | Missing input validation | Best Practices | Fixed |
| 7 | Perform input validation before external calls | Best Practices | Fixed |
| 8 | The MIN and MAX DSR conversion rate state variables could be made constant | Best Practices | Fixed |
| 9 | The validateConversationRate(...) function name contains a typo | Best Practices | Fixed |
| 10 | Unchecked return values of transfer(...) and transferFrom(...) calls | Best Practices | Acknowledged |
The Savings contract offers the World App users the ability to earn interest on their stablecoins. Users can deposit USDC and USDC.e tokens into the contract and receive the savings DAI token in return. The sDAI token can be redeemed back for stablecoins at any point in time. The token exchange rate, applied on both the deposit and withdrawal operations, is queried from the Dai Savings Rate Oracle (DSR) deployed on Optimism by MakerDAO. In the code, the exchange rate is referred to as the conversion rate.
To simplify the user experience, a special entity called Relayer interacts with the Savings contract on behalf of the user. The user is expected to sign a single approval transaction using his Safe smart contract wallet (formerly Gnosis Safe). He specifies the action to be performed and the token to be used: sDAI for withdrawals and USDC or USDC.e for deposits. Using the user’s signature, the relayer can call the Safe contract and approve the Savings contract on the user’s behalf. In the second step, the relayer can call the appropriate deposit or withdrawal function, which will transfer the tokens from the user to the Savings contract. For efficiency reasons, both calls executed by the relayer will be batched together in a single Multicall3 transaction.
The system distinguishes between 3 main roles:
Savings contract owner is a multi-signature wallet owned by the Worldcoin team, allowed to set and update protocol parameters. Below are the main functions an owner can call:setWithdrawalFee(...): This function allows to set the withdrawal fee, expressed in basis points (bips), applied to the sDAI amount during redemption operations.setFeeRecipient(...): This function sets the address of the account that will receive the withdrawal fees during the redemption operation.setRelayerAuthorized(...): This function enables adding or removing addresses from the mapping of authorized Relayers.withdraw(...): This function facilitates tokens withdrawal from the Savings contract to a defined recipient.Savings contract.The Savings contract will be initially funded by the Worldcoin team, enabling users to deposit USDC and USDC.e into the contract to earn interest on their stablecoins. For that, the contract provides the following functions:
depositUSDC(...): This function allows users to deposit USDC into the contract and receive an amount of sDAI in return, based on the exchange rate received from the MakerDAO DSR Oracle. This operation is performed by the Relayer on behalf of the user.depositUSDCE(...): Similarly, this function allows users to deposit USDC.e and receive sDAI in exchange.To make a deposit, users must approve the USDC or USDC.e token transfer beforehand. For that, they need to sign the approval transaction using their Safe account. This signed transaction is then aggregated in a multi-call, followed by the deposit function call. Subsequently, the Relayer executes the two actions in a single transaction using the Multicall3 contract.
Users have the option to redeem either USDC or USDC.e by providing an equivalent amount of sDAI. The Savings contract offers the following redemption functions:
redeemUSDC(...): This function allows users to exchange sDAI for USDC. The process involves two different fees: Initially, a withdrawal fee is applied as a percentage of the withdrawn amount, followed by a performance fee imposed on the accrued interest. The withdrawal operation is performed by the Relayer on behalf of the user.redeemUSDCE(...): Similarly, users can redeem USDC.e using this function. The process is similar to the redeemUSDC(...) function.Similarly to deposits, in order to initiate a redemption, users are required to sign the sDAI ERC20 approval transaction using their Safe account. A multi-call aggregating this approval with the redeem function call is then executed by the Relayer.
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.
tx.origin in the onlyRelayer(...) modifier| File | Fix commit | Type | Status |
Savings.sol | — | Info | Acknowledged |
The onlyRelayer(...) modifier is used to restrict access to contract functions authorized only to EOAs identified as relayers. This modifier uses the tx.origin global variable to authorize the caller to an operation. However, The use of tx.origin is associated with possible risks of phishing attacks and its use is not recommended for authorization by the best practices indicated in the Solidity language documentation. Also, there is a chance that tx.origin will be removed from the Ethereum protocol in the future, so code that uses tx.origin won’t be compatible with future releases Vitalik Buterin: ’Do NOT assume that tx.origin will continue to be usable or meaningful’.
modifier onlyRelayer() {
// @audit tx.origin used for authorization
if (!isAuthorizedRelayer[tx.origin]) {
revert UnauthorizedRelayer(msg.sender);
_;
}
}tx.origin is a global variable in Solidity that returns the account address that initiated the transaction. Using this variable for authorization could make a contract vulnerable if an authorized account calls into a malicious contract, so in a scenario where an attacker successfully persuades an authorized relayer to initiate a transaction by calling a function in their malicious contract and subsequently redirects the transaction to a function in the Savings contract that uses this modifier, the attacker could circumvent the authorization check. This is because the address of the attacking contract would be in msg.sender, while the address of the authorized relayer, who initially initiated the transaction, would be in tx.origin, thereby enabling the attacker to bypass the validation.
Given the level of authority that relayers possess, an attacker could execute calls to the functions unwrap(...), depositUSDC(...), depositUSDCE(...), redeemUSDC(...) and redeemUSDCE(.. .), but since these functions involve only an exchange of tokens between the contract and a receiving account there is no major impact for the contract.
Recommendation
Consider revisiting the system design and avoid relying on tx.origin for authorization. A recommended solution is implementing a signature validation scheme to verify the signatures of authorized relayers. Utilizing the OpenZeppelin ECDSA library for this purpose is recommended, along with adhering to the guidelines outlined in the ERC-712 standard.
Resolution
We acknowledge the risk of relying on tx.origin for authentication. To minimize the overhead on our backend, we will not implement ECDSA signature verification as a replacement for the tx.origin check.
| File | Fix commit | Type | Status |
Savings.sol | PR #5 | Info | Fixed |
The functions redeemUSDC(...) and redeemUSDCE(...) enable users to redeem USDC or USDCE, respectively, by providing sDAI. During redemption, two types of fees are involved: a performance fee, which is specified as a parameter, and a withdrawal fee, calculated as a percentage of the withdrawn amount. However, the current implementation only checks whether the withdrawn amount is greater than the performance fee, while both fees are subtracted from that amount. This can result in an underflow error during the computation process.
function redeemUSDCE(address recipient, uint256 amount, uint256 performanceFee) external onlyRelayer {
SDAI.transferFrom(recipient, address(this), amount);
require(amount > 0, "Redeem amount is 0");
// @audit The check only covers the `performanceFee`
require(performanceFee < amount, "Performance fee is greater than redeem amount");
uint256 withdrawalFee = (amount * withdrawalFeeBips) / 10_000;
uint256 amountAfterWithdrawalFee = amount - withdrawalFee;
// @audit Possible underflow error if
// `amountAfterWithdrawalFee < performanceFee`
uint256 amountAfterPerformanceFee = amountAfterWithdrawalFee - performanceFee;
require(amountAfterPerformanceFee > 0, "Amount after fees is 0");
// ...
}Recommendation
Consider verifying whether the withdrawn amount is greater than the sum of the performance and withdrawal fees.
Resolution
Fix: b90eeb7f566c34f9dcee06a0cfc5a234202f5704
onlyRelayer(...) modifier reverts with an incorrect relayer address| File | Fix commit | Type | Status |
Savings.sol | PR #5 | Info | Fixed |
The onlyRelayer(...) modifier ensures that the deposit/redeem multi-call transaction was initiated by an authorized relayer. The modifier checks that the tx.origin is present in the isAuthorizedRelayer mapping, and if not, the UnauthorizedRelayer error is thrown. However, the thrown error uses the address of the msg.sender, which corresponds to the multi-call contract, instead of the tx.origin relayer address that initiated the transaction.
modifier onlyRelayer() {
if (!isAuthorizedRelayer[tx.origin]) {
// @audit The msg.sender is the multi-call contract, not the relayer.
revert UnauthorizedRelayer(msg.sender);
}
_;
}Recommendation
To keep the condition consistent with the error value, consider reverting with the tx.origin address that initiated the transaction instead of the direct caller of the function.
Resolution
Fix: 0fea25245b3f8337d0254af18985c2d3c75bc0a0
sDAI amounts| File | Fix commit | Type | Status |
Savings.sol | — | Info | Acknowledged |
During the redemption process, a withdrawal fee is imposed as a percentage of the withdrawn amount. However, the function doesn’t validate whether the resulting fee amount is non-zero. This allows users to manipulate the withdrawal amount by providing small sums, leading to the fee amount rounding down to zero, thereby bypassing the fee. To illustrate, for a fee percentage of P, any withdrawal amount A such that: A * P < 10_000 results in zero fees.
function redeemUSDCE(address recipient, uint256 amount, uint256 performanceFee) external onlyRelayer {
SDAI.transferFrom(recipient, address(this), amount);
require(amount > 0, "Redeem amount is 0");
require(performanceFee < amount, "Performance fee is greater than redeem amount");
// @audit The `withdrawalFee` can be zero.
uint256 withdrawalFee = (amount * withdrawalFeeBips) / 10_000;
// ...
}Given that fees are deducted in sDAI, which has 18 decimals, the necessary amounts to perform this manipulation are extremely small and don’t make an important impact.
Recommendation
Consider incorporating a validation check in both redeemUSDC(...) and redeemUSDCE(...) functions to ensure that the computed withdrawal fee is non-zero.
Resolution
We acknowledge the risk but have decided to leave as is. We also have checks on the backend which prevent the creation of a large amount of small transactions from a single user.
10_000 could be made constant| File | Fix commit | Type | Status |
Savings.sol | PR #5 | Best Practices | Fixed |
The Savings contract calculates the withdrawal fee as a percentage of the requested withdrawal amount using basis points. The integer literal 10_000 is used in multiple places throughout the codebase to serve as a value of 100 percent. Where applicable, it is considered a best practice to use named constants instead of number literals to improve the codebase’s readability and give more context to the reader.
Recommendation
Consider refactoring the code to use a named constant with a meaningful name like ONE_HUNDRED_PERCENT.
Resolution
Fix: a67820cc89e3cdb2861fdcf23243cc0a3e27a1e6
| File | Fix commit | Type | Status |
Savings.sol | PR #54001cdd | Best Practices | Fixed |
Some parts of the code do not implement proper input validation checks. To mitigate human errors, it is considered a best practice to perform input validation to ensure that the contract is always in a proper state.
The following functions do not perform the address(0) check, on the address parameters:
Savings contract’s constructor(...) the address parameters are not checked;setFeeRecipient(...) function the parameter _feeRecipient is not checked;setRelayerAuthorized(...) function the parameter relayer is not checked;withdraw(...) function the parameter recipient is not checked;Recommendation
Consider adding validations for input parameters according to the recommendations above.
Resolution
Fix: c516e21b5e764acda15c8e743168f36b03817cfd and 4001cdd06832c08494784c9de989c7b49886febe
| File | Fix commit | Type | Status |
Savings.sol | PR #5 | Best Practices | Fixed |
In the functions redeemUSDC(...) and redeemUSDCE(...), external calls are made before validating the input parameters. This may lead to unnecessary gas expenditure in cases where the transaction reverts due to input validation. For example, in the redeemUSDC(...) function:
function redeemUSDC(address recipient, uint256 amount, uint256 performanceFee) external onlyRelayer {
// @audit External call
SDAI.transferFrom(recipient, address(this), amount);
// @audit Input parameter validation
require(amount > 0, "Redeem amount is 0");
require(performanceFee < amount, "Performance fee is greater than redeem amount");
// ...
}Recommendation
Consider verifying input parameters before initiating external calls. This is considered a best practice that helps save gas in the process.
Resolution
Fix: 7b8e503be5f75de9ed5e2c14afc39cbe02c41ea8
MIN and MAX DSR conversion rate state variables could be made constant| File | Fix commit | Type | Status |
Savings.sol | PR #5 | Best Practices | Fixed |
The Savings contract uses the MIN_DSR_CONVERSION_RATE and MAX_DSR_CONVERSION_RATE state variables to validate the conversion rate returned by the DSR oracle. Since these variables are fixed at compile time, their mutability could be changed from immutable to constant.
Recommendation
Consider changing the mutability of the above-mentioned variables from immutable to constant.
Resolution
Fix: cab8f0b08f15bb8ea7393cf7014c79036a08d5dd
validateConversationRate(...) function name contains a typo| File | Fix commit | Type | Status |
Savings.sol | PR #5 | Best Practices | Fixed |
The validateConversationRate(...) function validates the conversion rate returned by the DSR oracle. Given its purpose, we believe that the current function name contains a typo. Instead of conversation, it should contain the word conversion.
Recommendation
Consider changing the function’s name from validateConversationRate(...) to validateConversionRate(...).
Resolution
Fix: 2f54eb710f70b91d89f4d31818a2624f4e32eeb1
transfer(...) and transferFrom(...) calls| File | Fix commit | Type | Status |
Savings.sol | — | Best Practices | Acknowledged |
The relayer functions within the Savings contract allow the transfer of supported ERC20 tokens through swaps or withdrawals. However, these functions ignore the return values from the transfer(...) and transferFrom(...) ERC20 functions. Some tokens use this value to indicate the transfer status, returning false in case of failure.
While all the currently transferred tokens: sDAI, USDC, and USDC.e conform to the intended behavior of reverting on failure, the withdraw(...) function allows the withdrawal of any ERC20 token from the contract, potentially including tokens that return false on failure instead of reverting. Although there’s no significant impact currently, this may mislead users or third parties relying on the transaction’s success if the transfer actually fails despite the transaction being successful.
Recommendation
Consider using safeTransfer(...) and safeTransferFrom(...) functions from OpenZeppelin SafeERC20 contract. Alternatively, implement a check to verify that the return values for transfer(...) and transferFrom(...) are true.
Resolution
We acknowledge the risk but have decided to leave as is given that we only expect to receive USDC.e, USDC, and sDAI which all conform to the ERC20 standard and revert on fail.
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 contracts documentation is presented through inline comments within the code, providing explanations and insights about their implementation. Additionally, the PR description accessible at this link, outlines the important funtionnalities implemented within the contract. Furthermore, the Worldcoin team was available to address any inquiries or concerns raised by the Nethermind Security team.
| 18Tests passed | 0Failed |
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