GalloDaSballo / Apollon-Review

Notes for the Apollon Solo Security Review
0 stars 0 forks source link

Gas: Refactor code to not pass parameters that are unused #53

Closed GalloDaSballo closed 2 months ago

GalloDaSballo commented 3 months ago

Impact

In some instances of the code, you pass memory parameters such as _priceUpdateData without using them

This incurrs additional costs that can be avoided by passing an empty memory object

https://github.com/blkswnStudio/ap/blob/8fab2b32b4f55efd92819bd1d0da9bed4b339e87/packages/contracts/contracts/BorrowerOperations.sol#L360-L383

function increaseDebt(
    address _borrower,
    address _to,
    TokenAmount[] memory _debts,
    MintMeta memory _meta,
    bytes[] memory _priceUpdateData // Never used (skips due to being updated in swap)
  ) external payable override {
    _requireCallerIsSwapOperations();
    _increaseDebt(_borrower, _to, _debts, _meta, _priceUpdateData);
  }

  // increasing debt of a trove
  function _increaseDebt(
    address _borrower,
    address _to,
    TokenAmount[] memory _debts,
    MintMeta memory _meta,
    bytes[] memory _priceUpdateData
  ) internal {
    (ContractsCache memory contractsCache, LocalVariables_adjustTrove memory vars) = _prepareTroveAdjustment(
      _borrower,
      _priceUpdateData, /// @audit Just don't use the value if it's not updated
      true //will be called by swap operations, that handled the price update
    );

Mitigation

Use emptyUpdateData like you have in repayDebtFromPoolBurn

https://github.com/blkswnStudio/ap/blob/8fab2b32b4f55efd92819bd1d0da9bed4b339e87/packages/contracts/contracts/BorrowerOperations.sol#L500

bytes[] memory emptyUpdateData
sambP commented 2 months ago

not relevant anymore, removed _priceUpdateData from incraseDebt(), moved it into the swapOps