Platform: Code4rena
Start Date: 09/11/2021
Pot Size: $75,000 USDC
Total HM: 57
Participants: 27
Period: 7 days
Judge: alcueca
Total Solo HM: 49
Id: 52
League: ETH
Rank: 22/27
Findings: 1
Award: $130.43
🌟 Selected for report: 2
🚀 Solo Findings: 0
30.893 USDC - $30.89
0x0x0x
In solidity 0.8.*, there is already built in overflow check and using SafeMath consumes more gas without any advantage. In StakingRewards.sol
, SafeMath is used with solidity 0.8.9.
Manual
#0 - 0xstormtrooper
2021-11-16T05:55:35Z
30.893 USDC - $30.89
0x0x0x
Example:
for (uint i = 0; i < arr.length; i++) { //Operations not effecting the length of the array. }
Loading length of array costs gas. Therefore, the length should be cached, if the length of the array doesn't change inside the loop. Recommended implementation:
uint length = arr.length; for (uint i = 0; i < length; i++) { //Operations not effecting the length of the array. }
By doing so the length is only loaded once rather than loading it as many times as iterations (Therefore, less gas is spent).
./governance/GovernorAlpha.sol:571: for (uint256 i = 0; i < _targets.length; i++) { ./tokens/vesting/LinearVesting.sol:72: for (uint256 i = 0; i < vesters.length; i++) {
🌟 Selected for report: 0x0x0x
68.651 USDC - $68.65
0x0x0x
StakingRewards.sol#updateReward
is:
modifier updateReward(address account) { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); if (account != address(0)) { rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; } _; }
The case where account != address(0)
is a rare case, which only happens when notifyRewardAmount
is called. For other functions we do not require the if statement:
if (account != address(0)) {
Therefore by splitting this modifier to two modifiers, we can hardcode the result of this if-statement to save gas.
Manual Analysis
#0 - 0xstormtrooper
2021-11-16T02:14:19Z
The case where account != address(0) I think you meant
account == address(0)
is rare.
For code readability and less complexity, this suggestion will not be applied