Open code423n4 opened 2 years ago
WatchPug
https://github.com/code-423n4/2022-01-yield/blob/e946f40239b33812e54fafc700eb2298df1a2579/contracts/ConvexStakingWrapper.sol#L106-L111
if (rewardsLength == 0) { RewardType storage reward = rewards.push(); reward.reward_token = crv; reward.reward_pool = mainPool; rewardsLength += 1; }
When rewardsLength == 0, the new rewardsLength will always be 1. Therefore, replacing += with = can avoid the unnecessary arithmetic operations and memory reads
rewardsLength
0
+=
=
Change to:
if (rewardsLength == 0) { RewardType storage reward = rewards.push(); reward.reward_token = crv; reward.reward_pool = mainPool; rewardsLength = 1; }
Finding is valid and the sponsor used it, notice that this should save 3 gas as it's avoiding an MLOAD
Handle
WatchPug
Vulnerability details
https://github.com/code-423n4/2022-01-yield/blob/e946f40239b33812e54fafc700eb2298df1a2579/contracts/ConvexStakingWrapper.sol#L106-L111
When
rewardsLength
==0
, the newrewardsLength
will always be 1. Therefore, replacing+=
with=
can avoid the unnecessary arithmetic operations and memory readsRecommendation
Change to: