The BasketManager::createHash function will sort the _features array on-chain which incurs a significant gas cost for the caller.
Example:
/**
* @notice This method is used to create a unique hash given a category and list of sub categories.
* @param _tnftType Category identifier.
* @param _location ISO Code for country.
* @param _features List of subcategories.
*/
function createHash(uint256 _tnftType, uint16 _location, uint256[] memory _features) public pure returns (bytes32 hashedFeatures) {
hashedFeatures = keccak256(abi.encodePacked(_tnftType, _location, _features.sort()));
}
Recommendation:
As is standard across the DeFi space, we advise the code to instead expect the _features to already be sorted and to validate their sort order which is gas optimal and would not perform any mutations on the array.
BMR-03C: Inefficient On-Chain Sorting of Features
Description:
The
BasketManager::createHash
function will sort the_features
array on-chain which incurs a significant gas cost for the caller.Example:
Recommendation:
As is standard across the DeFi space, we advise the code to instead expect the
_features
to already be sorted and to validate their sort order which is gas optimal and would not perform any mutations on the array.