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

1 stars 0 forks source link

Prefix increments are cheaper than postfix increments #14

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

robee

Vulnerability details

Prefix increments are cheaper than postfix increments. Further more, using unchecked {++x} is even more gas efficient, and the gas saving accumulates every iteration and can make a real change There is no risk of overflow caused by increamenting the iteration index in for loops (the ++i in for (uint256 i = 0; i < numIterations; ++i)). But increments perform overflow checks that are not necessary in this case. These functions use not using prefix increments (++x) or not using the unchecked keyword:

    change to prefix increment and unchecked: ConvexStakingWrapper.sol, i, 115
    change to prefix increment and unchecked: ConvexStakingWrapper.sol, u, 172
    change to prefix increment and unchecked: ConvexStakingWrapper.sol, u, 227
    change to prefix increment and unchecked: ConvexYieldWrapper.sol, i, 111
    change to prefix increment and unchecked: ConvexStakingWrapper.sol, i, 287
    change to prefix increment and unchecked: ConvexStakingWrapper.sol, i, 271
    change to prefix increment and unchecked: ConvexStakingWrapper.sol, i, 315
    change to prefix increment and unchecked: ConvexYieldWrapper.sol, i, 63
devtooligan commented 2 years ago

neat