1

For the following:

pragma solidity >=0.5.0;

contract Include {
    uint z = 1;
}

contract CreationCode {
    uint k = 1;
    function get() external returns (bytes32) {
        return keccak256(type(Include).creationCode);
    }
}

why does creationCode for Include.sol change when changing k, which is not a variable in Include.sol?

1 Answer 1

3

By default, solc will embed a hash of compilation metadata in the generated bytecode. For the details see the solidity documentation. The source code's hash is included in the compiled metadata so a change in the source code will affect the metadata and bytecode generated.

One solution is to have Include in a separate file from CreationCode and import it when needed so any change to CreationCode will not affect Include's bytecode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.