Open code423n4 opened 2 years ago
Duplicate of #317
This does point to a valid gas optimization. Rewards could be disbursed without sending a corresponding zero transfer. Using an if statement here would have a net positive impact on gas. Even better would be to split into the more common withdraw / withdrawAndClaim pattern.
Handle
WatchPug
Vulnerability details
https://github.com/code-423n4/2022-01-trader-joe/blob/a1579f6453bc4bf9fb0db9c627beaa41135438ed/contracts/RocketJoeStaking.sol#L116-L135
Since
_amount
can be0
. Checkingif (_amount != 0)
before the transfer can potentially save an external call and the unnecessary gas cost of a 0 token transfer.When
withdraw(0)
,user.amount = user.amount - _amount;
can be skipped, to save storage write and external call ofjoe.safeTransfer(address(msg.sender), _amount);
.