Omniscia Boson Protocol Audit
SellerHandlerFacet Code Style Findings
SellerHandlerFacet Code Style Findings
SHF-01C: Inefficient mapping
Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | SellerHandlerFacet.sol:L95-L106, L114-L115, L122-L127 |
Description:
The linked statements perform key-based lookup operations on mapping
declarations from storage multiple times for the same key redundantly.
Example:
113require(114 protocolLookups().sellerIdByAuthToken[_authToken.tokenType][_authToken.tokenId] == 0 ||115 protocolLookups().sellerIdByAuthToken[_authToken.tokenType][_authToken.tokenId] == _seller.id,116 AUTH_TOKEN_MUST_BE_UNIQUE117);
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 (44009967e4f68092941d841e9e0f5dd2bb31bf0b):
The referenced mapping
lookups have been optimized to the greatest extent possible thus greatly reducing the gas cost of the codebase.
SHF-02C: Repetitive Invocations of Getter Function
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | SellerHandlerFacet.sol:L95-L106, L114-L115, L122-L127, L133-L136, L148 |
Description:
The linked statements repetitively invoke the same getter function whilst its return value remains unchanged.
Example:
95(protocolLookups().sellerIdByOperator[_seller.operator] == 0 ||96 protocolLookups().sellerIdByOperator[_seller.operator] == _seller.id) &&97 (protocolLookups().sellerIdByOperator[_seller.clerk] == 0 ||98 protocolLookups().sellerIdByOperator[_seller.clerk] == _seller.id) &&99 (protocolLookups().sellerIdByAdmin[_seller.operator] == 0 ||100 protocolLookups().sellerIdByAdmin[_seller.operator] == _seller.id) &&101 (protocolLookups().sellerIdByAdmin[_seller.clerk] == 0 ||102 protocolLookups().sellerIdByAdmin[_seller.clerk] == _seller.id) &&103 (protocolLookups().sellerIdByClerk[_seller.operator] == 0 ||104 protocolLookups().sellerIdByClerk[_seller.operator] == _seller.id) &&105 (protocolLookups().sellerIdByClerk[_seller.clerk] == 0 ||106 protocolLookups().sellerIdByClerk[_seller.clerk] == _seller.id),
Recommendation:
We advise the getter function to be invoked once and its result to be stored to a local variable that is consequently utilized optimizing the gas cost of the statements significantly.
Alleviation (44009967e4f68092941d841e9e0f5dd2bb31bf0b):
The protocol lookups are now correctly cached to local variable declarations thus optimizing the codebase's gas cost.