code-423n4 / 2022-10-inverse-findings

0 stars 0 forks source link

Gas Optimizations #130

Open code423n4 opened 1 year ago

code423n4 commented 1 year ago

Gas Optimizations

DBR.sol

balanceOf()

Public function used on function like transfer, transferFrom, _burn (state change functions)

if (duTokensAccruedUser + accrued > balanceUser) return 0; return balanceUser - duTokensAccruedUser - accrued;

### #deficitOf()
Public function used on function like onBorrow, onForceReplenish... (state change functions)
- Exactly the same gas opt. as balanceOf()

### #totalSupply()
Public view function, not used in other functions, so not really important.
- replace:
```js
if (totalDueTokensAccrued > _totalSupply) return 0;
return _totalSupply - totalDueTokensAccrued;

after:

uint256 totalSupply_ = _totalSupply;
uint256 totalDueTokensAccrued_ = totalDueTokensAccrued;
if (totalDueTokensAccrued_ > totalSupply_) return 0;
return totalSupply_ - totalDueTokensAccrued_;

accrueDueTokens()

Public function used on function like onBorrow, onRepay, onForceReplenish (state change functions)

Fed.sol

contraction()

Public function

Market.sol

setLiquidationFactorBps()

setLiquidationIncentiveBps()

predictEscrow()

getCollateralValue()

Public function used on function like getCreditLimit, getLiquidatableDebt (view functions)

getCollateralValueInternal()

Internal function used on function like getCreditLimitInternal, forceReplenish (state change functions)

getCreditLimit()

Public function used on function like getLiquidatableDebt (view functions)

getCreditLimitInternal()

Internal function used on function like borrowInternal, liquidate (state change functions)

getWithdrawalLimitInternal()

Internal function used on function like withdrawInternal, withdraw (state change functions)

borrowInternal()

Internal function used on function like borrow, borrowOnBehalf (state change functions)

withdrawInternal()

Internal function used on function like withdraw (state change functions)

repay()

Public function used on function like repayAndWithdraw (state change functions)

forceReplenish()

Public function (state change functions)

getLiquidatableDebt()

Public view function

Oracle.sol

getPrice()

Public function (state change function)

That's all !! Thank you for this contest (my first one).

Ozy42

c4-judge commented 1 year ago

0xean marked the issue as grade-b