Open code423n4 opened 2 years ago
When it is not possible for the arithmetic operation to underflow or overflow. The operation should be unchecked to save gas.
1.Consider unchecking the following arithmetic operations:
Line-L141-L143
Line-L157-L159
Line-L164-L166
Line-L229
Line-L247
Line-252
Line-L455-L455
Line-L478-L482
Line-L502-L503
Line-L801
Line-L810-L811
Line-L859
Line-L873-L874
Line-L922
Line-L931
Line-L936
Line-L945
Line-L257-L258
Line-L804-L805
Line-L109
Line-L45
1.Consider using this method only for the following state variables
Line-L811
Line-L810
The code can be optimized by minimizing the number of SLOADs, since SLOADs are more expensive than MLOADs.
1.Consider caching MAX_VOLUME_PER_LIQUIDITY in the following function
MAX_VOLUME_PER_LIQUIDITY
Line-L140
1.Consider declaring the constans UINT16_MODULO and MAX_VOLUME_PER_LIQUIDITY as private:
UINT16_MODULO
Line-L15-L16
Instead of using the && operator in a single require statement to check multiple conditions,using multiple require statements with 1 condition per require statement will save 8 GAS per &&.
Line-L110
Line-L953
Line-L968
Line-L46
Using storage pointer instead of memory location can save a decent amount of gas.
1.One function in the contract AlgebraPool, use a memory location to retrieve the struct Cumulatives
Line-L114
Line-125
2.One function in the contract AlgebraPool, use a memory location to retrieve the struct UpdatePositionCache
Line-L287
3.One function in the contract AlgebraPool, use a memory location to retrieve the struct SwapCalculationCache
Line-L719
4.One function in the contract AlgebraPool, use a memory location to retrieve the struct PriceMovementCache
Line-L779
Using unchecked blocks to save gas
When it is not possible for the arithmetic operation to underflow or overflow. The operation should be unchecked to save gas.
1.Consider unchecking the following arithmetic operations:
Line-L141-L143
Line-L157-L159
Line-L164-L166
Line-L229
Line-L247
Line-252
Line-L455-L455
Line-L478-L482
Line-L502-L503
Line-L801
Line-L810-L811
Line-L859
Line-L873-L874
Line-L922
Line-L931
Line-L936
Line-L945
Line-L257-L258
Line-L804-L805
Line-L109
Line-L45
Using "x += y" cost more gas than "x = x + y"
1.Consider using this method only for the following state variables
Line-L811
Line-L810
Line-L922
Line-L936
Cache storage values in memory to minimize the gas cost
The code can be optimized by minimizing the number of SLOADs, since SLOADs are more expensive than MLOADs.
1.Consider caching
MAX_VOLUME_PER_LIQUIDITY
in the following functionLine-L140
Constants can be set as private to save gas
1.Consider declaring the constans
UINT16_MODULO
andMAX_VOLUME_PER_LIQUIDITY
as private:Line-L15-L16
Splitting require() statements that use && saves gas
Instead of using the && operator in a single require statement to check multiple conditions,using multiple require statements with 1 condition per require statement will save 8 GAS per &&.
Line-L110
Line-L953
Line-L968
Line-L46
Copying state struct in memory is wrong and wastes gas
Using storage pointer instead of memory location can save a decent amount of gas.
1.One function in the contract AlgebraPool, use a memory location to retrieve the struct Cumulatives
Line-L114
Line-125
2.One function in the contract AlgebraPool, use a memory location to retrieve the struct UpdatePositionCache
Line-L287
3.One function in the contract AlgebraPool, use a memory location to retrieve the struct SwapCalculationCache
Line-L719
4.One function in the contract AlgebraPool, use a memory location to retrieve the struct PriceMovementCache
Line-L779