Bubble up returndata from reverted Create2 deployments (#5052)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: ernestognw <ernestognw@gmail.com>
This commit is contained in:
Dimitrios Papathanasiou
2024-05-27 13:45:32 +03:00
committed by GitHub
parent 52e0e3e783
commit 984233dcad
4 changed files with 101 additions and 1 deletions

View File

@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract ConstructorMock {
bool foo;
enum RevertType {
None,
RevertWithoutMessage,
RevertWithMessage,
RevertWithCustomError,
Panic
}
error CustomError();
constructor(RevertType error) {
// After transpilation to upgradeable contract, the constructor will become an initializer
// To silence the `... can be restricted to view` warning, we write to state
foo = true;
if (error == RevertType.RevertWithoutMessage) {
revert();
} else if (error == RevertType.RevertWithMessage) {
revert("ConstructorMock: reverting");
} else if (error == RevertType.RevertWithCustomError) {
revert CustomError();
} else if (error == RevertType.Panic) {
uint256 a = uint256(0) / uint256(0);
a;
}
}
}

View File

@ -44,6 +44,11 @@ library Create2 {
/// @solidity memory-safe-assembly
assembly {
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
// if no address was created, and returndata is not empty, bubble revert
if and(iszero(addr), not(iszero(returndatasize()))) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
if (addr == address(0)) {
revert Errors.FailedDeployment();