Reach out for an audit or to learn more about Macro
or Message on Telegram

thirdweb A-8

Security Audit

January 30th, 2023

Version 1.0.0

Presented by 0xMacro

Table of Contents

Introduction

This document includes the results of the security audit for thirdweb's smart contract code as found in the section titled ‘Source Code’. The security audit was performed by the Macro security team from December 26, 2022 to January 10, 2023.

The purpose of this audit is to review the source code of certain thirdweb Solidity contracts, and provide feedback on the design, architecture, and quality of the source code with an emphasis on validating the correctness and security of the software in its entirety.

Disclaimer: While Macro’s review is comprehensive and has surfaced some changes that should be made to the source code, this audit should not solely be relied upon for security, as no single audit is guaranteed to catch all possible bugs.

Overall Assessment

The following is an aggregation of issues found by the Macro Audit team:

Severity Count Acknowledged Won't Do Addressed
Critical 1 - - 1
High 2 - - 2
Medium 3 - - 3
Low 1 - - 1
Code Quality 1 - 1 -

thirdweb was quick to respond to these issues.

Specification

Our understanding of the specification was based on the following sources:

Source Code

The following source code was reviewed during the audit:

Specifically, we audited the following contracts as part of Wallet Account contracts audit:

Contract SHA256
Account.sol

27f178383dce8c174544eab00066ccd29f96098a657b4fd16544a147f76341b3

AccountAdmin.sol

da613cf128749a882649ce81bd8c0316081b68466d7c1c96ee312c9160a59d12

IAccount.sol

8b99adba4bd4a963c36573b469c460adcaef2200e0cd1e7c406183a0918833d8

IAccountAdmin.sol

351531c38f6fe322b42c6fbb314a482ba6edba6d282bff4f3a99d478d3248018

extension/Multicall.sol

3ec9119c7840d29e4c61092bbbf8f63e6c5204139490ed44d81bd348005bead8

extension/PermissionsEnumerable.sol

e11e8f40eb775c0ccc34b746b03a08e584f626b94fdde1396f538c3a76c487d4

openzeppelin-presets/metatx/ERC2771ContextUpgradeable.sol

4ef0ce1601048c10a4b0fdc3247062be8f1a9ca0441c862ddfadc16251a31edb

We audited the following contracts as part of SignatureDrop ERC-1155 contract audit:

Contract SHA256
openzeppelin-presets/metatx/ERC2771ContextUpgradeable.sol

4ef0ce1601048c10a4b0fdc3247062be8f1a9ca0441c862ddfadc16251a31edb

lib/CurrencyTransferLib.sol

ab7e40d1b333d675e23d9d4a4c70836c508b2e8b890cf1c6f3dc554424d1215d

lib/TWStrings.sol

d1fa327e26529fe1048a230a9fdaa183da21f9418729b665e0d57f68f136de0b

extension/ContractMetadata.sol

e2b7ba9418f86c2049b1ad85faae6d019bcf432307b61f36eeb025d3be77c615

extension/PlatformFee.sol

3d9b5d76e87e5d28f2ddf0ff52f0b2cbbc66a9987badd3ae13b2a9953919e36f

extension/Royalty.sol

f64dbb92dee9bfbe4ad6315fe9a1e174a9c7bd63fd84d17982b893dc6d5e47c8

extension/PrimarySale.sol

300b058b3d07edd1ec662fae8f2496500392eb2d14c9a9f3709d210f75ab37d6

extension/Ownable.sol

d28288423c41e9bcc22c4861dc6901087b7a2500a8415c39580de4f803591005

extension/LazyMint.sol

218107fe08602e304fd149f431978968aa7fdb9e435e09ea46b4b41c9fa7d028

extension/PermissionsEnumerable.sol

e11e8f40eb775c0ccc34b746b03a08e584f626b94fdde1396f538c3a76c487d4

extension/Drop1155.sol

8e961ee74cc169780902223f15cb2641768d0d23a3290f0af7bf2ff326ad9dd4

extension/SignatureMintERC1155Upgradeable.sol

e694e6c8204c373d6cd69a6eaee8fa5fcac000bd1923de25c202a156ecc6727c

SignatureDrop1155.sol

b446921a0ad9df016d4076d7721fb43ea378e0921d8ce5b818789bd370b00d68

SignatureDrop1155OperatorCheck.sol

2b2a1a00610c96a38a30cff147e13ca0b35201916310264573b7c5fb0be5f444

Note: This document contains an audit solely of the Solidity contracts listed above. Specifically, the audit pertains only to the contracts themselves, and does not pertain to any other programs or scripts, including deployment scripts.

