20,000 USDC
View results
Submission Details
Severity: gas

Variable Packing

Summary

Gas issue (Pack your variables to use less storage)

Vulnerability Details

In Lender.sol, Pack your variables(move uint256; under the addresses) because Small values are stored sequentially and use less storage space because they are packed together.

Impact

When processing data, the EVM adopts a novel approach: each contract has a storage location where data is kept permanently, as well as a persistent storage space where data can be read, written, and updated.

There are 2,256 slots in the storage, each of which holds 32 bytes. Depending on their particular nature, the "state variables," or variables declared in the Escrow contract that are not within any function, will be stored in these slots.

Smaller-sized state variables (i.e. variables with less than 32 bytes in size), are saved as index values in the sequence in which they were defined, with 0 for position 1, 1 for position 2, and so on. If small values are stated sequentially, they will be stored in the same slot, including very small values like uint64.

Tools Used

Manual Review

Recommendations

'''

/// @notice the maximum interest rate is 1000%
uint256 public constant MAX_INTEREST_RATE = 100000;
/// @notice the maximum auction length is 3 days
uint256 public constant MAX_AUCTION_LENGTH = 3 days;
/// @notice the fee taken by the protocol in BIPs
uint256 public lenderFee = 1000;
/// @notice the fee taken by the protocol in BIPs
uint256 public borrowerFee = 50;
/// @notice the address of the fee receiver
address public feeReceiver;

'''

Should be

'''

/// @notice the address of the fee receiver
address public feeReceiver;
/// @notice the maximum interest rate is 1000%
uint256 public constant MAX_INTEREST_RATE = 100000;
/// @notice the maximum auction length is 3 days
uint256 public constant MAX_AUCTION_LENGTH = 3 days;
/// @notice the fee taken by the protocol in BIPs
uint256 public lenderFee = 1000;
/// @notice the fee taken by the protocol in BIPs
uint256 public borrowerFee = 50;

'''

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!