Skip to content
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

Return the address when deploying a mastercopy #98

Merged
merged 3 commits into from
Dec 22, 2022

Conversation

asgeir-s
Copy link
Contributor

Also, add a computeTargetAddress function that can be used to get the address of an already deployed mastercopy

Also, add a `computeTargetAddress` function that can be used to get the address of an already deployed mastercopy
@asgeir-s asgeir-s requested a review from cristovaoth December 21, 2022 16:10
@cristovaoth
Copy link
Contributor

Before I submit my review, a quick clarification @manboy-eth

File mastercopyDeployer, line 109, there's the assumption that a targetAddress AddressZero would correspond to an already deployed contract. However, the call in line 94 (singletonFactory.deploy) internally uses create2, and this is specified to throw on address already occupied or address non zero nonce. See ethereum/EIPs#684

IT feels like the zero address assumption for already deployed is wrong. Thoughts?

@asgeir-s
Copy link
Contributor Author

Before I submit my review, a quick clarification @manboy-eth

File mastercopyDeployer, line 109, there's the assumption that a targetAddress AddressZero would correspond to an already deployed contract. However, the call in line 94 (singletonFactory.deploy) internally uses create2, and this is specified to throw on address already occupied or address non zero nonce. See ethereum/EIPs#684

IT feels like the zero address assumption for already deployed is wrong. Thoughts?

It seems to be working as expected. Also, reading about it here says, that it fails without reverting:

Deployment can fail due to:

A contract already exists at the destination address.
...
Note that these failures only affect the return value and do not cause the calling context to revert (unlike the error cases below).
From https://www.evm.codes/#f5?fork=merge

Perhaps [ethereum/EIPs#684] was closed without being implemented?

@cristovaoth
Copy link
Contributor

Before I submit my review, a quick clarification @manboy-eth
File mastercopyDeployer, line 109, there's the assumption that a targetAddress AddressZero would correspond to an already deployed contract. However, the call in line 94 (singletonFactory.deploy) internally uses create2, and this is specified to throw on address already occupied or address non zero nonce. See ethereum/EIPs#684
IT feels like the zero address assumption for already deployed is wrong. Thoughts?

It seems to be working as expected. Also, reading about it here says, that it fails without reverting:

Deployment can fail due to:
A contract already exists at the destination address.
...
Note that these failures only affect the return value and do not cause the calling context to revert (unlike the error cases below).
From https://www.evm.codes/#f5?fork=merge

Perhaps [ethereum/EIPs#684] was closed without being implemented?

Very interesting. Ok makes sense. Lets proceed assuming that the function does not revert and returns Zero if already deployed

Copy link
Contributor

@cristovaoth cristovaoth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for taking the time to improve the functions!

Left a bunch of low impact (mostly stylistic) comments

src/factory/mastercopyDeployer.ts Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Outdated Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Outdated Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Outdated Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Show resolved Hide resolved
src/factory/mastercopyDeployer.ts Outdated Show resolved Hide resolved
@asgeir-s asgeir-s requested a review from cristovaoth December 22, 2022 08:59
computedTargetAddress,
"The computed address does not match the target address."
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know this assert variation.

Usually I import from "assert"

And then simply do assert(a === b)

Copy link
Contributor

@cristovaoth cristovaoth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, let's merge

@asgeir-s asgeir-s merged commit 0b67170 into master Dec 22, 2022
@asgeir-s asgeir-s deleted the deployMasterCopy-return-address branch December 22, 2022 11:38
@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants