Omniscia Maverick Protocol Audit

RewardAccounting Code Style Findings

RewardAccounting Code Style Findings

RAG-01C: Redundant Duplicate Read of Account Balance

Description:

The RewardAccounting::_burnStake function will redundantly read the _stakeBalances[tokenId] value twice, once for evaluating there is sufficient balance and once in the assignment-and-decrement (-=) operation.

Example:

v2-rewards/contracts/rewardbase/RewardAccounting.sol
39/**
40 * @notice Burn from staking account for a tokenId account.
41 */
42function _burnStake(uint256 tokenId, uint256 value) internal {
43 uint256 currentBalance = _stakeBalances[tokenId];
44 if (value > currentBalance) revert InsufficientBalance(tokenId, currentBalance, value);
45 unchecked {
46 _stakeTotalSupply -= value;
47 _stakeBalances[tokenId] -= value;
48 }
49}

Recommendation:

We advise the assignment-and-decrement operation to be replaced by a direct assignment of the currentBalance - value result, optimizing the code's gas cost.

Alleviation (07ad29f773f16bdfbae3d97d3a7c2f9d64866093):

The optimization has been applied as advised, using the existing currentBalance variable to optimize the _stakeBalances assignment.