Suppose you have a contract like this:
pragma solidity >=0.8.19;
contract Bar {
uint256 public immutable value;
constructor(uint256 value_) {
value = value_;
}
}
Will Bar
have different bytecodes if different values are passed to the constructor?
Best Answer
Yes.
Bar
's bytecode depends onvalue_
, because immutable variables are not part of contract storage.We can prove this with the following Foundry test:
The bytecode of
bar1
will differ from that ofbar0
just by one character - in the 162nd position,bar0
hasa
, whereasbar1
hasb
.