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: 10/14
Findings: 2
Award: $143.32
🌟 Selected for report: 2
🚀 Solo Findings: 0
71.6561 USDC - $71.66
WatchPug
For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.
For example:
uint256 timeToMaturity = (maturityTime > currentTime) ? (maturityTime - currentTime) : 0;
maturityTime - currentTime
will never underflow.
#0 - RedFox20
2021-10-21T19:21:27Z
Relatively minor because it really affects code readability for a very small gain. Nevertheless, I added the change in the exact suggested location.
In the future, it would help if you shared exact findings on the amount of gas saved, using gasleft()
estimatedYield unchecked gas: 62 estimatedYield checked gas: 174
It's not a big amount of gas saved, but nevertheless, gas saved 😃 👍🏻
Fixed in https://github.com/tempus-finance/tempus-protocol/pull/377
71.6561 USDC - $71.66
WatchPug
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
Instances include:
function sub(uint256[] memory vec1, uint256[] memory vec2) internal pure { assert(vec1.length == vec2.length); for (uint256 i = 0; i < vec1.length; ++i) {
#0 - mijovic
2021-10-20T18:36:07Z
This will mostly be executed on small arrays. This gas saving is irrelevant to gas usage for any of the protocol functions. Also, compiler might be able to optimize out this, so I would not fix this, as in general code will be less readable for saving of 20 gas maximum ...