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

0 stars 0 forks source link

Local variables initialization inside a for loop #43

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

pants

Vulnerability details

Initialize local vars before the for loop is more gas efficient. See line 191 TempusAMM. There might be other places where it's more severe due to a longer for loop .

RedFox20 commented 2 years ago
getSwapAmountToEndWithEqualShares gas before: 57339
getSwapAmountToEndWithEqualShares gas after: 57396

After measuring, it appears gas usage with pre-defined variables takes more gas, so this report does not hold water. Most likely because it prevents certain optimizations in Solidity 0.7.6

0xean commented 2 years ago

Closing as invalid. Line 191 refers to

amountIn = (difference * _TEMPUS_SHARE_PRECISION) / (rate + _TEMPUS_SHARE_PRECISION);

amountIn is initialized in the function definition

) public view returns (uint256 amountIn) {

and solidity initializes a uint256 to 0.