Platform: Code4rena
Start Date: 14/10/2021
Pot Size: $50,000 USDC
Total HM: 3
Participants: 14
Period: 7 days
Judge: 0xean
Total Solo HM: 3
Id: 37
League: ETH
Rank: 8/14
Findings: 1
Award: $461.80
🌟 Selected for report: 2
🚀 Solo Findings: 0
🌟 Selected for report: TomFrenchBlockchain
Also found by: pauliax
71.6561 USDC - $71.66
pauliax
Lower than uint256 size storage variables are less gas efficient. E.g. using uint8 does not give any efficiency, actually, it is the opposite as EVM operates on default of 256-bit values so uint8 is more expensive in this case as it needs a conversion. It only gives improvements in cases where you can pack variables together, e.g. structs. An example where uint8 does not give any performance boost: for (uint8 i = 0; i < 32; i++)
Consider using optimal uint256 values.
#0 - mijovic
2021-10-21T09:53:05Z
This is a duplicate of https://github.com/code-423n4/2021-10-tempus-findings/issues/38 The quality of explanation in the linked issue is much better. Also, storage doesn't have to do anything with this issue and is mentioned here for some reason...
🌟 Selected for report: pauliax
159.2357 USDC - $159.24
pauliax
There are unused imports. They will increase the size of deployment with no real benefit. Consider removing unused imports to save some gas. Examples of such imports are:
In TempusAMMUserDataHelpers import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol";
In TempusController import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
In TempusAMM import "@balancer-labs/v2-solidity-utils/contracts/helpers/WordCodec.sol";
Consider removing them to reduce deployment gas usage.
#0 - mijovic
2021-10-20T20:25:39Z
Good catch for gas optimization. Fixed in https://github.com/tempus-finance/tempus-protocol/pull/373
🌟 Selected for report: pauliax
159.2357 USDC - $159.24
pauliax
The loop here is not really necessary as _TOTAL_TOKENS is a constant of 2 so there is always just 1 iteration: for (uint256 i = 1; i < _TOTAL_TOKENS; ++i) { uint256 currentBalance = balances[i]; if (currentBalance > maxBalance) { chosenTokenIndex = i; maxBalance = currentBalance; } }
Consider if you want to reduce gas usage by eliminating this loop here but taking the risk that _TOTAL_TOKENS will not be updated to a different value.
#0 - RedFox20
2021-10-21T20:30:48Z
I think this is a nice small cleanup for the code, it looks much simpler with this fix. Fixed in https://github.com/tempus-finance/tempus-protocol/pull/379
71.6561 USDC - $71.66
pauliax
Using the unchecked keyword to avoid redundant arithmetic underflow/overflow checks to save gas when an underflow/overflow cannot happen. E.g. 'unchecked' can be applied in the following lines of code since there are require statements before to ensure the arithmetic operations would not cause an integer underflow or overflow:
require(underlyingDecimals <= 18, "underlying decimals must be <= 18"); exchangeRateToBackingPrecision = 10**(18 - underlyingDecimals);
or if (sharesUsed[0] < mintedShares) { ammTokens[0].safeTransfer(msg.sender, mintedShares - sharesUsed[0]); } if (sharesUsed[1] < mintedShares) { ammTokens[1].safeTransfer(msg.sender, mintedShares - sharesUsed[1]); }
Consider if you want to apply this keyword and then carefully select where it is safe to do this.
#0 - RedFox20
2021-10-21T21:05:42Z
The gas saving is very small, only ended up adding the one in AaveTempusPool Fixed in https://github.com/tempus-finance/tempus-protocol/pull/380
#1 - 0xean
2021-10-27T03:16:46Z
duplicate of #30