gas

Use constants instead of `type(uint256).max`

Reward

Total

26.44 USDC

Selected
15.43 USDC
11.02 USDC
Selected Submission

Use constants instead of type(uint256).max

Severity

Gas Optimization / Informational

Relevant GitHub Links

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L329

Summary

At the places where type(uint256).max is used it can be replaced with constant variable with the same value as this from the expression, it will save gas because constant variables are stored in the contract byte code.

Each of the recommendations below saves 24 gas (Tested in remix)

Instances

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L329

Tools Used

Manual

Recommendations

uint private constant MAX_UINT256_NUMBER = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
uint private constant MAX_UINT256_HEX = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
uint private constant MAX_UINT256_EXPONENTIATION = 2**256 - 1;