Omniscia Maverick Protocol Audit

MaverickV2Reward Code Style Findings

MaverickV2Reward Code Style Findings

MVR-01C: Ineffectual Usage of Safe Arithmetics

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:

v2-rewards/contracts/MaverickV2Reward.sol
545if (reward > rewardOutput.amount) {
546 // set aside unboosted amount
547 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

Description:

The ERC721::ownerOf function invoked at the referenced statement is a non-standard way to ensure a token ID is owned.

Example:

v2-rewards/contracts/MaverickV2Reward.sol
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

Description:

The asVe assignment referenced is inefficient as it will evaluate an if clause to assign a bool literal.

Example:

v2-rewards/contracts/MaverickV2Reward.sol
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

Description:

The rewardTokenCount variable is redundantly assigned to on each if clause of the MaverickV2Reward::constructor.

Example:

v2-rewards/contracts/MaverickV2Reward.sol
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

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:

v2-rewards/contracts/MaverickV2Reward.sol
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 lockupId
544 );
545 if (reward > rewardOutput.amount) {
546 // set aside unboosted amount
547 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 lockupId
558 );
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.