code-423n4 / 2022-01-yield-findings

1 stars 0 forks source link

caching curveToken in memory can cost less gas #49

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Funen

Vulnerability details

https://github.com/code-423n4/2022-01-yield/blob/main/contracts/ConvexStakingWrapper.sol#L94-L95

IERC20(curveToken).approve(convexBooster, 0);
IERC20(curveToken).approve(convexBooster, type(uint256).max);

curveToken was called mutiple times, caching it in memory , it can cost less gas

GalloDaSballo commented 2 years ago

Agree with the finding, anytime you're reading from storage even just more than once, it's always cheaper to store in a memory variable