Issue Descriptions and Recommendations

Click on an issue to jump to it, or scroll down to see them all.

Security Level Reference

We quantify issues in three parts:

  1. The high/medium/low/spec-breaking impact of the issue:
    • How bad things can get (for a vulnerability)
    • The significance of an improvement (for a code quality issue)
    • The amount of gas saved (for a gas optimization)
  2. The high/medium/low likelihood of the issue:
    • How likely is the issue to occur (for a vulnerability)
  3. The overall critical/high/medium/low severity of the issue.

This third part – the severity level – is a summary of how much consideration the client should give to fixing the issue. We assign severity according to the table of guidelines below:

Severity Description
(C-x)
Critical

We recommend the client must fix the issue, no matter what, because not fixing would mean significant funds/assets WILL be lost.

(H-x)
High

We recommend the client must address the issue, no matter what, because not fixing would be very bad, or some funds/assets will be lost, or the code’s behavior is against the provided spec.

(M-x)
Medium

We recommend the client to seriously consider fixing the issue, as the implications of not fixing the issue are severe enough to impact the project significantly, albiet not in an existential manner.

(L-x)
Low

The risk is small, unlikely, or may not relevant to the project in a meaningful way.

Whether or not the project wants to develop a fix is up to the goals and needs of the project.

(Q-x)
Code Quality

The issue identified does not pose any obvious risk, but fixing could improve overall code quality, on-chain composability, developer ergonomics, or even certain aspects of protocol design.

(I-x)
Informational

Warnings and things to keep in mind when operating the protocol. No immediate action required.

(G-x)
Gas Optimizations

The presented optimization suggestion would save an amount of gas significant enough, in our opinion, to be worth the development cost of implementing it.

Issue Details

C-1

Cannot withdraw native tokens from Account

Topic
Locked Assets
Status
Impact
High
Likelihood
High

Account::_validateCallConditions contains require(msg.value == _value, "Account: incorrect value sent.");. This require statement enforces that only the same amount of ether that just came in with msg.value can be sent out using the value argument. The implications of this require statement are that existing ether in an Account can never be sent out, effectively making ether withdrawals from an Account impossible.

Any initial account balances sent in to AccountAdmin::createAccount will also be locked.

Remediations to Consider

Consider removing require(msg.value == _value, "Account: incorrect value sent."); from Account::_validateCallConditions.

H-1

Removing the last signer will lock assets in the contract

Topic
Locked Assets
Status
Impact
High
Likelihood
Medium
commits: 05f24cdc457b814b716637431a29e46f215e37b1, 771ca3938ca3d2dc8648ffcb9664646b6ba7e317

Removing roles in Account.sol executes without making any checks on current signers, and there is no mechanism to rescue locked funds from the contract. This may result in bricking the account if a signer (maliciously or not) removes the last account with sufficient permissions to withdraw funds.

Since these contracts are supposed to be used by a wide variety of users and they support external calls, we believe the probability of a user removing the last signer is not negligible.

Remediations to Consider

There is no easy way to keep track of all signers with permission to withdraw funds in the current setup. Because of that, we recommend enforcing at least one admin signer with full permissions to exist after every removeAdmin().

H-2

Arbitrary code execution facilitated by isApprovedForFunction / approveSignerForFunction

Topic
Protocol Design
Status
Impact
High
Likelihood
Medium

Once a signer has a function selector in isApprovedForFunction(), they can run any arbitrary code on any contract.

One example: If a signer is approved to call an arbitrary payable function on any contract the signer can steal all native ether from the Account by deploying a contract with an identical function selector.

Remediations to Consider

Consider removing isApprovedForFunction() and only allowing calls to approved contracts.

M-1

The signer registry in AccountAdmin can go out of sync with roles in Account

Topic
Interoperability
Status
Impact
Medium
Likelihood
Medium

(add/remove){Role}() in Account.sol are fail-safe functions, and they don’t revert in cases where underlying calls to AccountAdmin.sol fail. Instead, they set the role in Account.sol and silently catch the reverted error. This may cause AccountAdmin and Account contracts to go out of sync, and a signer with a role in Account may lose its entry in the signer registry in AccountAdmin.

The issue may cause a signer with a role not to be able to relay() calls in AccountAdmin, and a discrepancy between two contracts because getAllAccountsOfSigner() and getAllSignersOfAccount() will miss a signer with the correct role.

It’s worth mentioning that if Account.sol is used as a standalone wallet contract (without a controller), the try-catch statement would always revert, as stated in the solidity documentation:

If an error happens during the decoding of the return data inside a try/catch-statement, this causes an exception in the currently executing contract and because of that, it is not caught in the catch clause.

