Omniscia Maverick Protocol Audit
MaverickV2Reward Code Style Findings
MaverickV2Reward Code Style Findings
MVR-01C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | ![]() | MaverickV2Reward.sol:L547 |
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:
545if (reward > rewardOutput.amount) {546 // set aside unboosted amount547 data.unboostedAmount += (reward - rewardOutput.amount).toUint128();548}
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 referenced operation has been properly wrapped in an unchecked
code block, optimizing its gas cost whilst retaining its security guarantees via preceding statements.
MVR-02C: Non-Standard Validation of Ownership
Type | Severity | Location |
---|---|---|
Code Style | ![]() | MaverickV2Reward.sol:L447 |
Description:
The ERC721::ownerOf
function invoked at the referenced statement is a non-standard way to ensure a token ID is owned.
Example:
447ownerOf(tokenId);
Recommendation:
We advise the ERC721::_requireOwned
function to be utilized instead which clearly demonstrates its purpose.
Alleviation (07ad29f773f16bdfbae3d97d3a7c2f9d64866093):
The ERC721::_requireOwned
function is properly utilized in place of the ERC721::ownerOf
function per our recommendation, increasing the legibility of the statement.
MVR-03C: Optimization of Assignment
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | MaverickV2Reward.sol:L485 |
Description:
The asVe
assignment referenced is inefficient as it will evaluate an if
clause to assign a bool
literal.
Example:
485if (stakeDuration != 0) asVe = true;
Recommendation:
We advise the result of stakeDuration != 0
to be assigned to asVe
directly, optimizing the statement's generated bytecode.
Alleviation (07ad29f773f16bdfbae3d97d3a7c2f9d64866093):
The assignment has been optimized as advised, optimizing its bytecode.
MVR-04C: Optimization of Reward Token Count Assignment
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | MaverickV2Reward.sol:L117, L121, L123, L126, L128, L131, L133, L136, L138, L141 |
Description:
The rewardTokenCount
variable is redundantly assigned to on each if
clause of the MaverickV2Reward::constructor
.
Example:
117uint256 length = rewardTokens.length;118if (length > 0) {119 rewardToken0 = rewardTokens[0];120 veToken0 = veTokens[0];121 rewardTokenCount = 1;122}123if (length > 1) {124 rewardToken1 = rewardTokens[1];125 veToken1 = veTokens[1];126 rewardTokenCount = 2;127}128if (length > 2) {129 rewardToken2 = rewardTokens[2];130 veToken2 = veTokens[2];131 rewardTokenCount = 3;132}133if (length > 3) {134 rewardToken3 = rewardTokens[3];135 veToken3 = veTokens[3];136 rewardTokenCount = 4;137}138if (length > 4) {139 rewardToken4 = rewardTokens[4];140 veToken4 = veTokens[4];141 rewardTokenCount = 5;142}
Recommendation:
We advise it to be assigned to once to the value of length
.
To note, the length
is validated as at most 5
within the MaverickV2RewardFactory::createRewardsContract
and thus does not warrant validation.
Alleviation (07ad29f773f16bdfbae3d97d3a7c2f9d64866093):
The code has been optimized as advised, ensuring that the rewardTokenCount
variable is assigned-to only once optimally.
MVR-05C: Redundant Safe Casting Operations
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | MaverickV2Reward.sol:L547, L613 |
Description:
The referenced safe casting operations are redundant as the casts will be securely performed, either due to being preceded by a cast of a higher value or due to being the result of a reduced value already at the desired type.
Example:
532uint128 reward = data.rewards[tokenId];533if (reward != 0) {534 data.rewards[tokenId] = 0;535 data.escrowedReward -= reward;536 rewardOutput = _boostAndPay(537 tokenId,538 recipient,539 rewardTokenByIndex(rewardTokenIndex),540 veTokenByIndex(rewardTokenIndex),541 reward,542 stakeDuration,543 lockupId544 );545 if (reward > rewardOutput.amount) {546 // set aside unboosted amount547 data.unboostedAmount += (reward - rewardOutput.amount).toUint128();548 }549 emit GetReward(550 msg.sender,551 tokenId,552 recipient,553 rewardTokenIndex,554 stakeDuration,555 rewardTokenByIndex(rewardTokenIndex),556 rewardOutput,557 lockupId558 );559}
Recommendation:
We advise both safe casting operations to be omitted, optimizing each statement's gas cost.
Alleviation (07ad29f773f16bdfbae3d97d3a7c2f9d64866093):
Both safe casting operations have been removed as they are guaranteed to be safe by statements that precede them, optimizing each statement's gas cost.