Security Audit
January 30th, 2023
Version 1.0.0
Presented by 0xMacro
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.
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.
Our understanding of the specification was based on the following sources:
The following source code was reviewed during the audit:
c03ba94894bc5c9e72b5ba1e6210656866951153
016a98fda9a873257aa466019ac02d75858301dd
Specifically, we audited the following contracts as part of Wallet Account contracts audit:
Contract | SHA256 |
---|---|
Account.sol |
|
AccountAdmin.sol |
|
IAccount.sol |
|
IAccountAdmin.sol |
|
extension/Multicall.sol |
|
extension/PermissionsEnumerable.sol |
|
openzeppelin-presets/metatx/ERC2771ContextUpgradeable.sol |
|
We audited the following contracts as part of SignatureDrop ERC-1155 contract audit:
Contract | SHA256 |
---|---|
openzeppelin-presets/metatx/ERC2771ContextUpgradeable.sol |
|
lib/CurrencyTransferLib.sol |
|
lib/TWStrings.sol |
|
extension/ContractMetadata.sol |
|
extension/PlatformFee.sol |
|
extension/Royalty.sol |
|
extension/PrimarySale.sol |
|
extension/Ownable.sol |
|
extension/LazyMint.sol |
|
extension/PermissionsEnumerable.sol |
|
extension/Drop1155.sol |
|
extension/SignatureMintERC1155Upgradeable.sol |
|
SignatureDrop1155.sol |
|
SignatureDrop1155OperatorCheck.sol |
|
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.
Click on an issue to jump to it, or scroll down to see them all.
isApprovedForFunction
/ approveSignerForFunction
addSignerToAccount
with arbitrary parameters
setMaxTotalSupply
and setSaleRecipientForToken
do not check for new input data
We quantify issues in three parts:
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. |
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
.
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()
.
isApprovedForFunction
/ approveSignerForFunction
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.
(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.
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
.
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
.
addSignerToAccount
with arbitrary parameters
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
.
setMaxTotalSupply
and setSaleRecipientForToken
do not check for new input data
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.
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.