Closed code423n4 closed 2 years ago
Czar102
Storage variables are often read more than once, despite no change in their value.
function deposit(uint256 _amount) external { UserInfo storage user = userInfo[msg.sender]; updatePool(); if (user.amount > 0) { uint256 pending = (user.amount * accRJoePerShare) / PRECISION - user.rewardDebt; _safeRJoeTransfer(msg.sender, pending); } user.amount = user.amount + _amount; user.rewardDebt = (user.amount * accRJoePerShare) / PRECISION; joe.safeTransferFrom(address(msg.sender), address(this), _amount); emit Deposit(msg.sender, _amount); }
In the above example, user.amount is read 4 times, while it could have been read only once.
user.amount
Manual analysis
Cache unchanging storage variables on the stack.
Duplicate of #128
Handle
Czar102
Vulnerability details
Impact
Storage variables are often read more than once, despite no change in their value.
Example
In the above example,
user.amount
is read 4 times, while it could have been read only once.Tools Used
Manual analysis
Recommended Mitigation Steps
Cache unchanging storage variables on the stack.