Platform: Code4rena
Start Date: 26/01/2023
Pot Size: $60,500 USDC
Total HM: 7
Participants: 31
Period: 6 days
Judge: berndartmueller
Total Solo HM: 3
Id: 207
League: ETH
Rank: 25/31
Findings: 1
Award: $45.43
๐ Selected for report: 0
๐ Solo Findings: 0
๐ Selected for report: NoamYakov
Also found by: 0xSmartContract, 0xackermann, Aymen0909, Deivitto, Diana, IllIllI, RaymondFam, ReyAdmirado, Rolezn, antonttc, arialblack14, c3phas, cryptostellar5, matrix_0wl, nadin, oyc_109
45.4256 USDC - $45.43
<x> += <y>
costs more gas than <x> = <x> + <y>
for state variablesUsing the addition operator instead of plus-equals saves gas
There is a chance that the first part will be true so the second part doesnโt need to be checked, so it is better to use the part that we have instead of the part that needs to be called.
swapping these lines will have a chance to stop the getLendgine[token0][token1][token0Exp][token1Exp][upperBound]
SLOAD
Use a strict solidity version
Use a solidity version of at least 0.8.2 to get compiler automatic inlining
Use a solidity version of at least 0.8.3 to get better struct packing and cheaper multiple storage reads
Use a solidity version of at least 0.8.4 to get custom errors, which are cheaper at deployment than revert()/require() strings
Use a solidity version of at least 0.8.10 to have external
calls skip contract existence checks if the external call has a return value
Use a solidity version of at least 0.8.12 to get string.concat() to be used instead of abi.encodePacked(<str>,<str>)
Use a solidity version of at least 0.8.13 to get the ability to use using for
with a list of free functions
Use a solidity version of at least 0.8.15 because the conditions necessary for inlining are relaxed. Benchmarks show that the change significantly decreases the bytecode size (which impacts the deployment cost) while the effect on the runtime gas usage is smaller.
Use a solidity version of at least 0.8.17 to get prevention of the incorrect removal of storage writes before calls to Yul functions that conditionally terminate the external EVM call; Simplify the starting offset of zero-length operations to zero. More efficient overflow checks for multiplication.
Using ternary operator instead of the if else statement saves gas.
totalPositionSize
is already cached inside the _totalPositionSize
state var, use the cached version to save 100 gas
In the EVM, there is no opcode for non-strict inequalities (>=, <=) and two operations are performed (> + = or < + =).
consider replacing >= with the strict counterpart > and add - 1
to the second side
some parts of the code are doing operations on constants (e.g. (constantA * constantB) / 1e18) which will always give us the same answer so there is no need to calculate them every time the function is being used.
just calculate the answer to this part of the code and use it where it should be used.
(kink * multiplier) / 1e18;
always gives the same answer. (with this method the normalRate
stack variable wouldnt need to be made which also saves gas)
token0Exp
and token1Exp
are getting different declarations in some of the contracts. as they are small numbers they can be put into a small uint and be in the same slot with token0
and token1
which are 20 bytes. as they are used together in the same places it will both save gas for slotting and reads and writes. (Each slot saved can avoid an extra Gsset (20000 gas) for the first setting of the struct and subsequent reads as well as writes have smaller gas savings)
saves two slots here each
saves two slots here each
saves one slot here
#0 - c4-judge
2023-02-16T11:16:44Z
berndartmueller marked the issue as grade-b