Security Audit
January 15, 2024
Version 1.0.0
Presented by 0xMacro
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.
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.
Our understanding of the specification was based on the following sources:
The Mintra marketplace utilizes the following actors:
The following source code was reviewed during the audit:
96f014facd5e236806611bfe45ace9cb9baa7038
Specifically, we audited the following contracts within this repository:
Source Code | SHA256 |
---|---|
contracts/prebuilts/marketplace/direct-listings/MintraDirectListingsLogicStandalone.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.
indexed
fields
RoyaltyUpdated
event
platformFeeBpsMint
as a constant
nativeTokenWrapper
is not used
bulkBuyFromListing
calldata
instead of memory
for function arguments
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. |
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
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.
indexed
fields
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.
Indexes are not needed for off-chain components.
RoyaltyUpdated
event
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.
platformFeeBpsMint
as a constant
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.
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.
nativeTokenWrapper
is not used
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.
bulkBuyFromListing
Reference: #L265C2-L302
The function bulkBuyFromListing
can be improved as follows:
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.
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.
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.
calldata
instead of memory
for function arguments
Reference: #L265
bulkBuyFromListing
function uses memory
allocation for its function arguments.
Remediations to Consider
Consider using calldata
instead to save gas costs.
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.