Omniscia Tangible Audit
OnSaleTracker Code Style Findings
OnSaleTracker Code Style Findings
OST-01C: Inefficient Array Shifts
Type | Severity | Location |
---|---|---|
Gas Optimization | OnSaleTracker.sol:L113, L116, L117, L130, L133, L135 |
Description:
The referenced array shift operations will assign the last element of the array to the index of the element to-be-removed, however, these operations are inefficiently performed when the index of the element-to-be-removed is the actual last element of the array.
Example:
109function _removeCurrentlySellingTnft(ITangibleNFT tnft, uint256 index) internal {110 require(index < tnftTokensOnSale[tnft].length, "IndexT");111
112 //take last token113 uint256 tokenId = tnftTokensOnSale[tnft][tnftTokensOnSale[tnft].length - 1];114
115 //replace it with the one we are removing116 tnftTokensOnSale[tnft][index] = tokenId;117 //set it's new index in saleData118 tnftSaleMapper[tnft][tokenId].indexInCurrentlySelling = index;119 tnftTokensOnSale[tnft].pop();120}
Recommendation:
We advise all operations to avoid shifting elements if the element-to-be-removed is the last element of the array, performing a direct pop
operation instead.
Alleviation (1f394a00cc2ed1dc2020a9c07f982cff9029077d):
The array pop optimization has been properly applied to both referenced functions, optimizing the codebase as advised.
OST-02C: Inefficient mapping
Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | OnSaleTracker.sol:L74, L77, L78, L82, L86, L91, L93, L110, L113, L116, L119 |
Description:
The linked statements perform key-based lookup operations on mapping
declarations from storage multiple times for the same key redundantly.
Example:
109function _removeCurrentlySellingTnft(ITangibleNFT tnft, uint256 index) internal {110 require(index < tnftTokensOnSale[tnft].length, "IndexT");111
112 //take last token113 uint256 tokenId = tnftTokensOnSale[tnft][tnftTokensOnSale[tnft].length - 1];114
115 //replace it with the one we are removing116 tnftTokensOnSale[tnft][index] = tokenId;117 //set it's new index in saleData118 tnftSaleMapper[tnft][tokenId].indexInCurrentlySelling = index;119 tnftTokensOnSale[tnft].pop();120}
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 (1f394a00cc2ed1dc2020a9c07f982cff9029077d):
All referenced inefficient mapping
lookups have been optimized to the greatest extent possible, significantly reducing the gas cost of the functions the statements were located in.
OST-03C: Inexistent Error Message
Type | Severity | Location |
---|---|---|
Code Style | OnSaleTracker.sol:L69 |
Description:
The linked require
check has no error message explicitly defined.
Example:
69require(msg.sender == marketplace);
Recommendation:
We advise one to be set so to increase the legibility of the codebase and aid in validating the require
check's condition.
Alleviation (2ad448279d9e8e4b6edd94bcd2eb22129b6f7357):
An explicit error message has been introduced to the referenced require
check, addressing this exhibit.
OST-04C: Redundant Parenthesis Statement
Type | Severity | Location |
---|---|---|
Code Style | OnSaleTracker.sol:L86 |
Description:
The referenced statement is redundantly wrapped in parenthesis (()
).
Example:
86(tnftTokensOnSale[tnft].length - 1)
Recommendation:
We advise them to be safely omitted, increasing the legibility of the codebase.
Alleviation (2ad448279d9e8e4b6edd94bcd2eb22129b6f7357):
The redundant parenthesis in the referenced statement have been safely omitted.
OST-05C: Suboptimal Struct Declaration Styles
Type | Severity | Location |
---|---|---|
Code Style | OnSaleTracker.sol:L83-L87, L159 |
Description:
The linked declaration styles of the referenced structs are using index-based argument initialization.
Example:
83TnftSaleItem memory tsi = TnftSaleItem(84 tnft,85 tokenId,86 (tnftTokensOnSale[tnft].length - 1)87);
Recommendation:
We advise the key-value declaration format to be utilized instead in each instance, greatly increasing the legibility of the codebase.
Alleviation (1f394a00cc2ed1dc2020a9c07f982cff9029077d):
The key-value declaration style has been applied to both referenced struct
instantiations, optimizing the legibility of the codebase.