code-423n4 / 2021-10-tracer-findings

0 stars 0 forks source link

Gas: Use `isToken0` boolean instead of `uint256 token` #15

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

cmichel

Vulnerability details

The LeveragedPool often decides whether to use long or short tokens based on a uint256 token parameter taking the values 0 (long) or 1 (short), see mintTokens. Using 256 bit for boolean value is too much and gas can be saved by using a boolean parameter bool isToken0 or bool isShortToken instead. It's also more expressive

function mintTokens(
    // @audit gas: use bool isToken0
    uint256 token,
    uint256 amount,
    address minter
)
GalloDaSballo commented 3 years ago

I disagree with the finding as the second parameter is a 256bit parameter, hence the boolean will be padded to 256bits (a bunch of zeroes) anyway

Up to the sponsor to implement the change for readability / simplicity