Open code423n4 opened 2 years ago
Solidity ^0.8.4 allow the use of custom errors to optimize gas usage. https://blog.soliditylang.org/2021/04/21/custom-errors/
For example: https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/TimeswapPair.sol#L189
assetIn = param.xIncrease + feeStoredIncrease;
https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/TimeswapPair.sol#L238
assetOut = _assetOut + feeOut;
https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/TimeswapPair.sol#L314
assetIn = param.xIncrease + feeStoredIncrease + protocolFeeStoredIncrease;
https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/TimeswapPair.sol#L436
assetOut = param.xDecrease - feeStoredIncrease - protocolFeeStoredIncrease;
There are also a lot of similar case in https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/libraries/TimeswapMath.sol
https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/libraries/SafeCast.sol#L6 uint32(x) is same as uint32(x % 0x100000000)
uint32(x)
uint32(x % 0x100000000)
y = uint32(x % 0x100000000);
We will update for Unnecessary modulo issue
https://github.com/Timeswap-Labs/Timeswap-V1-Core/commit/962ee056ef60b7528d61aa9cc3c16fbdca179901
Use custom errors
Solidity ^0.8.4 allow the use of custom errors to optimize gas usage. https://blog.soliditylang.org/2021/04/21/custom-errors/
Consolidate operations
For example: https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/TimeswapPair.sol#L189
https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/TimeswapPair.sol#L238
https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/TimeswapPair.sol#L314
https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/TimeswapPair.sol#L436
There are also a lot of similar case in https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/libraries/TimeswapMath.sol
Unnecessary modulo
https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Core/contracts/libraries/SafeCast.sol#L6
uint32(x)
is same asuint32(x % 0x100000000)