Verification with Immutable Varibles
While Sourcify can verify contracts containing immutable variables, the process is more intricate than verifying contracts that don't have immutables. First, Sourcify recompiles the contract, which produces the runtime bytecode and the immutableReferences
object. This object indicates the specific position within the execution bytecode where the immutable variables are located. After obtaining these, the next step is to replace all instances of the immutables in both the runtime and deployed bytecodes with zeros. Finally, a direct comparison is made between the two bytecodes to get a full or a partial match.
More details on how immutables affect verification below:
Immutable variables
It is not as straightforward to verify contracts with immutable variables because of their nature. Quoting from the Solidity docs:
The contract creation code generated by the compiler will modify the contract’s runtime code before it is returned by replacing all references to immutables by the values assigned to the them.
That means the runtime bytecode generated after recompiling will be different than the one already deployed on chain, because the references will have been "filled" with the values of the immutables when deploying the code.
For example in the bytecode excerpt from the Görli contract 0xbdde4d595f2cdda92ca274423374e0e1c7286426 (Etherscan, Sourcify) the reference of the simple immutable variable will be the 64 consecutive 0
in hex in the recompiled bytecode:
...282565b5050565b7f000000000000000000000000000000000000000000000000000000000000000081565b828054600181600116156101...
...which will be modified in runtime when deploying the contract to the value 2
. So the deployed bytecode will be:
...282565b5050565b7f000000000000000000000000000000000000000000000000000000000000000281565b828054600181600116156101...
☝️