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

Bueno.art A-3

Security Audit

July 3rd, 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 June 26th, 2023 to June 27th, 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
Low 2 - - 2
Code Quality 3 - - 3

Bueno.art 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 within this repository:

Contract SHA256
contracts/Bueno1155Drop.sol

8b1b12243eb31d8b8b0e2a80acebd074822eca5ce169e2dc26a89f8ea868c517

contracts/Bueno721Drop.sol

2e082d4d9ff4149382f2f031de3ff9a91310683f98608169b702d2f15630bcb5

contracts/BuenoFactory.sol

46b543bb2f3c8dc594b36b6138ee562ba4b9ba86eba3a198884746d92b60800b

contracts/ICommon.sol

c751010efe8f5605c0b9968c34522f95429f4fb1fc5e358459a5bd999e63ca60

Note: This document contains an audit of the differences between Solidity contracts listed above and previous version from Bueno-Art-2 audit. 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

L-1

maxQuantity is ignored when maxPerWallet is exceeded

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

When minting through allowlist, maxQuantity can be specified for specific wallets, allowing for more granular control over who can mint how many tokens. Meaning that maxQuantity (on wallet-level) should take precedence over maxPerWallet (on phase-level).

This is currently not the case due to the following check in the _checkAllowlistPhaseMintConditions function:

if (
    // phases can have a maxPerWallet
    (phase.maxPerWallet > 0 && updatedAmountMinted > phase.maxPerWallet) ||
    // wallets can have a maxPerWallet encoded in the merkle tree
      (maxQuantity > 0 && updatedAmountMinted > maxQuantity)
    ) {
        revert ExceedMaxPerWallet();
    }

With the above logic, the transaction reverts when maxPerWallet is set and exceeds the amount of mints. Thus, it doesn’t support the case when specific wallets should be allowed to mint more (via maxQuantity) than the mint limit set on phase-level (via maxPerWallet).

Consider changing the above logic so that maxPerWallet is ignored when maxQuantity is specified.

L-2

Users can overpay

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

In Bueno721Drop.mintBatch users can pay more than needed when publicQuantity is set to 0. After the for loop, the following is checked when publicQuantity > 0:

if (publicQuantity > 0) { 
   _checkPublicMintConditions(publicQuantity, balance);
   ...

In this case, overpay is not possible as the balance is checked accordingly inside the _checkPublicMintConditions function. However, if publicQuantity = 0, there is no further check for the remaining balance.

Consider checking that there is no balance left (balance = 0) after the for-loop when publicQuantity = 0.

Q-1

Documentation nitpicks

Topic
Code Quality
Status
Fixed (closed source)
Quality Impact
Low

The documentation says:

updatePhaseSettings allows the creator to change all of the conditions of their minting phase, with the exception of amountMinted and maxSupply

In addition to the above, isActive also cannot be changed via updatePhaseSettings.

Q-2

Contract size exceeds limit

Topic
Code Quality
Status
Fixed (closed source)
Quality Impact
Medium

When compiling the Bueno721Drop contract, the compiler outputs the following message:

Warning: Contract code size is 25037 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
  --> contracts/Bueno721Drop.sol:49:1:
   |
49 | contract Bueno721Drop is
   | ^ (Relevant source part starts here and spans across multiple lines).

Saying that the contract size must not exceed the limit of 24576 bytes. Besides using proxy patterns such as Diamond proxy to address the issue with the maximum size, there are a couple of others, more simpler, solutions on how to reduce the contract size:

  1. Lowering number of runs

    • Runs: 20

      ·---------------------------------|--------------------------------|--------------------------------·
       |  Solc version: 0.8.17           ·  Optimizer enabled: true       ·  Runs: 20                      │
       ··································|································|·································
       |  Contract Name                  ·  Deployed size (KiB) (change)  ·  Initcode size (KiB) (change)  │
      ··································|································|·································
       |  Bueno1155Drop                  ·                     22.332 ()  ·                     22.570 ()  │
       ··································|································|·································
       |  Bueno721Drop                   ·                     **23.998 ()**  ·                     24.236 ()  │
       ·---------------------------------|--------------------------------|--------------------------------·
      
  2. Enabling viaIR flag

    • Runs: 20 and viaIR: true

      ·---------------------------------|--------------------------------|--------------------------------·
       |  Solc version: 0.8.17           ·  Optimizer enabled: true       ·  Runs: 20                      │
       ··································|································|·································
       |  Contract Name                  ·  Deployed size (KiB) (change)  ·  Initcode size (KiB) (change)  │
      ··································|································|·································
       |  Bueno1155Drop                  ·               20.838 (-0.407)  ·               21.037 (-0.407)  │
       ··································|································|·································
       |  Bueno721Drop                   ·               **22.617 (-0.778)**  ·               22.816 (-0.778)  │
       ·---------------------------------|--------------------------------|--------------------------------·
      

    Further details about viaIR flag can be found here.

  3. Refactor code to reuse redundant code blocks

    • Use _mintPhaseTo() and _mintPublicTo() helper functions

      mintPhaseAllowlist(), mintPhase() and mintPhaseTo() share common functionality that can be abstracted away into one internal function _mintPhaseTo(). It would result in the following code:

      /**
       * @notice Mint tokens for an allowlisted phase
       * @dev Calling this function for a phase that doesn't have an allowlist will fail
       */
      function mintPhaseAllowlist(
          uint256 phaseIndex,
          uint64 quantity,
          uint32 maxQuantity,
          bytes32[] calldata proof
      ) external payable {
          uint64 updatedAmountMinted = _checkAllowlistPhaseMintConditions(
              quantity,
              maxQuantity,
              proof,
              phaseIndex,
              msg.value
          );
      
          _mintPhaseTo(msg.sender, quantity, phaseIndex, updatedAmountMinted);
      }
      
      /**
       * @notice Mint tokens for a non-allowlist phase.
       * @dev Calling this function for a phase that has an allowlist will fail
       */
      function mintPhase(uint256 phaseIndex, uint64 quantity) external payable {
          uint64 updatedAmountMinted = _checkPhaseMintConditions(
              msg.sender,
              quantity,
              phaseIndex,
              msg.value
          );
      
          _mintPhaseTo(msg.sender, quantity, phaseIndex, updatedAmountMinted);
      }
      
      /**
       * @notice Mint a token to a specific address from a non-allowlisted sale phase
       * @dev Useful in case the recipient of the tokens is not the sender (gifting, fiat checkout, etc)
       */
      function mintPhaseTo(
          address account,
          uint256 phaseIndex,
          uint64 quantity
      ) external payable {
          uint64 updatedAmountMinted = _checkPhaseMintConditions(
              account,
              quantity,
              phaseIndex,
              msg.value
          );
      
          _mintPhaseTo(account, quantity, phaseIndex, updatedAmountMinted);
      }
      
      /**
       * @notice Mint tokens for a given phase
       * @param account The address to mint the tokens to
       * @param quantity The number of tokens to mint
       * @param phaseIndex The index of the phase to mint from
       * @param updatedAmountMinted The updated amount minted for the phase
       */
      function _mintPhaseTo(
          address account,
          uint64 quantity,
          uint256 phaseIndex,
          uint64 updatedAmountMinted
      ) internal {
          _checkGlobalPerWalletMax(account, quantity);
      
          saleState.phases[phaseIndex].amountMinted += quantity;
          amountMintedForPhase[account][phaseIndex] = updatedAmountMinted;
      
          _mint(account, quantity);
      
          emit TokensMinted(account, quantity);
      }
      

      Similarly, mintPublic() and mintPublicTo() also share repeated functionality which can be extracted out into internal helper function _mintPublicTo(), as such:

      /**
       * @notice Mint tokens in the public sale
       */
      function mintPublic(uint64 quantity) external payable {
          _mintPublicTo(msg.sender, quantity);
      }
      
      /**
       * @notice Mint a token to a specific address from the public sale
       * @dev Useful in case the recipient of the tokens is not the sender (gifting, fiat checkout, etc)
       */
      function mintPublicTo(address account, uint64 quantity) external payable {
          _mintPublicTo(account, quantity);
      }
      
      /**
       * @notice Mint tokens in the public sale
       * @param account The address to mint the tokens to
       * @param quantity The number of tokens to mint
       */
      function _mintPublicTo(address account, uint64 quantity) internal {
          uint64 updatedAmountMinted = _checkPublicMintConditions(
              quantity,
              msg.value
          );
          _checkGlobalPerWalletMax(account, quantity);
      
          baseSettings.amountMinted = updatedAmountMinted;
      
          _mint(account, quantity);
      
          emit TokensMinted(account, quantity);
      }
      

Our tests have shown that the contract size can be reduced to 22.4 KB by applying above optimizations.

Q-3

Redundant wallet parameter in _checkAllowlistPhaseMintConditions()

Topic
Gas
Status
Fixed (closed source)
Quality Impact
Low

In Bueno721Drop.sol, on line 698, msg.sender is used to verify that a given wallet is in allowlist. And later, on line 704, wallet parameter is used to check the amount of NFTs a given wallet has minted.

In both mintPhaseAllowlist and mintBatch when _checkAllowlistPhaseMintConditions() is called the wallet parameter that is being passed refers to msg.sender i.e:

function mintPhaseAllowlist(...) external payable {
    uint64 updatedAmountMinted = _checkAllowlistPhaseMintConditions(
        msg.sender,
        quantity,
        maxQuantity,
        proof,
        phaseIndex,
        msg.value
    );
        ...
}

function mintBatch(...) external payable { ...
    if (phase.merkleRoot == bytes32(0)) {
        ...
    } else {
        updatedAmount = _checkAllowlistPhaseMintConditions(
            msg.sender,
            quantity,
            maxQuantity,
            proof,
            phaseIndex,
            priceForPhase
        );
    }
}

Consider removing wallet parameter from _checkAllowlistPhaseMintConditions() entirely, and use msg.sender instead. This improves readability, saves a little gas, and reduces the contract’s bytecode size.

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.