Omniscia Maverick Protocol Audit
MaverickV2VotingEscrow Code Style Findings
MaverickV2VotingEscrow Code Style Findings
MVW-01C: Combination of Statements
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | MaverickV2VotingEscrow.sol:L74, L82 |
Description:
The referenced statements can be combined to become efficient.
Example:
74index = incentiveBatchCount;75
76_tokenIncentiveTotals[incentiveToken].totalIncentives += amount;77
78_incentiveBatches[index].totalIncentives = amount;79_incentiveBatches[index].incentiveToken = incentiveToken;80_incentiveBatches[index].claimTimepoint = timepoint;81_incentiveBatches[index].stakeDuration = stakeDuration;82incentiveBatchCount++;Recommendation:
We advise the index variable to be assigned to the value of incentiveBatchCount++, imitating the same behaviour of the existing implementation at a reduced gas cost.
Alleviation (07ad29f773f16bdfbae3d97d3a7c2f9d64866093):
The Maverick Protocol team evaluated this exhibit but opted to acknowledge it in the current iteration of the codebase
MVW-02C: Ineffectual Usage of Safe Arithmetics
| Type | Severity | Location |
|---|---|---|
| Language Specific | ![]() | MaverickV2VotingEscrow.sol:L82 |
Description:
The linked mathematical operation is guaranteed to be performed safely by logical inference, such as surrounding conditionals evaluated in require checks or if-else constructs.
Example:
82incentiveBatchCount++;Recommendation:
Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statement to be wrapped in an unchecked code block thereby optimizing its execution cost.
Alleviation (07ad29f773f16bdfbae3d97d3a7c2f9d64866093):
The Maverick Protocol team stated that the referenced operation can overflow, and has opted to not wrap it in an unchecked code block.
We would like to note that while it is not programmatically protected against overflows, a sequentially incrementing variable would have to be incremented in 2**256 - 1 separate invocations before it overflows which is practically impossible in a production environment.
In any case, we accept the acknowledgement by the Maverick Protocol team.
MVW-03C: Inefficient mapping Lookups
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | MaverickV2VotingEscrow.sol:L78-L81, L130, L133, L135, L137, L138 |
Description:
The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.
Example:
78_incentiveBatches[index].totalIncentives = amount;79_incentiveBatches[index].incentiveToken = incentiveToken;80_incentiveBatches[index].claimTimepoint = timepoint;81_incentiveBatches[index].stakeDuration = stakeDuration;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.
As the compiler's optimizations may take care of these caching operations automatically at-times, we advise the optimization to be selectively applied, tested, and then fully adopted to ensure that the proposed caching model indeed leads to a reduction in gas costs.
Alleviation (07ad29f773f16bdfbae3d97d3a7c2f9d64866093):
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.
