Argent
Starknet Account

Argent's Starknet account is a 2-of-2 multisig: the signer key lives on the user's phone and a guardian key helps with fraud monitoring and recovery. We reviewed the account, proxy and upgrade contracts.
report id
0052
category
Infra & Wallets
language
Cairo
final report
May 16, 2022
lines of code
0
Content

Download audit report

1

Executive Summary

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

development by the Argent team.

Code

Phase Repository Commit

Initial Report Argent Account on StarkNet 7225b83f30 Final Report Argent Account on StarkNet PR#40

Audit assessment
Audit TypeSecurity Review
Initial ReportMay 9, 2022
Final ReportMay 16, 2022
MethodsManual Review
Documentationhttps://github.com/argentlabs/argent-contracts-starknetreadme
Total findings
8
Fixed
4
Acknowledged
4
Mitigated
0
Unresolved
0

Findings by severity

  • Critical0
  • High2
  • Medium0
  • Low0
  • Informational4
  • Best Practices2

2

Audited Files

Cairo Files Reviewed (Initial Review)

Filemd5sum hash
ArgentAccount.cairoc847376ff551a6743569ec4962ce6ab0
Proxy.cairo64ee566dcd609fbf01489f1425263793
Upgradable.cairob59137fdedc9235f820f4d3f85963218

Cairo Files Reviewed (Final Review)

Filemd5sum hash
ArgentAccount.cairo3258c26fe8ed3e9f326145a24075d0e5
Proxy.cairo6c29c9f33aa2fc00669b098428836ccf
Upgradable.cairoSame as initial review

Test Files (Initial Review)

Filemd5sum hash
address_registry.pyfef7f78a2b9a351c2d7e5c54f98f3335
argent_account.pyeef4f9238ab566897b61dd0b0fabfdc0
multicall.py96616847021cfb076235215ef1fcabef
proxy.py8e7a2d275f20c7c15e7b787ecd61584d
struct_hash.py9f647df96c753daeb45d01a67a2451d8

Test Files (Final Review)

Filemd5sum hash
address_registry.pySame as initial review
argent_account.pySame as initial review
multicall.pySame as initial review
proxy.pyb63a3a9c68c6b5312689473777628581
struct_hash.pySame as initial review

4

System Overview

No system overview is included in this report.

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 Contract can be interacted with before initialization

FileFix commitTypeStatus
ArgentAccount.cairo#L160-L235—HighFixed

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.

6.2 The time-lock for escaping a guardian can be bypassed

FileFix commitTypeStatus
ArgentAccount.cairo#L399-L421—HighFixed

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.

6.3 No event emitted during contract initialization

FileFix commitTypeStatus
ArgentAccount.cairo#L145-L167—InfoFixed

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.

6.4 Batch of calls can fail

FileFix commitTypeStatus
ArgentAccount.cairo#L169-L235—InfoAcknowledged

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.

6.5 Signer, Guardian, and Backup Guardian can have the same address

FileFix commitTypeStatus
ArgentAccount.cairo#L125-L135—InfoAcknowledged

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.

6.6 Results from multiple calls are packed into a single array of bytes

FileFix commitTypeStatus
ArgentAccount.cairo#L688-L748—InfoAcknowledged

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.

6.7 State variable is overloaded to indicate if contract has been initialized

FileFix commitTypeStatus
ArgentAccount.cairo#L145-L167—Best PracticesAcknowledged

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.

6.8 Unused functions

FileFix commitTypeStatus
Proxy.cairo
ArgentAccount.cairo
—Best PracticesFixed

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.

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 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.