EVM word size is 32 bytes. The uint256 1 and uint256 2 will be cheaper to use than the boolean true and boolean false since the first are 32 bytes long and the last are only 1 byte
/// @audit Cache `dbr`. Used 3 times in `forceReplenish`
line#L560: uint deficit = dbr.deficitOf(user);
line#L563: uint replenishmentCost = amount * dbr.replenishmentPriceBps() / 10000;
line#L569: dbr.onForceReplenish(user, amount);
Mark functions as payable to avoid the low-level evm is-a-payment-provided check
The EVM checks whether a payment is provided to the function and this check costs additional gas. If the function is marked as payable there is no such check
line#L48: function changeGov(address _gov) public {
line#L57: function changeSupplyCeiling(uint _supplyCeiling) public {
line#L75: function resign() public {
line#L86: function expansion(IMarket market, uint amount) public {
line#L76: require(_replenishmentIncentiveBps < 10000, "Replenishment incentive must be less than 100%");
line#L214: require(msg.sender == pauseGuardian || msg.sender == gov, "Only pause guardian or governance can pause");
line#L63: require(newReplenishmentPriceBps_ > 0, "replenishment price must be over 0");
line#L326: require(markets[msg.sender], "Only markets can call onForceReplenish");
Use private visibility modifiers instead of public for storage constants
Saves 3000+ gas per variable when deploying contract
GAS OPTIMIZATIONS REPORT
INVERSE
Avoid using
&&
inrequire()
orif()
statementsUse multiple
require()
/if
statements insteadMarket.sol:
DBR.sol:
Use x = x + y instead of x += y for storage variables
Fed.sol:
DBR.sol:
Market.sol:
Use custom errors instead of
require
stringsDBR.sol:
Oracle.sol:
GovTokenEscrow.sol:
BorrowController.sol:
Fed.sol:
SimpleERC20Escrow.sol:
Market.sol:
INVEscrow.sol:
Use
1
and2
instead oftrue
andfalse
EVM word size is 32 bytes. The
uint256 1
anduint256 2
will be cheaper to use than theboolean true
andboolean false
since the first are 32 bytes long and the last are only 1 byteMarket.sol:
Use
uint256
instead of the smaller uints where possibleThe word-size in ethereum is 32 bytes which means that every variables which is sized with less bytes will cost more to operate with
Oracle.sol:
Market.sol:
DBR.sol:
Pack storage variables in less slots to save gas
Market.sol:
Do not compare a boolean to
true
orfalse
Directly use the boolean
DBR.sol:
Cache storage variables in memory
Optimization comes from using MSTORE and MLOAD instead of SSTORE and SLOAD
Oracle.sol:
Market.sol:
Mark functions as
payable
to avoid the low-level evmis-a-payment-provided
checkThe EVM checks whether a payment is provided to the function and this check costs additional gas. If the function is marked as
payable
there is no such checkMarket.sol:
Oracle.sol:
SimpleERC20Escrow.sol:
INVEscrow.sol:
Fed.sol:
GovTokenEscrow.sol:
DBR.sol:
x < y + 1
is cheaper thanx <= y
DBR.sol:
Fed.sol:
Market.sol:
Use
constant
andimmutable
keywords for storage varibles if they doesn't change through contract's lifecycleThat way the variable will go to the contract's bytecode and will not allocate a storage slot
DBR.sol:
Do not use strings longer than 32 bytes
Market.sol:
DBR.sol:
Use
private
visibility modifiers instead ofpublic
for storageconstant
sSaves 3000+ gas per variable when deploying contract
DBR.sol:
Use
if (x != 0)
instead ofif (x > 0)
for uints comparisonSaves 3 gas per
if
-checkDBR.sol:
Fed.sol:
Oracle.sol:
Market.sol:
INVEscrow.sol: