code-423n4 / 2022-04-phuture-findings

0 stars 0 forks source link

Gas Optimizations #59

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Gas Optimizations

Use calldata instead of memory:

For external function's dynamic params, calldata is the cheapest location to use.

Recommended Mitigation Steps:

Change params memory to calldata

Use Custom Errors to save Gas:

Custom errors from Solidity 0.8.4 are cheaper than require messages. https://blog.soliditylang.org/2021/04/21/custom-errors/

++i use less gas than i++:

./contracts/UniswapV2PathPriceOracle.sol
  line: 34   for (uint i = 0; i < path.length - 1; i++) {
  line: 49   for (uint i = 0; i < path.length - 1; i++) {

++i can save some gas use it like other places in code.

jn-lp commented 2 years ago

Data location must be "storage" or "memory" for constructor parameter.