Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas Optimization: Tight variable packing in LPoolStorage.sol #140

Open
code423n4 opened this issue Feb 1, 2022 · 2 comments
Open

Gas Optimization: Tight variable packing in LPoolStorage.sol #140

code423n4 opened this issue Feb 1, 2022 · 2 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Handle

Dravee

Vulnerability details

Impact

Saving 2 slots (deployment cost)

Proof of Concept & Remediation

These variables should change be reordered:

File: LPoolInterface.sol
07:     //Guard variable for re-entrancy checks
08:     bool internal _notEntered;  //@audit-info 1 byte
09: 
10:     /**
11:      * EIP-20 token name for this token
12:      */
13:     string public name;  //@audit-info 32 bytes
14: 
15:     /**
16:      * EIP-20 token symbol for this token
17:      */
18:     string public symbol;//@audit-info 32 bytes
19: 
20:     /**
21:      * EIP-20 token decimals for this token
22:      */
23:     uint8 public decimals; //@audit-info 1 byte
24: 
25:     /**
26:     * Total number of tokens in circulation
27:     */
28:     uint public totalSupply;//@audit-info 32 bytes
29: 
30: 
31:     //Official record of token balances for each account
32:     mapping(address => uint) internal accountTokens;//@audit-info 32 bytes
33: 
34:     //Approved token transfer amounts on behalf of others
35:     mapping(address => mapping(address => uint)) internal transferAllowances;//@audit-info 32 bytes
36: 
37: 
38:     //Maximum borrow rate that can ever be applied (.0005% / block)
39:     uint internal constant borrowRateMaxMantissa = 0.0005e16;
40: 
41:     /**
42:     * Maximum fraction of borrower cap(80%)
43:     */
44:     uint public  borrowCapFactorMantissa;
45:     /**
46:      * Contract which oversees inter-lToken operations
47:      */
48:     address public controller; //@audit-info 20 bytes
49: 
50: 
51:     // Initial exchange rate used when minting the first lTokens (used when totalSupply = 0)
52:     uint internal initialExchangeRateMantissa;
53: 
54:     /**
55:      * Block number that interest was last accrued at
56:      */
57:     uint public accrualBlockNumber;
58: 
59:     /**
60:      * Accumulator of the total earned interest rate since the opening of the market
61:      */
62:     uint public borrowIndex;
63: 
64:     /**
65:      * Total amount of outstanding borrows of the underlying in this market
66:      */
67:     uint public totalBorrows;
68: 
69:     //useless
70:     uint internal totalCash;
71: 
72:     /**
73:     * @notice Fraction of interest currently set aside for reserves 20%
74:     */
75:     uint public reserveFactorMantissa;
76: 
77:     uint public totalReserves;
78: 
79:     address public underlying; //@audit-info 20 bytes
80: 
81:     bool public isWethPool; //@audit-info 1 byte

This way:

File: ControllerInterface.sol
61:     address public openLev; //@audit-info 20 bytes
62:
63:     bool public suspend; //@audit-info 1 byte
64:
65:     DexAggregatorInterface public dexAggregator; //@audit-info 32 bytes
66:
67:     OLETokenDistribution public oleTokenDistribution; //@audit-info 32 bytes

This would save 2 slots

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Feb 1, 2022
code423n4 added a commit that referenced this issue Feb 1, 2022
@ColaM12 ColaM12 added the duplicate This issue or pull request already exists label Feb 2, 2022
@ColaM12
Copy link
Collaborator

ColaM12 commented Feb 2, 2022

Duplicate to #28

@ColaM12 ColaM12 closed this as completed Feb 2, 2022
@0xleastwood
Copy link
Collaborator

I think this is valid. Keeping it open.

@0xleastwood 0xleastwood removed the duplicate This issue or pull request already exists label Feb 20, 2022
@0xleastwood 0xleastwood reopened this Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

3 participants