Security Audit
March 31st, 2023
Version 1.0.0
Presented by 0xMacro
This document includes the results of the security audit for Bueno.art's smart contract code as found in the section titled ‘Source Code’. The security audit was performed by the Macro security team from March 16, 2023 to March 22, 2023.
The purpose of this audit is to review the source code of certain Bueno.art 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 | 2 | - | - | 2 |
| Low | 4 | - | - | 4 |
| Code Quality | 3 | - | - | 3 |
| Informational | 1 | - | 1 | - |
| Gas Optimization | 3 | - | 1 | 2 |
Bueno.art was quick to respond to these issues.
Our understanding of the specification was based on the following sources:
A clone factory is used to deploy Bueno1155Drop.sol contract. The address that is used to deploy the contract becomes the owner, and will have the following privileges:
uri of an NFT can be changed by the owner at any time using the setUri function.
While this is a common practice among NFT projects that handle metadata off-chain, minters have to trust the owner to not change the uri to something malicious or inappropriate.
The following source code was reviewed during the audit:
1a7d19ccd80547daa4fb1940f968c37aca0a7a93
Specifically, we audited the following contracts within this repository:
| Source Code | SHA256 |
|---|---|
| contracts/Bueno1155Drop.sol |
|
| contracts/BuenoFactory.sol |
|
Click on an issue to jump to it, or scroll down to see them all.
maxSupply is not capped
mintEnd can’t be minted
amountMinted
releaseBatch fails if one of the payees has already released
index param of airdropToken function
updateFallbackPaymentSplitterSettings
totalReleased() can be set to external
uuid in separate memory var
amountMinted setting param
UUID uniqueness relies on off-chain components
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. |
Tokens can be minted via mintToken, mintTokenTo, or mintTokenAllowlist functions. All of those functions call _mintAfterChecks to verify certain conditions before minting. The _mintAfterChecks function verifies the specified token id as follows:
if (id > _currentTokenId) {
revert InvalidToken();
}
According to the check above, _currentTokenId can be minted because it only reverts for id greater than _currentTokenId. This is problematic because _currentTokenId refers to the next token ID that will be created (rather than the last token ID that has been created).
This allows for the minting of the next token ID before the actual token has been created through the createDropToken or createDropTokens functions.
Consider the following scenario: a creator calls createDropToken to create a token with an amount of 100 and a price of 10 ether. A malicious user could front-run the transaction and pre-mint all 100 tokens by specifying the _currentTokenId when calling mintToken. Since token settings are not yet set for the token with ID _currentTokenId, the user can mint all 100 tokens for free.
Only allow minting of tokens for ids smaller than _currentTokenId.
maxSupply is not capped
According to specification, maxSupply should behave as follows:
A token with 0 supply is considered to have infinite possible supply (though it can still be bounded by mintEnd)
However, the airdropTokenfunction contains the following logic:
if (updatedAmountMinted > token.maxSupply) {
revert SoldOut();
}
As per the above logic, airdrops using tokens with maxSupply == 0 will revert with error SoldOut().
In addition, once a token has been minted, maxSupply can’t be changed anymore via updateTokenSettingsByIndex function - giving the issue a high severity impact.
Only apply above revert logic when maxSupply > 0.
As stated in the readme and checked in the _verifyPaymentSplitterSettings function, the sum of all payees shares must be 100:
if (shareTotal != 100) {
revert InvalidPaymentSplitterSettings();
}
This is correctly checked when adding payment settings via the initialize, updatePaymentSplitterSettingsByIndex, and updateFallbackPaymentSplitterSettings. However, the call to _verifyPaymentSplitterSettings is missing when creating tokens via createDropToken and createDropTokens. This allows creating payment settings that don’t comply to the contract’s invariant of shareTotal == 100.
This can have the following consequences:
shares == 0: Once a token with price > 0 gets minted, the paid ether is not added to the payee’s revenue - resulting in the paid amount being locked in the contractshareTotal > 100: In this case, payees will receive revenue that exceeds the allocated amount for the associated token id. As a result, other payees will fail to release their entitled revenue as there is not sufficient ether amount left in the contract.Note that specifying invalid payment settings can be set unintentionally by the owner, but can also happen due to a logic bug on the frontend (which is not uncommon).
Verify payment settings in createDropToken and createDropTokens by adding _verifyPaymentSplitterSettings to these functions.
mintEnd can’t be minted
In _mintAfterCheck, the following code validates the start/end time of minting:
if (
(token.mintStart > 0 || token.mintEnd > 0) &&
(block.timestamp < token.mintStart ||
block.timestamp > token.mintEnd)
) {
revert MintNotActive();
}
The specification defines tokens with mintEnd == 0 as follows:
A token with no mintEnd is assumed to be mintable forever
However, the above code breaks the specification as the line block.timestamp > token.mintEnd always evaluates to true when mintEnd is not specified, resulting in the transaction to revert. As a consequence, tokens with no mintEnd specified can’t be minted.
Note that the impact of this issue is considered low severity, as it can be remedied by updating token settings via updateTokenSettingsByIndex.
Change above logic so that tokens with startEnd > 0 and mintEnd == 0 are not being reverted.
amountMinted
An overflow can happen in _mintAfterChecks on the following lines:
unchecked {
token.amountMinted += quantity;
_mintBalanceByTokenId[id][account] += quantity;
}
A malicious user can cause an overflow on amountMinted by minting more than max(uint32)-1 tokens. This results in incorrect accounting of amountMinted, which can have various consequences, such as:
maxSupply, which breaks the protocol's invariant of amountMinted ≤ maxSupply.maxSupply = 0).max(uint32) tokens, thereby setting amountMinted back to 0.amountMinted is now equal to 0, the creator wrongly assumes that no tokens have been minted so far and may change the max supply or set the price > 0.max(uint32), which suddenly become worth a fortune.Don’t use unchecked arithmetic in above code logic.
The airdropToken function iterates over an array of provided recipients and mints the respective tokens to each recipient. During mint, if the recipient is a contract, ERC1155Upgradeable.sol calls onERC1155Received and gives execution control to the recipient contract. This means that the recipient contract can execute malicious code, such as consuming all the provided gas. If this occurs, calls to airdropToken could cost substantially more than expected or exceed the block gas limit, preventing calls from executing.
The impact of this vulnerability is considered low severity, as airdropToken can be called again by omitting the griefer contract.
We will ensure a reasonable gas limit is provided on the front end, which won’t require any contract mitigations.
releaseBatch fails if one of the payees has already released
The releaseBatch function iterates over the provided payees array and calls release for each payee. However, if a payee has already released the funds, a call to release will revert and cause the entire releaseBatch function to fail.
uint256 amount = releasable(payee);
if (amount == 0) {
revert NoFundsToRelease();
}
Don’t revert for amount == 0 in release function.
In updateTokenSettingsByIndexand updatePaymentSplitterSettingsByIndex, the following check should prevent non-existing token ids from being updated:
if (id > _currentTokenId) {
revert InvalidToken();
}
According to the check above, updates to _currentTokenId are allowed. However, _currentTokenId has not yet been created and refers to the next token that will be created. Therefore, a subsequent call to createDropToken or createDropTokens would overwrite the previously defined settings.
Only allow updates for token ids smaller than _currentTokenId.
Token settings can be specified by calling initialize, createDropToken, and createDropTokens. However, these functions do not check whether the settings passed are valid. For instance, if a token is created with mintEnd < block.timestamp, no tokens can ever be minted. Similarly, if amountMinted > 0 on token creation, amountMinted would be wrongly tracked.
Add validation checks to only allow meaningful token settings.
The following fields/cases are intentionally left invalidated
- mintStart in the past
- uuid
index param of airdropToken function
Consider renaming the index parameter to id in the airdropToken function to match the naming convention used in all the other functions parameter.
In calculateRevenueSplit function, there is the following comment:
// each token can have different payment splitter settings, and those settings can change while mint is occurring
// therefore we need to do some revenue accounting at the time of mint based on the price paid
However, this comment is incorrect, since payment splitter settings cannot be modified after a token has been minted.
updateFallbackPaymentSplitterSettings
Generally it is considered a good practice to emit an event on state changes. Consider emitting an event when fallBackPaymentSplitterSettings are being changed.
totalReleased() can be set to external
totalReleased() is defined as public but not used anywhere else in code. Consider saving gas costs by using external keyword instead of public.
uuid in separate memory var
In createDropTokens, uuid is stored in memory variable and only used once when emitting the event. Consider saving gas costs by using settings.uuid instead.
amountMinted setting param
On every mint, amountMinted is increased by the number of minted tokens, thus increasing gas costs as a storage variable needs to be updated. At the same time, ERC1155SupplyUpgradeable tracks the totalSupply per token id. Consider removing amountMinted and use totalSupply(uint256 id) instead to save gas costs.
This would violate the desired spec in the scenario where burning is enabled and a token is created with supply, as if a token sold out, users who burn their tokens would make it possible to mint more tokens. This could put the minting experience indefinitely in limbo, where most artists would like minting to end once a number is reached.
UUID uniqueness relies on off-chain components
Each token created via the Bueno1155Drop contract is assigned a unique UUID to identify it within the Bueno ecosystem. It is important to note that the uniqueness of the UUID is not checked on-chain and relies on properly functioning off-chain components.
We acknowledge this is off-chain data, and this is to support the fact that metadata is technically stored off-chain as well. As an invalid UUID/duplicate won’t affect anything pertaining to the minting or contract functions themselves, and considering the gas impact of including the mapping, we’ve opted to accept this trade-off.
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 Bueno.art 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.