-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
CREATE2 can re-run constructor multiple times in a selfdestructed contract #17882
Comments
So, a 'constructor' is built out of a piece of I'll use the same numbering as you and explain some quirks
Quoting from the EIP:
(emphasis mine) -- immediate effect means that it does not go into effect within the same transaction/block, but only after the block postprocessing where selfdestructs are handled. |
ps: I don't know what type of setup you are using, but it might be simpler to investigate if you trace the execution. If you're using the raw |
@holiman What confuses me here is that I thought that when constructor code is deployed the nonce of the target account is actually set to 1. If this happens, then if the constructor is ran again it should fail (and set a to 0x0). So the question here is, if no bytecode is deployed at a contract then the nonce of the contract we are deploying to is not set to 1. (In case of a CREATE this would still increase the nonce of the contract which is trying to create this new contract) |
So, it's totally ok not to return bytecode from the constructor, and thereby create a code-less contract with nonce 1. And then it shouldn't be possible to recreate it. However, you're also selfdestructing the account, so it becomes erased. |
Yes the latter is an assumption of mine which was wrong. I assumed that when you selfdestruct an existing contract it would not erase the nonce. Thanks again =) |
System information
Geth version:
geth Version: 1.8.17-stable
Expected behaviour
Via EIP 1014:
Specifically, if nonce or code is nonzero, then the create-operation fails.
It should also be noted that SELFDESTRUCT has no immediate effect on nonce or code, thus a contract cannot be destroyed and recreated within one transaction.
Hence if you selfdestruct a contract created with the same init_code and salt via CREATE2 and then redeploy it with the same parameters it should not be able to recreate.
Actual behaviour
You can selfdestruct a contract and redeploy it.
Steps to reproduce the behaviour
Step 1: Deploy TestMe:
Step 2) Validate that Go() has been called by calling time() in TestMe.
Step 3) Re-call Deploy() with the same seed (note: for this implementation use a different block)
Step 4) Validate that time() has been changed hence the constructor has ran twice.
The text was updated successfully, but these errors were encountered: