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

Mintra 1

Security Audit

January 15, 2024

Version 1.0.0

Presented by 0xMacro

Table of Contents

Introduction

This document includes the results of the security audit for Mintra's smart contract code as found in the section titled ‘Source Code’. The security audit was performed by the Macro security team from January 3, 2024 to January 5, 2024.

The purpose of this audit is to review the source code of certain Mintra 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
Code Quality 10 2 - 8
Gas Optimization 2 - - 2

Mintra 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)

The Mintra marketplace utilizes the following actors:

Invariants

Source Code

The following source code was reviewed during the audit:

Specifically, we audited the following contracts within this repository:

Contract SHA256
contracts/prebuilts/marketplace/direct-listings/MintraDirectListingsLogicStandalone.sol

5516e15b71df0a3292e76a1efff532c459e408b19f555475fa2bc520eda92e31

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

Q-1

Rename contract to a more accurate name

Topic
Readability
Status
Quality Impact
Low

Reference: #L23

The current contract name MintraDirectListingsLogicStandalone is quite long and can be shortened. In addition, the term Logic could imply the use of a Proxy, which is not the case for the current implementation.

Remediations to Consider

Consider renaming the contract to a shorter name and remove the term Logic, e.g. rename to MintraDirectListings

Q-2

Missing event for important state change

Topic
Events
Status
Quality Impact
Medium

Reference: #L678

The function setPlatformFeeBps doesn’t emit an event, but it is recommended to emit an event for every state-changing function.

Remediations to Consider

Consider adding an appropriate event for above function.

Q-3

Not all events use indexed fields

Topic
Events
Status
Acknowledged
Quality Impact
Low

Reference: #L32, #L40, #L51

Indexed fields allow off-chain components to quicker accessing them. The following events don’t use indexed fields:

  • MintraNewSale
  • MintraRoyaltyTransfered
  • RoyaltyUpdated

Remediations to Consider

Consider adding indexed keywords to above events where needed.

Response by Mintra

Indexes are not needed for off-chain components.

Q-4

Refactor RoyaltyUpdated event

Topic
Events
Quality Impact
Low

Reference: #L51

The RoyaltyUpdated event is declared as follows:

event RoyaltyUpdated(address assetContract, uint256 royaltyAmount, address royaltyRecipient);   // @audit not royaltyAmount but royaltyBps

The event is lacking a msg.sender value which could be helpful to properly track the address of who updated the royalty. In addition, one of the arguments is named royaltyAmount, where e.g. royaltyBps is more appropriate, as the argument is referring to the bps rather than the actual calculated royalty amount.

Remediations to Consider

Consider refactoring the RoyaltyUpdated event to include above recommendations.

Q-5

Declare platformFeeBpsMint as a constant

Topic
Best Practices
Status
Quality Impact
Low

Reference: #L57

It is recommended to declare variables that cannot be changed as constants. In addition, this saves gas as the variable is stored in the contract’s bytecode.

Remediations to Consider

Consider adding the constant keyword to the platformFeeBpsMint variable declaration.

Q-6

Use constants instead of magic numbers

Topic
Readability
Quality Impact
Low

Reference: #L457, #L647, #L679

The following lines use the number 10000 instead of the declared constant MAX_BPS

457:     require(_royaltyInBasisPoints >= 0 && _royaltyInBasisPoints <= **10000**, "Royalty not in range");
647:     royaltyAmount = (_price * royalties[_tokenAddress].basisPoints) / **10000**;

Consider using MAX_BPS instead.

In addition, the following line uses 369 to define the upper limit for the platform fee:

require(_platformFeeBps <= 369, "Fee not in range");

Consider using a more descriptive constant variable for this value.

Q-7

nativeTokenWrapper is not used

Topic
Readability
Status
Quality Impact
Low

Reference: #L68, #L102

nativeTokenWrapper is declared and has a value assigned in the constructor, but the value is not used anywhere in the code.

Remediations to Consider

Consider removing all occurrences of nativeTokenWrapper from the code.

Q-8

Named return variables don’t need to be explicitly returned

Topic
Best Practice
Status
Acknowledged
Quality Impact
Low

Reference: #L118, #L638

When using named return variables as in the following function, values need to be assigned to the return variable but there is no need to explicitly return the variable itself.

function createListing(ListingParameters calldata _params) external returns (uint256 **listingId**) {

Above function declares a return variable listingId and a value is correctly assigned on #L119, thus there is no need to return the variable at the end of the function on #L156.

The same applies to the processRoyalty function.

Remediations to Consider

Consider removing the lines that return values in createListing and processRoyalty functions.

Q-9

Improve bulkBuyFromListing

Topic
Readability
Quality Impact
Medium

Reference: #L265C2-L302

The function bulkBuyFromListing can be improved as follows:

  1. The function performs the following logic for buys with currency specified as NATIVE_TOKEN:
282:   if (_currency[i] == CurrencyTransferLib.NATIVE_TOKEN) {
283:       //calculate total amount for items being sold for PLS
284:       if (_directListingsStorage().currencyPriceForListing[_listingId[i]][_currency[i]] > 0) {
285:           price =
286:               _quantity[i] *
287:               _directListingsStorage().currencyPriceForListing[_listingId[i]][_currency[i]];
288:       } else {
289:           require(_currency[i] == listing.currency, "Paying in invalid currency.");
290:           price = _quantity[i] * listing.pricePerToken;
291:       }
292:
293:       totalAmountPls += price;
294:   }

The above logic can be simplified by removing #283-#291 entirely and replacing the calculated price with _expectedTotalPrice[i] on line 293, leading to:

if (_currency[i] == CurrencyTransferLib.NATIVE_TOKEN) {
   totalAmountPls += _expectedTotalPrice[i];
}

Removing #283-#291 works as the logic is redundant and the same check is done in the internal _buyFromListing function which is called subsequently. In addition, the check on line #L349 ensures that the calculated price must be equal to the _expectedTotalPrice.

Consider refactoring bulkBuyFromListing function as shown above.

  1. Line #L301 ensures that the correct amount for msg.value was sent:
require(msg.value == totalAmountPls || (totalAmountPls == 0 && msg.value == 0), "Incorrect PLS amount sent");

However, the right branch of the OR operator is redundant as the case of totalAmountPls == 0 && msg.value == 0 is already covered on the left check.

Consider removing the right branch from the require statement.

Above recommendations increase the code readability and above that, also reduce the gas costs.

Q-10

Follow Solidity naming convention for function

Topic
Readability
Status
Quality Impact
Low

Reference: #L638, #L660

Functions:

According to Solidity naming conventions, private and internal functions should be prefixed using an underscore. This is not the case for the processRoyalty and isERC2981 functions.

Remediations to Consider

Consider renaming processRoyalty and isERC2981 functions to _processRoyalty and _isERC2981 respectively.

G-1

Public functions not called internally

Topic
Best Practice
Status
Gas Savings
Low

Reference: #L451, #L678

The following functions can be declared as external instead of public, as they are not called internally by any other function:

  • createOrUpdateRoyalty
  • setPlatformFeeBps
G-2

Use calldata instead of memory for function arguments

Topic
Best Practice
Status
Gas Savings
Low

Reference: #L265

bulkBuyFromListing function uses memory allocation for its function arguments.

Remediations to Consider

Consider using calldata instead to save gas costs.

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