Omniscia Nexera Protocol Audit
GenericSingleDatasetSubscriptionManager Code Style Findings
GenericSingleDatasetSubscriptionManager Code Style Findings
GSD-01C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | GenericSingleDatasetSubscriptionManager.sol:L133, L310, L311, L328 |
Description:
The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require
checks or if-else
constructs.
Example:
133return (newFee > currentFee) ? (newFee - currentFee) : 0;
Recommendation:
Given that safe arithmetics are toggled on by default in pragma
versions of 0.8.X
, we advise the linked statements to be wrapped in unchecked
code blocks thereby optimizing their execution cost.
Alleviation (fb50b5c39665f7df086b2de1fdbf93ba2d836bf9):
All referenced arithmetic statements have been safely wrapped in an unchecked
code block, optimizing each code block's gas cost.
GSD-02C: Inefficient Loop Limit Evaluation
Type | Severity | Location |
---|---|---|
Gas Optimization | GenericSingleDatasetSubscriptionManager.sol:L93 |
Description:
The linked for
loop evaluates its limit inefficiently on each iteration.
Example:
93for (uint256 i; i < subscrs.length(); i++) {
Recommendation:
We advise the statements within the for
loop limit to be relocated outside to a local variable declaration that is consequently utilized for the evaluation to significantly reduce the codebase's gas cost. We should note the same optimization is applicable for storage reads present in such limits as they are newly read on each iteration (i.e. length
members of arrays in storage).
Alleviation (fb50b5c39665f7df086b2de1fdbf93ba2d836bf9):
The referenced loop limit evaluation (subscrs.length()
) has been properly cached outside the for
loop to a dedicated local variable totalSubscribers
that is consequently utilized, optimizing the loop's gas cost significantly.
GSD-03C: Inexistent Event Indexing
Type | Severity | Location |
---|---|---|
Language Specific | GenericSingleDatasetSubscriptionManager.sol:L22-L24 |
Description:
The SubscriptionPaid
, ConsumerAdded
, and ConsumerRemoved
events of the GenericSingleDatasetSubscriptionManager
contract do not contain any indexed
arguments.
Example:
22event SubscriptionPaid(uint256 id, uint256 validSince, uint256 validTill, uint256 paidConsumers);23event ConsumerAdded(uint256 id, address consumer);24event ConsumerRemoved(uint256 id, address consumer);
Recommendation:
We advise them to be introduced, particularly in relation to the id
as well as consumer
to ensure off-chain processes can optimally filter these events.
Alleviation (fb50b5c39665f7df086b2de1fdbf93ba2d836bf9):
The indexed
keyword has been properly introduced to the id
and consumer
values as advised, optimizing their off-chain usability.
GSD-04C: Loop Iterator Optimizations
Type | Severity | Location |
---|---|---|
Gas Optimization | GenericSingleDatasetSubscriptionManager.sol:L93, L348, L368, L394 |
Description:
The linked for
loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X
).
Example:
93for (uint256 i; i < subscrs.length(); i++) {
Recommendation:
We advise the increment / decrement operations to be performed in an unchecked
code block as the last statement within each for
loop to optimize their execution cost.
Alleviation (fb50b5c39665f7df086b2de1fdbf93ba2d836bf9):
The referenced loop iterator increment statements have been relocated at the end of each respective for
loop's body and have been unwrapped in an unchecked
code block, optimizing their gas cost.
GSD-05C: Repetitive Value Literals
Type | Severity | Location |
---|---|---|
Code Style | GenericSingleDatasetSubscriptionManager.sol:L114, L272, L300, L310, L311 |
Description:
The linked value literals are repeated across the codebase multiple times.
Example:
114if (durationInDays == 0 || durationInDays > 365) revert SUBSCRIPTION_DURATION_INVALID(1, 365, durationInDays);
Recommendation:
We advise each to be set to its dedicated constant
variable instead optimizing the legibility of the codebase.
Alleviation (fb50b5c39665f7df086b2de1fdbf93ba2d836bf9):
The referenced value literals 365
, and 30
have all been relocated to contract-level constant
declarations labelled MAX_SUBSCRIPTION_DURATION_IN_DAYS
, and MAX_SUBSCRIPTION_EXTENSION_IN_DAYS
respectively, optimizing the code's legibility.