1

Who has access to this?

For example, if I call type(SimpleStorage).creationCode, wouldn't this cause an issue because there are a lot of SimpleStorage's

How does the type() function know the specific C/contract I am calling without an address?

So from the Solidity Docs website

Memory byte array that contains the creation bytecode of the contract. This can be used in inline assembly to build custom creation routines, especially by using the create2 opcode. This property can not be accessed in the contract itself or any derived contract. It causes the bytecode to be included in the bytecode of the call site and thus circular references like that are not possible.

So it cannot be called within the contract itself (which makes sense) and cannot be called from a contract that is made from the contract we want the creationCode from.

So the contract can only be called from a parent contract?

To be clear I have at least three questions

  1. What if there are multiple contracts named C?
  2. Where can I call this function?
  3. What is its range of scope? What are the security considerations?

2 Answers 2

1

You cannot run into a situation where multiple contracts are named C. This language construct is compile-time (not runtime), meaning contract C would have to be imported in order for you to use type(C).creationCode, and Solidity does not allow conflicting names in the same source file.

You can call this function if:

  • It is not referring to itself, i.e. in contract C you cannot use type(C).creationCode
  • It is not referring to a contract that is a base of itself, i.e. if contract C inherits from contract B you cannot use type(B).creationCode
  • It is not referring to its own contract factory, i.e. if contract C is created by contract B, then you cannot use type(B).creationCode in C

In all of these cases the usage is self-referential in some way, which is why it is disallowed.

There aren't really any security considerations I can think of, since calling e.g. create with the code from type(C).creationCode is effectively the same as new C().

0

From the docs that you shared, it says: "Memory byte array that contains the creation bytecode of the contract. ". This means that you are passing the current Contract code to the type function and it gives you the bytecode of the contract

    // SimpleStorage is not just the name, it is full contract code
    bytes memory bytecode = type(SimpleStorage).creationCode;

There might be a lot of contract named "SimpleStorage" but their code is different thus their byte code is different

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.