Download audit report
This document presents the security review performed by Nethermind on the Allowance Module containing 213 lines of code. The AllowanceModule contract is a fork from the repo safe-global/safe-modules with some modifications applied by the Worldcoin team. The contract is used to spend allowances set via Safe transactions. It also implements full control over allowances that are given to certain wallets. More specifically, the contract supports dynamic adjustments to allowances and periodic resets, providing a versatile solution for implementing complex allowance systems within the Safe environment.
Along the audit of this contract, we report 3 (three) points of attention, where two are classified as Low and one is classified as Informational.
| Audit assessment | |
| Audit Type | Security Review |
| Initial Report | Oct. 23, 2023 |
| Response from Client | Oct. 30, 2023 |
| Final Report | Dec. 5, 2023 |
| Methods | Manual Review, Automated Analysis |
| Repository | helper-contracts |
| Commit Hash (Audit) | abf345b152 |
| Documentation | README.md |
| Documentation Assessment | Medium |
| Test Suite Assessment | Not Provided (one single file audit) |
Findings by severity
| # | Contract | LoC | Comments | Ratio | Blank | Total |
| 1 | AllowanceModule.sol | 213 | 54 | 25.4% | 26 | 293 |
| Total | 213 | 54 | 25.4% | 26 | 293 |
| # | Finding | Severity | Update |
| 1 | Potential division by zero | Low | Fixed |
| 2 | The executeAlllowanceTransfer(...) function allows any user to do zero transfer on behalf of the Safe | Low | Fixed |
| 3 | Unnecessary overflow checks | Info | Fixed |
The AllowanceModule is a contract that extends the capabilities of Gnosis Safe, a multi-signature wallet. This module introduces a comprehensive system for managing token allowances, allowing the owner to delegate specific spending permissions to trusted parties. The contract employs a double-linked list to manage delegates, for addition and removal operations.
Detailed records of allowances are maintained for each token and delegate combination. These allowances include information on the permitted amount, amount spent, reset time, and initialization status. This level of granularity provides the owner with a nuanced control mechanism over fund utilization. Owners can set, reset, or delete allowances for individual delegates and tokens. The contract AllowanceModule has a number of important mappings and structs:
Mappings: The contract maintains several mappings that keep track of allowances, tokens, and delegates related to a given Safe address. These mappings are integral to the system’s structure.Structs: The contract defines two structures: Delegate and Allowance. They are used to store information about delegates and allowances, respectively.execTransactionFromModule
setAllowance
resetAllowance
deleteAllowance
executeAllowanceTransferaddDelegate
removeDelegateFig. 2 presents a structure diagram of the contract. As illustrated in it, the contract implements the following functions:
setAllowance(...): This function allows to update the allowance for a specific token. This operation can only be executed via a Safe transaction. It takes in parameters such as the delegate, token, allowance amount, and reset time.executeAllowanceTransfer(...): It allows for the execution of a transfer based on an allowance. It takes parameters such as the Safe address, delegate, token, receiver, and amount. The function checks if the delegate is allowed to execute the transfer, deducts the pertinent amount from the allowance, and then executes the transfer.resetAllowance(...): This function resets the allowance for a particular delegate and token addresses.getAllowance(...): This function queries the allowance for a particular delegate and token. It returns the allowance amount and the reset time. The function applies resets in regular intervals.addDelegate(...) and removeDelegate(...): These functions allow for the adding and the removal of a delegate.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 |
AllowanceModule.sol | b5a7bdf | Low | Fixed |
The function setAllowance(...) in the contract AllowanceModule is used to update the allowance for a particular token. The function is presented below:
function setAllowance(address delegate, address token, uint96 allowanceAmount, uint16 resetTimeMin, uint32 resetBaseMin)
public
{
...
uint32 currentMin = uint32(block.timestamp / 60);
if (resetBaseMin > 0) {
require(resetBaseMin <= currentMin, "resetBaseMin <= currentMin");
///////////////////////////////////////////////////////
// @audit resetTimeMin need to be greater than zero
// before updating allowance.lastResetMin
///////////////////////////////////////////////////////
allowance.lastResetMin = currentMin - ((currentMin - resetBaseMin) % resetTimeMin);
} else if (allowance.lastResetMin == 0) {
allowance.lastResetMin = currentMin;
}
...
}When the parameter resetBaseMin is greater than zero, and the following condition is satisfied, the allowance.lastResetMin is updated.
require(resetBaseMin <= currentMin, "resetBaseMin <= currentMin");However, if resetTimeMin == 0, the transaction reverts. While this does not reveal a security issue, the scenario where the division by zero will cause the transaction to revert with an unexpected error message. Therefore, to avoid unexpected behaviors, consider returning ...
Recommendation
Apply a check for resetTimeMin > 0 to avoid unexpected behaviors before updating allowance.lastResetMin.
Resolution
executeAlllowanceTransfer(...) function allows any user to do zero transfer on behalf of the Safe| File | Fix commit | Type | Status |
AllowanceModule.sol | b5a7bdf | Low | Fixed |
The executeAllowanceTransfer(...) function is designed to execute transfers from Safe contracts; these transfers can be executed by users with the required allowances. However, the current implementation allows the bypassing of checks when the transfer amount is set to zero
function executeAllowanceTransfer(GnosisSafe safe, address token, address payable to, uint96 amount) public {
// Get current state
address delegate = msg.sender;
Allowance memory allowance = getAllowance(address(safe), delegate, token);
// Update state
uint96 newSpent = allowance.spent + amount;
// Check new spent amount and overflow
// @audit - This requirement can be bypassed by any user using an amount equal to zero
require(
newSpent > allowance.spent && newSpent <= allowance.amount,
"newSpent > allowance.spent && newSpent <= allowance.amount"
);
allowance.spent = newSpent;
updateAllowance(address(safe), delegate, token, allowance);
// Transfer token
transfer(safe, token, to, amount);
emit ExecuteAllowanceTransfer(address(safe), delegate, token, to, amount);
}The vulnerability arises because a zero transfer amount does not trigger the allowance checks, enabling any user, regardless of their allowance status, to execute calls on behalf of the Safe contracts. This could be potentially exploited by malicious actors to execute calls on behalf of the Safe contracts.
Recommendation
Disallow the transfer of zero amounts to avoid the mentioned case.
Resolution
| File | Fix commit | Type | Status |
AllowanceModule.sol | b5a7bdf8436e2d | Info | Fixed |
The executeAllowanceTransfer(...) function includes a redundant overflow check.
function executeAllowanceTransfer(...) public {
...
// Update state
uint96 newSpent = allowance.spent + amount;
// Check new spent amount and overflow
// @audit - Redundant overflow check
require(
newSpent > allowance.spent && newSpent <= allowance.amount,
"newSpent > allowance.spent && newSpent <= allowance.amount"
);
...
}Beginning with version 0.8.0, the Solidity compiler automatically adds overflow checks for arithmetic operations. Consequently, the manual check in this function is redundant.
Recommendation
Consider removing the unnecessary operation.
Resolution
Update from Nethermind Security
The unnecessary overflow check was removed but this change added a new issue. As presented below, the condition that checks whether the new spent amount (newSpent) does not exceed the allowed amount (allowance.amount) has also been removed. In other words, the function allows to transfer more than the allowed amount.
- // Check new spent amount and overflow
- require(
- newSpent > allowance.spent && newSpent <= allowance.amount,
- "newSpent > allowance.spent && newSpent <= allowance.amount"
- );Update from the client
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 provided a README file describing how to build, run tests, etc. However, there is not any documentation to explain how the module should work and test implementation. During the audit process, the client remained in constant communication with the audit team for clarifications to tackle the lack of documentation.
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