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

0 stars 0 forks source link

Gas Optimizations #595

Open code423n4 opened 1 year ago

code423n4 commented 1 year ago

1. Use multiple requires instead of a single one with &&

src/DBR.sol: L249

src/Market.sol: L75 L162 L173 L195 L512

2. Custom error are cheaper than string messages

src/escrows/GovTokenEscrow.sol: L31 L44

src/Oracle.sol: L36 L83 L104 L117 L143

src/Fed.sol: L49 L58 L67 L76 L88 L104 L107

src/escrows/SimpleERC20Escrow.sol: L26 L37

src/escrows/INVEscrow.sol: L45 L60

src/Market.sol: L74 L75 L93 L162 L184 L204 L214 L236 L390 L423 L448 L462 L487 L512 L533 L561 L567 L592 L595

src/DBR.sol: L45 L71 L171 L195 L224 L301 L303 L314 L328 L329 L350

src/BorrowController.sol: L18

3. Strings messages in require statements should not be longer than 32 bytes of length

src/Market.sol: L76 L214

src/DBR.sol: L63 L326

4. use x = x + y instead of x+= y

src/Market.sol: L397 L568 L395 L534 L565 L599

src/Fed.sol: L111 L91 L110

src/DBR.sol: L360 L174 L196 L362 L374 L304 L316 L332 L288

5. public storage constant(and immutable) variable should be private

saves tons of gas on deployment

src/DBR.sol: L13

6. Use 1 and 2 for true and false

src/Market.sol: L52 L53

7. You can make state variables take less slots than they currently are

src/Market.sol: L38

8. Use x < y + 1 in stead of x <= y

src/Fed.sol: L93 L107 L123

src/DBR.sol: L195 L224 L329 L373

src/Market.sol: L162 L361 L396 L423 L462 L487 L562 L567 L595

9. When comparing variables of type uint, use require(x != 0) instead of require(x > 0)

src/Oracle.sol: L83 L96 L97 L117 L135

src/escrows/INVEscrow.sol: L81

src/DBR.sol: L63 L328

src/Market.sol: L75 L162 L173 L195 L592

src/Fed.sol: L133

10. Use require(x) instead of require(x == true)

src/DBR.sol: L350

11. Use constant and immutable for constants

src/DBR.sol: L11 L12

c4-judge commented 1 year ago

0xean marked the issue as grade-b