Take the following code:
pragma solidity >=0.8.19 <0.9.0;
contract Foo {
uint256 public constant SIZE = 10;
function func(uint256 x) external pure returns (uint256) {
uint256 y = SIZE * 3;
return x + y;
}
}
Since this function doesn't wrap the calculations in an unchecked
block, x + y
is calculated using checked arithmetic.
But will SIZE * 3
also be calculated like that? Or will Solidity inline this value (30 in this case) in the contract's bytecode because SIZE
is a constant?