code-423n4 / 2022-06-canto-v2-findings

0 stars 0 forks source link

Gas Optimizations #153

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

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

File: lending-market-v2\contracts\CTokenInterfaces.sol

15 uint8 public stable; // 0: volatile, 1: stable, 2: LP, stable, vol, 3: LP, vol, stable, 4: vol, vol, 5: LP, stable, stable

/**
 * @notice EIP-20 token name for this token
 */

20 string public name;

/**
 * @notice EIP-20 token symbol for this token
 */

25 string public symbol;

/**
 * @notice EIP-20 token decimals for this token
 */

30 uint8 public decimals;

Variable ordering with 3 slots instead of the current 4: uint8(1):stable, uint8(1):decimals, string(32):name, string(32):symbol

File: lending-market-v2\contracts\Stableswap\BaseV1-core.sol

43 uint8 public constant decimals = 18;

// Used to denote stable or volatile pair, not immutable since construction happens in the initialize method for CREATE2 deterministic addresses
bool public immutable stable;

uint public totalSupply = 0;

mapping(address => mapping (address => uint)) public allowance;
mapping(address => uint) public balanceOf;

bytes32 internal DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 internal constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;

uint internal constant MINIMUM_LIQUIDITY = 10**3;

60 address public immutable token0;

Variable ordering with 8 slots instead of the current 9: uint8(1):decimals, bool(1):stable, address(20):token0,bytes32(32):DOMAIN_SEPARATOR,bytes32(32):PERMIT_TYPEHASH, mapping(32):allowance, mapping(32):nonces,uint(32):MINIMUM_LIQUIDITY

JeeberC4 commented 2 years ago

Warden submitted multiple Gas Optimizations. Will not be judged.