-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler should export constructor code #8803
Comments
The problem with the constructor argument offset is that we do not know how many bytes it would need. Can you please elaborate on what you would do with the constructor code? Would it work to have a constructor routine that abi-decodes the parameters from calldata? |
Different people may have different uses for it. One option is to deploy a contract whose runtime code is the constructor code. A proxy contract could then be created like this: contract Proxy {
constructor(address ctor, address runtime, bytes args) {
ctor.delegatecall(args); // require success
_setImplementation(runtime); // sets the delegatecall target in the fallback
}
...
} Keep in mind that there is an expectation that code on chain be verified by Etherscan or similar services, and the way they currently work they are not able to verify runtime code in isolation, or constructor code in isolation, so there would need to be a standard way to deploy these things that source code verification services can correctly detect. It's not clear whether defining this should be in the scope of the compiler, but I think it should be a consideration. |
Disregarding the problem with the argument offset, something like
|
Yes immutables seem incompatible. Maybe it would be an error to access or output the The other two things you mention should be included yes. This includes for example setting the initial values of state variables. |
We just discussed that in the meeting and found that this is a rather complicated feature that is easy to get wrong both on the user and on the compiler side. If someone can come up with a cleaner specification, we are happy to implement it, but at the current time this does not seem like a good idea. |
@chriseth Thanks for the update. Can you share some detail on the different ways you see this could go wrong? I'd like to understand what kind of problems we're talking about. |
We also discussed that #2296 seems to be a safer way, in our opinion. |
@frangio the problem is that the constructor code is deeply coupled with the code deposit routine. Maybe you could try if you can easily extract the required code from |
While #2296 is nice it requires that the "Proxy" code is agreed on, right? (e.g. https://eips.ethereum.org/EIPS/eip-1167) Just as a reference how it looks like currently if you want to do this in solidity at runtime: https://gist.github.com/cag/41c68a6402fc7c80b03f72cbf42f27f6#file-erc1155toerc20adapter-sol-L113 |
Hi everyone! This issue has been closed due to inactivity. |
Result from the open discussion about upgradable contracts at the Solidity Summit
See https://hackmd.io/zjYDbVL5TEqgpOgMXXNT1g?both
As proxies cannot make use of the constructor code if the "master copy" it is very common to use some initializer code. This can cause issues and often requires overhead (e.g. adding a
init
function to the master copy)Currently it's not possible to grab the constructor bytecode from the deployBytecode since the constructor argument positions are hardcoded, so a different-length runtime code would yield differ.
Therefore it would be very valuable to expose the constructor in a way that it can be reused.
The text was updated successfully, but these errors were encountered: