Omniscia Avocado Fund Audit

VaultRewards Code Style Findings

VaultRewards Code Style Findings

VRS-01C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificVaultRewards.sol:
I-1: L120
I-2: L154
I-3: L208

Description:

The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

contracts/src/VaultRewards.sol
119if (block.timestamp > lastRewardTime && totalStaked > 0) {
120 uint256 elapsed = block.timestamp - lastRewardTime;

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 (a859cd2191):

The alleviation of this exhibit was improperly applied as the full code block in VaultRewards::pendingRewards was wrapped in an unchecked block rather than the individual elapsed calculation.

Additionally, the third instance (I-3) optimization was not applied.

Alleviation (ca4268ecd3):

The optimization's application in I-2 has been corrected while I-3 remains unaddressed, rendering this exhibit partially alleviated.

Alleviation (28abe24a8b):

The VaultRewards file has been omitted from the repository entirely rendering this exhibit no longer applicable.

VRS-02C: Inefficient Handling of User's Amount

TypeSeverityLocation
Gas OptimizationVaultRewards.sol:
I-1: L177, L186, L187
I-2: L198, L202, L208, L210
I-3: L222, L226

Description:

The referenced code segments will inefficiently handle the user.amount data entry as they will read it three to four distinct times from storage instead of using a memory copy of it.

Example:

contracts/src/VaultRewards.sol
198if (user.amount < amount) revert InsufficientStake();
199
200updatePool();
201
202uint256 pending = (user.amount * accRewardPerShare / 1e18) - user.rewardDebt;
203if (pending > 0) {
204 _safeRewardTransfer(msg.sender, pending);
205 emit Claim(msg.sender, pending);
206}
207
208user.amount -= amount;
209totalStaked -= amount;
210user.rewardDebt = user.amount * accRewardPerShare / 1e18;

Recommendation:

We advise the user.amount to be loaded into memory at the beginning and to be re-used across statements until the final write, optimizing the code's gas cost significantly.

Alleviation (a859cd2191d509cbc6d47508bdd44ec6d3cc9844):

The optimizations have been applied albeit in a different manner due to a revision of the system to use a boosted balance parallel.

VRS-03C: Repetitive Value Literal

Description:

The linked value literal is repeated across the codebase multiple times.

Example:

contracts/src/VaultRewards.sol
123_accRewardPerShare += (reward * 1e18) / totalStaked;

Recommendation:

We advise it to be set to a constant variable instead, optimizing the legibility of the codebase.

In case the constant has already been declared, we advise it to be properly re-used across the code.

Alleviation (a859cd2191d509cbc6d47508bdd44ec6d3cc9844):

The referenced value literal 1e18 has been properly relocated to a contract-level constant declaration labelled ACC_PRECISION, optimizing the code's legibility.