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

Bueno.art A-2

Security Audit

March 31st, 2023

Version 1.0.0

Presented by 0xMacro

Table of Contents

Introduction

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.

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

Specification

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

Trust Model, Assumptions, and Accepted Risks (TMAAR)

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:


Specifically, we'd like to point out that the 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.

Source Code

The following source code was reviewed during the audit:

Specifically, we audited the following contracts within this repository:

Source Code SHA256
contracts/Bueno1155Drop.sol

74944a81649225fc31a7911147f4cb6bcb3139942f31b71375e829691592a918

contracts/BuenoFactory.sol

d4d2263d5ff04e4a4126f9e7b4c9c983757bccae173c47e755e314e3e8afbb1a

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

Next token id can be minted for free before the actual token has been created

Topic
Use Cases
Status
Fixed (closed source)
Impact
High
Likelihood
High

Description

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.

Remediations to Consider

Only allow minting of tokens for ids smaller than _currentTokenId.

H-1

Airdrops don’t work when maxSupply is not capped

Topic
Spec
Status
Fixed (closed source)
Impact
High
Likelihood
High

Description

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.

Remediations to Consider

Only apply above revert logic when maxSupply > 0.

H-2

Tokens can be created with shares > 100, resulting in unfair distribution of revenue

Topic
Incentive Design
Status
Fixed (closed source)
Impact
High
Likelihood
Medium

Description

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:

  1. Payees can be specified with 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 contract
  2. Payees can be specified with shareTotal > 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).

Remediations to Consider

Verify payment settings in createDropToken and createDropTokens by adding _verifyPaymentSplitterSettings to these functions.

M-1

Tokens with no mintEnd can’t be minted

Topic
Spec
Status
Fixed (closed source)
Impact
Low
Likelihood
High

Description

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.

Remediations to Consider

Change above logic so that tokens with startEnd > 0 and mintEnd == 0 are not being reverted.

M-2

A malicious user can take advantage of possible overflow in amountMinted

Topic
Incentive Design
Status
Fixed (closed source)
Impact
Medium
Likelihood
Medium

Description

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:

  1. The number of minted tokens can exceed maxSupply, which breaks the protocol's invariant of amountMinted ≤ maxSupply.
  2. An attacker can trick the creator into assuming that no tokens have been minted. Consider the following scenario:
    1. The creator creates a token with an infinite supply (maxSupply = 0).
    2. A malicious user takes advantage of overflow and mints max(uint32) tokens, thereby setting amountMinted back to 0.
    3. As 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.
    4. The creator holds a number of tokens equal to max(uint32), which suddenly become worth a fortune.

Remediations to Consider

Don’t use unchecked arithmetic in above code logic.

L-1

Airdropping can be griefed

Topic
Griefing
Status
Fixed (closed source)
Impact
Low
Likelihood
Low

Description

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.

Remediations to Consider

  • Switch from a push method of transferring tokens, to a pull method. This makes users claim their airdrop and prevents malicious users from preventing others from receiving theirs.
  • Or explicitly pass in the amount of gas for the transfer, ensuring there is enough gas to allow the contract to execute normal operations, but not provide the entire gas of the transaction that can be used maliciously.
Response by Bueno.art

We will ensure a reasonable gas limit is provided on the front end, which won’t require any contract mitigations.

L-2

releaseBatch fails if one of the payees has already released

Topic
Use Cases
Status
Fixed (closed source)
Impact
Low
Likelihood
Low

Description

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();
}

Remediations to Consider

Don’t revert for amount == 0 in release function.

L-3

Settings for not next token id can be updated

Topic
Protocol Design
Status
Fixed (closed source)
Impact
Low
Likelihood
Low

Description

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.

Remediations to Consider

Only allow updates for token ids smaller than _currentTokenId.

L-4

Missing validation of token settings

Topic
Input Validation
Status
Fixed (closed source)
Impact
Low
Likelihood
Low

Description

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.

Remediations to Consider

Add validation checks to only allow meaningful token settings.

Response by Bueno.art

The following fields/cases are intentionally left invalidated

  • mintStart in the past
  • uuid
Q-1

Rename index param of airdropToken function

Topic
Naming
Status
Fixed (closed source)
Quality Impact
Low

Consider renaming the index parameter to id in the airdropToken function to match the naming convention used in all the other functions parameter.

Q-2

Inaccurate comment

Topic
Documentation
Status
Fixed (closed source)
Quality Impact
Low

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.

Q-3

Missing event for updateFallbackPaymentSplitterSettings

Topic
Best Practices
Status
Fixed (closed source)
Quality Impact
Low

Generally it is considered a good practice to emit an event on state changes. Consider emitting an event when fallBackPaymentSplitterSettings are being changed.

G-1

totalReleased() can be set to external

Topic
Best Practices
Status
Fixed (closed source)
Gas Savings
Low

totalReleased() is defined as public but not used anywhere else in code. Consider saving gas costs by using external keyword instead of public.

G-2

No need to store uuid in separate memory var

Topic
Variable Usage
Status
Fixed (closed source)
Gas Savings
Low

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.

G-3

Remove amountMinted setting param

Topic
Variable Usage
Status
Wont Do
Gas Savings
Low

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.

Response by Bueno.art

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.

I-1

UUID uniqueness relies on off-chain components

Topic
Protocol Design
Status
Wont Do
Impact
Informational

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.

Response by Bueno.art

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.

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