Platform: Code4rena
Start Date: 08/06/2022
Pot Size: $115,000 USDC
Total HM: 26
Participants: 72
Period: 11 days
Judge: leastwood
Total Solo HM: 14
Id: 132
League: ETH
Rank: 69/72
Findings: 1
Award: $84.65
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0x29A, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, 0xmint, BowTiedWardens, ElKu, Fitraldys, Funen, Kaiziron, Lambda, Metatron, MiloTruck, Randyyy, Ruhum, SmartSek, TomJ, Tomio, UnusualTurtle, Waze, _Adam, apostle0x01, asutorufos, c3phas, catchup, csanuragjain, defsec, fatherOfBlocks, hansfriese, hyh, ignacio, joestakey, k, kaden, nahnah, oyc_109, rfa, robee, sach1r0, simon135, slywaters
84.6501 USDC - $84.65
1.Use Custom Error instead of Revert String to Save Gas
Custom error from solidity 0.8.4 are cheaper than revert strings, custom error are defined using the error
statement can use inside and outside the contract.
source https://blog.soliditylang.org/2021/04/21/custom-errors/
i suggest replacing revert error strings with custom error
POC :
https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/facets/BaseConnextFacet.sol#L38 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/ConnextPriceOracle.sol#L72 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/ConnextPriceOracle.sol#L150 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/LPToken.sol#L35 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/LPToken.sol#L50 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L75 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L76 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L77 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L86 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L89 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L90 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L96 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L97 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L98 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L102 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L125 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L155 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L167 https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/StableSwap.sol#L177
> 0
is less efficient than != 0
for unsigned integers!= 0
costs less gas compared to > 0
for unsigned integers in require statements with the optimizer enabled (6 gas)
While it may seem that > 0
is cheaper than !=
, this is only true without the optimizer enabled and outside a require statement. If you enable the optimizer at 10k AND you’re in a require statement, this will save gas.
source : https://twitter.com/gzeon/status/1485428085885640706
I suggest changing > 0
with != 0
POC :
Reducing from public
to private
or internal
can save gas when a constant isn’t used outside of its contract. I suggest changing the visibility from public
to internal
or private
.
POC :