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

Bubble up returndata from reverted Create2 deployments #5052

Merged

Conversation

dimitriospapathanasiou
Copy link
Contributor

@dimitriospapathanasiou dimitriospapathanasiou commented May 22, 2024

Fixes #5046

I am uploading this PR to propose a solution for issue #5046. The current implementation simply reverts with a generic FailedDeployment error, which obscures potentially useful debugging information contained in the returndata.
So in the changes, deploy function was enhanced in the following way:

  • returndata is captured when a create2 deployment fails.
  • If returndata is available, it is used to revert, providing the original error message from the failed deployment.
  • If no returndata is available, the function reverts with the existing generic FailedDeployment error.

The changes were tested locally, and the expected output was given.

  • Tests
  • Documentation
  • Changeset entry (run npx changeset add)

contracts/utils/Create2.sol Outdated Show resolved Hide resolved
contracts/utils/Create2.sol Outdated Show resolved Hide resolved
@Amxx
Copy link
Collaborator

Amxx commented May 23, 2024

Thank you @dimitriospapathanasiou for this PR.

I like the idea ... but I'm not sure I like the current implementation.

contracts/utils/Create2.sol Outdated Show resolved Hide resolved
contracts/utils/Create2.sol Outdated Show resolved Hide resolved
@Amxx Amxx requested a review from ernestognw May 23, 2024 09:49
@ernestognw ernestognw changed the title Update Error Handling in Create2 Deployment by Bubbling Up Revert Reasons Bubble up returndata from reverted Create2 deployments May 24, 2024
Copy link
Member

@ernestognw ernestognw left a comment

Choose a reason for hiding this comment

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

LGTM. The CI should be fine after we merge #5055.

I shared some thoughts in the original issue. Although I'm approving, it may make sense to reconsider.

@Amxx Amxx merged commit 984233d into OpenZeppelin:master May 27, 2024
19 checks passed
Comment on lines +49 to +50
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
Copy link
Contributor

Choose a reason for hiding this comment

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

This snippet is explicitly mentioned in Solidity documentation as something that is not memory-safe.

https://docs.soliditylang.org/en/latest/assembly.html#memory-safety

cc @Amxx @ernestognw

Copy link
Contributor

Choose a reason for hiding this comment

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

See #5057

Copy link
Member

Choose a reason for hiding this comment

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

Been thinking about the consequences of this, but does it even matter given it's reverting? It's "memory unsafe" because it may overwrite memory but there's no way to do something unsafe afterwards.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah the docs say it matters if the assembly block reverts and this exact snippet is used to illustrate the point.

Copy link
Contributor

Choose a reason for hiding this comment

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

image

Copy link
Member

@ernestognw ernestognw May 27, 2024

Choose a reason for hiding this comment

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

Yeah, it's kinda unclear what's the relationship between being "mainly about the optimizer" and still needing to ensure memory safetiness

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I should look into this for my next blog post to give you a reason to read it. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create2 doesn't bubble up returndata on revert
4 participants