Remediations to Consider

Prevent addresses from having both roles in AccountAdmin as outlined in the code snippet below. This will still allow for the use case where an Account exists without an AccountAdmin, but keeps updates when there are both atomic. Also, consider adding a check in addSigner that the signer doesn’t already have the Admin role, and adding a check in addAdmin that the signer doesn’t already have the signer role. This way, with or without an AccountAdmin , Account will behave identically.

M-2

Signers approved to interact with the Account contract can demote admins

Topic
Use Cases
Status
Impact
High
Likelihood
Low

Account admins can allow or disallow signers to interact with any function in a contract by calling approveSignerForContract(). If an admin allows a signer to interact with the Account contract itself, that signer will acquire the same permissions as admins, allowing them to demote the previous admin and essentially gain control over the account.

Note: This needs to be performed by an admin, but since the proper way to give those permissions would be adding a new admin, this could lead to unintentional takeovers from signers.

Remediations to Consider:

Disallow approveSignerForContract with the Account as a _target.

M-3

Native tokens can get locked in the contract

Topic
Locked Assets
Status
Impact
Medium
Likelihood
Low

In SignatureDrop1155OperatorCheck.sol and SignatureDrop1155.sol contracts, signature mint requests can include pricePerToken and a currency. This price can be in native tokens (e.g. ETH) or any other ERC20 tokens.

Suppose in a mint request, the currency in a request is different from the native token, and by mistake, a user calls mintWithSignature() sending a msg.value =! 0. In that case, this transaction will succeed, and the native tokens sent will be locked inside the contract.

Remediations to Consider:

Consider adding a check to verify that, for requests with non-native token claim prices, the msg.value is 0.

L-1

Accounts can call addSignerToAccount with arbitrary parameters

Topic
Interoperability
Status
Impact
Spec Breaking
Likelihood
Low

AccountAdmin.sol addSignerToAccount() function has the modifier onlyAssociatedAccount as a restriction. However, any Account created from the AccountAdmin can call this function with arbitrary accountId and signer as parameters, changing the internal registry inside AccountAdmin.sol from other accounts since the pairHashToAccount mapping will be set to a value even if the Account does not correspond to that accountId.

Any Account can deny other's account creation calls by adding signers in the AccoundAdmin.sol contract. Also, applications that rely on the external view functions of this contract could become out of sync with the account's actual permissions.

Remediations to Consider:

Saving the accountId inside Account.sol, and adding a check that asserts the Account calling the function corresponds to the respective accountId.

Q-1

setMaxTotalSupply and setSaleRecipientForToken do not check for new input data

Topic
Input Validation
Status
Wont Do
Quality Impact
Low

This applies to both, SignatureDrop1155OperatorCheck.sol and SignatureDrop1155.sol contracts. An event from these functions will be emitted even if the “new” value was already set. Consider checking that the input parameters are different from the state values.

Disclaimer

Macro makes no warranties, either express, implied, statutory, or otherwise, with respect to the services or deliverables provided in this report, and Macro specifically disclaims all implied warranties of merchantability, fitness for a particular purpose, noninfringement and those arising from a course of dealing, usage or trade with respect thereto, and all such warranties are hereby excluded to the fullest extent permitted by law.

Macro will not be liable for any lost profits, business, contracts, revenue, goodwill, production, anticipated savings, loss of data, or costs of procurement of substitute goods or services or for any claim or demand by any other party. In no event will Macro be liable for consequential, incidental, special, indirect, or exemplary damages arising out of this agreement or any work statement, however caused and (to the fullest extent permitted by law) under any theory of liability (including negligence), even if Macro has been advised of the possibility of such damages.

The scope of this report and review is limited to a review of only the code presented by the thirdweb team and only the source code Macro notes as being within the scope of Macro’s review within this report. This report does not include an audit of the deployment scripts used to deploy the Solidity contracts in the repository corresponding to this audit. Specifically, for the avoidance of doubt, this report does not constitute investment advice, is not intended to be relied upon as investment advice, is not an endorsement of this project or team, and it is not a guarantee as to the absolute security of the project. In this report you may through hypertext or other computer links, gain access to websites operated by persons other than Macro. Such hyperlinks are provided for your reference and convenience only, and are the exclusive responsibility of such websites’ owners. You agree that Macro is not responsible for the content or operation of such websites, and that Macro shall have no liability to your or any other person or entity for the use of third party websites. Macro assumes no responsibility for the use of third party software and shall have no liability whatsoever to any person or entity for the accuracy or completeness of any outcome generated by such software.