code-423n4 / 2022-07-swivel-findings

0 stars 1 forks source link

Gas Optimizations #41

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

1. state variables can be packed into fewer storage slots

If variables occupying the same slot are both written the same function or by the constructor, avoids a separate Gsset (20000 gas). Reads of the variables are also cheaper.

change the position of line 26 to after a address state variable:

2. state variables should be cached in stack variables rather than re-reading them from storage

marketPlace in function setMarketPlace:

maturityRate in function addNotional:

maturityRate in function removeNotional:

maturityRate in function redeemInterest:

maturityRate in function transferNotionalFrom:

maturityRate in function transferNotionalFee:

feeChange in function setFee:

3. x = x + y is cheaper than x += y

4. better to use ++i than i++