Platform: Code4rena
Start Date: 03/07/2023
Pot Size: $40,000 USDC
Total HM: 14
Participants: 74
Period: 7 days
Judge: alcueca
Total Solo HM: 9
Id: 259
League: ETH
Rank: 63/74
Findings: 1
Award: $7.89
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: SM3_SS
Also found by: 0x11singh99, 0xAnah, 0xSmartContract, 0xn006e7, 0xprinc, DavidGiladi, ElCid, JCN, K42, MIQUINHO, Raihan, Rolezn, SAAJ, SY_S, Strausses, TheSavageTeddy, bigtone, erebus, hunter_w3b, josephdara, lsaudit, mahdirostami, oakcobalt, peanuts, pfapostol, seth_lawson
7.8853 USDC - $7.89
<x> += <y>
instead of <x> = <x> + <y>
In Well.sol
line 504, the reserves of the TokenAmountIn
are updated in the following way:
reserves[i] = reserves[i] + tokenAmountsIn[i]
This spends unnecessary gas as this is not an update to a state variable. The code should be as follows:
reserves[i] += tokenAmountsIn
In Well.sol
under removeLiquidity()
function, the variable tokenAmountsOut
is initialised with an empty array.
The function _calcLPTokenUnderlying()
already returns an uint256 array, so there is no need for the declaration of an empty uint256 array in line 552.
For every iteration in the loop, the value _tokens.length
will be fetched afresh. This is expensive. Consider caching the _tokens.length
value outside the loop or use assembly.
These are the following instances of this issue in Well.sol
: lines 44, 45, 113, 410, 433, 486, 497, 528, 561, 670, 692, 708, 725, 757, 788, 877, 902
It is possible to calculate a contract’s address before mainnet deployment. It is less expensive than using address(this)
Foundry has a specific tool designed for that: https://book.getfoundry.sh/reference/forge-std/compute-create-address
These are the instances of this issue in Well.sol
: lines 212, 343, 411, 434, 501, 709, 726, 758, 921, 922, 923
>=
is costs less than >
When the symbol >
is used the compiler uses GT
and ISZERO
, however when >=
is used the compiler only uses LT
. This saves 3 gas.
Issue Instances in Well.sol
: lines 324, 678, 758, 932.
payable
to the constructor saves gasIn Aquifier.sol
, the constructor does not have payable
keyword spending unnecessary gas.
Declaring the constructor as payable enables the removal of 10 opcodes from the EVM bytecode generated during creation time. By making the constructor payable, there is no longer a requirement to check if msg.value == 0 during deployment, resulting in a savings of 13 gas without introducing any security risks.
Starting from Solidity version 0.8.4, developers can utilise custom errors, which provide a gas-saving advantage of approximately 50 units per occurrence by eliminating the need for allocating and storing the revert string. Furthermore, omitting the definition of these strings also contributes to reducing the gas consumption during deployment.
#0 - c4-pre-sort
2023-07-12T07:53:08Z
141345 marked the issue as low quality report
#1 - c4-judge
2023-08-05T11:28:16Z
alcueca marked the issue as grade-b