Download audit report
This document presents the security review performed by Nethermind on the source code for the Argent Account on StarkNet. The project is composed of 4 (four) contracts (ArgentAccount.cairo, Multicall.cairo, Proxy.cairo and Upgradable.cairo), along with 2 (two) libraries (AddressRegistry.cairo and ERC20.cairo). The audit scope is restricted to the following files: ArgentAccount.cairo, Proxy.cairo and Upgradable.cairo. The project also contains a high level specification, which was referenced during the audit process. The Argent Account on StarkNet is 2-of-2 custom multisig where the signer key is typically stored on the user’s phone and the guardian key is managed by an off-chain service to enable fraud monitoring. The guardian acts both as a co-validator for typical operations of the wallet, and as the trusted actor that can recover the wallet in case the signer key is lost or compromised. Alternatively, the user can add a second backup_guardian key to the account that has the same role as the guardian and can be used as the ultimate censorship resistance guarantee. The audit was carried out using manual inspection of the code base, interview with the client and automated tests provided by the Argent team. This document reports 8 (eight) points of attention. All the high severity issues were promptly addressed by the Argent team. In summary, 4 (four) issues have been resolved and 4 (four) issues have been acknowledged by the client. The code is well-written, easy to follow and is actively under
Code
Initial Report Argent Account on StarkNet 7225b83f30 Final Report Argent Account on StarkNet PR#40
| Audit assessment | |
| Audit Type | Security Review |
| Initial Report | May 9, 2022 |
| Final Report | May 16, 2022 |
| Methods | Manual Review |
| Documentation | https://github.com/argentlabs/argent-contracts-starknetreadme |
Findings by severity
| File | md5sum hash |
ArgentAccount.cairo | c847376ff551a6743569ec4962ce6ab0 |
Proxy.cairo | 64ee566dcd609fbf01489f1425263793 |
Upgradable.cairo | b59137fdedc9235f820f4d3f85963218 |
| File | md5sum hash |
ArgentAccount.cairo | 3258c26fe8ed3e9f326145a24075d0e5 |
Proxy.cairo | 6c29c9f33aa2fc00669b098428836ccf |
Upgradable.cairo | Same as initial review |
| File | md5sum hash |
address_registry.py | fef7f78a2b9a351c2d7e5c54f98f3335 |
argent_account.py | eef4f9238ab566897b61dd0b0fabfdc0 |
multicall.py | 96616847021cfb076235215ef1fcabef |
proxy.py | 8e7a2d275f20c7c15e7b787ecd61584d |
struct_hash.py | 9f647df96c753daeb45d01a67a2451d8 |
| File | md5sum hash |
address_registry.py | Same as initial review |
argent_account.py | Same as initial review |
multicall.py | Same as initial review |
proxy.py | b63a3a9c68c6b5312689473777628581 |
struct_hash.py | Same as initial review |
| # | Finding | Severity | Update |
| 1 | Contract can be interacted with before initialization | High | Fixed |
| 2 | The time-lock for escaping a guardian can be bypassed | High | Fixed |
| 3 | No event emitted during contract initialization | Info | Fixed |
| 4 | Batch of calls can fail | Info | Acknowledged |
| 5 | Signer, Guardian, and Backup Guardian can have the same address | Info | Acknowledged |
| 6 | Results from multiple calls are packed into a single array of bytes | Info | Acknowledged |
| 7 | State variable is overloaded to indicate if contract has been initialized | Best Practices | Acknowledged |
| 8 | Unused functions | Best Practices | Fixed |
No system overview is included in this report.
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 |
ArgentAccount.cairo#L160-L235 | — | High | Fixed |
The function ArgentAccount.__execute__(...) can be called before the contract has been initialized. Since all contract logic assumes that the function ArgentAccount.initialize(...) is called before any other function, the code must assert this intended behavior. Thus, the function ArgentAccount.__execute__(...) must perform a check to ensure that the contract has been properly initialized. Furthermore, the function ArgentAccount.__execute__(...) must require that ArgentAccount._signer is not address(0x0) and revert otherwise.
Recommendation
1. Designate an specific state variable for recording if the contract has been initialized. Set this variable accordingly in the function ArgentAccount.initialize(...). Whenever executing any action on the contract, firstly check if this state variable contains the proper value, especially in the core function ArgentAccount.__execute__(...).
2. In the function ArgentAccount.__execute__(...) assure that ArgentAccount._signer is different from address(0x0). Revert otherwise.
Resolution
1) added a assert_initialized check at the beginning of the __execute__ method to make sure the signer is not 0; 2) updated the constructor of the proxy to execute a first delegatecall to the implementation. This makes it possible to create and initialize the account in one transaction.
| File | Fix commit | Type | Status |
ArgentAccount.cairo#L399-L421 | — | High | Fixed |
The time-lock of seven days to call escape_guardian(...) can be bypassed by the signer by calling escape_guardian(...) when the storage variable _escape’s struct has both values active_at and type equal to zero. It is possible for _escape to be in this state when there is no current escape in the contract. The function escape_guardian(...) has two checks to ensure that the escape is valid: a) the current time has exceeded the current_escape.active_at, i.e., enough time has passed since trigger_escape_guardian has been called; b) the escape type is ESCAPE_TYPE_GUARDIAN. When there is no current escape in the contract both values are zero so the checks pass in the following way:
assert_le(current_escape.active_at, block_timestamp)# Variable `current_escape.active_at` is zero. # Variable `block_timestamp` is Unix time and will always be above zero. # This assert statement will pass.
assert current_escape.type = ESCAPE_TYPE_GUARDIAN#Variable `current_escape.type` is zero. #Constant `ESCAPE_TYPE_GUARDIAN` is zero. #This assert statement will pass.
Both asserts will pass and _guardian will be changed immediately instead of having to wait seven days which is the expected functionality. The following test can be added to test/argent_account.py to verify this:
@pytest.mark.asyncio
async def test_bypass_escape_guardian_timelock(get_starknet, account_factory):
account = account_factory
starknet = get_starknet
sender = TransactionSender(account)
new_guardian = Signer(55555555)# reset block_timestamp
reset_starknet_block(starknet=starknet)# trigger immediate escape without calling `trigger_escape_guardian`
tx_exec_info = await sender.send_transaction(
[
(
account.contract_address,
'escape_guardian',
[new_guardian.public_key]
)
],
[
signer
]
)
assert_event_emmited( tx_exec_info, from_address=account.contract_address, name='guardian_escaped',,! data=[new_guardian.public_key] )
assert (await account.get_guardian().call()).result.guardian == (new_guardian.public_key)Recommendation
To address this issue both of the following recommended changes should be implemented.
1. Change the constants ESCAPE_TYPE_GUARDIAN and ESCAPE_TYPE_SIGNER so that neither constants are zero.
2. Add a sanity check to ensure that current_escape.active_at is not zero in the functions escape_guardian and escape_signer.
Resolution
1) changed the values of ESCAPE_TYPE_GUARDIAN and ESCAPE_TYPE_SIGNER to be nonzero; 2) added the sanity check assert_not_zero(current_escape.active_at) in escape_guardian and escape_signer.
| File | Fix commit | Type | Status |
ArgentAccount.cairo#L145-L167 | — | Info | Fixed |
The function ArgentAccount.initialize(...) makes changes to state but does not emit any event. This function is the basis from which the code is built upon, and the emission of an event with the input parameters could support post-deployment investigations.
Recommendation
Emit an event in the last line of ArgentAccount.initialize(...) containing _signer and the _guardian.
Resolution
Added the account_initialized event.
| File | Fix commit | Type | Status |
ArgentAccount.cairo#L169-L235 | — | Info | Acknowledged |
In the case where you call the function ArgentAccount.__execute__(...) to run a batch of calls at once, should any of them fail this will cause the entire transaction to revert. StarkNet does not support the ability to “catch” failed asserts so it is not possible to allow all other successful calls to run. This should be explained to users as there can be circumstances where the user may want all other calls to succeed. For example: A batch of calls to swap different tokens on an exchange, if one swap reverts (EG: a swap exceeds its defined slippage) then the entire transaction will fail including all other swap calls that would have otherwise succeeded.
Recommendation
Clearly state this condition in the user facing documentation.
Resolution
Will make sure this is properly documented in the future.
Signer, Guardian, and Backup Guardian can have the same address| File | Fix commit | Type | Status |
ArgentAccount.cairo#L125-L135 | — | Info | Acknowledged |
By analyzing the functions ArgentAccount.change_signer(...), ArgentAccount.change_guardian(...), and ArgentAccount.change_guardian_backup(...) we notice that the same address can be set to the state variables ArgentAccount._signer, ArgentAccount._backup, and ArgentAccount._guardian_backup. As explained by the Argent team, this is the intended behavior.
Recommendation
Since this is the intended behavior, no action is required from the client.
Resolution
As discussed this is a conscious choice but will make sure it is properly documented.
| File | Fix commit | Type | Status |
ArgentAccount.cairo#L688-L748 | — | Info | Acknowledged |
The function ArgentAccount.execute_list(...) is responsible for executing an array of actions. The output of these actions are placed into the variable execute_list.reponse (notice the missing s in the variable name) without including the size of each particular response. The developers are already aware of this situation.
Recommendation
The decision on how the system must operate belongs to the client. Thus, no action is required from the client on this matter.
Resolution
As discussed this is intentional and the unpacking is left to the calling contract.
| File | Fix commit | Type | Status |
ArgentAccount.cairo#L145-L167 | — | Best Practices | Acknowledged |
The state variable ArgentAccount._signer in function ArgentAccount.initialize(...) is overloaded. Its purposes are to keep track of the signer as well as signal if the contract has already been initialized. In some case where ArgentAccount._signer is reset to address(0x0), both of these purposes will be affected and anybody would be able to call ArgentAccount.initialize(...). The current implementation of the ArgentAccount contract prevents _signer from being reset, however splitting this overloaded state variable into two state variables with specific purposes could make the code more robust.
Recommendation
Consider designating a specific state variable for recording if the contract has been initialized or ensure that no future functionality will be able to reset ArgentAccount._signer to address(0x0).
Resolution
This is a conscious choice to lower the cost of creating accounts as on StarkNet the main cost comes from storage vars that need to be propagated to L1. We do not see a need to introduce another storage var given that the contract logic guarantees the account is initialized if and only if the signer is not 0.
| File | Fix commit | Type | Status |
Proxy.cairoArgentAccount.cairo | — | Best Practices | Fixed |
In Proxy.cairo the imported function assert_not_zero(...) is never used. In ArgentAccount.Cairo the imported functions get_fp_and_pc(), hash_init(...), hash_finalize(...), hash_update(...), and hash_update_single(...) are never used.
Recommendation
Remove unused imports and functions from the code to improve overall readability and maintainability.
Resolution
Unused methods removed.
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 volume of inline comments can be improved. In its actual form, the audited files present 709 lines of code and just 108 lines of comments. As the system grows and novel functionalities are included, having a robust development documentation can make a huge difference. Thus, we would like to recommend formalizing the functional requirements of this project, keeping this updated while the project is being built.
The README.md is missing the information for compiling ArgentAccount.cairo. It would be helpful to state that the compile order should be:
1. nile compile
2. nile compile --account_contract contracts/ArgentAccount.cairo
The test suite has room for improvement. In its actual format, it performs the basic validations required for unitary tests. However, systemic validations can be incorporated in order to catch non-trivial edge cases. The test suite is composed of the following files:
In the following subsections, we present the tests output for the initial report and the final 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