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

2 stars 0 forks source link

call a function and save its return value before the loop instead of calling it in every iteration #125

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

OriDabush

Vulnerability details

TimeswapPair.sol - Gas Optimization

calculate BlockNumber.get() before the loop in line 289 and save it in a variable to prevent calculating it (and calling the get function) in every iteration.

code before:

for (uint256 i; i < ids.length; i++) {
            ...
            require(due.startBlock != BlockNumber.get(), 'E207');
            ...
}

code after:

uint32 startblock = BlockNumber.get();
for (uint256 i; i < ids.length; i++) {
            ...
            require(due.startBlock != startblock , 'E207');
            ...
}
amateur-dev commented 2 years ago

Similar issue reported over here #142; hence closing this