code-423n4 / 2022-01-trader-joe-findings

2 stars 0 forks source link

Caching `rJoe` variable #227

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Jujic

Vulnerability details

Impact

The rJoe variable can be cached to slightly reduce gas usage

Proof of Concept

https://github.com/code-423n4/2022-01-trader-joe/blob/a1579f6453bc4bf9fb0db9c627beaa41135438ed/contracts/RocketJoeStaking.sol#L181-L188

function _safeRJoeTransfer(address _to, uint256 _amount) internal {
        uint256 rJoeBal = rJoe.balanceOf(address(this));
        if (_amount > rJoeBal) {
            rJoe.transfer(_to, rJoeBal);
        } else {
            rJoe.transfer(_to, _amount);
        }
    }

Tools Used

Remix

Recommended Mitigation Steps

Consider caching those variable for read and make sure write back to storage