Platform: Code4rena
Start Date: 14/09/2022
Pot Size: $50,000 USDC
Total HM: 25
Participants: 110
Period: 5 days
Judge: hickuphh3
Total Solo HM: 9
Id: 162
League: ETH
Rank: 71/110
Findings: 1
Award: $52.83
π Selected for report: 0
π Solo Findings: 0
π Selected for report: pfapostol
Also found by: 0x040, 0x1f8b, 0x4non, 0xNazgul, 0xSmartContract, 0xc0ffEE, 0xkatana, Aymen0909, Bnke0x0, Deivitto, Diana, JAGADESH, KIntern_NA, Lambda, MiloTruck, R2, RaymondFam, Respx, ReyAdmirado, Rohan16, RoiEvenHaim, Rolezn, Ruhum, Saintcode_, Samatak, Sm4rty, SnowMan, Tomio, Tomo, WilliamAmbrozic, _Adam, __141345__, ajtra, ak1, async, c3phas, ch0bu, cryptostellar5, d3e4, delfin454000, dharma09, djxploit, durianSausage, eierina, erictee, fatherOfBlocks, gianganhnguyen, gogo, ignacio, imare, jag, jonatascm, leosathya, lukris02, malinariy, oyc_109, pashov, pauliax, peanuts, peiw, prasantgupta52, robee, rokinot, rotcivegaf, rvierdiiev, seyni, simon135, slowmoses, sryysryy, tnevler, zishansami
52.8286 USDC - $52.83
File Vault.sol, line 443:
for (uint256 i = 0; i < epochsLength(); i++) { ... }
Becomes:
for (uint256 i = 0; i < epochsLength(); ++i) { ... }
File Vault.sol, line 443:
for (uint256 i = 0; i < epochsLength(); i++) { ... }
Becomes:
uint256 epochsLength = epochsLength(); for (uint256 i = 0; i < epochsLength; ++i) { ... }
File Vault.sol, line 443:
for (uint256 i = 0; i < epochsLength(); i++) { ... }
Becomes:
uint256 epochsLength = epochsLength(); for (uint256 i = 0; i < epochsLength ;) { ... unchecked { ++i; } }
File Vault.sol, line 443:
for (uint256 i = 0; i < epochsLength(); i++) { ... }
Becomes:
for (uint256 i; i < epochsLength(); i++) { ... }
File StakingRewards.sol, line 36:
uint256 public periodFinish = 0;
Becomes:
uint256 public periodFinish;
Solidity version 0.8+ comes with implicit overflow and underflow checks on unsigned integers. When an overflow or an underflow isnβt possible (as an example, when a comparison is made before the arithmetic operation), some gas can be saved by using an unchecked block
File PegOracle.sol, line 67-74:
if (price1 > price2) { nowPrice = (price2 * 10000) / price1; } else { nowPrice = (price1 * 10000) / price2; } int256 decimals10 = int256(10**(18 - priceFeed1.decimals())); nowPrice = nowPrice * decimals10;
Becomes:
unchecked { if (price1 > price2) { nowPrice = (price2 * 10000) / price1; } else { nowPrice = (price1 * 10000) / price2; } int256 decimals10 = int256(10**(18 - priceFeed1.decimals())); nowPrice = nowPrice * decimals10; }
File Controller.sol, line 277:
bool isSequencerUp = answer == 0;
Becomes:
bool isSequencerUp; unchecked { isSequencerUp = answer == 0; }
File Controller.sol, line 283:
uint256 timeSinceUp = block.timestamp - startedAt;
Becomes:
uint256 timeSinceUp; unchecked { timeSinceUp = block.timestamp - startedAt; }
File Controller.sol, line 299, 300:
uint256 decimals = 10**(18-(priceFeed.decimals())); price = price * int256(decimals);
Becomes:
uint256 decimals; unchecked { decimals = 10**(18-(priceFeed.decimals())); price = price * int256(decimals); }
File Vault.sol, line 266:
return (amount * epochFee[_epoch]) / 1000;
Becomes:
unchecked { return (amount * epochFee[_epoch]) / 1000; }
File Vault.sol, line 399, 407, 419
File Controller.sol, line 96-99:
if( vault.strikePrice() < getLatestPrice(vault.tokenInsured()) ) revert PriceNotAtStrikePrice(getLatestPrice(vault.tokenInsured()));
Becomes:
int256 nowPrice = getLatestPrice(vault.tokenInsured()); if( vault.strikePrice() < nowPrice ) revert PriceNotAtStrikePrice(nowPrice);
File Controller.sol, line 199-206:
if( vaultFactory.getVaults(marketIndex).length != VAULTS_LENGTH) revert MarketDoesNotExist(marketIndex); if( block.timestamp < epochEnd) revert EpochNotExpired(); address[] memory vaultsAddress = vaultFactory.getVaults(marketIndex);
Becomes:
address[] memory vaultsAddress = vaultFactory.getVaults(marketIndex); if( vaultsAddress.length != VAULTS_LENGTH) revert MarketDoesNotExist(marketIndex); if( block.timestamp < epochEnd) revert EpochNotExpired();
#0 - HickupHH3
2022-11-08T09:26:34Z
- [G-6] Using temporary memory
Essentially avoiding multiple external calls which had significant gas savings