Omniscia Mantissa Finance Audit

Marketplace Code Style Findings

Marketplace Code Style Findings

MEC-01C: Inefficient mapping Lookups

TypeSeverityLocation
Gas OptimizationMarketplace.sol:L163, L169, L174, L184, L198, L207, L217, L231

Description:

The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.

Example:

contracts/Marketplace.sol
163Listing memory listing = listings[msg.sender][lid];
164require(listing.veMntAmount > 0 && !listing.sold, "No such listing");
165require(bids[msg.sender][lid].bidder == address(0), "Bid already made");
166
167mntLp.approve(address(veMnt), listing.mntLpAmount);
168require(veMnt.releaseVeMnt(msg.sender, listing.mntLpAmount, listing.veMntAmount, listing.veMntRate), "Error");
169delete listings[msg.sender][lid];

Recommendation:

As the lookups internally perform an expensive keccak256 operation, we advise the lookups to be cached wherever possible to a single local declaration that either holds the value of the mapping in case of primitive types or holds a storage pointer to the struct contained.

Alleviation (418ee413ad8e26f7eea383764c19953ff31b2bf3):

The Mantissa Finance team evaluated this exhibit as if it was referring to the data locations of the struct entries rather than the lookups itself.

While a partial remediation has been applied, what our exhibit's original advice is the caching of interim mapping lookups.

To illustrate, a mapping lookup of bids[seller][lid] is performed twice in Marketplace::makeAuctionBid. This can be optimized by storing bids[seller] to a mapping(uint256 => Bid) variable and utilizing it for the two lookups, reducing the number of mapping lookups that need to be performed in the function from 4 to 3.

MEC-02C: Repetitive Value Literals

TypeSeverityLocation
Code StyleMarketplace.sol:L138, L177, L178, L202, L205, L224, L225

Description:

The linked value literals are repeated across the codebase multiple times.

Example:

contracts/Marketplace.sol
138require(percent < 100_00, "Cannot be > 100%");

Recommendation:

We advise each to be set to its dedicated constant variable instead optimizing the legibility of the codebase.

Alleviation (418ee413ad8e26f7eea383764c19953ff31b2bf3):

All repetitive value literals have been replaced by two constant contract-level variables that are aptly named PERCENT_DECIMALS and AMOUNT_DECIMALS, increasing the legibility of the codebase and addressing this exhibit in full.