Closed code423n4 closed 2 years ago
WatchPug
https://github.com/code-423n4/2022-01-trader-joe/blob/a1579f6453bc4bf9fb0db9c627beaa41135438ed/contracts/LaunchEvent.sol#L377-L435
function createPair() external isStopped(false) atPhase(Phase.PhaseThree) { (address wavaxAddress, address tokenAddress) = ( address(WAVAX), address(token) ); // ... if ( floorPrice > (wavaxReserve * 10**token.decimals()) / tokenAllocated ) { tokenAllocated = (wavaxReserve * 10**token.decimals()) / floorPrice; // ... } WAVAX.approve(address(router), wavaxReserve); token.approve(address(router), tokenAllocated); // ... }
WAVAX
wavaxAddress
token
tokenAddress
Reusing the cached local variable instead of reading from storage again can save gas.
Read from the stack can save ~100 gas from each extra read (SLOAD after Berlin).
SLOAD
Duplicate of #236
Handle
WatchPug
Vulnerability details
https://github.com/code-423n4/2022-01-trader-joe/blob/a1579f6453bc4bf9fb0db9c627beaa41135438ed/contracts/LaunchEvent.sol#L377-L435
WAVAX
at L407 is already cached in the local variablewavaxAddress
at L378 ~ L379.token
at L396, L398, L408 is already cached in the local variabletokenAddress
at L378 ~ L380.Reusing the cached local variable instead of reading from storage again can save gas.
Read from the stack can save ~100 gas from each extra read (
SLOAD
after Berlin).